samer@0: /* samer@0: * Copyright (c) 2000, Samer Abdallah, King's College London. samer@0: * All rights reserved. samer@0: * samer@0: * This software is provided AS iS and WITHOUT ANY WARRANTY; samer@0: * without even the implied warranty of MERCHANTABILITY or samer@0: * FITNESS FOR A PARTICULAR PURPOSE. samer@0: */ samer@0: samer@0: package samer.core.util.swing; samer@0: import javax.swing.*; samer@0: import java.awt.*; samer@0: import java.awt.event.*; samer@0: samer@0: public class LED extends JComponent samer@0: { samer@0: boolean state=false; samer@0: samer@0: public LED(Color fg) { this(fg,fg.darker().darker()); } samer@0: public LED(Color fg, Color bg) { this(); setBackground(bg); setForeground(fg); } samer@0: public LED() {} samer@0: samer@0: public void update(Graphics g) { paint(g); } samer@0: public void paint(Graphics g) { samer@0: g.setColor( state ? getForeground() : getBackground()); samer@0: g.fillRect(0,0,getWidth(),getHeight()); samer@0: } samer@0: samer@0: public final void on() { set(true); } samer@0: public final void off() { set(false); } samer@0: public final void set( boolean state) { samer@0: if (state!=this.state) { this.state=state; repaint(); } samer@0: } samer@0: samer@0: public Dimension getPreferredSize() { return new Dimension(8,8); } samer@0: }