001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.schema.abe.wizard;
043:
044: import java.awt.event.ItemListener;
045: import java.util.ArrayList;
046: import java.util.Iterator;
047: import java.util.List;
048: import javax.swing.JPanel;
049: import javax.swing.event.ChangeEvent;
050: import javax.swing.event.ChangeListener;
051: import org.netbeans.modules.xml.axi.SchemaGenerator;
052: import org.openide.util.NbBundle;
053:
054: public final class SchemaTransformPatternSelectionUI extends JPanel {
055: private static final long serialVersionUID = 1L;
056:
057: private transient SchemaGenerator.Pattern edp;
058:
059: /**
060: * Creates new form SchemaTransformPatternSelectionUI
061: */
062: public SchemaTransformPatternSelectionUI(SchemaGenerator.Pattern edp) {
063: this .edp = edp;
064: initComponents();
065: patternExamplePane.setActionMap(null);
066: patternExamplePane.getActions();
067: patternExamplePane.getEditorKit().getActions();
068: reset();
069: }
070:
071: public String getName() {
072: return NbBundle.getMessage(
073: SchemaTransformPatternSelectionUI.class,
074: "SchemaTransform_PatternSelection");
075: }
076:
077: public void reset() {
078: removeListeners();
079: initializeUISelection();
080: addListeners();
081: }
082:
083: private void addListeners() {
084: if (elementCheckBoxListener == null) {
085: elementCheckBoxListener = new ItemListener() {
086: public void itemStateChanged(
087: java.awt.event.ItemEvent evt) {
088: if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED
089: || evt.getStateChange() == java.awt.event.ItemEvent.DESELECTED) {
090: selectPattern(getSelectedDesignPattern());
091: }
092: }
093: };
094: }
095: if (typeCheckBoxListener == null) {
096: typeCheckBoxListener = new ItemListener() {
097: public void itemStateChanged(
098: java.awt.event.ItemEvent evt) {
099: if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED
100: || evt.getStateChange() == java.awt.event.ItemEvent.DESELECTED) {
101: selectPattern(getSelectedDesignPattern());
102: }
103: }
104: };
105: }
106: singleGlobalElement.addItemListener(elementCheckBoxListener);
107: createtype.addItemListener(elementCheckBoxListener);
108: }
109:
110: private void removeListeners() {
111: singleGlobalElement.removeItemListener(elementCheckBoxListener);
112: createtype.removeItemListener(elementCheckBoxListener);
113: }
114:
115: private void initializeUISelection() {
116: selectInitialDesignPattern(edp);
117:
118: existingPatternText.setText(NbBundle.getMessage(
119: SchemaTransformPatternSelectionUI.class,
120: "LBL_SchemaTransform_" + edp.toString()));
121: }
122:
123: public boolean isSingleGlobalElementSelected() {
124: return singleGlobalElement.isSelected();
125: }
126:
127: public void setSingleGlobalElementSelected(boolean select) {
128: singleGlobalElement.setSelected(select);
129: multipleGlobalElement.setSelected(!select);
130: }
131:
132: public boolean isTypeReuseSelected() {
133: return createtype.isSelected();
134: }
135:
136: public void setTypeReuseSelected(boolean select) {
137: createtype.setSelected(select);
138: noType.setSelected(!select);
139: }
140:
141: private void selectPattern(SchemaGenerator.Pattern p) {
142: selectedPatternText.setText(NbBundle.getMessage(
143: SchemaTransformPatternSelectionUI.class,
144: "LBL_SchemaTransform_" + p.toString()));
145: patternDescText.setText(NbBundle.getMessage(
146: SchemaTransformPatternSelectionUI.class,
147: "MSG_SchemaTransform_" + p.toString() + "_Desc"));
148: // patternDescText.setToolTipText(
149: // NbBundle.getMessage(
150: // SchemaTransformPatternSelectionUI.class,
151: // "MSG_SchemaTransform_"+p.toString()+"_Desc"));
152: patternExamplePane.setText(NbBundle.getMessage(
153: SchemaTransformPatternSelectionUI.class,
154: "MSG_SchemaTransform_" + p.toString() + "_Example"));
155: patternExamplePane.setCaretPosition(0);
156: fireChange();
157: }
158:
159: public SchemaGenerator.Pattern getSelectedDesignPattern() {
160: if (isSingleGlobalElementSelected() && !isTypeReuseSelected())
161: return SchemaGenerator.Pattern.RUSSIAN_DOLL;
162: else if (isSingleGlobalElementSelected()
163: && isTypeReuseSelected())
164: return SchemaGenerator.Pattern.VENITIAN_BLIND;
165: else if (!isSingleGlobalElementSelected()
166: && !isTypeReuseSelected())
167: return SchemaGenerator.Pattern.SALAMI_SLICE;
168: else if (!isSingleGlobalElementSelected()
169: && isTypeReuseSelected())
170: return SchemaGenerator.Pattern.GARDEN_OF_EDEN;
171:
172: return SchemaGenerator.DEFAULT_DESIGN_PATTERN;
173: }
174:
175: private void selectInitialDesignPattern(SchemaGenerator.Pattern p) {
176: if (p == SchemaGenerator.Pattern.RUSSIAN_DOLL) {
177: setSingleGlobalElementSelected(true);
178: setTypeReuseSelected(false);
179: } else if (p == SchemaGenerator.Pattern.VENITIAN_BLIND) {
180: setSingleGlobalElementSelected(true);
181: setTypeReuseSelected(true);
182: } else if (p == SchemaGenerator.Pattern.SALAMI_SLICE) {
183: setSingleGlobalElementSelected(false);
184: setTypeReuseSelected(false);
185: } else if (p == SchemaGenerator.Pattern.GARDEN_OF_EDEN) {
186: setSingleGlobalElementSelected(false);
187: setTypeReuseSelected(true);
188: }
189:
190: selectPattern(p);
191: }
192:
193: private final List<ChangeListener> listeners = new ArrayList<ChangeListener>();
194:
195: public void addChangeListener(ChangeListener l) {
196: listeners.add(l);
197: }
198:
199: public void removeChangeListener(ChangeListener l) {
200: listeners.remove(l);
201: }
202:
203: private void fireChange() {
204: ChangeEvent e = new ChangeEvent(this );
205: Iterator it = listeners.iterator();
206: while (it.hasNext()) {
207: ((ChangeListener) it.next()).stateChanged(e);
208: }
209: }
210:
211: /** This method is called from within the constructor to
212: * initialize the form.
213: * WARNING: Do NOT modify this code. The content of this method is
214: * always regenerated by the Form Editor.
215: */
216: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
217: private void initComponents() {
218:
219: globalElementGroup = new javax.swing.ButtonGroup();
220: typeGroup = new javax.swing.ButtonGroup();
221: selectedPatternDescLabel = new javax.swing.JLabel();
222: patternExampleLabel = new javax.swing.JLabel();
223: selectedPatternText = new javax.swing.JLabel();
224: jScrollPane1 = new javax.swing.JScrollPane();
225: patternExamplePane = new javax.swing.JEditorPane() {
226: static final long serialVersionUID = 1L;
227:
228: // disable mouse and mouse motion events
229: protected void processMouseEvent(java.awt.event.MouseEvent e) {
230: e.consume();
231: }
232:
233: protected void processMouseMotionEvent(
234: java.awt.event.MouseEvent e) {
235: e.consume();
236: }
237: };
238: existingPatternDescLabel = new javax.swing.JLabel();
239: existingPatternText = new javax.swing.JLabel();
240: singleGlobalElement = new javax.swing.JRadioButton();
241: multipleGlobalElement = new javax.swing.JRadioButton();
242: globalElement = new javax.swing.JLabel();
243: reusableType = new javax.swing.JLabel();
244: createtype = new javax.swing.JRadioButton();
245: noType = new javax.swing.JRadioButton();
246: patternDescText = new javax.swing.JLabel();
247:
248: java.util.ResourceBundle bundle = java.util.ResourceBundle
249: .getBundle("org/netbeans/modules/xml/schema/abe/wizard/Bundle"); // NOI18N
250: org.openide.awt.Mnemonics
251: .setLocalizedText(
252: selectedPatternDescLabel,
253: bundle
254: .getString("LBL_SchemaTransform_Selected_DesignPattern_Desc")); // NOI18N
255: selectedPatternDescLabel
256: .setToolTipText(bundle
257: .getString("HINT_SchemaTransform_Selected_DesignPattern_Desc")); // NOI18N
258:
259: org.openide.awt.Mnemonics
260: .setLocalizedText(
261: patternExampleLabel,
262: bundle
263: .getString("LBL_SchemaTransform_DesignPattern_Example")); // NOI18N
264: patternExampleLabel
265: .setToolTipText(bundle
266: .getString("HINT_SchemaTransform_DesignPattern_Example")); // NOI18N
267:
268: org.openide.awt.Mnemonics
269: .setLocalizedText(
270: selectedPatternText,
271: bundle
272: .getString("LBL_SchemaTransform_Selected_DesignPattern_Text")); // NOI18N
273:
274: jScrollPane1.setMinimumSize(null);
275: jScrollPane1.setPreferredSize(null);
276:
277: patternExamplePane.setContentType("text/xml");
278: patternExamplePane.setEditable(false);
279: patternExamplePane.setToolTipText(bundle
280: .getString("HINT_SchemaTransform_Example")); // NOI18N
281: patternExamplePane.setEnabled(false);
282: patternExamplePane.setMinimumSize(null);
283: patternExamplePane.setPreferredSize(null);
284: jScrollPane1.setViewportView(patternExamplePane);
285: patternExamplePane.getAccessibleContext().setAccessibleName(
286: bundle.getString("MSG_SchemaTransform_Example")); // NOI18N
287: patternExamplePane
288: .getAccessibleContext()
289: .setAccessibleDescription(
290: bundle
291: .getString("HINT_SchemaTransform_Example")); // NOI18N
292:
293: org.openide.awt.Mnemonics
294: .setLocalizedText(
295: existingPatternDescLabel,
296: bundle
297: .getString("LBL_SchemaTransform_Existing_DesignPattern_Desc")); // NOI18N
298: existingPatternDescLabel
299: .setToolTipText(bundle
300: .getString("HINT_SchemaTransform_Existing_DesignPattern_Desc")); // NOI18N
301:
302: org.openide.awt.Mnemonics
303: .setLocalizedText(
304: existingPatternText,
305: bundle
306: .getString("LBL_SchemaTransform_Existing_DesignPattern_Text")); // NOI18N
307:
308: globalElementGroup.add(singleGlobalElement);
309: org.openide.awt.Mnemonics
310: .setLocalizedText(
311: singleGlobalElement,
312: bundle
313: .getString("LBL_SchemaTransform_SingleGlobalElement")); // NOI18N
314: singleGlobalElement.setToolTipText(bundle
315: .getString("HINT_SchemaTransform_SingleGlobalElement")); // NOI18N
316: singleGlobalElement.setBorder(javax.swing.BorderFactory
317: .createEmptyBorder(0, 0, 0, 0));
318: singleGlobalElement.setMargin(new java.awt.Insets(0, 0, 0, 0));
319:
320: globalElementGroup.add(multipleGlobalElement);
321: org.openide.awt.Mnemonics
322: .setLocalizedText(
323: multipleGlobalElement,
324: bundle
325: .getString("LBL_SchemaTransform_MultipleGlobalElement")); // NOI18N
326: multipleGlobalElement
327: .setToolTipText(bundle
328: .getString("HINT_SchemaTransform_MultipleGlobalElement")); // NOI18N
329: multipleGlobalElement.setBorder(javax.swing.BorderFactory
330: .createEmptyBorder(0, 0, 0, 0));
331: multipleGlobalElement
332: .setMargin(new java.awt.Insets(0, 0, 0, 0));
333:
334: org.openide.awt.Mnemonics.setLocalizedText(globalElement,
335: bundle.getString("LBL_SchemaTransform_GlobalElement")); // NOI18N
336: globalElement.setToolTipText(bundle
337: .getString("HINT_SchemaTransform_GlobalElement")); // NOI18N
338:
339: org.openide.awt.Mnemonics.setLocalizedText(reusableType, bundle
340: .getString("LBL_SchemaTransform_Type")); // NOI18N
341: reusableType.setToolTipText(bundle
342: .getString("HINT_SchemaTransform_Type")); // NOI18N
343:
344: typeGroup.add(createtype);
345: org.openide.awt.Mnemonics.setLocalizedText(createtype, bundle
346: .getString("LBL_SchemaTransform_ReusableTypes")); // NOI18N
347: createtype.setToolTipText(bundle
348: .getString("HINT_SchemaTransform_ReusableTypes")); // NOI18N
349: createtype.setBorder(javax.swing.BorderFactory
350: .createEmptyBorder(0, 0, 0, 0));
351: createtype.setMargin(new java.awt.Insets(0, 0, 0, 0));
352:
353: typeGroup.add(noType);
354: org.openide.awt.Mnemonics.setLocalizedText(noType, bundle
355: .getString("LBL_SchemaTransform_No_ReusableTypes")); // NOI18N
356: noType.setToolTipText(bundle
357: .getString("HINT_SchemaTransform_No_ReusableTypes")); // NOI18N
358: noType.setBorder(javax.swing.BorderFactory.createEmptyBorder(0,
359: 0, 0, 0));
360: noType.setMargin(new java.awt.Insets(0, 0, 0, 0));
361:
362: patternDescText
363: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
364: patternDescText
365: .setVerticalAlignment(javax.swing.SwingConstants.TOP);
366: patternDescText.setMaximumSize(new java.awt.Dimension(333333,
367: 333333));
368: patternDescText.setMinimumSize(null);
369: patternDescText.setPreferredSize(null);
370:
371: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
372: this );
373: this .setLayout(layout);
374: layout
375: .setHorizontalGroup(layout
376: .createParallelGroup(
377: org.jdesktop.layout.GroupLayout.LEADING)
378: .add(
379: org.jdesktop.layout.GroupLayout.TRAILING,
380: layout
381: .createSequentialGroup()
382: .addContainerGap()
383: .add(
384: layout
385: .createParallelGroup(
386: org.jdesktop.layout.GroupLayout.TRAILING)
387: .add(
388: org.jdesktop.layout.GroupLayout.LEADING,
389: jScrollPane1,
390: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
391: 505,
392: Short.MAX_VALUE)
393: .add(
394: org.jdesktop.layout.GroupLayout.LEADING,
395: patternDescText,
396: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
397: 505,
398: Short.MAX_VALUE)
399: .add(
400: org.jdesktop.layout.GroupLayout.LEADING,
401: globalElement)
402: .add(
403: org.jdesktop.layout.GroupLayout.LEADING,
404: layout
405: .createSequentialGroup()
406: .add(
407: 10,
408: 10,
409: 10)
410: .add(
411: layout
412: .createParallelGroup(
413: org.jdesktop.layout.GroupLayout.TRAILING)
414: .add(
415: org.jdesktop.layout.GroupLayout.LEADING,
416: singleGlobalElement)
417: .add(
418: org.jdesktop.layout.GroupLayout.LEADING,
419: multipleGlobalElement)))
420: .add(
421: org.jdesktop.layout.GroupLayout.LEADING,
422: reusableType)
423: .add(
424: org.jdesktop.layout.GroupLayout.LEADING,
425: layout
426: .createSequentialGroup()
427: .add(
428: 10,
429: 10,
430: 10)
431: .add(
432: layout
433: .createParallelGroup(
434: org.jdesktop.layout.GroupLayout.LEADING)
435: .add(
436: noType)
437: .add(
438: createtype)))
439: .add(
440: org.jdesktop.layout.GroupLayout.LEADING,
441: layout
442: .createSequentialGroup()
443: .add(
444: selectedPatternDescLabel)
445: .addPreferredGap(
446: org.jdesktop.layout.LayoutStyle.RELATED)
447: .add(
448: selectedPatternText)
449: .add(
450: 35,
451: 35,
452: 35)
453: .add(
454: existingPatternDescLabel)
455: .addPreferredGap(
456: org.jdesktop.layout.LayoutStyle.RELATED)
457: .add(
458: existingPatternText))
459: .add(
460: org.jdesktop.layout.GroupLayout.LEADING,
461: patternExampleLabel))
462: .addContainerGap()));
463: layout
464: .setVerticalGroup(layout
465: .createParallelGroup(
466: org.jdesktop.layout.GroupLayout.LEADING)
467: .add(
468: layout
469: .createSequentialGroup()
470: .addContainerGap()
471: .add(globalElement)
472: .addPreferredGap(
473: org.jdesktop.layout.LayoutStyle.RELATED)
474: .add(singleGlobalElement)
475: .add(7, 7, 7)
476: .add(multipleGlobalElement)
477: .add(6, 6, 6)
478: .add(reusableType)
479: .addPreferredGap(
480: org.jdesktop.layout.LayoutStyle.RELATED)
481: .add(createtype)
482: .addPreferredGap(
483: org.jdesktop.layout.LayoutStyle.RELATED)
484: .add(noType)
485: .add(18, 18, 18)
486: .add(
487: layout
488: .createParallelGroup(
489: org.jdesktop.layout.GroupLayout.BASELINE)
490: .add(
491: selectedPatternDescLabel)
492: .add(
493: selectedPatternText)
494: .add(
495: existingPatternDescLabel)
496: .add(
497: existingPatternText))
498: .addPreferredGap(
499: org.jdesktop.layout.LayoutStyle.RELATED)
500: .add(
501: patternDescText,
502: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
503: 72,
504: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
505: .addPreferredGap(
506: org.jdesktop.layout.LayoutStyle.RELATED)
507: .add(patternExampleLabel)
508: .addPreferredGap(
509: org.jdesktop.layout.LayoutStyle.RELATED)
510: .add(
511: jScrollPane1,
512: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
513: 95,
514: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
515: .add(29, 29, 29)));
516:
517: patternDescText.getAccessibleContext().setAccessibleName(
518: bundle.getString("MSG_SchemaTransform_Desc")); // NOI18N
519: patternDescText.getAccessibleContext()
520: .setAccessibleDescription(
521: bundle.getString("HINT_SchemaTransform_Desc")); // NOI18N
522: }// </editor-fold>//GEN-END:initComponents
523:
524: // Variables declaration - do not modify//GEN-BEGIN:variables
525: private javax.swing.JRadioButton createtype;
526: private javax.swing.JLabel existingPatternDescLabel;
527: private javax.swing.JLabel existingPatternText;
528: private javax.swing.JLabel globalElement;
529: private javax.swing.ButtonGroup globalElementGroup;
530: private javax.swing.JScrollPane jScrollPane1;
531: private javax.swing.JRadioButton multipleGlobalElement;
532: private javax.swing.JRadioButton noType;
533: private javax.swing.JLabel patternDescText;
534: private javax.swing.JLabel patternExampleLabel;
535: private javax.swing.JEditorPane patternExamplePane;
536: private javax.swing.JLabel reusableType;
537: private javax.swing.JLabel selectedPatternDescLabel;
538: private javax.swing.JLabel selectedPatternText;
539: private javax.swing.JRadioButton singleGlobalElement;
540: private javax.swing.ButtonGroup typeGroup;
541: // End of variables declaration//GEN-END:variables
542:
543: private transient ItemListener typeCheckBoxListener;
544: private transient ItemListener elementCheckBoxListener;
545: private transient SchemaGenerator.Pattern currentPattern;
546: }
|