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

Last change on this file since 17365 was 17365, checked in by cc108, 16 years ago

Updating Mat Source Code

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