1 | package org.greenstone3.ms;
|
---|
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() {
|
---|
18 |
|
---|
19 | this.setTitle("Choose a collection");
|
---|
20 |
|
---|
21 | DescribeMessager dm = new DescribeMessager();
|
---|
22 | dm.describe();
|
---|
23 | Node cList = dm.getCollectionList();
|
---|
24 | Element collectionList = (Element) cList;
|
---|
25 | NodeList collectionNameList = collectionList.getElementsByTagName("collection");
|
---|
26 | String[] collectionStrings = new String[collectionNameList.getLength()];
|
---|
27 |
|
---|
28 | for(int i = 0; i< collectionNameList.getLength(); i++){
|
---|
29 | Node nameNode = collectionNameList.item(i);
|
---|
30 | collectionStrings[i] = nameNode.getAttributes().item(0).getNodeValue();
|
---|
31 | }
|
---|
32 |
|
---|
33 |
|
---|
34 | jButton1 = new JButton("Enter");
|
---|
35 | jButton1.setPreferredSize(new Dimension(150,30));
|
---|
36 | jButton1.setFont(new java.awt.Font("Times New Roman", Font.BOLD, 16));
|
---|
37 | jButton1.addActionListener(new collectionChooser_jButton1_Adapter(this));
|
---|
38 |
|
---|
39 | collectionComboBox = new JComboBox(collectionStrings);
|
---|
40 | collectionComboBox.setSelectedIndex(0);
|
---|
41 | collectionComboBox.setPreferredSize(new Dimension(150,30));
|
---|
42 | collectionComboBox.setFont(new java.awt.Font("Times New Roman", Font.BOLD, 16));
|
---|
43 |
|
---|
44 | JLabel text = new JLabel();
|
---|
45 | text.setFont(new java.awt.Font("Times New Roman", Font.BOLD, 14));
|
---|
46 | text.setText("Available Collection");
|
---|
47 | text.setPreferredSize(new Dimension(150,30));
|
---|
48 |
|
---|
49 | //Lay out the demo.
|
---|
50 | jPanel = new JPanel();
|
---|
51 | jPanel.setLayout(new AbsoluteLayout());
|
---|
52 | jPanel.add(text, new AbsoluteConstraints(30,20,170,30));
|
---|
53 | jPanel.add(collectionComboBox, new AbsoluteConstraints(30,60,170,30));
|
---|
54 | jPanel.add(jButton1, new AbsoluteConstraints(30,120,170,30));
|
---|
55 | jPanel.setPreferredSize(new Dimension(225,180));
|
---|
56 | this.setContentPane(jPanel);
|
---|
57 |
|
---|
58 | //Display the window.
|
---|
59 | this.pack();
|
---|
60 | this.setVisible(true);
|
---|
61 | }
|
---|
62 |
|
---|
63 |
|
---|
64 | /** Listens to the combo box. */
|
---|
65 | public void jButton1_actionPerformed(ActionEvent e){
|
---|
66 | String collectionName = collectionComboBox.getSelectedItem().toString();
|
---|
67 | this.dispose();
|
---|
68 | MainApplication ma = new MainApplication(collectionName);
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Create the GUI and show it. For thread safety,
|
---|
73 | * this method should be invoked from the
|
---|
74 | * event-dispatching thread.
|
---|
75 | */
|
---|
76 |
|
---|
77 | public static void main(String[] args) {
|
---|
78 | //Schedule a job for the event-dispatching thread:
|
---|
79 | //creating and showing this application's GUI.
|
---|
80 | collectionChooser cc = new collectionChooser();
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | class collectionChooser_jButton1_Adapter implements ActionListener {
|
---|
85 | private collectionChooser adaptee;
|
---|
86 |
|
---|
87 | collectionChooser_jButton1_Adapter(collectionChooser adaptee) {
|
---|
88 | this.adaptee = adaptee;
|
---|
89 | }
|
---|
90 |
|
---|
91 | public void actionPerformed(ActionEvent e) {
|
---|
92 | adaptee.jButton1_actionPerformed(e);
|
---|
93 | }
|
---|
94 | }
|
---|