@Override public void setMinimumSize(final Dimension DIM) { int width = DIM.width < 16 ? 16 : DIM.width; int height = DIM.height < 16 ? 16 : DIM.height; final int SIZE = width <= height ? width : height; super.setMinimumSize(new Dimension(SIZE, SIZE)); calcInnerBounds(); init(INNER_BOUNDS.width); initialized = true; invalidate(); repaint(); }
/** * Sets the type of LED. * @param LED_TYPE Possible values are ROUND, RECT_VERTICAL and RECT_HORIZONTAL */ public void setLedType(final LedType LED_TYPE) { if (ledType == LED_TYPE) {return;} ledType = LED_TYPE; final boolean LED_WAS_ON = currentLedImage.equals(ledImageOn) ? true : false; flushImages(); ledImageOff = create_LED_Image(getWidth(), 0, ledColor, ledType); ledImageOn = create_LED_Image(getWidth(), 1, ledColor, ledType); currentLedImage = LED_WAS_ON == true ? ledImageOn : ledImageOff; repaint(); }
@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 setBorder(Border BORDER) { super.setBorder(BORDER); calcInnerBounds(); init(INNER_BOUNDS.width); }
@Override public void actionPerformed(ActionEvent event) { if (event.getSource().equals(LED_BLINKING_TIMER)) { currentLedImage = ledOn == true ? getLedImageOn() : getLedImageOff(); ledOn ^= true; repaint(); } } // </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); }
ledColor = LedColor.RED_LED; customLedColor = new CustomLedColor(Color.RED); ledImageOff = create_LED_Image(16, 0, ledColor, LedType.ROUND); ledImageOn = create_LED_Image(16, 1, ledColor, LedType.ROUND); currentLedImage = ledImageOff; LED_BLINKING_TIMER = new javax.swing.Timer(500, this); horizontalAlignment = SwingConstants.CENTER; verticalAlignment = SwingConstants.CENTER; init(INNER_BOUNDS.width); addComponentListener(COMPONENT_LISTENER);
/** * Sets the state of the threshold led. * The led could blink which will be triggered by a javax.swing.Timer * that triggers every 500 ms. The blinking will be done by switching * between two images. * @param LED_BLINKING */ public void setLedBlinking(final boolean LED_BLINKING) { if (ledBlinking == LED_BLINKING) {return;} ledBlinking = LED_BLINKING; if (LED_BLINKING) { LED_BLINKING_TIMER.start(); } else { setCurrentLedImage(getLedImageOff()); LED_BLINKING_TIMER.stop(); } }
private void init(final int WIDTH) { if (WIDTH <= 1) { return; } if (ledImageOff != null) { ledImageOff.flush(); } ledImageOff = create_LED_Image(WIDTH, 0, ledColor, ledType); if (ledImageOn != null) { ledImageOn.flush(); } ledImageOn = create_LED_Image(WIDTH, 1, ledColor, ledType); if (ledOn) { setCurrentLedImage(ledImageOn); } else { setCurrentLedImage(ledImageOff); } } // </editor-fold>
@Override protected void paintComponent(Graphics g) { if (!initialized) { return; } final Graphics2D G2 = (Graphics2D) g.create(); G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); G2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); G2.translate(INNER_BOUNDS.x, INNER_BOUNDS.y); G2.drawImage(getCurrentLedImage(), 0, 0, null); G2.translate(-INNER_BOUNDS.x, -INNER_BOUNDS.y); G2.dispose(); } // </editor-fold>
@Override public void setBorder(Border BORDER) { super.setBorder(BORDER); calcInnerBounds(); init(INNER_BOUNDS.width); }
@Override public void actionPerformed(ActionEvent event) { if (event.getSource().equals(LED_BLINKING_TIMER)) { currentLedImage = ledOn == true ? getLedImageOn() : getLedImageOff(); ledOn ^= true; repaint(); } } // </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); }
ledColor = LedColor.RED_LED; customLedColor = new CustomLedColor(Color.RED); ledImageOff = create_LED_Image(16, 0, ledColor, LedType.ROUND); ledImageOn = create_LED_Image(16, 1, ledColor, LedType.ROUND); currentLedImage = ledImageOff; LED_BLINKING_TIMER = new javax.swing.Timer(500, this); horizontalAlignment = SwingConstants.CENTER; verticalAlignment = SwingConstants.CENTER; init(INNER_BOUNDS.width); addComponentListener(COMPONENT_LISTENER);
/** * Sets the state of the threshold led. * The led could blink which will be triggered by a javax.swing.Timer * that triggers every 500 ms. The blinking will be done by switching * between two images. * @param LED_BLINKING */ public void setLedBlinking(final boolean LED_BLINKING) { if (ledBlinking == LED_BLINKING) {return;} ledBlinking = LED_BLINKING; if (LED_BLINKING) { LED_BLINKING_TIMER.start(); } else { setCurrentLedImage(getLedImageOff()); LED_BLINKING_TIMER.stop(); } }
private void init(final int WIDTH) { if (WIDTH <= 1) { return; } if (ledImageOff != null) { ledImageOff.flush(); } ledImageOff = create_LED_Image(WIDTH, 0, ledColor, ledType); if (ledImageOn != null) { ledImageOn.flush(); } ledImageOn = create_LED_Image(WIDTH, 1, ledColor, ledType); if (ledOn) { setCurrentLedImage(ledImageOn); } else { setCurrentLedImage(ledImageOff); } } // </editor-fold>
@Override protected void paintComponent(Graphics g) { if (!initialized) { return; } final Graphics2D G2 = (Graphics2D) g.create(); G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); G2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); G2.translate(INNER_BOUNDS.x, INNER_BOUNDS.y); G2.drawImage(getCurrentLedImage(), 0, 0, null); G2.translate(-INNER_BOUNDS.x, -INNER_BOUNDS.y); G2.dispose(); } // </editor-fold>
@Override public void setMaximumSize(final Dimension DIM) { int width = DIM.width > 1080 ? 1080 : DIM.width; int height = DIM.height > 1080 ? 1080 : DIM.height; final int SIZE = width <= height ? width : height; super.setMaximumSize(new Dimension(SIZE, SIZE)); calcInnerBounds(); init(INNER_BOUNDS.width); initialized = true; invalidate(); repaint(); }