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