Mercurial > hg > jslab
view src/samer/core_/util/swing/LED.java @ 8:5e3cbbf173aa tip
Reorganise some more
author | samer |
---|---|
date | Fri, 05 Apr 2019 22:41:58 +0100 |
parents | bf79fb79ee13 |
children |
line wrap: on
line source
/* * Copyright (c) 2000, Samer Abdallah, King's College London. * All rights reserved. * * This software is provided AS iS and WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. */ package samer.core.util.swing; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class LED extends JComponent { boolean state=false; public LED(Color fg) { this(fg,fg.darker().darker()); } public LED(Color fg, Color bg) { this(); setBackground(bg); setForeground(fg); } public LED() {} public void update(Graphics g) { paint(g); } public void paint(Graphics g) { g.setColor( state ? getForeground() : getBackground()); g.fillRect(0,0,getWidth(),getHeight()); } public final void on() { set(true); } public final void off() { set(false); } public final void set( boolean state) { if (state!=this.state) { this.state=state; repaint(); } } public Dimension getPreferredSize() { return new Dimension(8,8); } }