001: package jimm.datavision.gui;
002:
003: import jimm.datavision.*;
004: import jimm.datavision.field.Field;
005: import jimm.datavision.gui.cmd.BoundsCommand;
006: import jimm.util.I18N;
007: import java.awt.BorderLayout;
008: import javax.swing.*;
009:
010: /**
011: * A field bounds (position and size) editing dialog box.
012: *
013: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
014: */
015: public class BoundsWin extends EditWin implements FieldWalker {
016:
017: protected static final int TEXT_FIELD_COLS = 8;
018:
019: protected Field field;
020: protected jimm.datavision.field.Rectangle origBounds;
021: protected jimm.datavision.field.Rectangle fieldBounds;
022: protected JTextField x_text;
023: protected JTextField y_text;
024: protected JTextField w_text;
025: protected JTextField h_text;
026:
027: /**
028: * Constructor.
029: *
030: * @param designer the window to which this dialog belongs
031: * @param f a field from which we will take the bounds
032: */
033: public BoundsWin(Designer designer, Field f) {
034: super (designer, I18N.get("BoundsWin.title"),
035: "BoundsCommand.name");
036:
037: field = f;
038: origBounds = field.getBounds();
039: fieldBounds = new jimm.datavision.field.Rectangle(origBounds);
040:
041: buildWindow();
042: pack();
043: setVisible(true);
044: }
045:
046: /**
047: * Builds the window contents.
048: */
049: protected void buildWindow() {
050: JPanel editorPanel = buildBoundsEditor();
051:
052: // OK, Apply, Revert, and Cancel Buttons
053: JPanel buttonPanel = closeButtonPanel();
054:
055: // Add values and buttons to window
056: getContentPane().add(editorPanel, BorderLayout.CENTER);
057: getContentPane().add(buttonPanel, BorderLayout.SOUTH);
058: }
059:
060: protected JPanel buildBoundsEditor() {
061: JPanel panel = new JPanel();
062: panel.setLayout(new BorderLayout());
063:
064: x_text = addCoord(panel, I18N.get("BoundsWin.x"),
065: fieldBounds.x, BorderLayout.WEST);
066: y_text = addCoord(panel, I18N.get("BoundsWin.y"),
067: fieldBounds.y, BorderLayout.NORTH);
068: w_text = addCoord(panel, I18N.get("BoundsWin.width"),
069: fieldBounds.width, BorderLayout.EAST);
070: h_text = addCoord(panel, I18N.get("BoundsWin.height"),
071: fieldBounds.height, BorderLayout.SOUTH);
072:
073: return panel;
074: }
075:
076: protected JTextField addCoord(JPanel parent, String label,
077: double value, String compassPoint) {
078: JPanel coordPanel = new JPanel();
079: coordPanel.add(new JLabel(label));
080: JTextField text = new JTextField("" + value, TEXT_FIELD_COLS);
081: coordPanel.add(text);
082: parent.add(coordPanel, compassPoint);
083: return text;
084: }
085:
086: protected void fillCoords(jimm.datavision.field.Rectangle bounds) {
087: x_text.setText("" + bounds.x);
088: y_text.setText("" + bounds.y);
089: w_text.setText("" + bounds.width);
090: h_text.setText("" + bounds.height);
091: }
092:
093: protected void doSave() {
094: fieldBounds.setBounds(Double.parseDouble(x_text.getText()),
095: Double.parseDouble(y_text.getText()), Double
096: .parseDouble(w_text.getText()), Double
097: .parseDouble(h_text.getText()));
098:
099: if (designer.countSelectedFields() == 0
100: || field == field.getReport().getDefaultField()) // "==", not "equals"
101: step(field);
102: else
103: // Call step() for all selected fields
104: designer.withSelectedFieldsDo(this );
105: }
106:
107: /**
108: * Creates and performs a command that gives the bounds to the specified
109: * field.
110: *
111: * @param f the field
112: */
113: public void step(Field f) {
114: BoundsCommand command = new BoundsCommand(f, fieldBounds);
115: command.perform();
116: commands.add(command);
117: }
118:
119: protected void doRevert() {
120: fillCoords(origBounds);
121: }
122:
123: }
|