Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/merlotxml/merlot/CommentEditPanel.java


1   /*
2     ====================================================================
3     Copyright (c) 1999-2001 ChannelPoint, Inc..  All rights reserved.
4     ====================================================================
5   
6     Redistribution and use in source and binary forms, with or without 
7     modification, are permitted provided that the following conditions 
8     are met:
9   
10    1. Redistribution of source code must retain the above copyright 
11    notice, this list of conditions and the following disclaimer. 
12  
13    2. Redistribution in binary form must reproduce the above copyright
14    notice, this list of conditions and the following disclaimer in the 
15    documentation and/or other materials provided with the distribution.
16  
17    3. All advertising materials mentioning features or use of this 
18    software must display the following acknowledgment:  "This product 
19    includes software developed by ChannelPoint, Inc. for use in the 
20    Merlot XML Editor (http://www.channelpoint.com/merlot/)."
21   
22    4. Any names trademarked by ChannelPoint, Inc. must not be used to 
23    endorse or promote products derived from this software without prior
24    written permission. For written permission, please contact
25    legal@channelpoint.com.
26  
27    5.  Products derived from this software may not be called "Merlot"
28    nor may "Merlot" appear in their names without prior written
29    permission of ChannelPoint, Inc.
30  
31    6. Redistribution of any form whatsoever must retain the following
32    acknowledgment:  "This product includes software developed by 
33    ChannelPoint, Inc. for use in the Merlot XML Editor 
34    (http://www.channelpoint.com/merlot/)."
35  
36    THIS SOFTWARE IS PROVIDED BY CHANNELPOINT, INC. "AS IS" AND ANY EXPRESSED OR 
37    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
38    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO 
39    EVENT SHALL CHANNELPOINT, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
40    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
41    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
42    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 
43    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
44    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
45    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46   ====================================================================
47  
48   For more information on ChannelPoint, Inc. please see http://www.channelpoint.com.  
49   For information on the Merlot project, please see 
50   http://www.channelpoint.com/merlot.
51  */
52  
53  package org.merlotxml.merlot;
54  
55  import java.io.*;
56  import java.awt.*;
57  import java.beans.*;
58  import java.text.MessageFormat;
59  
60  import java.awt.event.*;
61  import java.util.*;
62  import org.w3c.dom.*;
63  import javax.swing.*;
64  import javax.swing.text.*;
65  import com.sun.javax.swing.*;
66  
67  import matthew.awt.StrutLayout;
68  import com.ibm.xml.parser.*;
69  import org.merlotxml.util.xml.*;
70  
71  
72  /**
73   * This is a generic node editing panel which provides a component for each attribute
74   * listed with the element it's created to edit, along with a text box for PCDATA.
75   *  <P>
76   * This class can be extended to change what the user sees for each attribute field.
77   * Typically the easiest methods to overload for this type of custom editors are getEditComponent()
78   * and sometimes save().
79   *
80   * @author Kelly Campbell
81   */
82  
83  public class CommentEditPanel extends GenericDOMEditPanel
84  {
85    public CommentEditPanel(MerlotDOMComment node) 
86    {
87      super(node);
88    }
89    
90    protected void setupPanel() 
91    {
92      MerlotDebug.msg("SetupPanel");
93  
94      MerlotDOMComment commentNode = (MerlotDOMComment)_node;
95              
96      String s = commentNode.getText();
97      _text = new JTextArea(s);
98      _text.setLineWrap(true);
99      _text.setWrapStyleWord(true);
100     JScrollPane sp = new JScrollPane(_text, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 
101        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
102     sp.setPreferredSize(new Dimension(350,200));
103     JLabel l = new JLabel(MerlotResource.getString(UI,"xml.comment.label") + ":",JLabel.RIGHT);
104       
105     addAttributeComponent(l,sp,ALIGN_TOP);
106   }  
107 
108 
109 
110   protected void save(HashMap attributes) 
111     throws PropertyVetoException
112   {
113     MerlotDOMComment _commentNode = (MerlotDOMComment)_node;
114     if (_text != null) {
115       if (_text.getText().trim().equals("")) {
116           _commentNode.setText(null);
117       } else {
118         MerlotDebug.msg("Comment Node setText " + _text.getText());
119         _commentNode.setText(_text.getText());
120           
121         if (_subtext == null) {
122           // create a new TextNode
123           MerlotDOMNode nd = _node.newChild(DTDConstants.PCDATA_KEY);
124           if (nd instanceof MerlotDOMText) {
125             _subtext = (MerlotDOMText)nd;
126           }
127         }
128         if (_subtext != null) {
129           _subtext.setText(_text.getText());
130         }
131       }
132     }
133 
134 /*    // put together a hashtable of attributes to pass back to the node
135     Enumeration e = _attrComponents.keys();
136     while (e.hasMoreElements()) {
137       String key = (String)e.nextElement();
138       DTDAttribute dtdAttr = (DTDAttribute)_dtd_attributes.get(key);
139       Node oldnode = _node_attributes.getNamedItem(key);
140       String oldval;
141       if (oldnode != null) {
142         oldval = oldnode.getNodeValue();
143       } else {
144         oldval = "";
145       }
146       JComponent c = (JComponent)_attrComponents.get(key);
147       String newval = null;
148       if (c instanceof JTextField) {
149         newval = ((JTextField)c).getText();
150       } else if (c instanceof JComboBox) {
151         Object item = ((JComboBox)c).getSelectedItem();
152         if (item != null) {
153           newval = item.toString().trim();
154         }
155       } else {
156         // nothing to do now
157         MerlotDebug.msg("Unknown editing component in GenericDOMEditPanel.save: "+c);
158         if (attributes.containsKey(key)) {
159           newval = (String)attributes.get(key);
160         }
161       }
162       if (newval != null && newval.trim().equals("")) {
163         newval = null;
164       }
165       if (newval == null && dtdAttr != null && dtdAttr.getDefaultType() == DTDAttribute.REQUIRED) {
166         String err[] = new String[2];
167         err[0] = _node.getNodeName();
168         err[1] = key;
169         throw new PropertyVetoException(MessageFormat.format(MerlotResource.getString(ERR,"required.field"),err),new PropertyChangeEvent(_node,key,oldval,newval));
170       }
171 
172       fireVetoableChange(new PropertyChangeEvent(_node,key,oldval,newval));
173 
174       // check if the attribute is already set in the hashtable
175       if (!attributes.containsKey(key)) {
176         attributes.put(key,newval);
177       }
178                 
179     }
180     _node.setAttributes(attributes);
181 */  }
182   
183 }