1 package jimm.datavision.gui; 2 import jimm.datavision.*; 3 import jimm.datavision.field.Field; 4 import jimm.datavision.gui.cmd.BoundsCommand; 5 import jimm.util.I18N; 6 import java.awt.BorderLayout ; 7 import javax.swing.*; 8 9 14 public class BoundsWin extends EditWin implements FieldWalker { 15 16 protected static final int TEXT_FIELD_COLS = 8; 17 18 protected Field field; 19 protected jimm.datavision.field.Rectangle origBounds; 20 protected jimm.datavision.field.Rectangle fieldBounds; 21 protected JTextField x_text; 22 protected JTextField y_text; 23 protected JTextField w_text; 24 protected JTextField h_text; 25 26 32 public BoundsWin(Designer designer, Field f) { 33 super(designer, I18N.get("BoundsWin.title"), "BoundsCommand.name"); 34 35 field = f; 36 origBounds = field.getBounds(); 37 fieldBounds = new jimm.datavision.field.Rectangle(origBounds); 38 39 buildWindow(); 40 pack(); 41 setVisible(true); 42 } 43 44 47 protected void buildWindow() { 48 JPanel editorPanel = buildBoundsEditor(); 49 50 JPanel buttonPanel = closeButtonPanel(); 52 53 getContentPane().add(editorPanel, BorderLayout.CENTER); 55 getContentPane().add(buttonPanel, BorderLayout.SOUTH); 56 } 57 58 protected JPanel buildBoundsEditor() { 59 JPanel panel = new JPanel(); 60 panel.setLayout(new BorderLayout ()); 61 62 x_text = addCoord(panel, I18N.get("BoundsWin.x"), fieldBounds.x, 63 BorderLayout.WEST); 64 y_text = addCoord(panel, I18N.get("BoundsWin.y"), fieldBounds.y, 65 BorderLayout.NORTH); 66 w_text = addCoord(panel, I18N.get("BoundsWin.width"), fieldBounds.width, 67 BorderLayout.EAST); 68 h_text = addCoord(panel, I18N.get("BoundsWin.height"), fieldBounds.height, 69 BorderLayout.SOUTH); 70 71 return panel; 72 } 73 74 protected JTextField addCoord(JPanel parent, String label, double value, 75 String compassPoint) 76 { 77 JPanel coordPanel = new JPanel(); 78 coordPanel.add(new JLabel(label)); 79 JTextField text = new JTextField("" + value, TEXT_FIELD_COLS); 80 coordPanel.add(text); 81 parent.add(coordPanel, compassPoint); 82 return text; 83 } 84 85 protected void fillCoords(jimm.datavision.field.Rectangle bounds) { 86 x_text.setText("" + bounds.x); 87 y_text.setText("" + bounds.y); 88 w_text.setText("" + bounds.width); 89 h_text.setText("" + bounds.height); 90 } 91 92 protected void doSave() { 93 fieldBounds.setBounds(Double.parseDouble(x_text.getText()), 94 Double.parseDouble(y_text.getText()), 95 Double.parseDouble(w_text.getText()), 96 Double.parseDouble(h_text.getText())); 97 98 if (designer.countSelectedFields() == 0 99 || field == field.getReport().getDefaultField()) step(field); 101 else designer.withSelectedFieldsDo(this); 103 } 104 105 111 public void step(Field f) { 112 BoundsCommand command = new BoundsCommand(f, fieldBounds); 113 command.perform(); 114 commands.add(command); 115 } 116 117 protected void doRevert() { 118 fillCoords(origBounds); 119 } 120 121 } 122 | Popular Tags |