1 package jimm.datavision.gui.cmd; 2 import jimm.datavision.field.Rectangle; 3 import jimm.datavision.gui.SectionWidget; 4 import jimm.datavision.gui.TextFieldWidget; 5 import jimm.util.I18N; 6 import javax.swing.JTextPane ; 7 8 13 public class TypingCommand extends CommandAdapter { 14 15 protected TextFieldWidget fw; 16 protected SectionWidget sw; 17 protected String oldText; 18 protected String newText; 19 protected Rectangle oldBounds; 20 protected Rectangle newBounds; 21 protected int origHeight; 22 protected SectionResizeCommand sectionResizeCommand; 23 24 public TypingCommand(TextFieldWidget fw, int origHeight) { 25 super(I18N.get("TypingCommand.name")); 26 27 this.fw = fw; 28 this.origHeight = origHeight; 29 sw = fw.getSectionWidget(); 30 31 oldText = (String )fw.getField().getValue(); 32 oldBounds = new Rectangle(fw.getField().getBounds()); sectionResizeCommand = new SectionResizeCommand(sw); 34 } 35 36 39 public void perform() { 40 JTextPane textPane = (JTextPane )fw.getComponent(); 41 if (textPane.isEditable()) { 42 newText = textPane.getText(); 46 47 textPane.setEditable(false); 48 textPane.getCaret().setVisible(false); 49 50 newBounds = new Rectangle(textPane.getBounds()); 51 if (newBounds.height != origHeight) 52 fw.getField().getBounds().setBounds(newBounds); 53 54 fw.getField().setValue(newText); 61 62 fw.getSectionWidget().setIgnoreKeys(false); 63 64 textPane.addMouseListener(fw); 65 textPane.addMouseMotionListener(fw); 66 } 67 68 sectionResizeCommand.perform(); 69 } 70 71 public void undo() { 72 fw.getField().setValue(oldText); 73 fw.getField().getBounds().setBounds(oldBounds); 74 75 sectionResizeCommand.undo(); 76 } 77 78 public void redo() { 79 fw.getField().setValue(newText); 80 fw.getField().getBounds().setBounds(newBounds); 81 sectionResizeCommand.redo(); 82 } 83 84 } 85 | Popular Tags |