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

Last change on this file since 10250 was 10011, checked in by mdewsnip, 19 years ago

Moved Utility.getImage into JarTools, as part of tidying up the Utility class.

  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 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();
83 Dictionary.setText(title_one_label, "General.Warning");
84 JTextArea title_two_textarea = new JTextArea();
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 Dictionary.setText(title_two_textarea, "LockFileDialog.Lockfile_Message_One");
91 JPanel central_pane = new JPanel();
92
93 JPanel name_pane = new JPanel();
94 JLabel name_label = new JLabel();
95 name_label.setPreferredSize(LABEL_SIZE);
96 Dictionary.setText(name_label, "LockFileDialog.Name");
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();
103 person_label.setPreferredSize(LABEL_SIZE);
104 Dictionary.setText(person_label, "LockFileDialog.User");
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();
111 machine_label.setPreferredSize(LABEL_SIZE);
112 Dictionary.setText(machine_label, "LockFileDialog.Machine");
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();
119 created_label.setPreferredSize(LABEL_SIZE);
120 Dictionary.setText(created_label, "LockFileDialog.Date");
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();
126 Dictionary.setText(central_label, "LockFileDialog.Lockfile_Message_Two");
127 JPanel button_pane = new JPanel();
128 ok_button = new GLIButton();
129 ok_button.setMnemonic(KeyEvent.VK_O);
130 Dictionary.setBoth(ok_button, "General.OK", "LockFileDialog.OK_Tooltip");
131 cancel_button = new GLIButton();
132 cancel_button.setMnemonic(KeyEvent.VK_C);
133 Dictionary.setBoth(cancel_button, "General.Cancel", "LockFileDialog.Cancel_Tooltip");
134
135 // Connection
136 ok_button.addActionListener(new MyActionListener());
137 cancel_button.addActionListener(new MyActionListener());
138
139 // Layout
140 icon_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,10));
141
142 title_pane.setLayout(new BorderLayout());
143 title_pane.add(title_one_label, BorderLayout.NORTH);
144 title_pane.add(title_two_textarea, BorderLayout.CENTER);
145
146 upper_pane.setLayout(new BorderLayout());
147 upper_pane.add(icon_label, BorderLayout.WEST);
148 upper_pane.add(title_pane, BorderLayout.CENTER);
149
150 name_pane.setLayout(new BorderLayout());
151 name_pane.add(name_label, BorderLayout.WEST);
152 name_pane.add(name_field, BorderLayout.CENTER);
153
154 person_pane.setLayout(new BorderLayout());
155 person_pane.add(person_label, BorderLayout.WEST);
156 person_pane.add(person_field, BorderLayout.CENTER);
157
158 machine_pane.setLayout(new BorderLayout());
159 machine_pane.add(machine_label, BorderLayout.WEST);
160 machine_pane.add(machine_field, BorderLayout.CENTER);
161
162 created_pane.setLayout(new BorderLayout());
163 created_pane.add(created_label, BorderLayout.WEST);
164 created_pane.add(created_field, BorderLayout.CENTER);
165
166 central_pane.setLayout(new GridLayout(5,1,0,5));
167 central_pane.add(name_pane);
168 central_pane.add(person_pane);
169 central_pane.add(machine_pane);
170 central_pane.add(created_pane);
171 central_pane.add(central_label);
172
173 button_pane.setLayout(new GridLayout(1,2,5,0));
174 button_pane.add(ok_button);
175 button_pane.add(cancel_button);
176
177 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
178 content_pane.setLayout(new BorderLayout());
179 content_pane.add(upper_pane, BorderLayout.NORTH);
180 content_pane.add(central_pane, BorderLayout.CENTER);
181 content_pane.add(button_pane, BorderLayout.SOUTH);
182
183 // Display
184 if (parent != null) {
185 Rectangle frame_bounds = parent.getBounds();
186 setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
187 }
188 else {
189 Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
190 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
191 }
192 }
193
194 public int getChoice() {
195 setVisible(true);
196 return choice;
197 }
198
199 private String getValue(String name) {
200 String value = "";
201 if(document != null) {
202 try {
203 Element value_element = (Element) XMLTools.getNodeFromNamed(document.getDocumentElement(), name);
204 value = XMLTools.getValue(value_element);
205 }
206 catch (Exception error) {
207 }
208 }
209 else {
210 value = Dictionary.get("LockFileDialog.Error");
211 }
212 return value;
213 }
214
215 private class MyActionListener
216 implements ActionListener {
217 public void actionPerformed(ActionEvent event) {
218 if(event.getSource() == ok_button) {
219 choice = YES_OPTION;
220 }
221 else {
222 choice = NO_OPTION;
223 }
224 self.dispose();
225 }
226 }
227}
Note: See TracBrowser for help on using the repository browser.