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.uml.project.ui.customizer.uiapi;
043:
044: import java.awt.Component;
045: import java.awt.GridBagConstraints;
046: import java.beans.PropertyChangeEvent;
047: import java.beans.PropertyChangeListener;
048: import javax.swing.JComponent;
049: import javax.swing.JPanel;
050: import org.netbeans.spi.project.ui.support.ProjectCustomizer;
051: import org.openide.util.HelpCtx;
052: import org.openide.util.NbBundle;
053:
054: /**
055: *
056: * @author phrebejk
057: */
058: public class CustomizerPane extends javax.swing.JPanel implements
059: HelpCtx.Provider {
060:
061: public static final String HELP_CTX_PROPERTY = "helpCtxProperty";
062: public static final String OK_ENABLE_PROPERTY = "okEnableProperty";
063:
064: private Component currentCustomizer;
065: private HelpCtx currentHelpCtx;
066:
067: private GridBagConstraints fillConstraints;
068:
069: private ProjectCustomizer.CategoryComponentProvider componentProvider;
070:
071: //private DialogDescriptor dialogDescriptor;
072:
073: /** Creates new form J2SECustomizer */
074: public CustomizerPane(
075: JPanel categoryView,
076: CategoryModel categoryModel,
077: ProjectCustomizer.CategoryComponentProvider componentProvider) {
078: initComponents();
079: // HelpCtx.setHelpIDString( customizerPanel, "org.netbeans.modules.java.j2seproject.ui.customizer.J2SECustomizer" ); // NOI18N
080: this .getAccessibleContext().setAccessibleDescription(
081: NbBundle.getMessage(CustomizerPane.class,
082: "AD_CustomizerPane")); // NOI18N
083: this .componentProvider = componentProvider;
084: fillConstraints = new GridBagConstraints();
085: fillConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
086: fillConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
087: fillConstraints.fill = java.awt.GridBagConstraints.BOTH;
088: fillConstraints.weightx = 1.0;
089: fillConstraints.weighty = 1.0;
090: categoryModel
091: .addPropertyChangeListener(new CategoryChangeListener());
092: categoryPanel.add(categoryView, fillConstraints);
093: setCategory(categoryModel.getCurrentCategory());
094: }
095:
096: /** This method is called from within the constructor to
097: * initialize the form.
098: * WARNING: Do NOT modify this code. The content of this method is
099: * always regenerated by the Form Editor.
100: */
101: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
102: private void initComponents() {
103: java.awt.GridBagConstraints gridBagConstraints;
104:
105: jLabel1 = new javax.swing.JLabel();
106: categoryPanel = new javax.swing.JPanel();
107: customizerPanel = new javax.swing.JPanel();
108:
109: setLayout(new java.awt.GridBagLayout());
110:
111: setPreferredSize(new java.awt.Dimension(750, 450));
112: jLabel1.setLabelFor(categoryPanel);
113: gridBagConstraints = new java.awt.GridBagConstraints();
114: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
115: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
116: gridBagConstraints.insets = new java.awt.Insets(8, 11, 0, 0);
117: add(jLabel1, gridBagConstraints);
118: jLabel1.getAccessibleContext().setAccessibleName("");
119: jLabel1.getAccessibleContext().setAccessibleDescription("");
120:
121: categoryPanel.setLayout(new java.awt.GridBagLayout());
122:
123: categoryPanel.setBorder(javax.swing.BorderFactory
124: .createEtchedBorder());
125: categoryPanel.setMinimumSize(new java.awt.Dimension(220, 4));
126: categoryPanel.setPreferredSize(new java.awt.Dimension(220, 4));
127: gridBagConstraints = new java.awt.GridBagConstraints();
128: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
129: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
130: gridBagConstraints.weighty = 1.0;
131: gridBagConstraints.insets = new java.awt.Insets(3, 11, 8, 11);
132: add(categoryPanel, gridBagConstraints);
133: categoryPanel.getAccessibleContext().setAccessibleName("");
134: categoryPanel.getAccessibleContext().setAccessibleDescription(
135: "");
136:
137: customizerPanel.setLayout(new java.awt.GridBagLayout());
138:
139: gridBagConstraints = new java.awt.GridBagConstraints();
140: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
141: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
142: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
143: gridBagConstraints.weightx = 1.0;
144: gridBagConstraints.weighty = 1.0;
145: gridBagConstraints.insets = new java.awt.Insets(3, 0, 8, 11);
146: add(customizerPanel, gridBagConstraints);
147: customizerPanel.getAccessibleContext().setAccessibleName("");
148: customizerPanel.getAccessibleContext()
149: .setAccessibleDescription("");
150:
151: }// </editor-fold>//GEN-END:initComponents
152:
153: // Variables declaration - do not modify//GEN-BEGIN:variables
154: private javax.swing.JPanel categoryPanel;
155: private javax.swing.JPanel customizerPanel;
156: private javax.swing.JLabel jLabel1;
157:
158: // End of variables declaration//GEN-END:variables
159:
160: // HelpCtx.Provider implementation -----------------------------------------
161:
162: public HelpCtx getHelpCtx() {
163: return currentHelpCtx;
164: /*
165: Debug.out.println("Get Help Ctx");
166: Thread.dumpStack();
167:
168: if ( currentCustomizer != null ) {
169: // Debug.out.println( "C " + HelpCtx.findHelp( currentCustomizer ) );
170: return HelpCtx.findHelp( currentCustomizer );
171: }
172:
173: else {
174: // Debug.out.println( "P " + HelpCtx.findHelp( currentCustomizer ) );
175: return HelpCtx.findHelp( customizerPanel );
176: }
177:
178: // XXX
179: return null;
180: */
181: }
182:
183: // Private methods ---------------------------------------------------------
184:
185: private void setCategory(ProjectCustomizer.Category newCategory) {
186: if (newCategory == null) {
187: return;
188: }
189:
190: if (currentCustomizer != null) {
191: customizerPanel.remove(currentCustomizer);
192: }
193:
194: JComponent newCustomizer = componentProvider
195: .create(newCategory);
196:
197: if (newCustomizer != null) {
198: currentCustomizer = newCustomizer;
199: currentHelpCtx = HelpCtx.findHelp(currentCustomizer);
200:
201: /*
202: if ( currentCustomizer instanceof javax.swing.JComponent ) {
203: ((javax.swing.JComponent)currentCustomizer).setPreferredSize( new java.awt.Dimension( 600, 0 ) );
204: }
205: */
206: customizerPanel.add(currentCustomizer, fillConstraints);
207: customizerPanel.validate();
208: customizerPanel.repaint();
209: newCustomizer.addPropertyChangeListener(mListener);
210: firePropertyChange(HELP_CTX_PROPERTY, null, getHelpCtx());
211: } else {
212: currentCustomizer = null;
213: }
214:
215: }
216:
217: CategoryPanelChangeListener mListener = new CategoryPanelChangeListener();
218:
219: // Private innerclasses ----------------------------------------------------
220:
221: /** Listens to selection change and shows the customizers as
222: * panels
223: */
224: private class CategoryChangeListener implements
225: PropertyChangeListener {
226:
227: public void propertyChange(PropertyChangeEvent evt) {
228:
229: if (CategoryModel.PROP_CURRENT_CATEGORY.equals(evt
230: .getPropertyName())) {
231: ProjectCustomizer.Category newCategory = (ProjectCustomizer.Category) evt
232: .getNewValue();
233: setCategory(newCategory);
234: }
235: }
236: }
237:
238: private class CategoryPanelChangeListener implements
239: PropertyChangeListener {
240: public void propertyChange(PropertyChangeEvent evt) {
241: // Just forward this property change event to my listeners
242: firePropertyChange(evt.getPropertyName(),
243: evt.getOldValue(), evt.getNewValue());
244: }
245: }
246: }
|