Example usage for javax.swing JComponent getWidth

List of usage examples for javax.swing JComponent getWidth

Introduction

In this page you can find the example usage for javax.swing JComponent getWidth.

Prototype

@BeanProperty(bound = false)
public int getWidth() 

Source Link

Document

Returns the current width of this component.

Usage

From source file:TapTapTap.java

@Override
public void paint(Graphics g, JComponent c) {
    int w = c.getWidth();
    int h = c.getHeight();

    // Paint the view.
    super.paint(g, c);

    if (!mIsRunning) {
        return;/* ww w .  j a  va2 s  .  co m*/
    }

    Graphics2D g2 = (Graphics2D) g.create();

    float fade = (float) mFadeCount / (float) mFadeLimit;
    // Gray it out.
    Composite urComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f * fade));
    g2.fillRect(0, 0, w, h);
    g2.setComposite(urComposite);

    // Paint the wait indicator.
    int s = Math.min(w, h) / 5;
    int cx = w / 2;
    int cy = h / 2;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setStroke(new BasicStroke(s / 4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    g2.setPaint(Color.white);
    g2.rotate(Math.PI * mAngle / 180, cx, cy);
    for (int i = 0; i < 12; i++) {
        float scale = (11.0f - (float) i) / 11.0f;
        g2.drawLine(cx + s, cy, cx + s * 2, cy);
        g2.rotate(-Math.PI / 6, cx, cy);
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, scale * fade));
    }

    g2.dispose();
}

From source file:accessories.plugins.util.html.ClickableImageCreator.java

/**
 *//*ww w.ja v  a2 s. co  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:LayeredPaneDemo.java

public void paint(Graphics g, JComponent c) {
    super.paint(g, c);
    if (c.getBorder() != null)
        c.getBorder().paintBorder(c, g, 0, 0, c.getWidth(), c.getHeight());
}

From source file:de.cismet.cids.custom.objecteditors.wunda_blau.WebDavPicturePanel.java

/**
 * DOCUMENT ME!/* w w w  . j av a 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  ww.  j a v  a2  s  .c  om
        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 w ww  . j  a  v a2 s .  com
    }

    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);/* www.  j  a va  2 s . co  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();/*  www . j a v  a 2  s  . c  o  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  . ja  va2s  .co  m

        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_/*w  w w  .j a v  a2 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;

}