KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > bluej > CustomizerProviderImpl


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.bluej;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.awt.event.WindowAdapter JavaDoc;
26 import java.awt.event.WindowEvent JavaDoc;
27 import java.text.MessageFormat JavaDoc;
28 import javax.swing.JComponent JavaDoc;
29 import org.netbeans.api.project.Project;
30 import org.netbeans.api.project.ProjectUtils;
31 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
32 import org.netbeans.spi.project.ui.CustomizerProvider;
33 import org.netbeans.spi.project.ui.support.ProjectCustomizer;
34 import org.netbeans.spi.project.ui.support.ProjectCustomizer.CategoryComponentProvider;
35 import org.openide.util.NbBundle;
36
37 /**
38  *
39  * @author mkleint
40  */

41 public class CustomizerProviderImpl implements CustomizerProvider {
42     private BluejProject project;
43
44     private UpdateHelper updateHelper;
45
46     private PropertyEvaluator evaluator;
47     /** Creates a new instance of CustomizerProviderImpl */
48     public CustomizerProviderImpl(BluejProject proj, PropertyEvaluator eval, UpdateHelper helper) {
49         project = proj;
50         updateHelper = helper;
51         evaluator = eval;
52     }
53     
54     public void showCustomizer() {
55         
56         ProjectCustomizer.Category runCat = ProjectCustomizer.Category.create("run", "Run", null, null);
57         BluejProjectProperties props = new BluejProjectProperties(project, updateHelper, evaluator);
58         CategoryComponentProvider provider = new SubCategoryProvider(props);
59         OptionListener listener = new OptionListener(project, props);
60         Dialog JavaDoc dialog = ProjectCustomizer.createCustomizerDialog(new ProjectCustomizer.Category[] {runCat}, provider, null, listener, null);
61 //// OptionListener listener = new OptionListener( project, uiProperties );
62
// dialog = ProjectCustomizer.createCustomizerDialog( CUSTOMIZER_FOLDER_PATH, context, preselectedCategory, listener, null );
63
dialog.addWindowListener( listener );
64             dialog.setTitle( MessageFormat.format(
65                     NbBundle.getMessage( CustomizerProviderImpl.class, "LBL_Customizer_Title" ), // NOI18N
66
new Object JavaDoc[] { ProjectUtils.getInformation(project).getDisplayName() } ) );
67 //
68
dialog.setVisible(true);
69         
70     }
71     
72     
73     
74     /** Listens to the actions on the Customizer's option buttons */
75     private class OptionListener extends WindowAdapter JavaDoc implements ActionListener JavaDoc {
76         
77         private Project project;
78         private BluejProjectProperties uiProperties;
79         private Dialog JavaDoc dialog;
80         
81         OptionListener( Project project, BluejProjectProperties uiProperties ) {
82             this.project = project;
83             this.uiProperties = uiProperties;
84         }
85         
86         public void setDialog(Dialog JavaDoc dial) {
87             dialog = dial;
88         }
89         
90         // Listening to OK button ----------------------------------------------
91

92         public void actionPerformed( ActionEvent JavaDoc e ) {
93             // Store the properties into project
94
uiProperties.save();
95             
96             // Close & dispose the the dialog
97
if ( dialog != null ) {
98                 dialog.setVisible(false);
99                 dialog.dispose();
100             }
101         }
102         
103         // Listening to window events ------------------------------------------
104

105         public void windowClosed( WindowEvent JavaDoc e) {
106         }
107         
108         public void windowClosing(WindowEvent JavaDoc e) {
109             //Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed}
110
//may not be called
111
if ( dialog != null ) {
112                 dialog.setVisible(false);
113                 dialog.dispose();
114             }
115         }
116     }
117     
118     static final class SubCategoryProvider implements ProjectCustomizer.CategoryComponentProvider {
119
120         private BluejProjectProperties properties;
121         
122         
123         SubCategoryProvider(BluejProjectProperties props) {
124             properties = props;
125         }
126         
127         public JComponent JavaDoc create(ProjectCustomizer.Category category) {
128             return new CustomizerRun(properties);
129         }
130     }
131     
132 }
133
Popular Tags