public LightBulb() { super(); propertySupport = new PropertyChangeSupport(this); CENTER = new Point2D.Double(); offImage = createImage(INNER_BOUNDS.width, INNER_BOUNDS.height, Transparency.TRANSLUCENT); onImage = createImage(INNER_BOUNDS.width, INNER_BOUNDS.height, Transparency.TRANSLUCENT); bulbImage = createImage(INNER_BOUNDS.width, INNER_BOUNDS.height, Transparency.TRANSLUCENT); alpha = 1.0f; direction = SwingUtilities.NORTH; glowColor = new Color(1.0f, 1.0f, 0.0f); horizontalAlignment = SwingConstants.CENTER; verticalAlignment = SwingConstants.CENTER; addComponentListener(COMPONENT_LISTENER); }
@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, INNER_BOUNDS.height); invalidate(); repaint(); }
@Override public void componentResized(ComponentEvent event) { final int SIZE = getWidth() <= getHeight() ? getWidth() : getHeight(); Container parent = getParent(); if ((parent != null) && (parent.getLayout() == null)) { if (SIZE < getMinimumSize().width || SIZE < getMinimumSize().height) { setSize(getMinimumSize()); } else{ setSize(SIZE, SIZE); } } else { if (SIZE < getMinimumSize().width || SIZE < getMinimumSize().height) { setPreferredSize(getMinimumSize()); } else{ setPreferredSize(new Dimension(SIZE, SIZE)); } } calcInnerBounds(); init(getInnerBounds().width, getInnerBounds().height); } };
/** * Sets the glow color of the lightbulb * @param GLOW_COLOR */ public void setGlowColor(final Color GLOW_COLOR) { glowColor = GLOW_COLOR; init(getInnerBounds().width, getInnerBounds().height); repaint(getInnerBounds()); }
/** * Sets the alpha value of the glow effect. A value of 0.0f makes * the glow completly invisible and the bulb will look like switched off * @param ALPHA */ public void setAlpha(final float ALPHA) { alpha = ALPHA < 0 ? 0 : (ALPHA > 1 ? 1: ALPHA); repaint(getInnerBounds()); }
@Override public void setBorder(Border BORDER) { super.setBorder(BORDER); calcInnerBounds(); init(INNER_BOUNDS.width, INNER_BOUNDS.height); }
public final void init(final int WIDTH, final int HEIGHT) { if (WIDTH <= 1 || HEIGHT <= 1) { return; } if (offImage != null) { offImage.flush(); } offImage = createOffImage(WIDTH, HEIGHT); if (onImage != null) { onImage.flush(); } onImage = createOnImage(WIDTH, HEIGHT, glowColor); if (bulbImage != null) { bulbImage.flush(); } bulbImage = createBulbImage(WIDTH, HEIGHT); CENTER.setLocation(WIDTH / 2.0, HEIGHT / 2.0); }
G2.translate(getInnerBounds().x, getInnerBounds().y);
@Override public void setBorder(Border BORDER) { super.setBorder(BORDER); calcInnerBounds(); init(INNER_BOUNDS.width, INNER_BOUNDS.height); }
/** * Sets the alpha value of the glow effect. A value of 0.0f makes * the glow completly invisible and the bulb will look like switched off * @param ALPHA */ public void setAlpha(final float ALPHA) { alpha = ALPHA < 0 ? 0 : (ALPHA > 1 ? 1: ALPHA); repaint(getInnerBounds()); }
/** * Sets the glow color of the lightbulb * @param GLOW_COLOR */ public void setGlowColor(final Color GLOW_COLOR) { glowColor = GLOW_COLOR; init(getInnerBounds().width, getInnerBounds().height); repaint(getInnerBounds()); }
public final void init(final int WIDTH, final int HEIGHT) { if (WIDTH <= 1 || HEIGHT <= 1) { return; } if (offImage != null) { offImage.flush(); } offImage = createOffImage(WIDTH, HEIGHT); if (onImage != null) { onImage.flush(); } onImage = createOnImage(WIDTH, HEIGHT, glowColor); if (bulbImage != null) { bulbImage.flush(); } bulbImage = createBulbImage(WIDTH, HEIGHT); CENTER.setLocation(WIDTH / 2.0, HEIGHT / 2.0); }
G2.translate(getInnerBounds().x, getInnerBounds().y);
@Override public void componentResized(ComponentEvent event) { final int SIZE = getWidth() <= getHeight() ? getWidth() : getHeight(); Container parent = getParent(); if ((parent != null) && (parent.getLayout() == null)) { if (SIZE < getMinimumSize().width || SIZE < getMinimumSize().height) { setSize(getMinimumSize()); } else{ setSize(SIZE, SIZE); } } else { if (SIZE < getMinimumSize().width || SIZE < getMinimumSize().height) { setPreferredSize(getMinimumSize()); } else{ setPreferredSize(new Dimension(SIZE, SIZE)); } } calcInnerBounds(); init(getInnerBounds().width, getInnerBounds().height); } };
@Override public void setMinimumSize(final Dimension DIM) { int width = DIM.width < 24 ? 24 : DIM.width; int height = DIM.height < 24 ? 24 : DIM.height; final int SIZE = width <= height ? width : height; super.setMinimumSize(new Dimension(SIZE, SIZE)); calcInnerBounds(); init(INNER_BOUNDS.width, INNER_BOUNDS.height); invalidate(); repaint(); }
@Override public void setSize(final int WIDTH, final int HEIGHT) { final int SIZE = WIDTH <= HEIGHT ? WIDTH : HEIGHT; super.setSize(SIZE, SIZE); calcInnerBounds(); init(INNER_BOUNDS.width, INNER_BOUNDS.height); }
/** * Enables/disables the glowing of the lightbulb * @param ON */ public void setOn(final boolean ON) { boolean oldState = on; on = ON; propertySupport.firePropertyChange(STATE_PROPERTY, oldState, on); repaint(getInnerBounds()); }
public LightBulb() { super(); propertySupport = new PropertyChangeSupport(this); CENTER = new Point2D.Double(); offImage = createImage(INNER_BOUNDS.width, INNER_BOUNDS.height, Transparency.TRANSLUCENT); onImage = createImage(INNER_BOUNDS.width, INNER_BOUNDS.height, Transparency.TRANSLUCENT); bulbImage = createImage(INNER_BOUNDS.width, INNER_BOUNDS.height, Transparency.TRANSLUCENT); alpha = 1.0f; direction = SwingUtilities.NORTH; glowColor = new Color(1.0f, 1.0f, 0.0f); horizontalAlignment = SwingConstants.CENTER; verticalAlignment = SwingConstants.CENTER; addComponentListener(COMPONENT_LISTENER); }