User: ko5tik Date: 02/04/07 10:02:28 Modified: src/java/xdocletgui/swing/editor CommentaryEditorPanel.java Log: comment editor even cooler. undo & redo work Revision Changes Path 1.3 +62 -1 xdocletgui/src/java/xdocletgui/swing/editor/CommentaryEditorPanel.java Index: CommentaryEditorPanel.java =================================================================== RCS file: /cvsroot/xdoclet/xdocletgui/src/java/xdocletgui/swing/editor/CommentaryEditorPanel.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -r1.2 -r1.3 --- CommentaryEditorPanel.java 7 Apr 2002 16:15:55 -0000 1.2 +++ CommentaryEditorPanel.java 7 Apr 2002 17:02:27 -0000 1.3 @@ -38,6 +38,7 @@ import javax.swing.*; import javax.swing.text.*; import javax.swing.event.*; +import javax.swing.undo.*; import java.awt.*; import java.awt.event.*; @@ -54,6 +55,10 @@ public class CommentaryEditorPanel extends JPanel implements DocumentListener { /** + * undo manager for our text panel + */ + UndoManager _undo; + /** * XDoc we are editing */ XDoc _xdoc; @@ -79,6 +84,25 @@ JButton _cancelButton; /** + * pointer to undo button + */ + JButton _undoButton; + /** + * pointer to redo button + */ + JButton _redoButton; + + /** + * string for undo button + */ + final static String BUTTON_UNDO = "Undo"; + + /** + * string for redo button + */ + final static String BUTTON_REDO = "Redo"; + + /** * string for Set button */ final static String BUTTON_SET = "Set"; @@ -102,10 +126,12 @@ super(new BorderLayout()); setBorder(BorderFactory.createTitledBorder("Program element description")); + _undo = new UndoManager(); _description = new JLabel(); add(_description, BorderLayout.NORTH); _docText = new JTextArea(); _docText.getDocument().addDocumentListener(this); + _docText.getDocument().addUndoableEditListener(_undo); JScrollPane _scp = new JScrollPane(_docText); add(_scp, BorderLayout.CENTER); @@ -131,7 +157,36 @@ } }); + _undoButton = new JButton(BUTTON_UNDO); + + _undoButton.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (_undo.canUndo()) { + _undo.undo(); + enableButtons(true); + } + } + }); + + _redoButton = new JButton(BUTTON_REDO); + + _redoButton.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (_undo.canRedo()) { + _undo.redo(); + enableButtons(true); + } + } + }); + buttonPanel.add(Box.createHorizontalGlue()); + buttonPanel.add(_undoButton); + buttonPanel.add(Box.createRigidArea(new Dimension(10, 0))); + buttonPanel.add(_redoButton); + buttonPanel.add(Box.createRigidArea(new Dimension(50, 0))); + buttonPanel.add(_cancelButton); buttonPanel.add(Box.createRigidArea(new Dimension(10, 0))); buttonPanel.add(_setButton); @@ -189,7 +244,7 @@ /** - * enable buttons + * change button status. also change status of undo & redo buttons * * @param enable Describe what the parameter does * @todo-javadoc Write javadocs for method parameter @@ -198,6 +253,10 @@ void enableButtons(boolean enable) { _cancelButton.setEnabled(enable); _setButton.setEnabled(enable); + + _undoButton.setEnabled(_undo.canUndo()); + _redoButton.setEnabled(_undo.canRedo()); + } @@ -206,6 +265,7 @@ */ private void save() { _xdoc.setCommentText(_docText.getText()); + _undo.discardAllEdits(); enableButtons(false); } @@ -215,6 +275,7 @@ */ private void revert() { _docText.setText(_xdoc.commentText()); + _undo.discardAllEdits(); enableButtons(false); } }
_______________________________________________ Xdoclet-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-devel