comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 /*
2 * Copyright (c) 2000, Samer Abdallah, King's College London.
3 * All rights reserved.
4 *
5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
6 * without even the implied warranty of MERCHANTABILITY or
7 * FITNESS FOR A PARTICULAR PURPOSE.
8 */
9
10 package samer.core.util.swing;
11 import javax.swing.*;
12 import java.awt.*;
13 import java.awt.event.*;
14
15 public class LED extends JComponent
16 {
17 boolean state=false;
18
19 public LED(Color fg) { this(fg,fg.darker().darker()); }
20 public LED(Color fg, Color bg) { this(); setBackground(bg); setForeground(fg); }
21 public LED() {}
22
23 public void update(Graphics g) { paint(g); }
24 public void paint(Graphics g) {
25 g.setColor( state ? getForeground() : getBackground());
26 g.fillRect(0,0,getWidth(),getHeight());
27 }
28
29 public final void on() { set(true); }
30 public final void off() { set(false); }
31 public final void set( boolean state) {
32 if (state!=this.state) { this.state=state; repaint(); }
33 }
34
35 public Dimension getPreferredSize() { return new Dimension(8,8); }
36 }