KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > jdev > PanelOne


1 package org.enhydra.kelp.jdev;
2
3
4 import javax.swing.JPanel JavaDoc;
5 import java.awt.*;
6 import javax.swing.*;
7 import oracle.bali.ewt.wizard.WizardEvent;
8 import oracle.bali.ewt.wizard.WizardValidateListener;
9 import oracle.bali.ewt.event.Cancelable;
10 import java.awt.GridBagConstraints JavaDoc;
11 import java.awt.event.ActionListener JavaDoc;
12 import java.awt.event.ActionEvent JavaDoc;
13 import java.awt.Insets JavaDoc;
14 import java.io.File JavaDoc;
15 import java.util.Hashtable JavaDoc;
16 import javax.swing.JLabel JavaDoc;
17 import javax.swing.JTextField JavaDoc;
18 import java.awt.Dimension JavaDoc;
19
20 import oracle.jdeveloper.model.JProject;
21 import oracle.ide.net.URLPath;
22 import oracle.ide.Ide;
23
24 public class PanelOne extends JPanel JavaDoc
25                    implements WizardValidateListener
26 {
27   Model model;
28   
29   GridBagLayout gridBagLayout1 = new GridBagLayout();
30   JLabel JavaDoc jLabel1 = new JLabel JavaDoc();
31   JLabel JavaDoc jLabel2 = new JLabel JavaDoc();
32   JLabel JavaDoc jLabel3 = new JLabel JavaDoc();
33   JTextField JavaDoc projectName = new JTextField JavaDoc();
34   JTextField JavaDoc projectRoot = new JTextField JavaDoc();
35   JButton jButtonBrowse = new JButton();
36   
37   public PanelOne(Model m)
38   {
39     try
40     {
41       jbInit();
42     }
43     catch(Exception JavaDoc e)
44     {
45       e.printStackTrace();
46     }
47     this.model = m;
48   }
49   private void jbInit() throws Exception JavaDoc
50   {
51     jLabel1.setText("Project name: ");
52     jLabel1.setHorizontalTextPosition(SwingConstants.RIGHT);
53     jLabel1.setHorizontalAlignment(SwingConstants.RIGHT);
54     jLabel2.setText("Project root: ");
55     jLabel2.setHorizontalTextPosition(SwingConstants.RIGHT);
56     jLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
57     jLabel3.setText("Enhydra Application Wizard parameters");
58     jLabel3.setFont(new Font("Dialog", 1, 14));
59     jButtonBrowse.setText("Browse");
60     jButtonBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
61         public void actionPerformed(ActionEvent JavaDoc e) {
62             jButtonBrowse_actionPerformed(e);
63         }
64     });
65     this.setLayout(gridBagLayout1);
66     this.add(jLabel1, new GridBagConstraints JavaDoc(0, 1, 1, 1, 0.0, 0.2, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.BOTH, new Insets JavaDoc(0, 0, 0, 0), 0, 0));
67     this.add(jLabel3, new GridBagConstraints JavaDoc(0, 0, 3, 1, 0.0, 0.5, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets JavaDoc(0, 0, 0, 16), 97, 16));
68     this.add(projectName, new GridBagConstraints JavaDoc(1, 1, 2, 1, 0.0, 0.2, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.HORIZONTAL, new Insets JavaDoc(0, 0, 0, 0), 0, 0));
69     this.add(jLabel2, new GridBagConstraints JavaDoc(0, 2, 1, 1, 0.0, 0.5, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.BOTH, new Insets JavaDoc(0, 0, 0, 0), 0, 0));
70     this.add(projectRoot, new GridBagConstraints JavaDoc(1, 2, 1, 1, 0.1, 0.5, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.HORIZONTAL, new Insets JavaDoc(0, 0, 0, 0), 0, 0));
71     this.add(jButtonBrowse, new GridBagConstraints JavaDoc(2, 2, 1, 1, 0.0, 0.5, java.awt.GridBagConstraints.CENTER, java.awt.GridBagConstraints.HORIZONTAL, new Insets JavaDoc(0, 0, 0, 0), 0, 0));
72     
73   }
74   public void wizardValidatePage(WizardEvent p0)
75   {
76     if ((projectName.getText().equalsIgnoreCase("")) ||
77         (projectRoot.getText().equalsIgnoreCase("")) )
78     {
79       JOptionPane.showMessageDialog(null,
80                                     "Please fill both input fields",
81                                     "Ooops",
82                                     JOptionPane.ERROR_MESSAGE);
83       Cancelable cancel = (Cancelable)p0;
84       cancel.cancel();
85     }
86     model.setProjectName(this.projectName.getText());
87     model.setProjectRoot(this.projectRoot.getText());
88   }
89
90   public void setDefaultValues()
91   {
92     this.projectName.setText(model.getProjectName());
93     this.projectRoot.setText(model.getProjectRoot());
94   }
95
96     void jButtonBrowse_actionPerformed(ActionEvent JavaDoc e) {
97         browseForDir();
98     }
99
100     private void browseForDir() {
101         JFileChooser chooser;
102         chooser = new JFileChooser();
103         chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
104         chooser.setCurrentDirectory(new File JavaDoc(model.getProjectRoot()));
105         chooser.setDialogTitle("Choose Project Root Directory");
106         chooser.setApproveButtonText("OK");
107         int v = chooser.showOpenDialog(this);
108
109         this.requestFocus();
110         jButtonBrowse.requestFocus();
111         if (v == JFileChooser.APPROVE_OPTION) {
112             if (!(chooser.getCurrentDirectory() == null)) {
113                 model.setProjectRoot(chooser.getSelectedFile().toString());
114                 projectRoot.setText(model.getProjectRoot());
115             }
116         }
117         chooser.removeAll();
118         chooser = null;
119     }
120   
121 }
122
Popular Tags