source: other-projects/trunk/greenstone3-extension/mat/src/org/greenstone/gsdl3_extension/mat/CollectionChooser.java@ 18197

Last change on this file since 18197 was 18197, checked in by cc108, 15 years ago

set frame size

File size: 4.2 KB
Line 
1package org.greenstone.gsdl3_extension.mat;
2
3import java.awt.*;
4import java.awt.event.*;
5import java.io.File;
6
7import javax.swing.*;
8
9import org.w3c.dom.Element;
10import org.w3c.dom.Node;
11import org.w3c.dom.NodeList;
12
13public class CollectionChooser extends JFrame {
14
15 JPanel jPanel;
16 JButton jButton1;
17 JComboBox collectionComboBox;
18 String fileSeparator = File.separator;
19
20 public CollectionChooser(String collectionName){
21 new MainApplication(collectionName);
22 }
23
24 public CollectionChooser() {
25 super();
26 this.setTitle("Choose a collection");
27 this.setResizable(false);
28 DescribeMessenger dm = new DescribeMessenger();
29 dm.describe();
30
31 Node cList = dm.getCollectionList();
32 Element collectionList = (Element) cList;
33 NodeList collectionNameList = collectionList.getElementsByTagName("collection");
34
35 String[] collectionTemp = new String[collectionNameList.getLength()];
36
37 int count =0;
38 for(int i=0; i<collectionNameList.getLength(); i++){
39 Node nameNode = collectionNameList.item(i);
40 String collName = nameNode.getAttributes().item(0).getNodeValue();;
41
42
43 String path = dm.site_home+fileSeparator+"collect"+fileSeparator+collName+fileSeparator+"index"+fileSeparator+"text"+fileSeparator+collName+".ldb";
44
45 File dbFile = new File(path);
46 if(dbFile.exists()){
47 collectionTemp[count] = collName;
48 count++;
49 }
50 }
51
52 String[] collectionStrings = new String[count];
53
54 for(int i = 0; i<count; i++){
55 collectionStrings[i]= collectionTemp[i];
56 }
57
58 if(collectionStrings.length==0){
59 JOptionPane.showMessageDialog(new JFrame(),"No collections available.");
60 System.exit(0);
61 }
62 jButton1 = new JButton("Enter");
63 jButton1.setPreferredSize(new Dimension(150,30));
64 jButton1.setFont(new java.awt.Font("Sans-serif", Font.BOLD, 16));
65 jButton1.addActionListener(new collectionChooser_jButton1_Adapter(this));
66
67 collectionComboBox = new JComboBox(collectionStrings);
68 collectionComboBox.setSelectedIndex(0);
69 collectionComboBox.setPreferredSize(new Dimension(150,30));
70 collectionComboBox.setFont(new java.awt.Font("Sans-serif", Font.BOLD, 16));
71
72 JLabel text = new JLabel();
73 text.setFont(new java.awt.Font("Sans-serif", Font.BOLD, 14));
74 text.setText("Available Collection");
75 text.setPreferredSize(new Dimension(150,30));
76
77 //Lay out the demo.
78 jPanel = new JPanel();
79 jPanel.setLayout(new AbsoluteLayout());
80 jPanel.add(text, new AbsoluteConstraints(30,20,170,30));
81 jPanel.add(collectionComboBox, new AbsoluteConstraints(30,60,170,30));
82 jPanel.add(jButton1, new AbsoluteConstraints(30,120,170,30));
83 jPanel.setPreferredSize(new Dimension(225,180));
84 this.setContentPane(jPanel);
85
86 //Display the window.
87 this.pack();
88 this.setVisible(true);
89 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
90 }
91
92
93 /** Listens to the combo box. */
94 public void jButton1_actionPerformed(ActionEvent e){
95 String collectionName = collectionComboBox.getSelectedItem().toString();
96 this.dispose();
97 MainApplication ma = new MainApplication(collectionName);
98 }
99
100 /**
101 * Create the GUI and show it. For thread safety,
102 * this method should be invoked from the
103 * event-dispatching thread.
104 */
105
106 public static void main(String[] args) {
107 //Schedule a job for the event-dispatching thread:
108 //creating and showing this application's GUI.
109 if(args.length==0){
110 new CollectionChooser();
111 }
112 else if (args.length==1){
113 new CollectionChooser(args[0]);
114 }
115 else{
116 System.out.println("Sorry. This application cannot accept more than one argument.");
117 }
118 }
119}
120
121class collectionChooser_jButton1_Adapter implements ActionListener {
122 private CollectionChooser adaptee;
123
124 collectionChooser_jButton1_Adapter(CollectionChooser adaptee) {
125 this.adaptee = adaptee;
126 }
127
128 public void actionPerformed(ActionEvent e) {
129 adaptee.jButton1_actionPerformed(e);
130 }
131}
Note: See TracBrowser for help on using the repository browser.