Mercurial > hg > jslab
view src/samer/core_/util/swing/LED.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
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); } }