KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > customizer > SuiteCustomizerBasicBranding


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project.ui.customizer;
21
22 import java.awt.AlphaComposite JavaDoc;
23 import java.awt.Graphics JavaDoc;
24 import java.awt.Graphics2D JavaDoc;
25 import java.io.File JavaDoc;
26 import java.net.MalformedURLException JavaDoc;
27 import java.net.URL JavaDoc;
28 import javax.swing.ImageIcon JavaDoc;
29 import javax.swing.JFileChooser JavaDoc;
30 import javax.swing.JLabel JavaDoc;
31 import javax.swing.event.DocumentEvent JavaDoc;
32 import javax.swing.event.DocumentListener JavaDoc;
33 import org.netbeans.modules.apisupport.project.ui.UIUtil;
34 import org.netbeans.spi.project.ui.support.ProjectCustomizer;
35 import org.openide.ErrorManager;
36 import org.openide.util.NbBundle;
37
38 /**
39  * Represents <em>Application</em> panel in Suite customizer.
40  *
41  * @author Radek Matous
42  */

43 final class SuiteCustomizerBasicBranding extends NbPropertyPanel.Suite {
44     
45     private URL JavaDoc iconSource;
46     private ProjectCustomizer.Category cat;
47     private BasicCustomizer.SubCategoryProvider prov;
48     /**
49      * Creates new form SuiteCustomizerLibraries
50      */

51     public SuiteCustomizerBasicBranding(final SuiteProperties suiteProps, ProjectCustomizer.Category cat,
52             BasicCustomizer.SubCategoryProvider prov) {
53         super(suiteProps, SuiteCustomizerBasicBranding.class);
54         initComponents();
55         this.cat = cat;
56         this.prov = prov;
57         refresh();
58         checkValidity();
59         DocumentListener JavaDoc textFieldChangeListener = new UIUtil.DocumentAdapter() {
60             public void insertUpdate(DocumentEvent JavaDoc e) {
61                 checkValidity();
62             }
63         };
64         nameValue.getDocument().addDocumentListener(textFieldChangeListener);
65         titleValue.getDocument().addDocumentListener(textFieldChangeListener);
66     }
67     
68     public void addNotify() {
69         super.addNotify();
70         if (prov != null) {
71             showSubCategory(prov);
72             // do preselect just once..
73
prov = null;
74         }
75     }
76     
77     
78     protected void checkValidity() {
79         boolean panelValid = true;
80         
81         if (panelValid && nameValue.getText().trim().length() == 0) {
82             cat.setErrorMessage(NbBundle.getMessage(SuiteCustomizerBasicBranding.class, "ERR_EmptyName"));//NOI18N
83
panelValid = false;
84         }
85
86         if (panelValid && !nameValue.getText().trim().matches("[a-z][a-z0-9]*(_[a-z][a-z0-9]*)*")) {//NOI18N
87
cat.setErrorMessage(NbBundle.getMessage(SuiteCustomizerBasicBranding.class, "ERR_InvalidName"));//NOI18N
88
panelValid = false;
89         }
90         
91         if (panelValid && titleValue.getText().trim().length() == 0) {
92             cat.setErrorMessage(NbBundle.getMessage(SuiteCustomizerBasicBranding.class, "ERR_EmptyTitle"));//NOI18N
93
panelValid = false;
94         }
95         
96         if (panelValid) {
97             cat.setErrorMessage(null);
98         }
99         cat.setValid(panelValid);
100     }
101     
102     void refresh() {
103         getBrandingModel().brandingEnabledRefresh();
104         getBrandingModel().initName(true);
105         getBrandingModel().initTitle(true);
106         standaloneApp.setSelected(getBrandingModel().isBrandingEnabled());
107         addOn.setSelected(!getBrandingModel().isBrandingEnabled());
108         nameValue.setText(getBrandingModel().getName());
109         titleValue.setText(getBrandingModel().getTitle());
110         iconSource = getBrandingModel().getIconSource();
111         if (iconSource != null) {
112             ((ImagePreview)iconPreview).setImage(new ImageIcon JavaDoc(iconSource));
113         }
114         //iconLocation.setText(getBrandingModel().getIconLocation());
115

116         enableOrDisableComponents();
117         
118     }
119     
120     public void store() {
121         //getBrandingModel().setBrandingEnabled(buildWithBranding.isSelected());
122
getBrandingModel().setName(nameValue.getText());
123         getBrandingModel().setTitle(titleValue.getText());
124         getBrandingModel().setIconSource(iconSource);
125     }
126     
127     private void enableOrDisableComponents() {
128         nameValue.setEnabled(standaloneApp.isSelected());
129         name.setEnabled(standaloneApp.isSelected());
130         
131         titleValue.setEnabled(standaloneApp.isSelected());
132         title.setEnabled(standaloneApp.isSelected());
133         
134         browse.setEnabled(standaloneApp.isSelected());
135         
136         icon.setEnabled(standaloneApp.isSelected());
137         
138         iconPreview.setEnabled(standaloneApp.isSelected());
139     }
140     
141     /** This method is called from within the constructor to
142      * initialize the form.
143      * WARNING: Do NOT modify this code. The content of this method is
144      * always regenerated by the Form Editor.
145      */

146     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
147
private void initComponents() {
148         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
149
150         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
151         title = new javax.swing.JLabel JavaDoc();
152         titleValue = new javax.swing.JTextField JavaDoc();
153         iconPreview = new ImagePreview(BasicBrandingModel.ICON_WIDTH, BasicBrandingModel.ICON_HEIGHT);
154         name = new javax.swing.JLabel JavaDoc();
155         nameValue = new javax.swing.JTextField JavaDoc();
156         browse = new javax.swing.JButton JavaDoc();
157         icon = new javax.swing.JLabel JavaDoc();
158         addOn = new javax.swing.JRadioButton JavaDoc();
159         standaloneApp = new javax.swing.JRadioButton JavaDoc();
160
161         setLayout(new java.awt.GridBagLayout JavaDoc());
162
163         title.setLabelFor(titleValue);
164         org.openide.awt.Mnemonics.setLocalizedText(title, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/customizer/Bundle").getString("LBL_AppTitle"));
165         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
166         gridBagConstraints.gridx = 0;
167         gridBagConstraints.gridy = 3;
168         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
169         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
170         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
171         add(title, gridBagConstraints);
172         title.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/customizer/Bundle").getString("ACS_Title"));
173
174         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
175         gridBagConstraints.gridx = 1;
176         gridBagConstraints.gridy = 3;
177         gridBagConstraints.gridwidth = 2;
178         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
179         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
180         gridBagConstraints.weightx = 1.0;
181         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
182         add(titleValue, gridBagConstraints);
183
184         iconPreview.setLabelFor(iconPreview);
185         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
186         gridBagConstraints.gridx = 1;
187         gridBagConstraints.gridy = 4;
188         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
189         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
190         gridBagConstraints.weightx = 1.0;
191         gridBagConstraints.weighty = 1.0;
192         gridBagConstraints.insets = new java.awt.Insets JavaDoc(23, 0, 0, 12);
193         add(iconPreview, gridBagConstraints);
194
195         name.setLabelFor(nameValue);
196         org.openide.awt.Mnemonics.setLocalizedText(name, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/customizer/Bundle").getString("LBL_AppName"));
197         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
198         gridBagConstraints.gridx = 0;
199         gridBagConstraints.gridy = 2;
200         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
201         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
202         gridBagConstraints.insets = new java.awt.Insets JavaDoc(18, 0, 0, 0);
203         add(name, gridBagConstraints);
204         name.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/customizer/Bundle").getString("ACS_Name"));
205
206         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
207         gridBagConstraints.gridx = 1;
208         gridBagConstraints.gridy = 2;
209         gridBagConstraints.gridwidth = 2;
210         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
211         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
212         gridBagConstraints.weightx = 1.0;
213         gridBagConstraints.insets = new java.awt.Insets JavaDoc(18, 0, 0, 0);
214         add(nameValue, gridBagConstraints);
215
216         org.openide.awt.Mnemonics.setLocalizedText(browse, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/customizer/Bundle").getString("CTL_Browse"));
217         browse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
218             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
219                 browseActionPerformed(evt);
220             }
221         });
222
223         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
224         gridBagConstraints.gridx = 2;
225         gridBagConstraints.gridy = 4;
226         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
227         gridBagConstraints.insets = new java.awt.Insets JavaDoc(23, 0, 0, 0);
228         add(browse, gridBagConstraints);
229         browse.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/customizer/Bundle").getString("ACS_Browse"));
230
231         org.openide.awt.Mnemonics.setLocalizedText(icon, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/customizer/Bundle").getString("LBL_AppIcon"));
232         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
233         gridBagConstraints.gridx = 0;
234         gridBagConstraints.gridy = 4;
235         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
236         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
237         gridBagConstraints.insets = new java.awt.Insets JavaDoc(23, 0, 0, 12);
238         add(icon, gridBagConstraints);
239
240         buttonGroup1.add(addOn);
241         org.openide.awt.Mnemonics.setLocalizedText(addOn, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/customizer/Bundle").getString("LBL_AppAddOn"));
242         addOn.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
243         addOn.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
244         addOn.addActionListener(new java.awt.event.ActionListener JavaDoc() {
245             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
246                 addOnActionPerformed(evt);
247             }
248         });
249
250         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
251         gridBagConstraints.gridwidth = 3;
252         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
253         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
254         add(addOn, gridBagConstraints);
255         addOn.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/customizer/Bundle").getString("ACS_AddOn"));
256
257         buttonGroup1.add(standaloneApp);
258         org.openide.awt.Mnemonics.setLocalizedText(standaloneApp, java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/customizer/Bundle").getString("LBL_AppStandAlone"));
259         standaloneApp.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
260         standaloneApp.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
261         standaloneApp.addActionListener(new java.awt.event.ActionListener JavaDoc() {
262             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
263                 standaloneAppActionPerformed(evt);
264             }
265         });
266
267         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
268         gridBagConstraints.gridx = 0;
269         gridBagConstraints.gridy = 1;
270         gridBagConstraints.gridwidth = 3;
271         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
272         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
273         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
274         add(standaloneApp, gridBagConstraints);
275         standaloneApp.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/apisupport/project/ui/customizer/Bundle").getString("ACS_StandAloneApp"));
276
277     }
278     // </editor-fold>//GEN-END:initComponents
279

280     private void standaloneAppActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_standaloneAppActionPerformed
281
//TODO: Exclude IDE Modules must be done
282
enableOrDisableComponents();
283         getBrandingModel().setBrandingEnabled(standaloneApp.isSelected());
284     }//GEN-LAST:event_standaloneAppActionPerformed
285

286     private void addOnActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addOnActionPerformed
287
enableOrDisableComponents();
288         getBrandingModel().setBrandingEnabled(standaloneApp.isSelected());
289     }//GEN-LAST:event_addOnActionPerformed
290

291     private void browseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseActionPerformed
292
JFileChooser JavaDoc chooser = UIUtil.getIconFileChooser();
293         int ret = chooser.showDialog(this, NbBundle.getMessage(getClass(), "LBL_Select")); // NOI18N
294
if (ret == JFileChooser.APPROVE_OPTION) {
295             File JavaDoc file = chooser.getSelectedFile();
296             try {
297                 iconSource = file.toURI().toURL();
298             } catch (MalformedURLException JavaDoc ex) {
299                 ErrorManager.getDefault().notify(ex);
300             }
301             ((ImagePreview)iconPreview).setImage(new ImageIcon JavaDoc(iconSource));
302         }
303     }//GEN-LAST:event_browseActionPerformed
304

305     
306     // Variables declaration - do not modify//GEN-BEGIN:variables
307
private javax.swing.JRadioButton JavaDoc addOn;
308     private javax.swing.JButton JavaDoc browse;
309     private javax.swing.ButtonGroup JavaDoc buttonGroup1;
310     private javax.swing.JLabel JavaDoc icon;
311     private javax.swing.JLabel JavaDoc iconPreview;
312     private javax.swing.JLabel JavaDoc name;
313     private javax.swing.JTextField JavaDoc nameValue;
314     private javax.swing.JRadioButton JavaDoc standaloneApp;
315     private javax.swing.JLabel JavaDoc title;
316     private javax.swing.JTextField JavaDoc titleValue;
317     // End of variables declaration//GEN-END:variables
318

319     static class ImagePreview extends JLabel JavaDoc {
320         private ImageIcon JavaDoc image = null;
321         private int width;
322         private int height;
323 // private javax.swing.border.Border border;
324
ImagePreview(int width, int height){
325             //this.image = im;
326
this.width = width;
327             this.height = height;
328             //border = new TitledBorder(NbBundle.getMessage(getClass(),"LBL_IconPreview"));//NOI18N
329
//setBorder(border);
330
}
331         
332         public void paint(Graphics JavaDoc g) {
333             super.paint(g);
334             Graphics2D JavaDoc g2d = (Graphics2D JavaDoc)g;
335             
336             if (!isEnabled()) {
337                 g2d.setComposite(AlphaComposite.getInstance(
338                         AlphaComposite.SRC_OVER, 0.3f));
339             }
340             
341             if ((getWidth() > width) && (getHeight() > height) && image != null) {
342                 /*if (getBorder() == null) {
343                     setBorder(border);
344                 }*/

345                 int x = 0;//(getWidth()/2)-(width/2);
346
int y = 0;//(getHeight()/2)-(height/2);
347
g.drawImage(image.getImage(),x, y, width, height, this.getBackground(),null);
348             } /*else {
349                 if (getBorder() != null) {
350                     setBorder(null);
351                 }
352             }*/

353         }
354         
355         private void setImage(ImageIcon JavaDoc image) {
356             this.image = image;
357             repaint();
358         }
359     }
360     
361     private BasicBrandingModel getBrandingModel() {
362         return getProperties().getBrandingModel();
363     }
364     
365     private void showSubCategory(BasicCustomizer.SubCategoryProvider prov) {
366         if (SuiteCustomizer.APPLICATION.equals(prov.getCategory()) &&
367             SuiteCustomizer.APPLICATION_CREATE_STANDALONE_APPLICATION.equals(prov.getSubcategory())) {
368             standaloneApp.requestFocus();
369         }
370     }
371     
372 }
373
Popular Tags