source: gs3-extensions/mat/trunk/src/org/greenstone/admin/guiext/ControlPanel.java@ 22171

Last change on this file since 22171 was 22171, checked in by sjm84, 14 years ago

Updated the MAT code so that it now uses the new util classes

File size: 5.6 KB
Line 
1package org.greenstone.admin.guiext.mat;
2
3import javax.swing.BorderFactory;
4import javax.swing.Box;
5import javax.swing.BoxLayout;
6import javax.swing.JButton;
7import javax.swing.JCheckBox;
8import javax.swing.JLabel;
9import javax.swing.JPanel;
10import javax.swing.JTextField;
11
12import java.awt.BorderLayout;
13import java.awt.Color;
14import java.awt.Component;
15import java.awt.Dimension;
16import java.awt.GridLayout;
17
18import java.awt.event.ActionEvent;
19import java.awt.event.ActionListener;
20import java.awt.event.ItemEvent;
21import java.awt.event.ItemListener;
22
23import java.util.Properties;
24
25import java.io.FileInputStream;
26
27import org.greenstone.util.BrowserLauncher;
28
29import org.greenstone.admin.guiext.BasePanel;
30
31import org.greenstone.admin.GAI;
32
33public class ControlPanel implements BasePanel
34{
35 JPanel _controlPanel = null;
36 JCheckBox _localAnalysis = null;
37
38 public ControlPanel()
39 {
40 _controlPanel = new JPanel();
41 _controlPanel.setLayout(new BorderLayout());
42
43 Mat mat = new Mat();
44
45 final int left_margin = 7;
46 final int right_margin = 7;
47 final int HORIZONTAL_GAP = 5;
48 final int VERTICAL_GAP = 5;
49
50 String fileSep = System.getProperty("file.separator");
51
52 JButton start_button = new JButton("Analyse");
53 start_button.setPreferredSize(new Dimension(50,25));
54 start_button.setMaximumSize(new Dimension(50,25));
55 start_button.setName("Analyse");
56 start_button.setEnabled(true);
57 start_button.addActionListener(new aListener(mat));
58
59 JLabel oai_temp_directory = new JLabel();
60 oai_temp_directory.setText("OAI temporary download directory:");
61
62 JTextField oai_temp_directory_text = new JTextField();
63 oai_temp_directory_text.setText(GAI.getGSDL3ExtensionHome() + fileSep + "mat" + fileSep + "tmp");
64 oai_temp_directory_text.setEditable(false);
65 oai_temp_directory_text.setBackground(Color.WHITE);
66
67 JLabel install_path = new JLabel();
68 install_path.setText("Metadata Quality Tool is installed in:");
69
70 JTextField install_path_text = new JTextField();
71 install_path_text.setText(GAI.getGSDL3ExtensionHome() + fileSep + "mat");
72 install_path_text.setEditable(false);
73 install_path_text.setBackground(Color.WHITE);
74
75 JCheckBox web_tool_checkbox = new JCheckBox("Web OAI Collection Building");
76 web_tool_checkbox.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
77 web_tool_checkbox.setVisible(false);
78
79 _localAnalysis = new JCheckBox("Local Collection Analysis");
80 _localAnalysis.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
81
82 GridLayout gridLayout3 = new GridLayout(3,3);
83 gridLayout3.setVgap(VERTICAL_GAP);
84 JPanel control_content_pane = new JPanel(gridLayout3);
85 control_content_pane.setBorder(BorderFactory.createEmptyBorder(5, left_margin, 5, right_margin));
86
87 GridLayout gridLayout2 = new GridLayout(1,2);
88 gridLayout2.setHgap(HORIZONTAL_GAP);
89 JPanel control_button_pane = new JPanel(gridLayout2);
90 control_button_pane.setBorder(BorderFactory.createEmptyBorder(5, left_margin, 5, right_margin));
91
92 GridLayout gridLayout1 = new GridLayout(2,2);
93 gridLayout1.setVgap(VERTICAL_GAP);
94 JPanel control_description_pane = new JPanel(gridLayout1);
95 control_description_pane.setBorder(BorderFactory.createEmptyBorder(5, left_margin, 5, right_margin));
96
97 JPanel control_pane = new JPanel();
98 control_pane.setLayout(new BoxLayout(control_pane, BoxLayout.Y_AXIS));
99
100 control_content_pane.add(_localAnalysis);
101 control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
102 control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
103
104 JPanel tempPane = new JPanel(new BorderLayout());
105 tempPane.add(Box.createRigidArea(new Dimension(18,5)), BorderLayout.WEST);
106 tempPane.add(start_button, BorderLayout.CENTER);
107 control_content_pane.add(tempPane);
108 control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
109 control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
110
111 //control_content_pane.add(web_tool_checkbox);
112 control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
113 control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
114 control_content_pane.add(Box.createRigidArea(new Dimension(10,5)));
115
116 control_description_pane.add(install_path);
117 control_description_pane.add(install_path_text);
118
119 control_description_pane.add(oai_temp_directory);
120 control_description_pane.add(oai_temp_directory_text);
121
122 control_content_pane.setAlignmentX(Component.LEFT_ALIGNMENT);
123 control_pane.add(control_content_pane);
124
125 control_description_pane.setAlignmentX(Component.LEFT_ALIGNMENT);
126 control_pane.add(control_description_pane);
127
128 control_button_pane.setAlignmentX(Component.LEFT_ALIGNMENT);
129 control_pane.add(control_button_pane);
130 _controlPanel.add(control_pane, BorderLayout.CENTER);
131 }
132
133 public JPanel getPanel()
134 {
135 return _controlPanel;
136 }
137
138 class aListener implements ActionListener {
139
140 private Mat adaptee;
141
142 aListener(Mat adaptee) {
143 this.adaptee = adaptee;
144 }
145
146 public void actionPerformed(ActionEvent e) {
147
148 JButton button = (JButton)e.getSource();
149
150 if(button.getName().equalsIgnoreCase("Analyse")){
151 if(_localAnalysis.isSelected()){
152 execute_application();
153 }
154 else{
155 try{
156 Properties properties = new Properties();
157 FileInputStream fis = new FileInputStream(GAI.getGSDL3Home() + System.getProperty("file.separator") + "build.properties");
158 properties.load(fis);
159 fis.close();
160 Thread bl = new BrowserLauncher("", "http://" + properties.getProperty("tomcat.server") + ":" + properties.getProperty("tomcat.port") + "/mat/analyse");
161 bl.run();
162 }
163 catch(Exception ex){
164 ex.printStackTrace();
165 }
166 }
167 }
168 }
169
170 public void execute_application(){
171 MatLaunchApplication app = new MatLaunchApplication(adaptee);
172 app.start();
173 }
174 }
175}
Note: See TracBrowser for help on using the repository browser.