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

Last change on this file since 6160 was 6090, checked in by jmt12, 21 years ago

Added key mnemonics to buttons

  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 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.SimpleMenuBar;
10import org.greenstone.gatherer.gui.ModalDialog;
11import org.greenstone.gatherer.msm.MSMUtils;
12import org.greenstone.gatherer.util.Utility;
13import org.w3c.dom.*;
14
15/** 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. */
16public class LockFileDialog
17 extends ModalDialog {
18
19 private int choice;
20 private Document document;
21 private JButton cancel_button;
22 private JButton ok_button;
23 private LockFileDialog self;
24
25 static final public int NO_OPTION = 0;
26 static final public int YES_OPTION = 1;
27
28 static final private Dimension LABEL_SIZE = new Dimension(100, 25);
29 static final private Dimension SIZE = new Dimension(500, 250);
30 static final private int ICON_SIZE = 30;
31
32 public LockFileDialog(JFrame parent, String name, File lock_file) {
33 super(parent, Dictionary.get("LockFileDialog.Title"), true);
34 setSize(SIZE);
35 setJMenuBar(new SimpleMenuBar("openingacollection"));
36 this.self = this;
37
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
41 // Creation
42 JPanel content_pane = (JPanel) getContentPane();
43 JPanel upper_pane = new JPanel();
44 ImageIcon icon = Utility.getImage("lcolicn.gif");
45 ImageIcon scaled_icon = new ImageIcon(icon.getImage().getScaledInstance(ICON_SIZE, ICON_SIZE, Image.SCALE_DEFAULT));
46 JLabel icon_label = new JLabel(scaled_icon);
47 JPanel title_pane = new JPanel();
48 JLabel title_one_label = new JLabel();
49 Dictionary.setText(title_one_label, "General.Warning");
50 JTextArea title_two_textarea = new JTextArea();
51 title_two_textarea.setEditable(false);
52 title_two_textarea.setLineWrap(true);
53 title_two_textarea.setOpaque(false);
54 title_two_textarea.setRows(3);
55 title_two_textarea.setWrapStyleWord(true);
56 Dictionary.setText(title_two_textarea, "LockFileDialog.Lockfile_Message_One");
57 JPanel central_pane = new JPanel();
58
59 JPanel name_pane = new JPanel();
60 JLabel name_label = new JLabel();
61 name_label.setPreferredSize(LABEL_SIZE);
62 Dictionary.setText(name_label, "LockFileDialog.Name");
63 JTextField name_field = new JTextField(name);
64 name_field.setEditable(false);
65 name_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
66
67 JPanel person_pane = new JPanel();
68 JLabel person_label = new JLabel();
69 person_label.setPreferredSize(LABEL_SIZE);
70 Dictionary.setText(person_label, "LockFileDialog.User");
71 JTextField person_field = new JTextField(getValue("User"));
72 person_field.setEditable(false);
73 person_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
74
75 JPanel machine_pane = new JPanel();
76 JLabel machine_label = new JLabel();
77 machine_label.setPreferredSize(LABEL_SIZE);
78 Dictionary.setText(machine_label, "LockFileDialog.Machine");
79 JTextField machine_field = new JTextField(getValue("Machine"));
80 machine_field.setEditable(false);
81 machine_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
82
83 JPanel created_pane = new JPanel();
84 JLabel created_label = new JLabel();
85 created_label.setPreferredSize(LABEL_SIZE);
86 Dictionary.setText(created_label, "LockFileDialog.Date");
87 JTextField created_field = new JTextField(getValue("Date"));
88 created_field.setEditable(false);
89 created_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
90
91 JLabel central_label = new JLabel();
92 Dictionary.setText(central_label, "LockFileDialog.Lockfile_Message_Two");
93 JPanel button_pane = new JPanel();
94 ok_button = new JButton();
95 ok_button.setMnemonic(KeyEvent.VK_O);
96 Dictionary.setBoth(ok_button, "General.OK", "LockFileDialog.OK_Tooltip");
97 cancel_button = new JButton();
98 cancel_button.setMnemonic(KeyEvent.VK_C);
99 Dictionary.setBoth(cancel_button, "General.Cancel", "LockFileDialog.Cancel_Tooltip");
100
101 // Connection
102 ok_button.addActionListener(new MyActionListener());
103 cancel_button.addActionListener(new MyActionListener());
104
105 // Layout
106 icon_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,10));
107
108 title_pane.setLayout(new BorderLayout());
109 title_pane.add(title_one_label, BorderLayout.NORTH);
110 title_pane.add(title_two_textarea, BorderLayout.CENTER);
111
112 upper_pane.setLayout(new BorderLayout());
113 upper_pane.add(icon_label, BorderLayout.WEST);
114 upper_pane.add(title_pane, BorderLayout.CENTER);
115
116 name_pane.setLayout(new BorderLayout());
117 name_pane.add(name_label, BorderLayout.WEST);
118 name_pane.add(name_field, BorderLayout.CENTER);
119
120 person_pane.setLayout(new BorderLayout());
121 person_pane.add(person_label, BorderLayout.WEST);
122 person_pane.add(person_field, BorderLayout.CENTER);
123
124 machine_pane.setLayout(new BorderLayout());
125 machine_pane.add(machine_label, BorderLayout.WEST);
126 machine_pane.add(machine_field, BorderLayout.CENTER);
127
128 created_pane.setLayout(new BorderLayout());
129 created_pane.add(created_label, BorderLayout.WEST);
130 created_pane.add(created_field, BorderLayout.CENTER);
131
132 central_pane.setLayout(new GridLayout(5,1,0,5));
133 central_pane.add(name_pane);
134 central_pane.add(person_pane);
135 central_pane.add(machine_pane);
136 central_pane.add(created_pane);
137 central_pane.add(central_label);
138
139 button_pane.setLayout(new GridLayout(1,2,5,0));
140 button_pane.add(ok_button);
141 button_pane.add(cancel_button);
142
143 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
144 content_pane.setLayout(new BorderLayout());
145 content_pane.add(upper_pane, BorderLayout.NORTH);
146 content_pane.add(central_pane, BorderLayout.CENTER);
147 content_pane.add(button_pane, BorderLayout.SOUTH);
148
149 // Display
150 if (parent != null) {
151 Rectangle frame_bounds = parent.getBounds();
152 setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
153 }
154 else {
155 Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
156 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
157 }
158 }
159
160 public int getChoice() {
161 setVisible(true);
162 return choice;
163 }
164
165 private String getValue(String name) {
166 String value = "";
167 if(document != null) {
168 try {
169 Element value_element = (Element) MSMUtils.getNodeFromNamed(document.getDocumentElement(), name);
170 value = MSMUtils.getValue(value_element);
171 }
172 catch (Exception error) {
173 }
174 }
175 else {
176 value = Dictionary.get("LockFileDialog.Error");
177 }
178 return value;
179 }
180
181 private class MyActionListener
182 implements ActionListener {
183 public void actionPerformed(ActionEvent event) {
184 if(event.getSource() == ok_button) {
185 choice = YES_OPTION;
186 }
187 else {
188 choice = NO_OPTION;
189 }
190 self.dispose();
191 }
192 }
193}
Note: See TracBrowser for help on using the repository browser.