User: ko5tik  
  Date: 02/04/16 00:03:40

  Added:       src/java/xdocletgui/swing/editor UndoableEditorPanel.java
  Log:
  forgot to add it before...
  
  Revision  Changes    Path
  1.1                  
xdocletgui/src/java/xdocletgui/swing/editor/UndoableEditorPanel.java
  
  Index: UndoableEditorPanel.java
  ===================================================================
  /*
   * Copyright (c) 2001, Aslak Helles�y, BEKK Consulting
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modification,
   * are permitted provided that the following conditions are met:
   *
   * - Redistributions of source code must retain the above copyright notice,
   *   this list of conditions and the following disclaimer.
   *
   * - Redistributions in binary form must reproduce the above copyright
   *   notice, this list of conditions and the following disclaimer in the
   *   documentation and/or other materials provided with the distribution.
   *
   * - Neither the name of BEKK Consulting nor the names of its
   *   contributors may be used to endorse or promote products derived from
   *   this software without specific prior written permission.
   *
   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
   * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
   * DAMAGE.
   */
  
  /*
   * Change log
   *
   */
  package xdocletgui.swing.editor;
  
  import javax.swing.*;
  import javax.swing.text.*;
  import javax.swing.event.*;
  import javax.swing.undo.*;
  import java.awt.*;
  import java.awt.event.*;
  
  /**
   * Describe what this class does
   *
   * @author kostik
   * @created April 11, 2002
   * @todo-javadoc Write javadocs
   */
  public abstract class UndoableEditorPanel extends JPanel implements DocumentListener 
{
  
        /**
         * undo manager for our text panel
         */
        UndoManager _undo;
  
        /**
         * text area for text editing
         */
        JTextPane _text;
  
        /**
         * pointer to set button
         */
        JButton _setButton;
  
        /**
         * pointer to cancel button
         */
        JButton _cancelButton;
  
        /**
         * pointer to undo button
         */
        JButton _undoButton;
        /**
         * pointer to redo button
         */
        JButton _redoButton;
  
  
        /**
         * Describe what the UndoableEditorPanel constructor does
         *
         * @param layout Describe what the parameter does
         * @todo-javadoc Write javadocs for constructor
         * @todo-javadoc Write javadocs for method parameter
         */
        public UndoableEditorPanel(LayoutManager layout) {
                super(layout);
  
                // initialize common stuff
  
                _undo = new UndoManager();
                _text = new JTextPane();
                _text.getDocument().addDocumentListener(this);
                _text.getDocument().addUndoableEditListener(_undo);
  
                _setButton = new JButton("save");
                _setButton.addActionListener(
                        new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        save();
                                }
                        });
  
                _cancelButton = new JButton("cancel");
                _cancelButton.addActionListener(
                        new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        revert();
                                }
                        });
  
                _undoButton = new JButton("undo");
                _undoButton.addActionListener(
                        new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        if (_undo.canUndo()) {
                                                _undo.undo();
                                                enableButtons(true);
                                        }
                                }
                        });
                _redoButton = new JButton("redo");
  
                _redoButton.addActionListener(
                        new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        if (_undo.canRedo()) {
                                                _undo.redo();
                                                enableButtons(true);
                                        }
                                }
                        });
  
        }
  
  
        /**
         * insert notificator
         *
         * @param e Describe what the parameter does
         * @todo-javadoc Write javadocs for method parameter
         */
        public void insertUpdate(DocumentEvent e) {
                enableButtons(true);
        }
  
  
        /**
         * remove notificator
         *
         * @param e Describe what the parameter does
         * @todo-javadoc Write javadocs for method parameter
         */
        public void removeUpdate(DocumentEvent e) {
                enableButtons(true);
        }
  
  
        /**
         * change notificator
         *
         * @param e Describe what the parameter does
         * @todo-javadoc Write javadocs for method parameter
         */
        public void changedUpdate(DocumentEvent e) {
                enableButtons(true);
        }
  
  
        /**
         * save changes
         */
        public abstract void save();
  
  
        /**
         * revert to default value
         */
        public abstract void revert();
  
  
        /**
         * change button status. also change status of undo & redo buttons
         *
         * @param enable Describe what the parameter does
         * @todo-javadoc Write javadocs for method parameter
         */
  
        void enableButtons(boolean enable) {
                _cancelButton.setEnabled(enable);
                _setButton.setEnabled(enable);
  
                _undoButton.setEnabled(_undo.canUndo());
                _redoButton.setEnabled(_undo.canRedo());
  
        }
  }
  
  
  

_______________________________________________
Xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel

Reply via email to