001: /*
002: * To change this template, choose Tools | Templates
003: * and open the template in the editor.
004: */
005:
006: package com.caucho.netbeans.ide.ui;
007:
008: import com.caucho.netbeans.ide.AddInstanceIterator;
009: import java.io.File;
010: import javax.swing.JFileChooser;
011: import javax.swing.JPanel;
012: import javax.swing.SwingUtilities;
013: import javax.swing.event.ChangeEvent;
014: import javax.swing.event.DocumentEvent;
015: import javax.swing.event.DocumentListener;
016:
017: public final class AddServerVisualPanel extends JPanel {
018: private AddInstanceIterator _addServer;
019: private AddServerLocationPanel _wizardPanel;
020:
021: AddServerVisualPanel(AddInstanceIterator addServer,
022: AddServerLocationPanel wizardPanel) {
023: initComponents();
024:
025: _addServer = addServer;
026: _wizardPanel = wizardPanel;
027:
028: this .jResinHome.setText(addServer.getResinHome());
029: this .jSpinner1.setValue(addServer.getPort());
030:
031: this .jResinHome.getDocument().addDocumentListener(
032: new DocumentListener() {
033: public void changedUpdate(DocumentEvent e) {
034: _wizardPanel
035: .stateChanged(new ChangeEvent(this ));
036: }
037:
038: public void insertUpdate(DocumentEvent e) {
039: _wizardPanel
040: .stateChanged(new ChangeEvent(this ));
041: }
042:
043: public void removeUpdate(DocumentEvent e) {
044: _wizardPanel
045: .stateChanged(new ChangeEvent(this ));
046: }
047: });
048: }
049:
050: public String getResinHome() {
051: return this .jResinHome.getText().trim();
052: }
053:
054: public int getPort() {
055: return Integer.valueOf(this .jSpinner1.getValue().toString());
056: }
057:
058: @Override
059: public String getName() {
060: return "Set Resin Home";
061: }
062:
063: /** This method is called from within the constructor to
064: * initialize the form.
065: * WARNING: Do NOT modify this code. The content of this method is
066: * always regenerated by the Form Editor.
067: */
068: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
069: private void initComponents() {
070:
071: jLabel1 = new javax.swing.JLabel();
072: jResinHome = new javax.swing.JTextField();
073: jButton1 = new javax.swing.JButton();
074: jLabel2 = new javax.swing.JLabel();
075: jLabel3 = new javax.swing.JLabel();
076: jSpinner1 = new javax.swing.JSpinner();
077:
078: org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
079: "Resin Home");
080:
081: jResinHome.setText("jResinHome");
082:
083: org.openide.awt.Mnemonics.setLocalizedText(jButton1, "Browse");
084: jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
085: public void mouseClicked(java.awt.event.MouseEvent evt) {
086: jButton1MouseClicked(evt);
087: }
088: });
089:
090: org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
091: "Resin Home Location");
092:
093: org.openide.awt.Mnemonics.setLocalizedText(jLabel3, "Port");
094:
095: jSpinner1.setEditor(new javax.swing.JSpinner.NumberEditor(
096: jSpinner1, ""));
097: jSpinner1
098: .addChangeListener(new javax.swing.event.ChangeListener() {
099: public void stateChanged(
100: javax.swing.event.ChangeEvent evt) {
101: jSpinner1StateChanged(evt);
102: }
103: });
104: jSpinner1
105: .addPropertyChangeListener(new java.beans.PropertyChangeListener() {
106: public void propertyChange(
107: java.beans.PropertyChangeEvent evt) {
108: jSpinner1PropertyChange(evt);
109: }
110: });
111:
112: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
113: this );
114: this .setLayout(layout);
115: layout
116: .setHorizontalGroup(layout
117: .createParallelGroup(
118: org.jdesktop.layout.GroupLayout.LEADING)
119: .add(
120: layout
121: .createSequentialGroup()
122: .addContainerGap()
123: .add(
124: layout
125: .createParallelGroup(
126: org.jdesktop.layout.GroupLayout.LEADING)
127: .add(jLabel2)
128: .add(
129: layout
130: .createSequentialGroup()
131: .add(
132: layout
133: .createParallelGroup(
134: org.jdesktop.layout.GroupLayout.LEADING)
135: .add(
136: jLabel1)
137: .add(
138: jLabel3))
139: .add(
140: 28,
141: 28,
142: 28)
143: .add(
144: layout
145: .createParallelGroup(
146: org.jdesktop.layout.GroupLayout.LEADING)
147: .add(
148: layout
149: .createSequentialGroup()
150: .add(
151: jResinHome,
152: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
153: 154,
154: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
155: .add(
156: 18,
157: 18,
158: 18)
159: .add(
160: jButton1))
161: .add(
162: jSpinner1,
163: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
164: 55,
165: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
166: .addContainerGap(53,
167: Short.MAX_VALUE)));
168: layout
169: .setVerticalGroup(layout
170: .createParallelGroup(
171: org.jdesktop.layout.GroupLayout.LEADING)
172: .add(
173: layout
174: .createSequentialGroup()
175: .addContainerGap()
176: .add(jLabel2)
177: .add(31, 31, 31)
178: .add(
179: layout
180: .createParallelGroup(
181: org.jdesktop.layout.GroupLayout.BASELINE)
182: .add(
183: jResinHome,
184: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
185: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
186: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
187: .add(jLabel1)
188: .add(jButton1))
189: .addPreferredGap(
190: org.jdesktop.layout.LayoutStyle.RELATED)
191: .add(
192: layout
193: .createParallelGroup(
194: org.jdesktop.layout.GroupLayout.BASELINE)
195: .add(jLabel3)
196: .add(
197: jSpinner1,
198: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
199: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
200: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
201: .addContainerGap(195,
202: Short.MAX_VALUE)));
203: }// </editor-fold>//GEN-END:initComponents
204:
205: private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
206: String loc = browseResinHome();
207:
208: if (loc != null && !"".equals(loc))
209: this .jResinHome.setText(loc);
210: }//GEN-LAST:event_jButton1MouseClicked
211:
212: private void jSpinner1PropertyChange(
213: java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jSpinner1PropertyChange
214: _wizardPanel.stateChanged(new ChangeEvent(this ));
215: }//GEN-LAST:event_jSpinner1PropertyChange
216:
217: private void jSpinner1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner1StateChanged
218: _wizardPanel.stateChanged(evt);
219: }//GEN-LAST:event_jSpinner1StateChanged
220:
221: private String browseResinHome() {
222: JFileChooser chooser = getResinHomeChooser();
223: int ret = chooser.showDialog(SwingUtilities
224: .getWindowAncestor(this ), "Choose Resin Home");
225:
226: if (ret == JFileChooser.APPROVE_OPTION)
227: return chooser.getSelectedFile().getAbsolutePath();
228: else
229: return null;
230: }
231:
232: private JFileChooser getResinHomeChooser() {
233: JFileChooser chooser = new JFileChooser();
234: chooser.setDialogTitle("Select Resin Home");
235: chooser.setDialogType(JFileChooser.CUSTOM_DIALOG);
236:
237: chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
238: chooser.setApproveButtonMnemonic('C');
239: chooser.setMultiSelectionEnabled(false);
240: chooser.setApproveButtonToolTipText("Chooser");
241:
242: chooser.getAccessibleContext().setAccessibleName("Chooser");
243: chooser.getAccessibleContext().setAccessibleDescription(
244: "Chooser");
245:
246: chooser.setSelectedFile(new File(getResinHome()));
247:
248: return chooser;
249: }
250:
251: // Variables declaration - do not modify//GEN-BEGIN:variables
252: private javax.swing.JButton jButton1;
253: private javax.swing.JLabel jLabel1;
254: private javax.swing.JLabel jLabel2;
255: private javax.swing.JLabel jLabel3;
256: private javax.swing.JTextField jResinHome;
257: private javax.swing.JSpinner jSpinner1;
258: // End of variables declaration//GEN-END:variables
259: }
|