KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > ElementPropertiesPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * ElementPropertiesPanel.java
22  *
23  * Created on June 12, 2006, 5:15 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.abe;
30
31 import java.awt.Color JavaDoc;
32 import java.awt.Component JavaDoc;
33 import java.awt.Font JavaDoc;
34 import java.beans.PropertyChangeEvent JavaDoc;
35 import java.beans.PropertyChangeListener JavaDoc;
36 import javax.swing.JLabel JavaDoc;
37 import org.netbeans.modules.xml.axi.AXIType;
38 import org.netbeans.modules.xml.axi.AbstractElement;
39 import org.netbeans.modules.xml.axi.AnyElement;
40 import org.netbeans.modules.xml.axi.Element;
41 import org.netbeans.modules.xml.axi.datatype.Datatype;
42 import org.openide.util.NbBundle;
43 import org.netbeans.modules.xml.axi.ContentModel;
44
45 /**
46  *
47  * @author girix
48  */

49 public class ElementPropertiesPanel extends ExtraPropertiesPanel{
50     private static final long serialVersionUID = 7526472295622776147L;
51     private AbstractElement element;
52     private InstanceUIContext context;
53     private JLabel JavaDoc contentType;
54     JLabel JavaDoc contentModelInfoLabel;
55     int interComponentSpacingOrig = 0;
56     /** Creates a new instance of ElementPropertiesPanel */
57     public ElementPropertiesPanel(AbstractElement element, InstanceUIContext context) {
58         super(true, context);
59         this.element = element;
60         this.context = context;
61         interComponentSpacingOrig = getInterComponentSpacing();
62         initialize();
63         this.element.addPropertyChangeListener(new ModelEventMediator(this, this.element){
64             public void _propertyChange(PropertyChangeEvent JavaDoc evt) {
65                 /*if( (evt.getPropertyName() == Element.PROP_MAXOCCURS)
66                 || (evt.getPropertyName() == Element.PROP_MINOCCURS) ){*/

67                 refreshItems();
68                 //}
69
}
70         });
71         
72         if(element instanceof Element){
73             Element elm = ((Element)this.element);
74             AXIType at = elm.getType();
75             if((at instanceof ContentModel)){
76                 ((ContentModel)at).addPropertyChangeListener(new ModelEventMediator(this, ((ContentModel)at)){
77                     public void _propertyChange(PropertyChangeEvent JavaDoc evt) {
78                         refreshItems();
79                     }
80                 });
81             }
82         }
83     }
84     
85     private void initialize() {
86         refreshItems();
87     }
88     
89     private void refreshItems(){
90         cleanupAll();
91         setInterComponentSpacing(interComponentSpacingOrig);
92         //add the constraints str
93
JLabel JavaDoc constraints = null;
94         if(element.supportsCardinality()){
95             String JavaDoc str = UIUtilities.getConstraintsString(element.getMinOccurs(),
96                     element.getMaxOccurs());
97             if(str != null){
98                 constraints = new JLabel JavaDoc(str);//new InplaceEditableLabel(str);
99
Font JavaDoc font = constraints.getFont();
100                 font = new Font JavaDoc(font.getFontName(), Font.PLAIN,
101                         InstanceDesignConstants.PROPS_FONT_SIZE);
102                 constraints.setFont(font);
103                 constraints.setForeground(new Color JavaDoc(139, 139, 139));
104                 constraints.setToolTipText(NbBundle.getMessage(ElementPropertiesPanel.class,
105                         "TTP_ELEMENT_CARDINALITY"));
106             }
107         }
108         //add the content model info.
109
if(!(element instanceof AnyElement)){
110             contentModelInfoLabel = UIUtilities.getContentModelInfoLabel(this.element, false, true, context);
111         }
112         
113         if( (constraints != null) && (contentModelInfoLabel != null) ){
114             append(constraints, true);
115             append(contentModelInfoLabel, false);
116         }else if(( (constraints == null) && (contentModelInfoLabel == null) )){
117             return;
118         }else{
119             Component JavaDoc comp = contentModelInfoLabel == null ? constraints :
120                 contentModelInfoLabel;
121             boolean transmit = (contentModelInfoLabel == null);
122             append(comp, transmit);
123         }
124         revalidate();
125         repaint();
126     }
127 }
128
Popular Tags