List of usage examples for javax.swing JComponent getHeight
@BeanProperty(bound = false) public int getHeight()
From source file:accessories.plugins.util.html.ClickableImageCreator.java
/** *///from w w w.j a v a2 s . c o m private void createArea(MindMapNode node) { final NodeView nodeView = mapView.getNodeView(node); if (nodeView != null) { AreaHolder holder = new AreaHolder(); holder.title = node.getShortText(modeController); holder.alt = node.getShortText(modeController); holder.href = node.getObjectId(modeController); Point contentXY = mapView.getNodeContentLocation(nodeView); final JComponent content = nodeView.getContent(); holder.coordinates.x = (int) (contentXY.x - innerBounds.getMinX()); holder.coordinates.y = (int) (contentXY.y - innerBounds.getMinY()); holder.coordinates.width = content.getWidth(); holder.coordinates.height = content.getHeight(); area.add(holder); for (Iterator i = node.childrenUnfolded(); i.hasNext();) { MindMapNode child = (MindMapNode) i.next(); createArea(child); } } }
From source file:de.cismet.cids.custom.objecteditors.wunda_blau.WebDavPicturePanel.java
/** * DOCUMENT ME!/*from ww w. j ava 2 s. co m*/ * * @param bi DOCUMENT ME! * @param component DOCUMENT ME! * @param insetX DOCUMENT ME! * @param insetY DOCUMENT ME! * * @return DOCUMENT ME! */ public static Image adjustScale(final BufferedImage bi, final JComponent component, final int insetX, final int insetY) { final double scalex = (double) component.getWidth() / bi.getWidth(); final double scaley = (double) component.getHeight() / bi.getHeight(); final double scale = Math.min(scalex, scaley); if (scale <= 1d) { return bi.getScaledInstance((int) (bi.getWidth() * scale) - insetX, (int) (bi.getHeight() * scale) - insetY, Image.SCALE_SMOOTH); } else { return bi; } }
From source file:FieldValidator.java
@Override public void paint(Graphics g, JComponent c) { super.paint(g, c); JLayer jlayer = (JLayer) c; JFormattedTextField ftf = (JFormattedTextField) jlayer.getView(); if (!ftf.isEditValid()) { Graphics2D g2 = (Graphics2D) g.create(); // Paint the red X. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = c.getWidth(); int h = c.getHeight(); int s = 8; int pad = 4; int x = w - pad - s; int y = (h - s) / 2; g2.setPaint(Color.red);/*from w w w . ja v a 2s . c o m*/ g2.fillRect(x, y, s + 1, s + 1); g2.setPaint(Color.white); g2.drawLine(x, y, x + s, y + s); g2.drawLine(x, y + s, x + s, y); g2.dispose(); } }
From source file:Main.java
public void paint(Graphics g, JComponent c) { JLabel label = (JLabel) c; String text = label.getText(); Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon(); if ((icon == null) && (text == null)) { return;/*from ww w.j a va 2 s . c om*/ } FontMetrics fm = g.getFontMetrics(); paintViewInsets = c.getInsets(paintViewInsets); paintViewR.x = paintViewInsets.left; paintViewR.y = paintViewInsets.top; // Use inverted height & width paintViewR.height = c.getWidth() - (paintViewInsets.left + paintViewInsets.right); paintViewR.width = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom); paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0; paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0; String clippedText = layoutCL(label, fm, text, icon, paintViewR, paintIconR, paintTextR); Graphics2D g2 = (Graphics2D) g; AffineTransform tr = g2.getTransform(); if (clockwise) { g2.rotate(Math.PI / 2); g2.translate(0, -c.getWidth()); } else { g2.rotate(-Math.PI / 2); g2.translate(-c.getHeight(), 0); } if (icon != null) { icon.paintIcon(c, g, paintIconR.x, paintIconR.y); } if (text != null) { int textX = paintTextR.x; int textY = paintTextR.y + fm.getAscent(); if (label.isEnabled()) { paintEnabledText(label, g, clippedText, textX, textY); } else { paintDisabledText(label, g, clippedText, textX, textY); } } g2.setTransform(tr); }
From source file:Diva.java
@Override public void paint(Graphics g, JComponent c) { Graphics2D g2 = (Graphics2D) g.create(); // Paint the view. super.paint(g2, c); if (mActive) { // Create a radial gradient, transparent in the middle. java.awt.geom.Point2D center = new java.awt.geom.Point2D.Float(mX, mY); float radius = 72; float[] dist = { 0.0f, 1.0f }; Color[] colors = { new Color(0.0f, 0.0f, 0.0f, 0.0f), Color.BLACK }; RadialGradientPaint p = new RadialGradientPaint(center, radius, dist, colors); g2.setPaint(p);/* ww w . j a v a 2 s . c o m*/ g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .6f)); g2.fillRect(0, 0, c.getWidth(), c.getHeight()); } g2.dispose(); }
From source file:jboost.visualization.HistogramFrame.java
private void toPDF() { File pdf = selectPDFFile();/*from w w w .j a va2s . co m*/ if (pdf != null) { JComponent toDraw = this.jSplitPane2; File[] tmpFiles = new File[infoParser.maxNumIter]; for (int i = 0; i < infoParser.maxNumIter; i++) { post("Printing " + infoParser.iterNoList[i] + "..."); jList1.setSelectedIndex(i); jList1.scrollRectToVisible(jList1.getCellBounds(i, i)); loadIteration(i); BufferedImage bimg = new BufferedImage(toDraw.getWidth(), toDraw.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D g = bimg.createGraphics(); toDraw.paint(g); g.dispose(); // add leading zeros String file_idx = Integer.toString(i); while (file_idx.length() < 3) file_idx = "0" + file_idx; try { tmpFiles[i] = new File("scorevistmp" + file_idx + ".png"); javax.imageio.ImageIO.write(bimg, "png", tmpFiles[i]); } catch (Exception e) { e.printStackTrace(); } } // restore plots jList1.setSelectedIndex(iter); loadIteration(iter); boolean success = true; // call convert to make pdf try { Process p = Runtime.getRuntime().exec("convert scorevistmp*.png " + pdf.getAbsolutePath()); p.waitFor(); } catch (Exception e) { success = false; } if (!success) { System.out.println("'convert' is missing. You need to have ImageMagick installed."); System.out.println("PDF is not generated but you can find PNG files in the current directory."); } else { /* * for (int i=0;i<maxNumIter-1;i++) { tmpFiles[i].delete(); } */ if (infoParser.maxNumIter > 0) { tmpFiles[infoParser.maxNumIter - 1].renameTo(new File(pdf.getAbsolutePath() + ".png")); } JOptionPane.showMessageDialog(this, "PDF file is generated!", "Done", JOptionPane.INFORMATION_MESSAGE); } } }
From source file:ca.phon.ipamap.IpaMap.java
public void showSearchFrame(ActionEvent ae) { if (searchFrame == null) { searchFrame = new JFrame("IPA Map : Search"); searchFrame.setAlwaysOnTop(true); searchFrame.setUndecorated(true); searchFrame.getRootPane().putClientProperty("Window.shadow", Boolean.FALSE); searchField = createSearchField(); searchFrame.add(searchField);// w w w. jav a 2s . c om searchField.getTextField().addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { searchFrame.setVisible(false); } } @Override public void keyReleased(KeyEvent e) { } @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { searchFrame.setVisible(false); } } }); searchField.getEndButton().addActionListener(evt -> { searchFrame.setVisible(false); }); searchFrame.addWindowFocusListener(new WindowFocusListener() { @Override public void windowLostFocus(WindowEvent e) { searchFrame.setVisible(false); } @Override public void windowGainedFocus(WindowEvent e) { } }); } final JComponent source = (JComponent) ae.getSource(); searchFrame.setSize(source.getWidth(), source.getHeight()); Point sourcePt = ((JComponent) ae.getSource()).getLocationOnScreen(); searchFrame.setLocation(sourcePt.x, sourcePt.y); searchFrame.setVisible(true); searchFrame.requestFocus(); searchField.getTextField().requestFocus(); }
From source file:ucar.unidata.idv.flythrough.Flythrough.java
/** * _more_/*from www. ja va2 s .c o m*/ * * @param g2 _more_ * @param comp _more_ * @param ptsIdx _more_ * @param ul _more_ * * @return _more_ */ private Rectangle drawDial(Graphics g2, JComponent comp, int ptsIdx, Point ul) { if (ptsIdx >= dialPts.length) { return null; } int w = comp.getWidth(); int h = comp.getHeight(); boolean useUpperLeft = false; if (comp instanceof ChartPanel) { int desiredWidth = dialPts[ptsIdx][2]; double scale = w / (double) desiredWidth; if (scale != 0) { h = (int) (h / scale); } comp.setSize(new Dimension(desiredWidth, h)); } else if (comp instanceof JLabel) { //Don't set size for labels useUpperLeft = true; } else { comp.setSize(new Dimension(dialPts[ptsIdx][2], dialPts[ptsIdx][3])); } try { int x = ul.x + dialPts[ptsIdx][0] - (useUpperLeft ? 0 : dialPts[ptsIdx][2] / 2); int y = ul.y + dialPts[ptsIdx][1] - (useUpperLeft ? 0 : dialPts[ptsIdx][3] / 2); Image image = ImageUtils.getImage(comp); g2.translate(x, y); g2.drawImage(image, 0, 0, null); return new Rectangle(x, y, comp.getWidth(), comp.getHeight()); } catch (Exception exc) { exc.printStackTrace(); } return null; }
From source file:org.freeplane.view.swing.map.ClickableImageCreator.java
private void createArea(final NodeModel node) { final NodeView nodeView = mapView.getNodeView(node); if (nodeView != null) { final AreaHolder holder = new AreaHolder(); holder.title = TextController.getController().getShortText(node); holder.alt = TextController.getController().getShortText(node); holder.href = node.createID();/*from w w w . j a v a 2 s.co m*/ final Point contentXY = mapView.getNodeContentLocation(nodeView); final JComponent content = nodeView.getContent(); holder.coordinates.x = (int) (contentXY.x - innerBounds.getMinX()); holder.coordinates.y = (int) (contentXY.y - innerBounds.getMinY()); holder.coordinates.width = content.getWidth(); holder.coordinates.height = content.getHeight(); area.add(holder); for (final NodeModel child : mapView.getModeController().getMapController().childrenUnfolded(node)) { createArea(child); } } }
From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java
/** * Sets the lens's visibility. If the lens hasn't previously created, * we first create the lens.//from w w w. ja v a 2 s . c om * * @param b Pass <code>true</code> to display the lens, * <code>false</code> otherwise. * @param historyIndex The index of the tab pane. */ void setLensVisible(boolean b, int historyIndex) { boolean firstTime = false; if (lens == null) { if (b) { firstTime = true; lens = new LensComponent(this, ImViewerAgent.hasOpenGLSupport()); lens.setImageName(model.getImageName()); lens.setXYPixelMicron(model.getPixelsSizeX(), model.getPixelsSizeY()); lens.addPropertyChangeListener(LensComponent.LENS_LOCATION_PROPERTY, controller); } else return; } else { Browser browser = model.getBrowser(); JComponent c = lens.getLensUI(); browser.removeComponent(c, ImViewer.VIEW_INDEX); browser.removeComponent(c, ImViewer.GRID_INDEX); browser.removeComponent(c, ImViewer.PROJECTION_INDEX); } if (!b) { lens.setVisible(b); repaint(); return; } //depending on the previous selected tabbed pane, //we reset the location of the lens int maxX = model.getMaxX(); int maxY = model.getMaxY(); float f = 1.0f; //BufferedImage img; int index = model.getTabbedIndex(); JComponent c = lens.getLensUI(); int width = c.getWidth(); int height = c.getHeight(); Point p = lens.getLensLocation(); int lensX = p.x; int lensY = p.y; if (maxX < width || maxY < height) return; if (firstTime) { //firstTimeLensShown = false; int diffX = maxX - width; int diffY = maxY - height; lensX = diffX / 2; lensY = diffY / 2; if (lensX + width > maxX) lensX = diffX; if (lensY + height > maxY) lensY = diffY; } else { switch (historyIndex) { case ImViewer.GRID_INDEX: if (historyIndex != index) { Point point = model.getBrowser().isOnImageInGrid(lens.getLensScaledBounds()); if (point == null) { int diffX = maxX - width; int diffY = maxY - height; lensX = diffX / 2; lensY = diffY / 2; if (lensX + width > maxX) lensX = diffX; if (lensY + height > maxY) lensY = diffY; } else { double r = model.getBrowser().getRatio(); lensX = (int) (point.x / r); lensY = (int) (point.y / r); } } break; case ImViewer.PROJECTION_INDEX: case ImViewer.VIEW_INDEX: if (index == ImViewer.GRID_INDEX) { double r = model.getBrowser().getRatio(); lensX = (int) (lensX * r); lensY = (int) (lensY * r); } } } if (ImViewerAgent.hasOpenGLSupport()) { TextureData image; switch (index) { case ImViewer.VIEW_INDEX: default: f = (float) model.getZoomFactor(); image = model.getImageAsTexture(); //img = model.getOriginalImage(); break; case ImViewer.PROJECTION_INDEX: f = (float) model.getZoomFactor(); image = model.getProjectedImageAsTexture(); //img = model.getProjectedImage(); break; case ImViewer.GRID_INDEX: //img = model.getGridImage(); image = null; } if (image != null) lens.resetLensAsTexture(image, f, lensX, lensY); } else { BufferedImage img; switch (index) { case ImViewer.VIEW_INDEX: default: f = (float) model.getZoomFactor(); img = model.getOriginalImage(); break; case ImViewer.PROJECTION_INDEX: f = (float) model.getZoomFactor(); img = model.getProjectedImage(); break; case ImViewer.GRID_INDEX: img = model.getGridImage(); } if (img != null) lens.resetLens(img, f, lensX, lensY); } model.getBrowser().addComponent(c, index, true); scrollLens(); UIUtilities.setLocationRelativeTo(this, lens.getZoomWindow()); lens.setVisible(b); repaint(); }