User: ko5tik  
  Date: 02/04/14 07:27:40

  Modified:    src/java/xdocletgui/swing/editor
                        TagParameterEditorPanel.java
  Added:       src/java/xdocletgui/swing/editor UnknownTagPanel.java
  Log:
  delegated TagParameter changes to property editors.
  
  Revision  Changes    Path
  1.2       +83 -41    
xdocletgui/src/java/xdocletgui/swing/editor/TagParameterEditorPanel.java
  
  Index: TagParameterEditorPanel.java
  ===================================================================
  RCS file: 
/cvsroot/xdoclet/xdocletgui/src/java/xdocletgui/swing/editor/TagParameterEditorPanel.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -r1.1 -r1.2
  --- TagParameterEditorPanel.java      12 Apr 2002 17:01:17 -0000      1.1
  +++ TagParameterEditorPanel.java      14 Apr 2002 14:27:39 -0000      1.2
  @@ -38,6 +38,7 @@
   import javax.swing.*;
   import javax.swing.text.*;
   import javax.swing.tree.*;
  +import javax.swing.event.*;
   
   import java.awt.*;
   import java.awt.event.*;
  @@ -50,6 +51,7 @@
   
   import xjavadoc.*;
   
  +import java.beans.*;
   /**
    * Describe what this class does
    *
  @@ -77,12 +79,12 @@
        /**
         * panel for editing string value representation
         */
  -     JPanel _stringEditorPanel;
  +     JPanel _editorPanel;
   
        /**
  -      * panel to select choice
  +      * edit pane holding string area
         */
  -     JPanel _choicePanel;
  +     JScrollPane _editorPane;
   
        /**
         * text field for string entry
  @@ -90,11 +92,6 @@
        JTextArea _stringValue;
   
        /**
  -      * combo box for choice selection
  -      */
  -     JComboBox _valueChoice;
  -
  -     /**
         * label describing parameter
         */
        JLabel _description;
  @@ -138,6 +135,16 @@
         */
        XProgramElement _programElement;
   
  +     /**
  +      * property editor
  +      */
  +     PropertyEditor _editor;
  +
  +     /**
  +      * Get static reference to Log4J Logger
  +      */
  +     private static org.apache.log4j.Category _log = 
org.apache.log4j.Category.getInstance(TagParameterEditorPanel.class.getName());
  +
   
        /**
         * Describe what the TagParameterEditorPanel constructor does
  @@ -154,7 +161,23 @@
                setBorder(BorderFactory.createTitledBorder("Tag parameter"));
   
                _stringValue = new JTextArea();
  -             _valueChoice = new JComboBox();
  +
  +             _stringValue.getDocument().addDocumentListener(
  +                     new DocumentListener() {
  +                             public void changedUpdate(DocumentEvent e) {
  +                                     valueChanged();
  +                             }
  +
  +
  +                             public void insertUpdate(DocumentEvent e) {
  +                                     valueChanged();
  +                             }
  +
  +
  +                             public void removeUpdate(DocumentEvent e) {
  +                                     valueChanged();
  +                             }
  +                     });
   
                _description = new JLabel();
   
  @@ -205,23 +228,20 @@
   
                _splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
   
  -             _stringEditorPanel = new JPanel(new BorderLayout());
  -
  -             JScrollPane scp = new JScrollPane(_stringValue);
  -             _stringEditorPanel.add(scp, BorderLayout.CENTER);
  +             _editorPane = new JScrollPane(_stringValue);
   
  -             _choicePanel = new JPanel(new BorderLayout());
  -             _choicePanel.add(_valueChoice, BorderLayout.NORTH);
  +             _editorPanel = new JPanel(new BorderLayout());
  +             _editorPanel.add(_editorPane, BorderLayout.CENTER);
   
                JPanel usagePanel = new JPanel(new BorderLayout());
   
                JLabel usageLabel = new JLabel("Parameter usage:");
                usagePanel.add(usageLabel, BorderLayout.NORTH);
   
  -             scp = new JScrollPane(_usage);
  +             JScrollPane scp = new JScrollPane(_usage);
                usagePanel.add(scp, BorderLayout.CENTER);
   
  -             _splitPane.setTopComponent(_stringEditorPanel);
  +             _splitPane.setTopComponent(_editorPanel);
                _splitPane.setBottomComponent(usagePanel);
   
                add(_splitPane, BorderLayout.CENTER);
  @@ -257,55 +277,76 @@
         * @todo-javadoc Write javadocs for method
         */
        public void save() {
  +
  +             if (!_editor.supportsCustomEditor()) {
  +                     _editor.setAsText(_stringValue.getText());
  +             }
  +             _xtag.setAttribute(_tagParameter.getName(), _editor.getAsText());
  +             enableButtons(false);
        }
   
   
        /**
  -      * Describe what the method does
  -      *
  -      * @todo-javadoc Write javadocs for method
  +      * remove parameter from the tag
         */
        public void remove() {
  +             if (_tagParameter.isMandatory()) {
  +                     // silently tell user to fuck off. but this shall not happen
  +                     // anyway. AFAIK - button is disabled ;)
  +                     return;
  +             }
  +
  +             // well, xtags is not against removal. do it
  +             _xtag.removeAttribute(_tagParameter.getName());
  +
  +             TagTreeNode ttn = (TagTreeNode)_node.getParent();
  +             ((DefaultTreeModel)_tree.getModel()).removeNodeFromParent(_node);
  +             _tree.setSelectionPath(new TreePath(ttn.getPath()));
  +
        }
   
   
        /**
  -      * Describe what the method does
  -      *
  -      * @todo-javadoc Write javadocs for method
  +      * set display data from parameter contens reverting all edits
         */
        public void revert() {
                _usage.setText(_tagParameter.getUsage());
   
  -             if (_tagParameter.hasOptions()) {
  -                     // this bean has option sets, so provide user with predefined 
choice
  -                     _splitPane.setTopComponent(_choicePanel);
  -
  -                     // fill choice with data
  -                     try {
  -                             String[] validOptions = 
_tagParameter.getOptions(_programElement);
  -                             _valueChoice.removeAllItems();
  -                             for (int i = 0; i < validOptions.length; i++) {
  -                                     _valueChoice.addItem(validOptions[i]);
  -                                     if 
(validOptions[i].equals(_xtag.attributeValue(_tagParameter.getName()))) {
  -                                             
_valueChoice.setSelectedItem(validOptions[i]);
  -                                     }
  -                             }
  -
  -                     } catch (IllegalStateException ex) {
  -                             // swallow silently.
  +             _log.debug("looking for property editor for: " + 
_tagParameter.getValueClass());
  +             _editor = _tagParameter.getPropertyEditor(_programElement, _xtag);
  +             _log.debug("found:" + _editor);
  +             if (_editor.supportsCustomEditor()) {
  +                     _editor.addPropertyChangeListener(
  +                             new PropertyChangeListener() {
  +                                     public void propertyChange(PropertyChangeEvent 
evt) {
  +                                             valueChanged();
                        }
  +                             });
  +                     _splitPane.setTopComponent(_editor.getCustomEditor());
  +                     //_editorPanel.add(_editor.getCustomEditor(), 
BorderLayout.CENTER);
                }
                else {
  -                     _splitPane.setTopComponent(_stringEditorPanel);
  +                     _splitPane.setTopComponent(_editorPanel);
  +                     //      _editorPanel.add(_editorPane, BorderLayout.CENTER);
                        
_stringValue.setText(_xtag.attributeValue(_tagParameter.getName()));
   
                }
  +             synchronized (this) {
  +                     validate();
  +             }
                enableButtons(false);
        }
   
   
        /**
  +      * react on value change
  +      */
  +     public void valueChanged() {
  +             enableButtons(true);
  +     }
  +
  +
  +     /**
         * Describe what the method does
         *
         * @param enable Describe what the parameter does
  @@ -316,4 +357,5 @@
                _saveButton.setEnabled(enable);
                _revertButton.setEnabled(enable);
        }
  +
   }
  
  
  
  1.1                  xdocletgui/src/java/xdocletgui/swing/editor/UnknownTagPanel.java
  
  Index: UnknownTagPanel.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 xdocletgui.swing.*;
  
  import javax.swing.*;
  import javax.swing.text.*;
  import javax.swing.tree.*;
  import javax.swing.event.*;
  import javax.swing.undo.*;
  
  import xjavadoc.XTag;
  import xjavadoc.XDoc;
  import xjavadoc.XTagFactory;
  
  import java.awt.*;
  import java.awt.event.*;
  
  import xdocletgui.swing.UnknownTagTreeNode;
  import xdocletgui.swing.UnknownTagsTreeNode;
  
  /**
   * Describe what this class does
   *
   * @author kostik
   * @created April 11, 2002
   * @todo-javadoc Write javadocs
   */
  public class UnknownTagPanel extends UndoableEditorPanel {
        /**
         * tree model
         */
        JTree _tree;
  
        /**
         * node containing unknown tags
         */
        UnknownTagTreeNode _node;
  
        /**
         * removeButton
         */
        JButton _removeButton;
  
        /**
         * text to be edited
         */
  
        JTextArea _tagText;
  
        /**
         * description label
         */
        JLabel _description;
  
        /**
         * xtag contained in node
         */
        XTag _xtag;
  
        /**
         * Get static reference to Log4J Logger
         */
        private static org.apache.log4j.Category _log = 
org.apache.log4j.Category.getInstance(UnknownTagPanel.class.getName());
  
  
        /**
         * Describe what the UnknownTagPanel constructor does
         *
         * @param tree Describe what the parameter does
         * @todo-javadoc Write javadocs for constructor
         * @todo-javadoc Write javadocs for method parameter
         */
        public UnknownTagPanel(JTree tree) {
                super(new BorderLayout());
                _tree = tree;
                setBorder(BorderFactory.createTitledBorder("Tag text"));
  
                _description = new JLabel();
  
                add(_description, BorderLayout.NORTH);
  
                JScrollPane _scp = new JScrollPane(_text);
  
                add(_scp, BorderLayout.CENTER);
  
                JPanel buttonPanel = new JPanel();
                buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
                buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
  
                JButton _removeButton = new JButton("remove");
  
                _removeButton.addActionListener(
                        new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        remove();
                                }
                        });
  
                buttonPanel.add(_removeButton);
                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);
  
                add(buttonPanel, BorderLayout.SOUTH);
  
        }
  
  
        /**
         * Sets the Node attribute of the UnknownTagPanel object
         *
         * @param node The new Node value
         */
        public void setNode(UnknownTagTreeNode node) {
                _node = node;
                _xtag = _node.getXTag();
                _description.setText("Contens of " + _xtag.name() + " tag");
                revert();
        }
  
  
        /**
         * save changed tag contens
         */
        public void save() {
                // since Xtag is does not allow setting whole value
                // we just create new one and replace it in the node.
                // zap old one from XDoc
  
                XDoc doc = 
((ProgramElementTreeNode)_node.getParent().getParent()).getProgramElement().doc();
                doc.removeTag(_xtag);
                _log.debug("setting text: " + _text.getText().replace('\n', ' '));
                _xtag = doc.addTag(_xtag.name(), _text.getText().replace('\n', ' '));
  
                _node.setXTag(_xtag);
  
        }
  
  
        /**
         * Describe what the method does
         *
         * @todo-javadoc Write javadocs for method
         */
        public void revert() {
                _text.setText(_xtag.value());
                _log.debug("set text: " + _text.getText());
                _undo.discardAllEdits();
                enableButtons(false);
  
        }
  
  
        /**
         * remove tag
         */
        public void remove() {
  
                // remove node in question and tag from xdoc
                // select parent node.
                XDoc doc = 
((ProgramElementTreeNode)_node.getParent().getParent()).getProgramElement().doc();
                doc.removeTag(_xtag);
  
                UnknownTagsTreeNode parent = (UnknownTagsTreeNode)_node.getParent();
  
                ((DefaultTreeModel)_tree.getModel()).removeNodeFromParent(_node);
                _tree.setSelectionPath(new TreePath(parent.getPath()));
        }
  }
  
  
  

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

Reply via email to