public Battery() { super(); lightPosition = Orientation.NORTH; INNER_BOUNDS = new Rectangle(40, 18); initialized = false; init(INNER_BOUNDS.width, INNER_BOUNDS.height); addComponentListener(COMPONENT_LISTENER); } // </editor-fold>
@Override public void setMinimumSize(final Dimension DIM) { int width = DIM.width < 40 ? 40 : DIM.width; int height = DIM.height < 18 ? 18 : DIM.height; super.setMinimumSize(new Dimension(width, height)); calcInnerBounds(); init(INNER_BOUNDS.width, (int) (0.45 * INNER_BOUNDS.width)); invalidate(); repaint(); }
@Override public void setBorder(final Border BORDER) { super.setBorder(BORDER); calcInnerBounds(); init(INNER_BOUNDS.width, (int) (0.45 * INNER_BOUNDS.width)); } // </editor-fold>
@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); } };
/** * 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)); }
/** * 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>
private void init(final int WIDTH, final int HEIGHT) { if (WIDTH <= 1) { return; } if (batteryImage != null) { batteryImage.flush(); } batteryImage = create_BATTERY_Image(WIDTH, HEIGHT - getInsets().bottom, value); } // </editor-fold>
@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); } };
@Override public void setBorder(final Border BORDER) { super.setBorder(BORDER); calcInnerBounds(); init(INNER_BOUNDS.width, (int) (0.45 * INNER_BOUNDS.width)); } // </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(); INNER_BOUNDS.setBounds(INSETS.left, INSETS.top, (getWidth() - INSETS.left - INSETS.right), (getHeight() - INSETS.top - INSETS.bottom)); }
/** * 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>
private void init(final int WIDTH, final int HEIGHT) { if (WIDTH <= 1) { return; } if (batteryImage != null) { batteryImage.flush(); } batteryImage = create_BATTERY_Image(WIDTH, HEIGHT - getInsets().bottom, value); } // </editor-fold>
@Override public void setMinimumSize(final Dimension DIM) { int width = DIM.width < 40 ? 40 : DIM.width; int height = DIM.height < 18 ? 18 : DIM.height; super.setMinimumSize(new Dimension(width, height)); calcInnerBounds(); init(INNER_BOUNDS.width, (int) (0.45 * INNER_BOUNDS.width)); invalidate(); repaint(); }
@Override public void setSize(final int WIDTH, final int HEIGHT) { super.setSize(WIDTH, (int) (0.45 * WIDTH)); calcInnerBounds(); init(INNER_BOUNDS.width, (int) (0.45 * INNER_BOUNDS.width)); initialized = true; }
public Battery() { super(); lightPosition = Orientation.NORTH; INNER_BOUNDS = new Rectangle(40, 18); initialized = false; init(INNER_BOUNDS.width, INNER_BOUNDS.height); addComponentListener(COMPONENT_LISTENER); } // </editor-fold>
@Override public void setMaximumSize(final Dimension DIM) { int width = DIM.width > 1920 ? 1920 : DIM.width; int height = DIM.height > 864 ? 864 : DIM.height; super.setMaximumSize(new Dimension(width, height)); calcInnerBounds(); init(INNER_BOUNDS.width, (int) (0.45 * INNER_BOUNDS.width)); invalidate(); repaint(); }
@Override public void setBounds(final int X, final int Y, final int WIDTH, final int HEIGHT) { super.setBounds(X, Y, WIDTH, (int) (0.45 * WIDTH)); calcInnerBounds(); init(INNER_BOUNDS.width, (int) (0.45 * INNER_BOUNDS.width)); initialized = true; }