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 | */
|
---|
37 | package org.greenstone.gatherer.gui;
|
---|
38 |
|
---|
39 | import java.awt.*;
|
---|
40 | import java.awt.event.*;
|
---|
41 | import java.io.*;
|
---|
42 | import javax.swing.*;
|
---|
43 | import org.greenstone.gatherer.Dictionary;
|
---|
44 | import org.greenstone.gatherer.Gatherer;
|
---|
45 | import org.greenstone.gatherer.gui.GLIButton;
|
---|
46 | import org.greenstone.gatherer.gui.SimpleMenuBar;
|
---|
47 | import org.greenstone.gatherer.gui.ModalDialog;
|
---|
48 | import org.greenstone.gatherer.msm.MSMUtils;
|
---|
49 | import org.greenstone.gatherer.util.Utility;
|
---|
50 | import org.w3c.dom.*;
|
---|
51 |
|
---|
52 | /** 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. */
|
---|
53 | public class LockFileDialog
|
---|
54 | extends ModalDialog {
|
---|
55 |
|
---|
56 | private int choice;
|
---|
57 | private Document document;
|
---|
58 | private JButton cancel_button;
|
---|
59 | private JButton ok_button;
|
---|
60 | private LockFileDialog self;
|
---|
61 |
|
---|
62 | static final public int NO_OPTION = 0;
|
---|
63 | static final public int YES_OPTION = 1;
|
---|
64 |
|
---|
65 | static final private Dimension LABEL_SIZE = new Dimension(100, 25);
|
---|
66 | static final private Dimension SIZE = new Dimension(500, 250);
|
---|
67 | static final private int ICON_SIZE = 30;
|
---|
68 |
|
---|
69 | public LockFileDialog(JFrame parent, String name, File lock_file) {
|
---|
70 | super(parent, Dictionary.get("LockFileDialog.Title"), true);
|
---|
71 | setSize(SIZE);
|
---|
72 | setJMenuBar(new SimpleMenuBar("openingacollection"));
|
---|
73 | this.self = this;
|
---|
74 |
|
---|
75 | // Parse the lock file, but do so quietly so that if the XML is poorly formed it doesn't show exception.
|
---|
76 | document = Utility.parse(lock_file, false);
|
---|
77 |
|
---|
78 | // Creation
|
---|
79 | JPanel content_pane = (JPanel) getContentPane();
|
---|
80 | JPanel upper_pane = new JPanel();
|
---|
81 | ImageIcon icon = Utility.getImage("lcolicn.gif");
|
---|
82 | ImageIcon scaled_icon = new ImageIcon(icon.getImage().getScaledInstance(ICON_SIZE, ICON_SIZE, Image.SCALE_DEFAULT));
|
---|
83 | JLabel icon_label = new JLabel(scaled_icon);
|
---|
84 | JPanel title_pane = new JPanel();
|
---|
85 | JLabel title_one_label = new JLabel();
|
---|
86 | Dictionary.setText(title_one_label, "General.Warning");
|
---|
87 | JTextArea title_two_textarea = new JTextArea();
|
---|
88 | title_two_textarea.setEditable(false);
|
---|
89 | title_two_textarea.setLineWrap(true);
|
---|
90 | title_two_textarea.setOpaque(false);
|
---|
91 | title_two_textarea.setRows(3);
|
---|
92 | title_two_textarea.setWrapStyleWord(true);
|
---|
93 | Dictionary.setText(title_two_textarea, "LockFileDialog.Lockfile_Message_One");
|
---|
94 | JPanel central_pane = new JPanel();
|
---|
95 |
|
---|
96 | JPanel name_pane = new JPanel();
|
---|
97 | JLabel name_label = new JLabel();
|
---|
98 | name_label.setPreferredSize(LABEL_SIZE);
|
---|
99 | Dictionary.setText(name_label, "LockFileDialog.Name");
|
---|
100 | JTextField name_field = new JTextField(name);
|
---|
101 | name_field.setEditable(false);
|
---|
102 | name_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
|
---|
103 |
|
---|
104 | JPanel person_pane = new JPanel();
|
---|
105 | JLabel person_label = new JLabel();
|
---|
106 | person_label.setPreferredSize(LABEL_SIZE);
|
---|
107 | Dictionary.setText(person_label, "LockFileDialog.User");
|
---|
108 | JTextField person_field = new JTextField(getValue("User"));
|
---|
109 | person_field.setEditable(false);
|
---|
110 | person_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
|
---|
111 |
|
---|
112 | JPanel machine_pane = new JPanel();
|
---|
113 | JLabel machine_label = new JLabel();
|
---|
114 | machine_label.setPreferredSize(LABEL_SIZE);
|
---|
115 | Dictionary.setText(machine_label, "LockFileDialog.Machine");
|
---|
116 | JTextField machine_field = new JTextField(getValue("Machine"));
|
---|
117 | machine_field.setEditable(false);
|
---|
118 | machine_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
|
---|
119 |
|
---|
120 | JPanel created_pane = new JPanel();
|
---|
121 | JLabel created_label = new JLabel();
|
---|
122 | created_label.setPreferredSize(LABEL_SIZE);
|
---|
123 | Dictionary.setText(created_label, "LockFileDialog.Date");
|
---|
124 | JTextField created_field = new JTextField(getValue("Date"));
|
---|
125 | created_field.setEditable(false);
|
---|
126 | created_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
|
---|
127 |
|
---|
128 | JLabel central_label = new JLabel();
|
---|
129 | Dictionary.setText(central_label, "LockFileDialog.Lockfile_Message_Two");
|
---|
130 | JPanel button_pane = new JPanel();
|
---|
131 | ok_button = new GLIButton();
|
---|
132 | ok_button.setMnemonic(KeyEvent.VK_O);
|
---|
133 | Dictionary.setBoth(ok_button, "General.OK", "LockFileDialog.OK_Tooltip");
|
---|
134 | cancel_button = new GLIButton();
|
---|
135 | cancel_button.setMnemonic(KeyEvent.VK_C);
|
---|
136 | Dictionary.setBoth(cancel_button, "General.Cancel", "LockFileDialog.Cancel_Tooltip");
|
---|
137 |
|
---|
138 | // Connection
|
---|
139 | ok_button.addActionListener(new MyActionListener());
|
---|
140 | cancel_button.addActionListener(new MyActionListener());
|
---|
141 |
|
---|
142 | // Layout
|
---|
143 | icon_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,10));
|
---|
144 |
|
---|
145 | title_pane.setLayout(new BorderLayout());
|
---|
146 | title_pane.add(title_one_label, BorderLayout.NORTH);
|
---|
147 | title_pane.add(title_two_textarea, BorderLayout.CENTER);
|
---|
148 |
|
---|
149 | upper_pane.setLayout(new BorderLayout());
|
---|
150 | upper_pane.add(icon_label, BorderLayout.WEST);
|
---|
151 | upper_pane.add(title_pane, BorderLayout.CENTER);
|
---|
152 |
|
---|
153 | name_pane.setLayout(new BorderLayout());
|
---|
154 | name_pane.add(name_label, BorderLayout.WEST);
|
---|
155 | name_pane.add(name_field, BorderLayout.CENTER);
|
---|
156 |
|
---|
157 | person_pane.setLayout(new BorderLayout());
|
---|
158 | person_pane.add(person_label, BorderLayout.WEST);
|
---|
159 | person_pane.add(person_field, BorderLayout.CENTER);
|
---|
160 |
|
---|
161 | machine_pane.setLayout(new BorderLayout());
|
---|
162 | machine_pane.add(machine_label, BorderLayout.WEST);
|
---|
163 | machine_pane.add(machine_field, BorderLayout.CENTER);
|
---|
164 |
|
---|
165 | created_pane.setLayout(new BorderLayout());
|
---|
166 | created_pane.add(created_label, BorderLayout.WEST);
|
---|
167 | created_pane.add(created_field, BorderLayout.CENTER);
|
---|
168 |
|
---|
169 | central_pane.setLayout(new GridLayout(5,1,0,5));
|
---|
170 | central_pane.add(name_pane);
|
---|
171 | central_pane.add(person_pane);
|
---|
172 | central_pane.add(machine_pane);
|
---|
173 | central_pane.add(created_pane);
|
---|
174 | central_pane.add(central_label);
|
---|
175 |
|
---|
176 | button_pane.setLayout(new GridLayout(1,2,5,0));
|
---|
177 | button_pane.add(ok_button);
|
---|
178 | button_pane.add(cancel_button);
|
---|
179 |
|
---|
180 | content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
---|
181 | content_pane.setLayout(new BorderLayout());
|
---|
182 | content_pane.add(upper_pane, BorderLayout.NORTH);
|
---|
183 | content_pane.add(central_pane, BorderLayout.CENTER);
|
---|
184 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
185 |
|
---|
186 | // Display
|
---|
187 | if (parent != null) {
|
---|
188 | Rectangle frame_bounds = parent.getBounds();
|
---|
189 | setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
|
---|
190 | }
|
---|
191 | else {
|
---|
192 | Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
|
---|
193 | setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | public int getChoice() {
|
---|
198 | setVisible(true);
|
---|
199 | return choice;
|
---|
200 | }
|
---|
201 |
|
---|
202 | private String getValue(String name) {
|
---|
203 | String value = "";
|
---|
204 | if(document != null) {
|
---|
205 | try {
|
---|
206 | Element value_element = (Element) MSMUtils.getNodeFromNamed(document.getDocumentElement(), name);
|
---|
207 | value = MSMUtils.getValue(value_element);
|
---|
208 | }
|
---|
209 | catch (Exception error) {
|
---|
210 | }
|
---|
211 | }
|
---|
212 | else {
|
---|
213 | value = Dictionary.get("LockFileDialog.Error");
|
---|
214 | }
|
---|
215 | return value;
|
---|
216 | }
|
---|
217 |
|
---|
218 | private class MyActionListener
|
---|
219 | implements ActionListener {
|
---|
220 | public void actionPerformed(ActionEvent event) {
|
---|
221 | if(event.getSource() == ok_button) {
|
---|
222 | choice = YES_OPTION;
|
---|
223 | }
|
---|
224 | else {
|
---|
225 | choice = NO_OPTION;
|
---|
226 | }
|
---|
227 | self.dispose();
|
---|
228 | }
|
---|
229 | }
|
---|
230 | }
|
---|