List of usage examples for java.awt Dimension equals
public boolean equals(Object obj)
From source file:Main.java
public static void center(Window frame, int left, int right, int top, int bottom) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > (screenSize.height - top - bottom)) { frameSize.height = screenSize.height - top - bottom; }/*from w w w . jav a 2 s . c o m*/ if (frameSize.width > screenSize.width - left - right) { frameSize.width = screenSize.width - left - right; } if (!frameSize.equals(frame.getSize())) { frame.setSize(frameSize); } frame.setLocation(left + (screenSize.width - frameSize.width) / 2, top + (screenSize.height - frameSize.height) / 2); }
From source file:com.moviejukebox.scanner.artwork.PosterScanner.java
/** * Read an URL and get the dimensions of the image. * * This will try to determine the image type from the URL, if that fails * then it will default to JPEG.//from ww w. j av a 2 s.co m * * If the reading of the image fails, then the other type (PNG or JPEG) will * be used instead in case there was an incorrectly named extension * * @param imageUrl * @return */ public static Dimension getUrlDimensions(String imageUrl) { String imageExtension = FilenameUtils.getExtension(imageUrl); if (StringUtils.isBlank(imageExtension)) { imageExtension = "jpeg"; } Dimension imageDimension = getUrlDimensions(imageUrl, imageExtension); if (imageDimension.equals(new Dimension(0, 0))) { LOG.info("Looks like an invalid image, trying a different reader for URL: {}", imageUrl); if ("png".equals(imageExtension)) { imageExtension = "jpeg"; } else { imageExtension = "png"; } imageDimension = getUrlDimensions(imageUrl, imageExtension); } return imageDimension; }
From source file:com.projity.pm.graphic.chart.TimeChartPanel.java
public void updateTimeScaleComponentSize() { Dimension dmain = viewport.getViewSize(); if (dmain.equals(olddmain)) return;//w ww . j av a 2 s . co m olddmain = dmain; Dimension d = chartInfo.getAxisPanel().getPreferredSize(); d.setSize(d.getWidth(), dmain.getHeight()); chartInfo.getAxisPanel().revalidate(); }
From source file:io.rhiot.gateway.camel.webcam.WebcamComponent.java
private Webcam openWebcam(Webcam webcam, Dimension dimension) { //Once started another endpoint may want to change from low res to high res, for example if (webcam.isOpen() && isStarted() && !dimension.equals(webcam.getViewSize())) { webcam.close();//from w w w . j ava2 s. c o m } if (!webcam.isOpen() && dimension != null) { webcam.setCustomViewSizes(new Dimension[] { dimension }); webcam.setViewSize(dimension); webcam.open(true); } else if (!webcam.isOpen()) { webcam.open(true); } return webcam; }
From source file:com.projity.pm.graphic.views.GanttView.java
public void init(ReferenceNodeModelCache cache, NodeModel model, CoordinatesConverter coord) { this.coord = coord; this.cache = NodeModelCacheFactory.getInstance().createFilteredCache((ReferenceNodeModelCache) cache, getViewName(), null);//from ww w .j a v a 2s .c o m fieldContext = new FieldContext(); fieldContext.setLeftAssociation(true); /*cellStyle=new CellStyle(){ CellFormat cellProperties=new CellFormat(); public CellFormat getCellProperties(GraphicNode node){ cellProperties.setBold(node.isSummary()); cellProperties.setItalic(node.isAssignment()); //cellProperties.setBackground((node.isAssignment())?"NORMAL_LIGHT_YELLOW":"NORMAL_YELLOW"); cellProperties.setCompositeIcon(node.isComposite()); return cellProperties; } };*/ super.init(); updateHeight(project); updateSize(); //sync the height of spreadsheet and gantt leftScrollPane.getViewport().addChangeListener(new ChangeListener() { private Dimension olddl = null; public void stateChanged(ChangeEvent e) { Dimension dl = leftScrollPane.getViewport().getViewSize(); if (dl.equals(olddl)) return; olddl = dl; // Dimension dr=rightScrollPane.getViewport().getViewSize(); // ((Gantt)rightScrollPane.getViewport().getView()).setPreferredSize(new Dimension((int)dr.getWidth(),(int)dl.getHeight())); // rightScrollPane.getViewport().revalidate(); ((Gantt) rightScrollPane.getViewport().getView()).setPreferredSize( new Dimension(rightScrollPane.getViewport().getViewSize().width, dl.height)); } }); //TODO automatic scrolling to add as an option // spreadSheet.getRowHeader().getSelectionModel().addListSelectionListener(new ListSelectionListener(){ // public void valueChanged(ListSelectionEvent e) { // if (!e.getValueIsAdjusting()&&spreadSheet.getRowHeader().getSelectedRowCount()==1){ // List impls=spreadSheet.getSelectedNodesImpl(); // if (impls.size()!=1) return; // Object impl=impls.get(0); // if (!(impl instanceof HasStartAndEnd)) return; // HasStartAndEnd interval=(HasStartAndEnd)impl; // gantt.scrollToTask(interval, true); // } // } // }); MouseWheelListener scrollManager = new MouseWheelListener() { public void mouseWheelMoved(MouseWheelEvent e) { if (0 != (e.getModifiers() & InputEvent.ALT_MASK)) { Component c = e.getComponent(); while ((c != null) && !(c instanceof JViewport)) c = c.getParent(); JViewport vp = (JViewport) c; Point p = vp.getViewPosition(); int newX = p.x + e.getUnitsToScroll() * getWidth() / 20; if (newX > 0) { p.x = newX; } else { p.x = 0; } vp.setViewPosition(p); } else if (0 != (e.getModifiers() & InputEvent.CTRL_MASK)) { zoom(-e.getUnitsToScroll() / 3); } else { //Vertical scroll allways on gantt chart JViewport vp = (JViewport) gantt.getParent(); Point p = vp.getViewPosition(); int newY = p.y + e.getUnitsToScroll() * gantt.getRowHeight(); if (newY > 0) { p.y = newY; } else { p.y = 0; } vp.setViewPosition(p); } } }; leftScrollPane.getViewport().addMouseWheelListener(scrollManager); gantt.addMouseWheelListener(scrollManager); cache.update(); //Call this last to be sure everything is initialized //gantt.insertCacheData(); //useless? }
From source file:net.sf.firemox.clickable.target.card.VirtualCard.java
/** * Generate a new random angle and update the bounds. * /*from w w w . j av a2 s.c om*/ * @return true if the sizes have been updated. */ public boolean updateSizes() { Dimension oldDimension = (Dimension) getSize().clone(); // Generate a new random angle if (Configuration.getBoolean("randomAngle", Boolean.FALSE).booleanValue()) { angle = (new Random().nextDouble() - 0.5) * ROTATE_SCALE; } else { angle = 0; } final int cardHeight = CardFactory.cardHeight; final int cardWidth = CardFactory.cardWidth; if (angle == 0) { rotateTransformX = 0; rotateTransformY = 0; // Update the bounds untappedSize = new Dimension(cardWidth, cardHeight); tappedSize = new Dimension(cardHeight, cardWidth); } else { if (angle > 0) { rotateTransformX = Math.floor(cardHeight * Math.sin(Math.abs(angle)) + 1); rotateTransformY = 0; } else { rotateTransformX = 0; rotateTransformY = Math.floor(cardWidth * Math.sin(Math.abs(angle)) + 1); } // Update the bounds untappedSize = new Dimension( (int) Math.floor(cardWidth * Math.cos(angle) + cardHeight * Math.sin(Math.abs(angle)) + 3), (int) Math.floor(cardHeight * Math.cos(angle) + cardWidth * Math.sin(Math.abs(angle)) + 3)); tappedSize = new Dimension( (int) Math.floor(cardHeight * Math.cos(angle) + cardWidth * Math.sin(Math.abs(angle)) + 3), (int) Math.floor(cardWidth * Math.cos(angle) + cardHeight * Math.sin(Math.abs(angle)) + 3)); } final Dimension newSize; if (card.tapped) { newSize = tappedSize; } else { newSize = untappedSize; } if (!newSize.equals(oldDimension)) { setSize(newSize); setPreferredSize(newSize); return true; } return false; }
From source file:edu.ku.brc.af.prefs.PreferencesDlg.java
/** * @param comp//w ww . j ava2 s .c o m * @param oldSize */ protected void showAndResizePane(final Component comp, final Dimension oldSize) { mainPanel.remove(currentComp); currentComp.setVisible(false); mainPanel.add(comp, BorderLayout.CENTER); comp.invalidate(); comp.validate(); comp.invalidate(); comp.doLayout(); comp.repaint(); doLayout(); repaint(); currentComp = comp; currentComp.setVisible(true); Dimension oldWinDim = getSize(); Dimension winDim = getSize(); winDim.width += currentComp.getPreferredSize().width - oldSize.width; winDim.width = Math.max(winDim.width, 400); winDim.height = Math.max(winDim.height, 250); Dimension pSize = prefsToolbar.getPreferredSize(); winDim.width = Math.max(winDim.width, pSize.width + 30); if (winDim.equals(oldWinDim)) // needed because JGoodies doesn't want to relayout when it is the same size. { winDim.height += 2; } setSize(winDim); currentComp.setSize(new Dimension(currentComp.getPreferredSize().width, oldSize.height)); // Not sure why this combination works mainPanel.invalidate(); mainPanel.validate(); mainPanel.invalidate(); mainPanel.doLayout(); mainPanel.repaint(); invalidate(); validate(); invalidate(); doLayout(); doLayout(); repaint(); // to here ((PrefsPanelIFace) comp).setShadeColor(null); // Without Animation comp.setVisible(true); winDim.height += currentComp.getPreferredSize().height - oldSize.height; winDim.height = Math.max(winDim.height, 250); setSize(winDim); }
From source file:org.alex73.skarynka.scan.ui.scan.ScanDialogController.java
private ScanDialogController(PanelEditController panelController) { this.panelController = panelController; this.book = panelController.getBook(); int currentZoom = DataStorage.device.getZoom(); Dimension[] deviceImageSizes = DataStorage.device.getImageSize(); Dimension imageSize = deviceImageSizes[0]; for (int i = 1; i < deviceImageSizes.length; i++) { if (!imageSize.equals(deviceImageSizes[i])) { JOptionPane.showMessageDialog(DataStorage.mainFrame, Messages.getString("ERROR_WRONG_NOTEQUALSSIZE"), Messages.getString("ERROR_TITLE"), JOptionPane.ERROR_MESSAGE); return; }/* ww w . j a v a 2 s. c om*/ } int pagesCount = book.getPagesCount(); if (pagesCount > 0) { int bookZoom = book.zoom; if (bookZoom != currentZoom) { if (JOptionPane.showConfirmDialog(DataStorage.mainFrame, Messages.getString("ERROR_WRONG_ZOOM", pagesCount, bookZoom, currentZoom), Messages.getString("ERROR_TITLE"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) { return; } } if (imageSize.width != book.imageSizeX || imageSize.height != book.imageSizeY) { if (JOptionPane.showConfirmDialog(DataStorage.mainFrame, Messages.getString("ERROR_WRONG_IMAGESIZE", pagesCount, s(new Dimension(book.imageSizeX, book.imageSizeY)), s(imageSize)), Messages.getString("ERROR_TITLE"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) { return; } for (String page : book.listPages()) { Book2.PageInfo pi = book.getPageInfo(page); pi.cropPosX = Integer.MIN_VALUE; pi.cropPosY = Integer.MIN_VALUE; } } } book.zoom = currentZoom; book.imageSizeX = imageSize.width; book.imageSizeY = imageSize.height; String dpi = Context.getSettings().get("dpi." + book.zoom); if (dpi != null) { book.dpi = Integer.parseInt(dpi); } else { book.dpi = 300; } dialog = new ScanDialog(DataStorage.mainFrame, true); dialog.btnClose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); dialog.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { DataStorage.device.setPreviewPanels(); panelController.show(); } }); init(dialog.controlLeft, dialog.liveLeft); init(dialog.controlRight, dialog.liveRight); checkNumbers(); showStatus(); boolean[] visible = DataStorage.device.setPreviewPanels(dialog.liveLeft, dialog.liveRight); dialog.controlLeft.setVisible(visible[0]); dialog.controlRight.setVisible(visible[1]); dialog.liveLeft.setVisible(visible[0]); dialog.liveRight.setVisible(visible[1]); int[] rotations = DataStorage.device.getRotations(); dialog.liveLeft.setRotation(rotations[0]); dialog.liveRight.setRotation(rotations[1]); dialog.setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds()); dialog.validate(); dialog.controlLeft.txtNumber.setVisible(false); dialog.controlLeft.txtNumber.setVisible(false); int keyCode = HIDScanController.getKeyCode(Context.getSettings().get("hidscan-keys")); if (keyCode != 0) { addAction(keyCode, actionScan); } if (keyCode != KeyEvent.VK_F1) { addAction(KeyEvent.VK_F1, actionScan); } dialog.btnScan.addActionListener(actionScan); addAction(KeyEvent.VK_F2, actionRescan); dialog.btnRescan.addActionListener(actionRescan); dialog.setVisible(true); }
From source file:org.apache.batchee.tools.maven.DiagramMojo.java
private void saveView(final Dimension currentSize, final Dimension desiredSize, final String name, final VisualizationViewer<Node, Edge> viewer) throws MojoExecutionException { BufferedImage bi = new BufferedImage(currentSize.width, currentSize.height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g = bi.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); final boolean db = viewer.isDoubleBuffered(); viewer.setDoubleBuffered(false);//from w w w .ja v a 2 s . com viewer.paint(g); viewer.setDoubleBuffered(db); if (!currentSize.equals(desiredSize)) { final double xFactor = desiredSize.width * 1. / currentSize.width; final double yFactor = desiredSize.height * 1. / currentSize.height; final double factor = Math.min(xFactor, yFactor); getLog().info("optimal size is (" + currentSize.width + ", " + currentSize.height + ")"); getLog().info("scaling with a factor of " + factor); final AffineTransform tx = new AffineTransform(); tx.scale(factor, factor); final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); BufferedImage biNew = new BufferedImage((int) (bi.getWidth() * factor), (int) (bi.getHeight() * factor), bi.getType()); bi = op.filter(bi, biNew); } g.dispose(); OutputStream os = null; try { final File file = new File(output, (outputFileName != null ? outputFileName : name) + "." + format); os = new FileOutputStream(file); if (!ImageIO.write(bi, format, os)) { throw new MojoExecutionException("can't save picture " + name + "." + format); } getLog().info("Saved " + file.getAbsolutePath()); } catch (final IOException e) { throw new MojoExecutionException("can't save the diagram", e); } finally { if (os != null) { try { os.flush(); os.close(); } catch (final IOException e) { // no-op } } } }
From source file:org.apache.batchee.tools.maven.doc.DiagramGenerator.java
private void saveView(final Dimension currentSize, final Dimension desiredSize, final String name, final VisualizationViewer<Node, Edge> viewer) { BufferedImage bi = new BufferedImage(currentSize.width, currentSize.height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g = bi.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); final boolean db = viewer.isDoubleBuffered(); viewer.setDoubleBuffered(false);//from ww w. j av a2s . c om viewer.paint(g); viewer.setDoubleBuffered(db); if (!currentSize.equals(desiredSize)) { final double xFactor = desiredSize.width * 1. / currentSize.width; final double yFactor = desiredSize.height * 1. / currentSize.height; final double factor = Math.min(xFactor, yFactor); info("optimal size is (" + currentSize.width + ", " + currentSize.height + ")"); info("scaling with a factor of " + factor); final AffineTransform tx = new AffineTransform(); tx.scale(factor, factor); final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); BufferedImage biNew = new BufferedImage((int) (bi.getWidth() * factor), (int) (bi.getHeight() * factor), bi.getType()); bi = op.filter(bi, biNew); } g.dispose(); OutputStream os = null; try { final File file = new File(output, (outputFileName != null ? outputFileName : name) + "." + format); os = new FileOutputStream(file); if (!ImageIO.write(bi, format, os)) { throw new IllegalStateException("can't save picture " + name + "." + format); } info("Saved " + file.getAbsolutePath()); } catch (final IOException e) { throw new IllegalStateException("can't save the diagram", e); } finally { if (os != null) { try { os.flush(); os.close(); } catch (final IOException e) { // no-op } } } }