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

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

new Mat source code

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