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-2006 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: */package org.netbeans.modules.vmd.midp.palette.wizard;
041:
042: import org.netbeans.api.project.Project;
043: import org.netbeans.api.project.ProjectInformation;
044: import org.netbeans.api.project.ui.OpenProjects;
045: import org.netbeans.modules.vmd.api.io.javame.MidpProjectPropertiesSupport;
046:
047: import javax.swing.*;
048: import java.awt.*;
049: import java.util.Vector;
050: import org.openide.util.NbBundle;
051:
052: /**
053: * @author David Kaspar
054: */
055: public final class AddToPaletteVisualPanel1 extends JPanel {
056:
057: private AddToPaletteWizardPanel1 wizardPanel;
058:
059: public AddToPaletteVisualPanel1(AddToPaletteWizardPanel1 wizardPanel) {
060: this .wizardPanel = wizardPanel;
061: initComponents();
062: projectCombo.setRenderer(new ProjectListCellRenderer());
063: }
064:
065: public String getName() {
066: return NbBundle.getMessage(AddToPaletteVisualPanel1.class,
067: "TITLE_SelectProject"); // NOI18N
068: }
069:
070: public Project getActiveProject() {
071: return (Project) projectCombo.getSelectedItem();
072: }
073:
074: public void reload(Project project) {
075: Project[] projects = OpenProjects.getDefault()
076: .getOpenProjects();
077: Vector projectsVector = new Vector();
078: for (Project prj : projects)
079: if (MidpProjectPropertiesSupport.isMobileProject(prj))
080: projectsVector.add(prj);
081: projectCombo.setModel(new DefaultComboBoxModel(projectsVector));
082: if (project == null) {
083: Project prj = OpenProjects.getDefault().getMainProject();
084: if (MidpProjectPropertiesSupport.isMobileProject(prj))
085: project = prj;
086: }
087: if (project == null && projects.length > 0)
088: project = projects[0];
089: projectCombo.setSelectedItem(project);
090: }
091:
092: /** This method is called from within the constructor to
093: * initialize the form.
094: * WARNING: Do NOT modify this code. The content of this method is
095: * always regenerated by the Form Editor.
096: */
097: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
098: private void initComponents() {
099:
100: projectCombo = new javax.swing.JComboBox();
101: javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
102:
103: projectCombo
104: .addActionListener(new java.awt.event.ActionListener() {
105: public void actionPerformed(
106: java.awt.event.ActionEvent evt) {
107: projectComboActionPerformed(evt);
108: }
109: });
110:
111: jLabel1.setLabelFor(projectCombo);
112: org.openide.awt.Mnemonics.setLocalizedText(jLabel1, NbBundle
113: .getMessage(AddToPaletteVisualPanel1.class,
114: "DISP_SelectProject")); // NOI18N
115:
116: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
117: this );
118: this .setLayout(layout);
119: layout
120: .setHorizontalGroup(layout
121: .createParallelGroup(
122: org.jdesktop.layout.GroupLayout.LEADING)
123: .add(
124: layout
125: .createSequentialGroup()
126: .addContainerGap()
127: .add(
128: layout
129: .createParallelGroup(
130: org.jdesktop.layout.GroupLayout.LEADING)
131: .add(jLabel1)
132: .add(
133: projectCombo,
134: 0,
135: 376,
136: Short.MAX_VALUE))
137: .addContainerGap()));
138: layout.setVerticalGroup(layout.createParallelGroup(
139: org.jdesktop.layout.GroupLayout.LEADING).add(
140: layout.createSequentialGroup().addContainerGap().add(
141: jLabel1).addPreferredGap(
142: org.jdesktop.layout.LayoutStyle.RELATED).add(
143: projectCombo,
144: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
145: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
146: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
147: .addContainerGap(243, Short.MAX_VALUE)));
148:
149: projectCombo.getAccessibleContext().setAccessibleName(
150: org.openide.util.NbBundle.getMessage(
151: AddToPaletteVisualPanel1.class,
152: "ACCESSIBLE_NAME_projectCombo")); // NOI18N
153: projectCombo.getAccessibleContext().setAccessibleDescription(
154: org.openide.util.NbBundle.getMessage(
155: AddToPaletteVisualPanel1.class,
156: "ACCESSIBLE_DESCRIPTION_projectCombo")); // NOI18N
157: jLabel1.getAccessibleContext().setAccessibleName(
158: org.openide.util.NbBundle.getMessage(
159: AddToPaletteVisualPanel1.class,
160: "ACCESSIBLE_NAME_jLabel1_2")); // NOI18N
161: jLabel1.getAccessibleContext().setAccessibleDescription(
162: org.openide.util.NbBundle.getMessage(
163: AddToPaletteVisualPanel1.class,
164: "ACCESSIBLE_DESCRIPTION_jLabel1_2")); // NOI18N
165: }// </editor-fold>//GEN-END:initComponents
166:
167: private void projectComboActionPerformed(
168: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_projectComboActionPerformed
169: wizardPanel.fireChangeEvent();
170: }//GEN-LAST:event_projectComboActionPerformed
171:
172: // Variables declaration - do not modify//GEN-BEGIN:variables
173: private javax.swing.JComboBox projectCombo;
174:
175: // End of variables declaration//GEN-END:variables
176:
177: public static class ProjectListCellRenderer extends
178: DefaultListCellRenderer {
179:
180: public Component getListCellRendererComponent(JList list,
181: Object value, int index, boolean isSelected,
182: boolean cellHasFocus) {
183: if (value == null)
184: return super .getListCellRendererComponent(list, value,
185: index, isSelected, cellHasFocus);
186: ProjectInformation info = ((Project) value).getLookup()
187: .lookup(ProjectInformation.class);
188: super.getListCellRendererComponent(list,
189: info != null ? info.getDisplayName() : null, index,
190: isSelected, cellHasFocus);
191: if (info != null)
192: setIcon(info.getIcon());
193: return this;
194: }
195:
196: }
197:
198: }
|