001: // StepIntegerAttributeEditor.java
002: // $Id: StepIntegerAttributeEditor.java,v 1.9 2000/08/16 21:37:28 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1997.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigadm.editors;
007:
008: import java.awt.BorderLayout;
009: import java.awt.Button;
010: import java.awt.Component;
011: import java.awt.Container;
012: import java.awt.Label;
013: import java.awt.Panel;
014:
015: import java.awt.event.ActionEvent;
016: import java.awt.event.ActionListener;
017:
018: import java.util.Properties;
019:
020: import org.w3c.tools.resources.Attribute;
021:
022: import org.w3c.jigsaw.admin.RemoteAccessException;
023: import org.w3c.jigsaw.admin.RemoteResource;
024:
025: import org.w3c.jigadm.RemoteResourceWrapper;
026:
027: public class StepIntegerAttributeEditor extends AttributeEditor {
028:
029: class StepListener implements ActionListener {
030:
031: public void actionPerformed(ActionEvent ae) {
032: if (ae.getActionCommand().equals("+"))
033: incr();
034: else
035: decr();
036: }
037: }
038:
039: private int origi = 0;
040: private int curri;
041: private Label l;
042: private Button p, m;
043: Panel widget;
044:
045: protected void incr() {
046: curri++;
047: l.setText((new Integer(curri)).toString());
048: }
049:
050: protected void decr() {
051: --curri;
052: l.setText((new Integer(curri)).toString());
053: }
054:
055: public boolean hasChanged() {
056: return (origi != curri);
057: }
058:
059: public void clearChanged() {
060: origi = curri;
061: }
062:
063: public void resetChanges() {
064: curri = origi;
065: l.setText((new Integer(curri)).toString());
066: }
067:
068: public Object getValue() {
069: return new Integer(curri);
070: }
071:
072: public void setValue(Object o) {
073: if (o instanceof Integer) {
074: curri = ((Integer) o).intValue();
075: l.setText(((Integer) o).toString());
076: }
077: }
078:
079: public Component getComponent() {
080: return widget;
081: }
082:
083: public StepIntegerAttributeEditor() {
084: StepListener sl = new StepListener();
085: widget = new Panel(new BorderLayout());
086: l = new Label();
087: l.setAlignment(Label.CENTER);
088: widget.add("Center", l);
089: p = new Button("+");
090: p.addActionListener(sl);
091: widget.add("East", p);
092: m = new Button("-");
093: m.addActionListener(sl);
094: widget.add("West", m);
095: }
096:
097: /**
098: * Initialize the editor
099: * @param w the ResourceWrapper father of the attribute
100: * @param a the Attribute we are editing
101: * @param o the value of the above attribute
102: * @param p some Properties, used to fine-tune the editor
103: * @exception RemoteAccessException if a remote access error occurs.
104: */
105: public void initialize(RemoteResourceWrapper w, Attribute a,
106: Object o, Properties p) throws RemoteAccessException {
107: RemoteResource r = w.getResource();
108: if (o == null) {
109: Integer i = null;
110: // FIXME
111: i = (Integer) r.getValue(a.getName());
112:
113: if (i == null)
114: if (a.getDefault() != null)
115: i = (Integer) a.getDefault();
116: if (i != null) {
117: origi = i.intValue();
118: l.setText(i.toString());
119: }
120: curri = origi;
121: } else {
122: if (o instanceof Integer)
123: origi = ((Integer) o).intValue();
124: }
125: l.setText((new Integer(origi)).toString());
126: curri = origi;
127: }
128: }
|