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

Last change on this file since 12119 was 12119, checked in by kjdon, 18 years ago

Changed text handling to use Dictionary.get rather than Dictionary.setText or Dictionary.registerBoth etc. also removed mnemonics cos they suck for other languages

  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.gui;
38
39import java.awt.*;
40import java.awt.event.*;
41import java.io.*;
42import javax.swing.*;
43import org.greenstone.gatherer.Configuration;
44import org.greenstone.gatherer.Dictionary;
45import org.greenstone.gatherer.util.JarTools;
46import org.greenstone.gatherer.util.XMLTools;
47import org.w3c.dom.*;
48
49/** 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. */
50public class LockFileDialog
51 extends ModalDialog {
52
53 private int choice;
54 private Document document;
55 private JButton cancel_button;
56 private JButton ok_button;
57 private LockFileDialog self;
58
59 static final public int NO_OPTION = 0;
60 static final public int YES_OPTION = 1;
61
62 static final private Dimension LABEL_SIZE = new Dimension(100, 25);
63 static final private Dimension SIZE = new Dimension(500, 250);
64 static final private int ICON_SIZE = 30;
65
66 public LockFileDialog(JFrame parent, String name, File lock_file) {
67 super(parent, Dictionary.get("LockFileDialog.Title"), true);
68 setSize(SIZE);
69 setJMenuBar(new SimpleMenuBar("openingacollection"));
70 this.self = this;
71
72 // Parse the lock file
73 document = XMLTools.parseXMLFile(lock_file);
74
75 // Creation
76 JPanel content_pane = (JPanel) getContentPane();
77 JPanel upper_pane = new JPanel();
78 ImageIcon icon = JarTools.getImage("lcolicn.gif");
79 ImageIcon scaled_icon = new ImageIcon(icon.getImage().getScaledInstance(ICON_SIZE, ICON_SIZE, Image.SCALE_DEFAULT));
80 JLabel icon_label = new JLabel(scaled_icon);
81 JPanel title_pane = new JPanel();
82 JLabel title_one_label = new JLabel(Dictionary.get("General.Warning"));
83
84 JTextArea title_two_textarea = new JTextArea(Dictionary.get("LockFileDialog.Lockfile_Message_One"));
85 title_two_textarea.setEditable(false);
86 title_two_textarea.setLineWrap(true);
87 title_two_textarea.setOpaque(false);
88 title_two_textarea.setRows(3);
89 title_two_textarea.setWrapStyleWord(true);
90
91 JPanel central_pane = new JPanel();
92
93 JPanel name_pane = new JPanel();
94 JLabel name_label = new JLabel(Dictionary.get("LockFileDialog.Name"));
95 name_label.setPreferredSize(LABEL_SIZE);
96
97 JTextField name_field = new JTextField(name);
98 name_field.setEditable(false);
99 name_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
100
101 JPanel person_pane = new JPanel();
102 JLabel person_label = new JLabel(Dictionary.get("LockFileDialog.User"));
103 person_label.setPreferredSize(LABEL_SIZE);
104
105 JTextField person_field = new JTextField(getValue("User"));
106 person_field.setEditable(false);
107 person_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
108
109 JPanel machine_pane = new JPanel();
110 JLabel machine_label = new JLabel(Dictionary.get("LockFileDialog.Machine"));
111 machine_label.setPreferredSize(LABEL_SIZE);
112
113 JTextField machine_field = new JTextField(getValue("Machine"));
114 machine_field.setEditable(false);
115 machine_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
116
117 JPanel created_pane = new JPanel();
118 JLabel created_label = new JLabel(Dictionary.get("LockFileDialog.Date"));
119 created_label.setPreferredSize(LABEL_SIZE);
120
121 JTextField created_field = new JTextField(getValue("Date"));
122 created_field.setEditable(false);
123 created_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
124
125 JLabel central_label = new JLabel(Dictionary.get("LockFileDialog.Lockfile_Message_Two"));
126
127 JPanel button_pane = new JPanel();
128 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("LockFileDialog.OK_Tooltip"));
129
130 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("LockFileDialog.Cancel_Tooltip"));
131
132 // Connection
133 ok_button.addActionListener(new MyActionListener());
134 cancel_button.addActionListener(new MyActionListener());
135
136 // Layout
137 icon_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,10));
138
139 title_pane.setLayout(new BorderLayout());
140 title_pane.add(title_one_label, BorderLayout.NORTH);
141 title_pane.add(title_two_textarea, BorderLayout.CENTER);
142
143 upper_pane.setLayout(new BorderLayout());
144 upper_pane.add(icon_label, BorderLayout.WEST);
145 upper_pane.add(title_pane, BorderLayout.CENTER);
146
147 name_pane.setLayout(new BorderLayout());
148 name_pane.add(name_label, BorderLayout.WEST);
149 name_pane.add(name_field, BorderLayout.CENTER);
150
151 person_pane.setLayout(new BorderLayout());
152 person_pane.add(person_label, BorderLayout.WEST);
153 person_pane.add(person_field, BorderLayout.CENTER);
154
155 machine_pane.setLayout(new BorderLayout());
156 machine_pane.add(machine_label, BorderLayout.WEST);
157 machine_pane.add(machine_field, BorderLayout.CENTER);
158
159 created_pane.setLayout(new BorderLayout());
160 created_pane.add(created_label, BorderLayout.WEST);
161 created_pane.add(created_field, BorderLayout.CENTER);
162
163 central_pane.setLayout(new GridLayout(5,1,0,5));
164 central_pane.add(name_pane);
165 central_pane.add(person_pane);
166 central_pane.add(machine_pane);
167 central_pane.add(created_pane);
168 central_pane.add(central_label);
169
170 button_pane.setLayout(new GridLayout(1,2,5,0));
171 button_pane.add(ok_button);
172 button_pane.add(cancel_button);
173
174 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
175 content_pane.setLayout(new BorderLayout());
176 content_pane.add(upper_pane, BorderLayout.NORTH);
177 content_pane.add(central_pane, BorderLayout.CENTER);
178 content_pane.add(button_pane, BorderLayout.SOUTH);
179
180 // Display
181 if (parent != null) {
182 Rectangle frame_bounds = parent.getBounds();
183 setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
184 }
185 else {
186 Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
187 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
188 }
189 }
190
191 public int getChoice() {
192 setVisible(true);
193 return choice;
194 }
195
196 private String getValue(String name) {
197 String value = "";
198 if(document != null) {
199 try {
200 Element value_element = (Element) XMLTools.getNodeFromNamed(document.getDocumentElement(), name);
201 value = XMLTools.getValue(value_element);
202 }
203 catch (Exception error) {
204 }
205 }
206 else {
207 value = Dictionary.get("LockFileDialog.Error");
208 }
209 return value;
210 }
211
212 private class MyActionListener
213 implements ActionListener {
214 public void actionPerformed(ActionEvent event) {
215 if(event.getSource() == ok_button) {
216 choice = YES_OPTION;
217 }
218 else {
219 choice = NO_OPTION;
220 }
221 self.dispose();
222 }
223 }
224}
Note: See TracBrowser for help on using the repository browser.