KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > generate > DialogGenerate


1 /*
2
3 [The "BSD licence"]
4 Copyright (c) 2005 Jean Bovet
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions
9 are met:
10
11 1. Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
16 3. The name of the author may not be used to endorse or promote products
17 derived from this software without specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 */

31
32 package org.antlr.works.generate;
33
34 import com.jgoodies.forms.factories.Borders;
35 import com.jgoodies.forms.factories.FormFactory;
36 import com.jgoodies.forms.layout.CellConstraints;
37 import com.jgoodies.forms.layout.ColumnSpec;
38 import com.jgoodies.forms.layout.FormLayout;
39 import com.jgoodies.forms.layout.RowSpec;
40 import org.antlr.xjlib.appkit.frame.XJDialog;
41 import org.antlr.xjlib.appkit.utils.XJFileChooser;
42 import org.antlr.xjlib.foundation.XJSystem;
43 import org.antlr.works.prefs.AWPrefs;
44
45 import javax.swing.*;
46 import java.awt.*;
47 import java.awt.event.ActionEvent JavaDoc;
48 import java.awt.event.ActionListener JavaDoc;
49
50 public class DialogGenerate extends XJDialog {
51
52     public DialogGenerate(Container parent) {
53         super(parent, true);
54
55         initComponents();
56         setSize(612, 145);
57
58         if(XJSystem.isMacOS()) {
59             CellConstraints cc = new CellConstraints();
60
61             buttonBar.remove(cancelButton);
62             buttonBar.remove(okButton);
63
64             buttonBar.add(cancelButton, cc.xy(2, 1));
65             buttonBar.add(okButton, cc.xy(4, 1));
66         }
67
68         setDefaultButton(okButton);
69         setOKButton(okButton);
70         setCancelButton(cancelButton);
71
72         outputPathField.setText(AWPrefs.getOutputPath());
73
74         browseButton.addActionListener(new ActionListener JavaDoc() {
75             public void actionPerformed(ActionEvent JavaDoc event) {
76                 if(XJFileChooser.shared().displayChooseDirectory(DialogGenerate.this.getJavaComponent())) {
77                     outputPathField.setText(XJFileChooser.shared().getSelectedFilePath());
78                 }
79             }
80         });
81     }
82
83     public void dialogWillCloseOK() {
84         AWPrefs.setOutputPath(getOutputPath());
85     }
86
87     public void setDebugOnly() {
88         debugInfoButton.setSelected(true);
89         debugInfoButton.setVisible(false);
90     }
91
92     public boolean generateDebugInformation() {
93         return debugInfoButton.isSelected();
94     }
95
96     public String JavaDoc getOutputPath() {
97         return outputPathField.getText();
98     }
99
100     private void initComponents() {
101         // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
102
// Generated using JFormDesigner Open Source Project license - ANTLR (www.antlr.org)
103
dialogPane = new JPanel();
104         contentPane = new JPanel();
105         label1 = new JLabel();
106         outputPathField = new JTextField();
107         browseButton = new JButton();
108         debugInfoButton = new JCheckBox();
109         buttonBar = new JPanel();
110         okButton = new JButton();
111         cancelButton = new JButton();
112         CellConstraints cc = new CellConstraints();
113
114         //======== this ========
115
setTitle("Generate");
116         Container contentPane2 = getContentPane();
117         contentPane2.setLayout(new BorderLayout());
118
119         //======== dialogPane ========
120
{
121             dialogPane.setBorder(Borders.DIALOG_BORDER);
122             dialogPane.setLayout(new BorderLayout());
123
124             //======== contentPane ========
125
{
126                 contentPane.setLayout(new FormLayout(
127                     new ColumnSpec[] {
128                         FormFactory.DEFAULT_COLSPEC,
129                         FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
130                         new ColumnSpec("max(min;200dlu):grow"),
131                         FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
132                         FormFactory.DEFAULT_COLSPEC
133                     },
134                     new RowSpec[] {
135                         FormFactory.DEFAULT_ROWSPEC,
136                         FormFactory.LINE_GAP_ROWSPEC,
137                         FormFactory.DEFAULT_ROWSPEC
138                     }));
139
140                 //---- label1 ----
141
label1.setText("Output path:");
142                 label1.setHorizontalAlignment(SwingConstants.RIGHT);
143                 contentPane.add(label1, cc.xy(1, 1));
144                 contentPane.add(outputPathField, cc.xy(3, 1));
145
146                 //---- browseButton ----
147
browseButton.setText("Browse...");
148                 contentPane.add(browseButton, cc.xy(5, 1));
149
150                 //---- debugInfoButton ----
151
debugInfoButton.setText("Debug information");
152                 contentPane.add(debugInfoButton, cc.xy(3, 3));
153             }
154             dialogPane.add(contentPane, BorderLayout.CENTER);
155
156             //======== buttonBar ========
157
{
158                 buttonBar.setBorder(Borders.BUTTON_BAR_GAP_BORDER);
159                 buttonBar.setLayout(new FormLayout(
160                     new ColumnSpec[] {
161                         FormFactory.GLUE_COLSPEC,
162                         FormFactory.BUTTON_COLSPEC,
163                         FormFactory.RELATED_GAP_COLSPEC,
164                         FormFactory.BUTTON_COLSPEC
165                     },
166                     RowSpec.decodeSpecs("pref")));
167
168                 //---- okButton ----
169
okButton.setText("OK");
170                 buttonBar.add(okButton, cc.xy(2, 1));
171
172                 //---- cancelButton ----
173
cancelButton.setText("Cancel");
174                 buttonBar.add(cancelButton, cc.xy(4, 1));
175             }
176             dialogPane.add(buttonBar, BorderLayout.SOUTH);
177         }
178         contentPane2.add(dialogPane, BorderLayout.CENTER);
179         pack();
180         // JFormDesigner - End of component initialization //GEN-END:initComponents
181
}
182
183     // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
184
// Generated using JFormDesigner Open Source Project license - ANTLR (www.antlr.org)
185
private JPanel dialogPane;
186     private JPanel contentPane;
187     private JLabel label1;
188     private JTextField outputPathField;
189     private JButton browseButton;
190     private JCheckBox debugInfoButton;
191     private JPanel buttonBar;
192     private JButton okButton;
193     private JButton cancelButton;
194     // JFormDesigner - End of variables declaration //GEN-END:variables
195

196 }
197
Popular Tags