source: trunk/gli/src/org/greenstone/gatherer/gui/LockFileDialog.java@ 5527

Last change on this file since 5527 was 5527, checked in by mdewsnip, 21 years ago

Partway through tooltip assignment. Made lots of little changes, registered a whole lot more components, removed dead code, fixed help links (with SimpleMenuBars). Lots more of the same to come.

  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1package org.greenstone.gatherer.gui;
2
3import java.awt.*;
4import java.awt.event.*;
5import java.io.*;
6import javax.swing.*;
7import org.greenstone.gatherer.Dictionary;
8import org.greenstone.gatherer.Gatherer;
9import org.greenstone.gatherer.gui.TextFieldLabel;
10import org.greenstone.gatherer.msm.MSMUtils;
11import org.greenstone.gatherer.util.Utility;
12import org.greenstone.gatherer.gui.SimpleMenuBar;
13import org.greenstone.gatherer.gui.ModalDialog;
14import org.w3c.dom.*;
15
16/** A lock file dialog is shown whenever GLI detects an existing lock on a collection it is trying to open. The user can look at the details provided with the dialog, and decide whether to 'steal' the lock or to cancel the loading. */
17public class LockFileDialog
18 extends ModalDialog {
19
20 private int choice;
21 private Document document;
22 private JButton cancel_button;
23 private JButton ok_button;
24 private LockFileDialog self;
25
26 static final public int NO_OPTION = 0;
27 static final public int YES_OPTION = 1;
28
29 static final private Dimension LABEL_SIZE = new Dimension(100, 25);
30 static final private Dimension SIZE = new Dimension(500, 250);
31 static final private int ICON_SIZE = 30;
32
33 public LockFileDialog(JFrame parent, String name, File lock_file) {
34 super(parent, get("LockFileDialog.Title"), true);
35 setSize(SIZE);
36 setJMenuBar(new SimpleMenuBar("openingacollection"));
37 this.self = this;
38 // Parse the lock file, but do so quietly so that if the XML is poorly formed it doesn't show exception.
39 document = Utility.parse(lock_file, false);
40 // Creation
41 JPanel content_pane = (JPanel) getContentPane();
42 JPanel upper_pane = new JPanel();
43 ImageIcon icon = Utility.getImage("lcolicn.gif");
44 ImageIcon scaled_icon = new ImageIcon(icon.getImage().getScaledInstance(ICON_SIZE, ICON_SIZE, Image.SCALE_DEFAULT));
45 JLabel icon_label = new JLabel(scaled_icon);
46 JPanel title_pane = new JPanel();
47 JLabel title_one_label = new JLabel(get("General.Warning"));
48 JLabel title_two_label = new JLabel(get("LockFileDialog.Lockfile_Message_One"));
49 JPanel central_pane = new JPanel();
50 JPanel name_pane = new JPanel();
51 JLabel name_label = new JLabel(get("LockFileDialog.Name"));
52 name_label.setPreferredSize(LABEL_SIZE);
53 TextFieldLabel name_field = new TextFieldLabel(name);
54 name_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
55 JPanel person_pane = new JPanel();
56 JLabel person_label = new JLabel(get("LockFileDialog.User"));
57 person_label.setPreferredSize(LABEL_SIZE);
58 TextFieldLabel person_field = new TextFieldLabel(getValue("User"));
59 person_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
60 JPanel machine_pane = new JPanel();
61 JLabel machine_label = new JLabel(get("LockFileDialog.Machine"));
62 machine_label.setPreferredSize(LABEL_SIZE);
63 TextFieldLabel machine_field = new TextFieldLabel(getValue("Machine"));
64 machine_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
65 JPanel created_pane = new JPanel();
66 JLabel created_label = new JLabel(get("LockFileDialog.Date"));
67 created_label.setPreferredSize(LABEL_SIZE);
68 TextFieldLabel created_field = new TextFieldLabel(getValue("Date"));
69 created_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
70 JLabel central_label = new JLabel(get("LockFileDialog.Lockfile_Message_Two"));
71 JPanel button_pane = new JPanel();
72 ok_button = new JButton(get("General.OK"));
73 cancel_button = new JButton(get("General.Cancel"));
74 // Connection
75 ok_button.addActionListener(new MyActionListener());
76 cancel_button.addActionListener(new MyActionListener());
77 // Layout
78 icon_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,10));
79
80 title_pane.setLayout(new GridLayout(2,1,0,5));
81 title_pane.add(title_one_label);
82 title_pane.add(title_two_label);
83
84 upper_pane.setLayout(new BorderLayout());
85 upper_pane.add(icon_label, BorderLayout.WEST);
86 upper_pane.add(title_pane, BorderLayout.CENTER);
87
88 name_pane.setLayout(new BorderLayout());
89 name_pane.add(name_label, BorderLayout.WEST);
90 name_pane.add(name_field, BorderLayout.CENTER);
91
92 person_pane.setLayout(new BorderLayout());
93 person_pane.add(person_label, BorderLayout.WEST);
94 person_pane.add(person_field, BorderLayout.CENTER);
95
96 machine_pane.setLayout(new BorderLayout());
97 machine_pane.add(machine_label, BorderLayout.WEST);
98 machine_pane.add(machine_field, BorderLayout.CENTER);
99
100 created_pane.setLayout(new BorderLayout());
101 created_pane.add(created_label, BorderLayout.WEST);
102 created_pane.add(created_field, BorderLayout.CENTER);
103
104 central_pane.setLayout(new GridLayout(5,1,0,5));
105 central_pane.add(name_pane);
106 central_pane.add(person_pane);
107 central_pane.add(machine_pane);
108 central_pane.add(created_pane);
109 central_pane.add(central_label);
110
111 button_pane.setLayout(new GridLayout(1,2,5,0));
112 button_pane.add(ok_button);
113 button_pane.add(cancel_button);
114
115 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
116 content_pane.setLayout(new BorderLayout());
117 content_pane.add(upper_pane, BorderLayout.NORTH);
118 content_pane.add(central_pane, BorderLayout.CENTER);
119 content_pane.add(button_pane, BorderLayout.SOUTH);
120 // Display
121 if(parent != null) {
122 Rectangle frame_bounds = parent.getBounds();
123 setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
124 }
125 else {
126 Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
127 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
128 }
129 }
130
131 public int getChoice() {
132 setVisible(true);
133 return choice;
134 }
135
136 private String getValue(String name) {
137 String value = "";
138 if(document != null) {
139 try {
140 Element value_element = (Element) MSMUtils.getNodeFromNamed(document.getDocumentElement(), name);
141 value = MSMUtils.getValue(value_element);
142 }
143 catch (Exception error) {
144 }
145 }
146 else {
147 value = get("LockFileDialog.Error");
148 }
149 return value;
150 }
151
152 private class MyActionListener
153 implements ActionListener {
154 public void actionPerformed(ActionEvent event) {
155 if(event.getSource() == ok_button) {
156 choice = YES_OPTION;
157 }
158 else {
159 choice = NO_OPTION;
160 }
161 self.dispose();
162 }
163 }
164
165 static public void main(String[] args) {
166 JFrame frame = new JFrame();
167 frame.setSize(640,480);
168 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
169 frame.show();
170 LockFileDialog dialog = new LockFileDialog(frame, "Test", new File(args[0]));
171 int choice = dialog.getChoice();
172 }
173
174 static private String get(String key) {
175 if(key.indexOf(".") == -1) {
176 key = "LockFileDialog." + key;
177 }
178 return Gatherer.dictionary.get(key);
179 }
180}
Note: See TracBrowser for help on using the repository browser.