source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/gui/LockFileDialog.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 9.4 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 this.setComponentOrientation(Dictionary.getOrientation());
69 setSize(SIZE);
70 setJMenuBar(new SimpleMenuBar("openingacollection"));
71 this.self = this;
72
73 // Parse the lock file
74 document = XMLTools.parseXMLFile(lock_file);
75
76 // Creation
77 JPanel content_pane = (JPanel) getContentPane();
78 content_pane.setComponentOrientation(Dictionary.getOrientation());
79 JPanel upper_pane = new JPanel();
80 upper_pane.setComponentOrientation(Dictionary.getOrientation());
81 ImageIcon icon = JarTools.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 icon_label.setComponentOrientation(Dictionary.getOrientation());
85 JPanel title_pane = new JPanel();
86 title_pane.setComponentOrientation(Dictionary.getOrientation());
87 JLabel title_one_label = new JLabel(Dictionary.get("General.Warning"));
88 title_one_label.setComponentOrientation(Dictionary.getOrientation());
89 JTextArea title_two_textarea = new JTextArea(Dictionary.get("LockFileDialog.Lockfile_Message_One"));
90 title_two_textarea.setComponentOrientation(Dictionary.getOrientation());
91 title_two_textarea.setEditable(false);
92 title_two_textarea.setLineWrap(true);
93 title_two_textarea.setOpaque(false);
94 title_two_textarea.setRows(3);
95 title_two_textarea.setWrapStyleWord(true);
96
97 JPanel central_pane = new JPanel();
98 central_pane.setComponentOrientation(Dictionary.getOrientation());
99
100 JPanel name_pane = new JPanel();
101 name_pane.setComponentOrientation(Dictionary.getOrientation());
102 JLabel name_label = new JLabel(Dictionary.get("LockFileDialog.Name"));
103 name_label.setComponentOrientation(Dictionary.getOrientation());
104 name_label.setPreferredSize(LABEL_SIZE);
105
106 JTextField name_field = new JTextField(name);
107 name_field.setComponentOrientation(Dictionary.getOrientation());
108 name_field.setEditable(false);
109 name_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
110
111
112 JPanel person_pane = new JPanel();
113 person_pane.setComponentOrientation(Dictionary.getOrientation());
114 JLabel person_label = new JLabel(Dictionary.get("LockFileDialog.User"));
115 person_label.setComponentOrientation(Dictionary.getOrientation());
116 person_label.setPreferredSize(LABEL_SIZE);
117
118 JTextField person_field = new JTextField(getValue("User"));
119 person_field.setComponentOrientation(Dictionary.getOrientation());
120 person_field.setEditable(false);
121 person_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
122
123 JPanel machine_pane = new JPanel();
124 machine_pane.setComponentOrientation(Dictionary.getOrientation());
125 JLabel machine_label = new JLabel(Dictionary.get("LockFileDialog.Machine"));
126 machine_label.setComponentOrientation(Dictionary.getOrientation());
127 machine_label.setPreferredSize(LABEL_SIZE);
128
129 JTextField machine_field = new JTextField(getValue("Machine"));
130 machine_field.setComponentOrientation(Dictionary.getOrientation());
131 machine_field.setEditable(false);
132 machine_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
133
134 JPanel created_pane = new JPanel();
135 created_pane.setComponentOrientation(Dictionary.getOrientation());
136 JLabel created_label = new JLabel(Dictionary.get("LockFileDialog.Date"));
137 created_label.setPreferredSize(LABEL_SIZE);
138 created_label.setComponentOrientation(Dictionary.getOrientation());
139
140 JTextField created_field = new JTextField(getValue("Date"));
141 created_field.setComponentOrientation(Dictionary.getOrientation());
142 created_field.setEditable(false);
143 created_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
144
145 JLabel central_label = new JLabel(Dictionary.get("LockFileDialog.Lockfile_Message_Two"));
146 central_label.setComponentOrientation(Dictionary.getOrientation());
147
148 JPanel button_pane = new JPanel();
149 button_pane.setComponentOrientation(Dictionary.getOrientation());
150 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("LockFileDialog.OK_Tooltip"));
151
152 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("LockFileDialog.Cancel_Tooltip"));
153
154 // Connection
155 ok_button.addActionListener(new MyActionListener());
156 cancel_button.addActionListener(new MyActionListener());
157
158 // Layout
159 icon_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,10));
160
161 title_pane.setLayout(new BorderLayout());
162 title_pane.add(title_one_label, BorderLayout.NORTH);
163 title_pane.add(title_two_textarea, BorderLayout.CENTER);
164
165 upper_pane.setLayout(new BorderLayout());
166 upper_pane.add(icon_label, BorderLayout.LINE_START);
167 upper_pane.add(title_pane, BorderLayout.CENTER);
168
169 name_pane.setLayout(new BorderLayout());
170 name_pane.add(name_label, BorderLayout.LINE_START);
171 name_pane.add(name_field, BorderLayout.CENTER);
172
173 person_pane.setLayout(new BorderLayout());
174 person_pane.add(person_label, BorderLayout.LINE_START);
175 person_pane.add(person_field, BorderLayout.CENTER);
176
177 machine_pane.setLayout(new BorderLayout());
178 machine_pane.add(machine_label, BorderLayout.LINE_START);
179 machine_pane.add(machine_field, BorderLayout.CENTER);
180
181 created_pane.setLayout(new BorderLayout());
182 created_pane.add(created_label, BorderLayout.LINE_START);
183 created_pane.add(created_field, BorderLayout.CENTER);
184
185 central_pane.setLayout(new GridLayout(5,1,0,5));
186 central_pane.add(name_pane);
187 central_pane.add(person_pane);
188 central_pane.add(machine_pane);
189 central_pane.add(created_pane);
190 central_pane.add(central_label);
191
192 button_pane.setLayout(new GridLayout(1,2,5,0));
193 button_pane.add(ok_button);
194 button_pane.add(cancel_button);
195
196 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
197 content_pane.setLayout(new BorderLayout());
198 content_pane.add(upper_pane, BorderLayout.NORTH);
199 content_pane.add(central_pane, BorderLayout.CENTER);
200 content_pane.add(button_pane, BorderLayout.SOUTH);
201
202 // Display
203 if (parent != null) {
204 Rectangle frame_bounds = parent.getBounds();
205 setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
206 }
207 else {
208 Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
209 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
210 }
211 }
212
213 public int getChoice() {
214 setVisible(true);
215 return choice;
216 }
217
218 private String getValue(String name) {
219 String value = "";
220 if(document != null) {
221 try {
222 Element value_element = (Element) XMLTools.getNodeFromNamed(document.getDocumentElement(), name);
223 value = XMLTools.getValue(value_element);
224 }
225 catch (Exception error) {
226 }
227 }
228 else {
229 value = Dictionary.get("LockFileDialog.Error");
230 }
231 return value;
232 }
233
234 private class MyActionListener
235 implements ActionListener {
236 public void actionPerformed(ActionEvent event) {
237 if(event.getSource() == ok_button) {
238 choice = YES_OPTION;
239 }
240 else {
241 choice = NO_OPTION;
242 }
243 self.dispose();
244 }
245 }
246}
Note: See TracBrowser for help on using the repository browser.