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