comparison src/samer/core_/util/heavy/TextualNumberViewer.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 package samer.core.util.heavy;
2 import samer.core.*;
3 import java.awt.*;
4 import java.awt.event.*;
5
6 public class TextualNumberViewer extends VPanel
7 implements NumberViewer, FocusListener, ActionListener
8 {
9 TextField rt;
10 NumberSink model;
11 boolean real;
12
13 public TextualNumberViewer(String label, int flags, NumberSink model)
14 {
15 setLayout(new BorderLayout());
16 setName(label);
17
18 rt = new TextField(Shell.getInt("field.width",4));
19 rt.setBackground(Shell.getColor("field.background",null));
20 rt.setForeground(Shell.getColor("field.foreground",null));
21 add( rt,"East");
22
23 if (model!=null) {
24 this.model=model;
25 rt.addFocusListener(this);
26 rt.addActionListener(this);
27 real = ((flags & INTEGER)==0);
28 }
29 }
30
31 public void set(int num) {
32 rt.setText(String.valueOf(num));
33 }
34 public void set(double num) {
35 rt.setText(X.string(num));
36 }
37
38 private void textChanged() {
39 if (real) model.set(X.parseDouble(rt.getText()));
40 else model.set(Integer.decode(rt.getText()).intValue());
41 }
42
43 public void focusGained( FocusEvent e) {}
44 public void focusLost( FocusEvent e) { textChanged(); }
45 public void actionPerformed( ActionEvent e) { textChanged(); }
46 }
47