/** * Returns the current component as buffered image. * To save this buffered image as png you could use for example: * File file = new File("image.png"); * ImageIO.write(Image, "png", file); * @return the current component as buffered image */ public BufferedImage getAsImage() { final BufferedImage IMAGE = UTIL.createImage(getWidth(), getHeight(), Transparency.TRANSLUCENT); final Graphics2D G2 = IMAGE.createGraphics(); paintAll(G2); G2.dispose(); return IMAGE; } // </editor-fold>
/** * Returns the current component as buffered image. * To save this buffered image as png you could use for example: * File file = new File("image.png"); * ImageIO.write(Image, "png", file); * @return the current component as buffered image */ public BufferedImage getAsImage() { final BufferedImage IMAGE = UTIL.createImage(getWidth(), getHeight(), Transparency.TRANSLUCENT); final Graphics2D G2 = IMAGE.createGraphics(); paintAll(G2); G2.dispose(); return IMAGE; } // </editor-fold>
/** * Calculates the rectangle that specifies the area that is available * for painting the gauge. This means that if the component has insets * that are larger than 0, these will be taken into account. */ private void calcInnerBounds() { // final java.awt.Insets INSETS = getInsets(); // if (getWidth() - INSETS.left - INSETS.right < getHeight() - INSETS.top - INSETS.bottom) { // INNER_BOUNDS.setBounds(INSETS.left, INSETS.top, getWidth() - INSETS.left - INSETS.right, getHeight() - INSETS.top - INSETS.bottom); // } else { // INNER_BOUNDS.setBounds(INSETS.left + (int) (((double) (getWidth() - INSETS.left - INSETS.right) - (double) (getHeight() - INSETS.top - INSETS.bottom)) / 2.0), INSETS.top, getHeight() - INSETS.top - INSETS.bottom, getHeight() - INSETS.top - INSETS.bottom); // } final Insets INSETS = getInsets(); final int SIZE = (getWidth() - INSETS.left - INSETS.right) <= (getHeight() - INSETS.top - INSETS.bottom) ? (getWidth() - INSETS.left - INSETS.right) : (getHeight() - INSETS.top - INSETS.bottom); //INNER_BOUNDS.setBounds(INSETS.left, INSETS.top, getWidth() - INSETS.left - INSETS.right, getHeight() - INSETS.top - INSETS.bottom); INNER_BOUNDS.setBounds(INSETS.left, INSETS.top, SIZE, SIZE); }
/** * Calculates the rectangle that specifies the area that is available * for painting the gauge. This means that if the component has insets * that are larger than 0, these will be taken into account. */ private void calcInnerBounds() { // final java.awt.Insets INSETS = getInsets(); // if (getWidth() - INSETS.left - INSETS.right < getHeight() - INSETS.top - INSETS.bottom) { // INNER_BOUNDS.setBounds(INSETS.left, INSETS.top, getWidth() - INSETS.left - INSETS.right, getHeight() - INSETS.top - INSETS.bottom); // } else { // INNER_BOUNDS.setBounds(INSETS.left + (int) (((double) (getWidth() - INSETS.left - INSETS.right) - (double) (getHeight() - INSETS.top - INSETS.bottom)) / 2.0), INSETS.top, getHeight() - INSETS.top - INSETS.bottom, getHeight() - INSETS.top - INSETS.bottom); // } final Insets INSETS = getInsets(); final int SIZE = (getWidth() - INSETS.left - INSETS.right) <= (getHeight() - INSETS.top - INSETS.bottom) ? (getWidth() - INSETS.left - INSETS.right) : (getHeight() - INSETS.top - INSETS.bottom); //INNER_BOUNDS.setBounds(INSETS.left, INSETS.top, getWidth() - INSETS.left - INSETS.right, getHeight() - INSETS.top - INSETS.bottom); INNER_BOUNDS.setBounds(INSETS.left, INSETS.top, SIZE, SIZE); }
@Override public void componentResized(ComponentEvent event) { final int SIZE = getWidth() <= getHeight() ? getWidth() : getHeight(); java.awt.Container parent = getParent(); if ((parent != null) && (parent.getLayout() == null)) { if (SIZE < getMinimumSize().width || SIZE < getMinimumSize().height) { setSize(getMinimumSize().width, getMinimumSize().height); } else { setSize(SIZE, SIZE); } } else { if (SIZE < getMinimumSize().width || SIZE < getMinimumSize().height) { setPreferredSize(getMinimumSize()); } else { setPreferredSize(new java.awt.Dimension(SIZE, SIZE)); } } calcInnerBounds(); init(INNER_BOUNDS.width); //revalidate(); //repaint(INNER_BOUNDS); } };
@Override public void componentResized(ComponentEvent event) { final int SIZE = getWidth() <= getHeight() ? getWidth() : getHeight(); java.awt.Container parent = getParent(); if ((parent != null) && (parent.getLayout() == null)) { if (SIZE < getMinimumSize().width || SIZE < getMinimumSize().height) { setSize(getMinimumSize().width, getMinimumSize().height); } else { setSize(SIZE, SIZE); } } else { if (SIZE < getMinimumSize().width || SIZE < getMinimumSize().height) { setPreferredSize(getMinimumSize()); } else { setPreferredSize(new java.awt.Dimension(SIZE, SIZE)); } } calcInnerBounds(); init(INNER_BOUNDS.width); //revalidate(); //repaint(INNER_BOUNDS); } };