View Javadoc

1   /*
2    * UML2MMBase module.
3    *
4    * The contents of this file are subject to the Mozilla Public License
5    * Version 1.0 (the "License"); you may not use this file except in
6    * compliance with the License. You may obtain a copy of the License at
7    * http://www.mozilla.org/MPL/
8    *
9    * Software distributed under the License is distributed on an "AS IS"
10   * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11   * License for the specific language governing rights and limitations
12   * under the License.
13   */
14  
15  package com.finalist.mmbase2uml;
16  
17  import javax.swing.*;
18  import java.awt.event.*;
19  import java.awt.*;
20  
21  /***
22   *
23   * @author kors
24   * @version $Revision: 1.3 $, $Date: 2004/10/23 08:54:40 $
25   */
26  public class DirChooserGui extends JFrame implements ActionListener {
27  
28     private JButton offlineButton;
29     private JButton generateButton;
30     private JButton outputButton;
31     private JFileChooser inputChooser;
32     private JFileChooser outputChooser;
33     private JLabel offlinePath;
34     private JLabel outputPath;
35     private JRadioButton offlineAppType;
36     private JRadioButton onlineAppType;
37     private JTextField onlinePath;
38     private JMenuItem menuItemExit;
39     private JMenuItem menuItemAbout;
40     private JMenuBar menuBar;
41     private JMenu menuFile;
42     private JMenu menuHelp;
43     private String choosertitle;
44     /***
45      * A gui to get two directories.
46      */
47     public DirChooserGui() {
48        this.setTitle("MMBase2uml application");
49  
50        Container contentPane = this.getContentPane();
51        this.addWindowListener(
52                new WindowAdapter() {
53                   public void windowClosing(WindowEvent e) {
54                      System.exit(0);
55                   }
56                }
57        );
58        this.setSize(600, 200);
59        this.setVisible(true);
60  
61        contentPane.setLayout(null);
62  
63  
64        offlineAppType = new JRadioButton();
65        offlineAppType.setBounds(10, 30, 20, 20);
66        offlineAppType.addActionListener(this);
67        offlineAppType.setSelected(true);
68        contentPane.add(offlineAppType);
69  
70        offlineButton = new JButton("app directory");
71        offlineButton.addActionListener(this);
72        offlineButton.setBounds(30, 30, 130, 20);
73        contentPane.add(offlineButton);
74  
75        offlinePath = new JLabel();
76        offlinePath.setBounds(170, 30, 400, 20);
77        offlinePath.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
78        contentPane.add(offlinePath);
79  
80        onlineAppType = new JRadioButton();
81        onlineAppType.setBounds(10, 50, 20, 20);
82        onlineAppType.addActionListener(this);
83        contentPane.add(onlineAppType);
84  
85        onlinePath = new JTextField("rmi://hostname/remotecloud");
86        onlinePath.setBounds(170, 50, 400, 20);
87        onlinePath.setEnabled(false);
88        contentPane.add(onlinePath);
89  
90        outputButton = new JButton("Choose where to put the file(s)");
91        outputButton = new JButton("Output directory");
92        outputButton.setBounds(10, 100, 150, 20);
93        outputButton.addActionListener(this);
94        contentPane.add(outputButton);
95  
96        outputPath = new JLabel();
97        outputPath.setBounds(170, 100, 400, 20);
98        outputPath.setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));
99        contentPane.add(outputPath);
100 
101       generateButton = new JButton("Generate the XMI file(s)");
102       generateButton.addActionListener(this);
103       generateButton.setBounds(10, 130, 560, 20);
104       contentPane.add(generateButton);
105 
106       menuBar = new JMenuBar();
107       menuFile = new JMenu("File");
108       menuBar.add(menuFile);
109 
110       menuItemExit = new JMenuItem("Exit");
111       menuItemExit.addActionListener(this);
112       menuFile.add(menuItemExit);
113 
114       menuHelp = new JMenu("Help");
115       menuBar.add(menuHelp);
116 
117       menuItemAbout = new JMenuItem("About");
118       menuHelp.add(menuItemAbout);
119 
120       contentPane.add(menuBar);
121       menuFile.setBounds(0, 0, 40, 20);
122       menuHelp.setBounds(40, 0, 40, 20);
123       menuBar.setBounds(0, 0, 600, 22);
124       this.repaint();
125 
126       choosertitle = "Find the correct directory";
127    }
128 
129    /***
130     * Handles the performed actions.
131     *
132     * @param e The ActionEvent that has been occured.
133     */
134    public void actionPerformed(ActionEvent e) {
135       if (offlineButton == e.getSource()) {
136          inputChooser = new JFileChooser();
137          inputChooser.setCurrentDirectory(new java.io.File("."));
138          inputChooser.setDialogTitle(choosertitle);
139          inputChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
140          if (inputChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
141             if (inputChooser.getSelectedFile().isDirectory()) {
142                offlinePath.setText(inputChooser.getSelectedFile().toString());
143             }
144          }
145       }
146       else if (outputButton == e.getSource()) {
147          outputChooser = new JFileChooser();
148          outputChooser.setCurrentDirectory(new java.io.File("."));
149          outputChooser.setDialogTitle(choosertitle);
150          outputChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
151          if (outputChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
152             if (outputChooser.getSelectedFile().isDirectory()) {
153                outputPath.setText(outputChooser.getSelectedFile().toString());
154             }
155          }
156       }
157       else if (onlineAppType == e.getSource()) {
158          offlineAppType.setSelected(false);
159          offlineButton.setEnabled(false);
160          offlinePath.setEnabled(false);
161          onlineAppType.setSelected(true);
162          onlinePath.setEnabled(true);
163       }
164       else if (offlineAppType == e.getSource()) {
165          onlineAppType.setSelected(false);
166          onlinePath.setEnabled(false);
167          offlinePath.setEnabled(true);
168          offlineButton.setEnabled(true);
169          offlineAppType.setSelected(true);
170       }
171       else if (menuItemExit == e.getSource()) {
172           System.exit(0);
173       }
174       else if (generateButton == e.getSource()) {
175          MMBase2UML mmbase2uml = new MMBase2UML();
176          if (offlineAppType.isSelected() && offlinePath.getText() != null && !offlinePath.getText().equals("")) {
177             mmbase2uml.parseApplication(offlinePath.getText(), outputPath.getText());
178          }
179          else if (onlineAppType.isSelected() && onlinePath.getText() != null && !onlinePath.getText().equals("")) {
180             mmbase2uml.parseApplication(onlinePath.getText(), outputPath.getText());
181          }
182       }
183    }
184 }