1 | package vishnu.builder;
|
---|
2 |
|
---|
3 | import java.awt.event.*;
|
---|
4 | import java.awt.*;
|
---|
5 | import javax.swing.*;
|
---|
6 | import javax.swing.SpringLayout;
|
---|
7 | import java.io.File;
|
---|
8 |
|
---|
9 | public class IndexerGUI {
|
---|
10 | public final static boolean RIGHT_TO_LEFT = false;
|
---|
11 | public Toolkit toolkit = Toolkit.getDefaultToolkit();
|
---|
12 | private static JTextField[] textFields;
|
---|
13 | private static JTextArea ja;
|
---|
14 |
|
---|
15 | public static void addComponentsToPane(Container pane)
|
---|
16 | {
|
---|
17 | //String[] labels = {"Top directory of Vishnu: ", "Name of Collection: ", "Directory of Collection: ", "Source directory: ", "Indexer (\"mg\" or \"luc\"): ", "Collection Description: "};
|
---|
18 | String [] labels = {"Collections directory: ", "Collection id (directory name): ", "Collection name: ","Collection description: ", "Indexer (\"mg\" or \"luc\"): "};
|
---|
19 | int numPairs = labels.length;
|
---|
20 | textFields = new JTextField[numPairs];
|
---|
21 |
|
---|
22 | pane.setLayout(new BoxLayout(pane,BoxLayout.Y_AXIS));
|
---|
23 |
|
---|
24 | JPanel p = new JPanel(new SpringLayout());
|
---|
25 |
|
---|
26 | for (int i = 0; i < numPairs; i++) {
|
---|
27 | JLabel l = new JLabel(labels[i], JLabel.TRAILING);
|
---|
28 | p.add(l);
|
---|
29 | textFields[i] = new JTextField(30);
|
---|
30 | l.setLabelFor(textFields[i]);
|
---|
31 | p.add(textFields[i]);
|
---|
32 | }
|
---|
33 |
|
---|
34 | SpringUtilities.makeCompactGrid(p,numPairs, 2, 6, 6, //initX, initY
|
---|
35 | 6, 6); //xPad, yPad
|
---|
36 |
|
---|
37 | pane.add(p);
|
---|
38 |
|
---|
39 | JPanel butPan = new JPanel();
|
---|
40 | butPan.setLayout(new BoxLayout(butPan,BoxLayout.X_AXIS));
|
---|
41 |
|
---|
42 | Dimension minSize = new Dimension(10, 50);
|
---|
43 | Dimension prefSize = new Dimension(10, 50);
|
---|
44 | Dimension maxSize = new Dimension(Short.MAX_VALUE, 50);
|
---|
45 | butPan.add(new Box.Filler(minSize, prefSize, maxSize));
|
---|
46 |
|
---|
47 | JButton button = new JButton(" Start indexing ");
|
---|
48 | button.setBorder(BorderFactory.createBevelBorder(0));
|
---|
49 | button.addActionListener(new ActionListener(){
|
---|
50 | public void actionPerformed(ActionEvent e){
|
---|
51 | build();
|
---|
52 | }
|
---|
53 | });
|
---|
54 | butPan.add(button);
|
---|
55 |
|
---|
56 | butPan.add(new Box.Filler(minSize, prefSize, maxSize));
|
---|
57 |
|
---|
58 | // button = new JButton(" Options ");
|
---|
59 | // button.setBorder(BorderFactory.createBevelBorder(0));
|
---|
60 | // butPan.add(button);
|
---|
61 |
|
---|
62 | butPan.add(new Box.Filler(minSize, prefSize, maxSize));
|
---|
63 |
|
---|
64 | // button = new JButton(" Help ");
|
---|
65 | // button.setBorder(BorderFactory.createBevelBorder(0));
|
---|
66 | // butPan.add(button);
|
---|
67 |
|
---|
68 | pane.add(butPan);
|
---|
69 |
|
---|
70 | butPan.add(new Box.Filler(minSize, prefSize, maxSize));
|
---|
71 |
|
---|
72 | ja = new JTextArea(5,5);
|
---|
73 | JScrollPane scrollingArea = new JScrollPane(ja);
|
---|
74 | scrollingArea.setBorder(BorderFactory.createBevelBorder(1));
|
---|
75 | pane.add(scrollingArea);
|
---|
76 | }
|
---|
77 |
|
---|
78 | private static void build()
|
---|
79 | {
|
---|
80 | // get data
|
---|
81 | //String source = textFields[3].getText();
|
---|
82 | //String dir = textFields[2].getText();
|
---|
83 | //String name = textFields[1].getText();
|
---|
84 | //String home = textFields[0].getText();
|
---|
85 | String colls_home = textFields[0].getText();
|
---|
86 | String coll_id = textFields[1].getText();
|
---|
87 | String coll_name = textFields[2].getText();
|
---|
88 | String coll_desc = textFields[3].getText();
|
---|
89 | String indexer = textFields[4].getText();
|
---|
90 | String coll_home = colls_home;
|
---|
91 | if (!coll_home.endsWith(File.separator)) {
|
---|
92 | coll_home += File.separator;
|
---|
93 | }
|
---|
94 | coll_home += coll_id + File.separator;
|
---|
95 | //String del = "";
|
---|
96 | //String description = textFields[5].getText();
|
---|
97 | //String output = "Launching Collection Builder with \n source = " + source + "\n dir = " + dir + "\n name = " + name + "\n home = " + home + "\n indexer = " + indexer + "\n description = " + description;
|
---|
98 | String output = "Launching Collection Builder with \n collections home = "+colls_home + "\n collection id = "+coll_name+"\n indexer = "+indexer;
|
---|
99 | ja.setText(output);
|
---|
100 |
|
---|
101 | //CollectionBuilder builder = new CollectionBuilder(dir,name,home,indexer);
|
---|
102 | CollectionBuilder builder = new CollectionBuilder(coll_home, coll_id, coll_name, coll_desc, indexer);
|
---|
103 | output += "\n Indexing Finished";
|
---|
104 | ja.setText(output);
|
---|
105 | }
|
---|
106 |
|
---|
107 | private static void createAndShowGUI() {
|
---|
108 | JFrame.setDefaultLookAndFeelDecorated(true);
|
---|
109 | JFrame frame = new JFrame("Indexing Tool");
|
---|
110 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
---|
111 | addComponentsToPane(frame.getContentPane());
|
---|
112 |
|
---|
113 | frame.pack();
|
---|
114 |
|
---|
115 | Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
|
---|
116 | int w = frame.getSize().width;
|
---|
117 | int h = frame.getSize().height;
|
---|
118 | int x = (dim.width-w)/2;
|
---|
119 | int y = (dim.height-h)/2;
|
---|
120 | frame.setLocation(x,y);
|
---|
121 |
|
---|
122 | frame.setVisible(true);
|
---|
123 | }
|
---|
124 |
|
---|
125 | public static void main(String[] args) {
|
---|
126 | //javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
---|
127 | // public void run() {
|
---|
128 | createAndShowGUI();
|
---|
129 | // }
|
---|
130 | //});
|
---|
131 | }
|
---|
132 | }
|
---|