/** * 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>
/** * Set the position of the light that affects the gradient of the battery frame * @param LIGHT_POSITION */ public void setLightPosition(final Orientation LIGHT_POSITION) { lightPosition = LIGHT_POSITION; init(getWidth(), getHeight()); repaint(INNER_BOUNDS); }
/** * Sets the current charge of the battery as integer from 0 - 100 * @param VALUE */ public void setValue(final int VALUE) { value = VALUE < 0 ? 0 : (VALUE > 100 ? 100 : VALUE); init(getWidth(), getHeight()); repaint(INNER_BOUNDS); }
/** * 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(); INNER_BOUNDS.setBounds(INSETS.left, INSETS.top, (getWidth() - INSETS.left - INSETS.right), (getHeight() - INSETS.top - INSETS.bottom)); }
/** * 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(); INNER_BOUNDS.setBounds(INSETS.left, INSETS.top, (getWidth() - INSETS.left - INSETS.right), (getHeight() - INSETS.top - INSETS.bottom)); }
@Override public void componentResized(java.awt.event.ComponentEvent event) { //init(getWidth(), getHeight()); //repaint(INNER_BOUNDS); //****************// java.awt.Container parent = getParent(); if ((parent != null) && (parent.getLayout() == null)) { setSize(getWidth(), getHeight()); } else { setPreferredSize(new java.awt.Dimension(getWidth(), getHeight())); } calcInnerBounds(); init(INNER_BOUNDS.width, INNER_BOUNDS.height); //revalidate(); //repaint(INNER_BOUNDS); } };
/** * Sets the current charge of the battery as integer from 0 - 100 * @param VALUE */ public void setValue(final int VALUE) { value = VALUE < 0 ? 0 : (VALUE > 100 ? 100 : VALUE); init(getWidth(), getHeight()); repaint(INNER_BOUNDS); }
/** * Set the position of the light that affects the gradient of the battery frame * @param LIGHT_POSITION */ public void setLightPosition(final Orientation LIGHT_POSITION) { lightPosition = LIGHT_POSITION; init(getWidth(), getHeight()); repaint(INNER_BOUNDS); }
@Override public void componentResized(java.awt.event.ComponentEvent event) { //init(getWidth(), getHeight()); //repaint(INNER_BOUNDS); //****************// java.awt.Container parent = getParent(); if ((parent != null) && (parent.getLayout() == null)) { setSize(getWidth(), getHeight()); } else { setPreferredSize(new java.awt.Dimension(getWidth(), getHeight())); } calcInnerBounds(); init(INNER_BOUNDS.width, INNER_BOUNDS.height); //revalidate(); //repaint(INNER_BOUNDS); } };