Mercurial > hg > jslab
view 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 |
line wrap: on
line source
package samer.core.util.heavy; import samer.core.*; import java.awt.*; import java.awt.event.*; public class TextualNumberViewer extends VPanel implements NumberViewer, FocusListener, ActionListener { TextField rt; NumberSink model; boolean real; public TextualNumberViewer(String label, int flags, NumberSink model) { setLayout(new BorderLayout()); setName(label); rt = new TextField(Shell.getInt("field.width",4)); rt.setBackground(Shell.getColor("field.background",null)); rt.setForeground(Shell.getColor("field.foreground",null)); add( rt,"East"); if (model!=null) { this.model=model; rt.addFocusListener(this); rt.addActionListener(this); real = ((flags & INTEGER)==0); } } public void set(int num) { rt.setText(String.valueOf(num)); } public void set(double num) { rt.setText(X.string(num)); } private void textChanged() { if (real) model.set(X.parseDouble(rt.getText())); else model.set(Integer.decode(rt.getText()).intValue()); } public void focusGained( FocusEvent e) {} public void focusLost( FocusEvent e) { textChanged(); } public void actionPerformed( ActionEvent e) { textChanged(); } }