KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > wizard > SchemaTransformPatternSelectionUI


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 package org.netbeans.modules.xml.schema.abe.wizard;
21
22 import java.awt.event.ItemListener JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import javax.swing.JPanel JavaDoc;
27 import javax.swing.event.ChangeEvent JavaDoc;
28 import javax.swing.event.ChangeListener JavaDoc;
29 import org.netbeans.modules.xml.axi.SchemaGenerator;
30 import org.openide.util.NbBundle;
31
32 public final class SchemaTransformPatternSelectionUI extends JPanel JavaDoc {
33     private static final long serialVersionUID = 1L;
34     
35     private transient SchemaGenerator.Pattern edp;
36     
37     /**
38      * Creates new form SchemaTransformPatternSelectionUI
39      */

40     public SchemaTransformPatternSelectionUI(SchemaGenerator.Pattern edp) {
41         this.edp = edp;
42         initComponents();
43         patternExamplePane.setActionMap(null);patternExamplePane.getActions();
44         patternExamplePane.getEditorKit().getActions();
45         reset();
46     }
47     
48     public String JavaDoc getName() {
49         return NbBundle.getMessage(
50                 SchemaTransformPatternSelectionUI.class,
51                 "SchemaTransform_PatternSelection");
52     }
53     
54     public void reset() {
55         removeListeners();
56         initializeUISelection();
57         addListeners();
58     }
59     
60     private void addListeners() {
61         if(elementCheckBoxListener == null) {
62             elementCheckBoxListener = new ItemListener JavaDoc() {
63                 public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
64                     if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED
65                             || evt.getStateChange() == java.awt.event.ItemEvent.DESELECTED) {
66                         selectPattern(getSelectedDesignPattern());
67                     }
68                 }
69             };
70         }
71         if(typeCheckBoxListener == null) {
72             typeCheckBoxListener = new ItemListener JavaDoc() {
73                 public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
74                     if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED
75                             || evt.getStateChange() == java.awt.event.ItemEvent.DESELECTED) {
76                         selectPattern(getSelectedDesignPattern());
77                     }
78                 }
79             };
80         }
81         singleGlobalElement.addItemListener(elementCheckBoxListener);
82         createtype.addItemListener(elementCheckBoxListener);
83     }
84     
85     private void removeListeners() {
86         singleGlobalElement.removeItemListener(elementCheckBoxListener);
87         createtype.removeItemListener(elementCheckBoxListener);
88     }
89     
90     private void initializeUISelection() {
91         selectInitialDesignPattern(edp);
92         
93         existingPatternText.setText(
94                 NbBundle.getMessage(
95                 SchemaTransformPatternSelectionUI.class,
96                 "LBL_SchemaTransform_"+edp.toString()));
97     }
98     
99     public boolean isSingleGlobalElementSelected() {
100         return singleGlobalElement.isSelected();
101     }
102     
103     public void setSingleGlobalElementSelected(boolean select) {
104         singleGlobalElement.setSelected(select);
105         multipleGlobalElement.setSelected(!select);
106     }
107     
108     public boolean isTypeReuseSelected() {
109         return createtype.isSelected();
110     }
111     
112     public void setTypeReuseSelected(boolean select) {
113         createtype.setSelected(select);
114         noType.setSelected(!select);
115     }
116     
117     private void selectPattern(SchemaGenerator.Pattern p){
118         selectedPatternText.setText(
119                 NbBundle.getMessage(
120                 SchemaTransformPatternSelectionUI.class,
121                 "LBL_SchemaTransform_"+p.toString()));
122         patternDescText.setText(
123                 NbBundle.getMessage(
124                 SchemaTransformPatternSelectionUI.class,
125                 "MSG_SchemaTransform_"+p.toString()+"_Desc"));
126 // patternDescText.setToolTipText(
127
// NbBundle.getMessage(
128
// SchemaTransformPatternSelectionUI.class,
129
// "MSG_SchemaTransform_"+p.toString()+"_Desc"));
130
patternExamplePane.setText(
131                 NbBundle.getMessage(
132                 SchemaTransformPatternSelectionUI.class,
133                 "MSG_SchemaTransform_"+p.toString()+"_Example"));
134         patternExamplePane.setCaretPosition(0);
135         fireChange();
136     }
137     
138     public SchemaGenerator.Pattern getSelectedDesignPattern() {
139         if(isSingleGlobalElementSelected() &&
140                 !isTypeReuseSelected())
141             return SchemaGenerator.Pattern.RUSSIAN_DOLL;
142         else if(isSingleGlobalElementSelected() &&
143                 isTypeReuseSelected())
144             return SchemaGenerator.Pattern.VENITIAN_BLIND;
145         else if(!isSingleGlobalElementSelected() &&
146                 !isTypeReuseSelected())
147             return SchemaGenerator.Pattern.SALAMI_SLICE;
148         else if(!isSingleGlobalElementSelected() &&
149                 isTypeReuseSelected())
150             return SchemaGenerator.Pattern.GARDEN_OF_EDEN;
151         
152         return SchemaGenerator.DEFAULT_DESIGN_PATTERN;
153     }
154     
155     private void selectInitialDesignPattern(SchemaGenerator.Pattern p) {
156         if(p == SchemaGenerator.Pattern.RUSSIAN_DOLL) {
157             setSingleGlobalElementSelected(true);
158             setTypeReuseSelected(false);
159         } else if(p == SchemaGenerator.Pattern.VENITIAN_BLIND) {
160             setSingleGlobalElementSelected(true);
161             setTypeReuseSelected(true);
162         } else if(p == SchemaGenerator.Pattern.SALAMI_SLICE) {
163             setSingleGlobalElementSelected(false);
164             setTypeReuseSelected(false);
165         } else if(p == SchemaGenerator.Pattern.GARDEN_OF_EDEN) {
166             setSingleGlobalElementSelected(false);
167             setTypeReuseSelected(true);
168         }
169         
170         selectPattern(p);
171     }
172     
173     private final List JavaDoc<ChangeListener JavaDoc> listeners = new ArrayList JavaDoc<ChangeListener JavaDoc>();
174     public void addChangeListener(ChangeListener JavaDoc l) {
175         listeners.add(l);
176     }
177     
178     public void removeChangeListener(ChangeListener JavaDoc l) {
179         listeners.remove(l);
180     }
181     
182     private void fireChange() {
183         ChangeEvent JavaDoc e = new ChangeEvent JavaDoc(this);
184         Iterator JavaDoc it = listeners.iterator();
185         while (it.hasNext()) {
186             ((ChangeListener JavaDoc)it.next()).stateChanged(e);
187         }
188     }
189     
190     /** This method is called from within the constructor to
191      * initialize the form.
192      * WARNING: Do NOT modify this code. The content of this method is
193      * always regenerated by the Form Editor.
194      */

195     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
196
private void initComponents() {
197         globalElementGroup = new javax.swing.ButtonGroup JavaDoc();
198         typeGroup = new javax.swing.ButtonGroup JavaDoc();
199         selectedPatternDescLabel = new javax.swing.JLabel JavaDoc();
200         patternExampleLabel = new javax.swing.JLabel JavaDoc();
201         selectedPatternText = new javax.swing.JLabel JavaDoc();
202         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
203         patternExamplePane = new javax.swing.JEditorPane JavaDoc()
204         {
205             static final long serialVersionUID = 1L;
206             // disable mouse and mouse motion events
207
protected void processMouseEvent(java.awt.event.MouseEvent JavaDoc e)
208             {
209                 e.consume();
210             }
211             protected void processMouseMotionEvent(java.awt.event.MouseEvent JavaDoc e)
212             {
213                 e.consume();
214             }
215         };
216         existingPatternDescLabel = new javax.swing.JLabel JavaDoc();
217         existingPatternText = new javax.swing.JLabel JavaDoc();
218         singleGlobalElement = new javax.swing.JRadioButton JavaDoc();
219         multipleGlobalElement = new javax.swing.JRadioButton JavaDoc();
220         globalElement = new javax.swing.JLabel JavaDoc();
221         reusableType = new javax.swing.JLabel JavaDoc();
222         createtype = new javax.swing.JRadioButton JavaDoc();
223         noType = new javax.swing.JRadioButton JavaDoc();
224         patternDescText = new javax.swing.JLabel JavaDoc();
225
226         org.openide.awt.Mnemonics.setLocalizedText(selectedPatternDescLabel, java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("LBL_SchemaTransform_Selected_DesignPattern_Desc"));
227         selectedPatternDescLabel.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("HINT_SchemaTransform_Selected_DesignPattern_Desc"));
228
229         org.openide.awt.Mnemonics.setLocalizedText(patternExampleLabel, java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("LBL_SchemaTransform_DesignPattern_Example"));
230         patternExampleLabel.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("HINT_SchemaTransform_DesignPattern_Example"));
231
232         org.openide.awt.Mnemonics.setLocalizedText(selectedPatternText, java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("LBL_SchemaTransform_Selected_DesignPattern_Text"));
233
234         patternExamplePane.setEditable(false);
235         patternExamplePane.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("MSG_SchemaTransform_Example"));
236         patternExamplePane.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("HINT_SchemaTransform_Example"));
237         patternExamplePane.setContentType("text/xml");
238         patternExamplePane.setEnabled(false);
239         jScrollPane1.setViewportView(patternExamplePane);
240         patternExamplePane.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("MSG_SchemaTransform_Example"));
241         patternExamplePane.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("HINT_SchemaTransform_Example"));
242
243         org.openide.awt.Mnemonics.setLocalizedText(existingPatternDescLabel, java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("LBL_SchemaTransform_Existing_DesignPattern_Desc"));
244         existingPatternDescLabel.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("HINT_SchemaTransform_Existing_DesignPattern_Desc"));
245
246         org.openide.awt.Mnemonics.setLocalizedText(existingPatternText, java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("LBL_SchemaTransform_Existing_DesignPattern_Text"));
247
248         globalElementGroup.add(singleGlobalElement);
249         org.openide.awt.Mnemonics.setLocalizedText(singleGlobalElement, java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("LBL_SchemaTransform_SingleGlobalElement"));
250         singleGlobalElement.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("HINT_SchemaTransform_SingleGlobalElement"));
251         singleGlobalElement.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
252         singleGlobalElement.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
253
254         globalElementGroup.add(multipleGlobalElement);
255         org.openide.awt.Mnemonics.setLocalizedText(multipleGlobalElement, java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("LBL_SchemaTransform_MultipleGlobalElement"));
256         multipleGlobalElement.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("HINT_SchemaTransform_MultipleGlobalElement"));
257         multipleGlobalElement.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
258         multipleGlobalElement.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
259
260         org.openide.awt.Mnemonics.setLocalizedText(globalElement, java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("LBL_SchemaTransform_GlobalElement"));
261         globalElement.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("HINT_SchemaTransform_GlobalElement"));
262
263         org.openide.awt.Mnemonics.setLocalizedText(reusableType, java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("LBL_SchemaTransform_Type"));
264         reusableType.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("HINT_SchemaTransform_Type"));
265
266         typeGroup.add(createtype);
267         org.openide.awt.Mnemonics.setLocalizedText(createtype, java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("LBL_SchemaTransform_ReusableTypes"));
268         createtype.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("HINT_SchemaTransform_ReusableTypes"));
269         createtype.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
270         createtype.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
271
272         typeGroup.add(noType);
273         org.openide.awt.Mnemonics.setLocalizedText(noType, java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("LBL_SchemaTransform_No_ReusableTypes"));
274         noType.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("HINT_SchemaTransform_No_ReusableTypes"));
275         noType.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
276         noType.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
277
278         patternDescText.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
279         patternDescText.setVerticalAlignment(javax.swing.SwingConstants.TOP);
280         patternDescText.setMaximumSize(new java.awt.Dimension JavaDoc(333333, 333333));
281         patternDescText.setMinimumSize(new java.awt.Dimension JavaDoc(3, 17));
282         patternDescText.setPreferredSize(new java.awt.Dimension JavaDoc(3, 17));
283         patternDescText.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("MSG_SchemaTransform_Desc"));
284         patternDescText.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle").getString("HINT_SchemaTransform_Desc"));
285
286         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
287         this.setLayout(layout);
288         layout.setHorizontalGroup(
289             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
290             .add(layout.createSequentialGroup()
291                 .addContainerGap()
292                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
293                     .add(globalElement)
294                     .add(layout.createSequentialGroup()
295                         .add(10, 10, 10)
296                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
297                             .add(org.jdesktop.layout.GroupLayout.LEADING, singleGlobalElement)
298                             .add(org.jdesktop.layout.GroupLayout.LEADING, multipleGlobalElement))
299                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
300                     .add(reusableType)
301                     .add(layout.createSequentialGroup()
302                         .add(10, 10, 10)
303                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
304                             .add(noType)
305                             .add(createtype)))
306                     .add(patternExampleLabel)
307                     .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE)
308                     .add(layout.createSequentialGroup()
309                         .add(selectedPatternDescLabel)
310                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
311                         .add(selectedPatternText)
312                         .add(35, 35, 35)
313                         .add(existingPatternDescLabel)
314                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
315                         .add(existingPatternText))
316                     .add(patternDescText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 482, Short.MAX_VALUE))
317                 .addContainerGap())
318         );
319         layout.setVerticalGroup(
320             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
321             .add(layout.createSequentialGroup()
322                 .addContainerGap()
323                 .add(globalElement)
324                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
325                 .add(singleGlobalElement)
326                 .add(7, 7, 7)
327                 .add(multipleGlobalElement)
328                 .add(6, 6, 6)
329                 .add(reusableType)
330                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
331                 .add(createtype)
332                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
333                 .add(noType)
334                 .add(18, 18, 18)
335                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
336                     .add(selectedPatternDescLabel)
337                     .add(selectedPatternText)
338                     .add(existingPatternDescLabel)
339                     .add(existingPatternText))
340                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
341                 .add(patternDescText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 64, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
342                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
343                 .add(patternExampleLabel)
344                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
345                 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 106, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
346                 .addContainerGap())
347         );
348     }// </editor-fold>//GEN-END:initComponents
349

350     // Variables declaration - do not modify//GEN-BEGIN:variables
351
private javax.swing.JRadioButton JavaDoc createtype;
352     private javax.swing.JLabel JavaDoc existingPatternDescLabel;
353     private javax.swing.JLabel JavaDoc existingPatternText;
354     private javax.swing.JLabel JavaDoc globalElement;
355     private javax.swing.ButtonGroup JavaDoc globalElementGroup;
356     private javax.swing.JScrollPane JavaDoc jScrollPane1;
357     private javax.swing.JRadioButton JavaDoc multipleGlobalElement;
358     private javax.swing.JRadioButton JavaDoc noType;
359     private javax.swing.JLabel JavaDoc patternDescText;
360     private javax.swing.JLabel JavaDoc patternExampleLabel;
361     private javax.swing.JEditorPane JavaDoc patternExamplePane;
362     private javax.swing.JLabel JavaDoc reusableType;
363     private javax.swing.JLabel JavaDoc selectedPatternDescLabel;
364     private javax.swing.JLabel JavaDoc selectedPatternText;
365     private javax.swing.JRadioButton JavaDoc singleGlobalElement;
366     private javax.swing.ButtonGroup JavaDoc typeGroup;
367     // End of variables declaration//GEN-END:variables
368

369     private transient ItemListener JavaDoc typeCheckBoxListener;
370     private transient ItemListener JavaDoc elementCheckBoxListener;
371     private transient SchemaGenerator.Pattern currentPattern;
372 }
373
374
Popular Tags