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

Last change on this file since 12762 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
RevLine 
[6318]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 */
[4293]37package org.greenstone.gatherer.gui;
38
39import java.awt.*;
40import java.awt.event.*;
41import java.io.*;
42import javax.swing.*;
[8231]43import org.greenstone.gatherer.Configuration;
[4293]44import org.greenstone.gatherer.Dictionary;
[10011]45import org.greenstone.gatherer.util.JarTools;
[8015]46import org.greenstone.gatherer.util.XMLTools;
[4293]47import org.w3c.dom.*;
48
[4459]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. */
[4293]50public class LockFileDialog
[4459]51 extends ModalDialog {
[4293]52
[4367]53 private int choice;
54 private Document document;
55 private JButton cancel_button;
56 private JButton ok_button;
57 private LockFileDialog self;
[4293]58
[4367]59 static final public int NO_OPTION = 0;
60 static final public int YES_OPTION = 1;
[4293]61
[4367]62 static final private Dimension LABEL_SIZE = new Dimension(100, 25);
[4427]63 static final private Dimension SIZE = new Dimension(500, 250);
[4367]64 static final private int ICON_SIZE = 30;
[4293]65
[4367]66 public LockFileDialog(JFrame parent, String name, File lock_file) {
[5593]67 super(parent, Dictionary.get("LockFileDialog.Title"), true);
[4367]68 setSize(SIZE);
[5527]69 setJMenuBar(new SimpleMenuBar("openingacollection"));
[4367]70 this.self = this;
[5564]71
[9036]72 // Parse the lock file
73 document = XMLTools.parseXMLFile(lock_file);
[5564]74
[4367]75 // Creation
76 JPanel content_pane = (JPanel) getContentPane();
77 JPanel upper_pane = new JPanel();
[10011]78 ImageIcon icon = JarTools.getImage("lcolicn.gif");
[4367]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();
[12119]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"));
[5673]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);
[12119]90
[4367]91 JPanel central_pane = new JPanel();
[5564]92
[4367]93 JPanel name_pane = new JPanel();
[12119]94 JLabel name_label = new JLabel(Dictionary.get("LockFileDialog.Name"));
[4367]95 name_label.setPreferredSize(LABEL_SIZE);
[12119]96
[5536]97 JTextField name_field = new JTextField(name);
98 name_field.setEditable(false);
[8231]99 name_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
[5564]100
[4367]101 JPanel person_pane = new JPanel();
[12119]102 JLabel person_label = new JLabel(Dictionary.get("LockFileDialog.User"));
[4367]103 person_label.setPreferredSize(LABEL_SIZE);
[12119]104
[5536]105 JTextField person_field = new JTextField(getValue("User"));
106 person_field.setEditable(false);
[8231]107 person_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
[5564]108
[4367]109 JPanel machine_pane = new JPanel();
[12119]110 JLabel machine_label = new JLabel(Dictionary.get("LockFileDialog.Machine"));
[4367]111 machine_label.setPreferredSize(LABEL_SIZE);
[12119]112
[5536]113 JTextField machine_field = new JTextField(getValue("Machine"));
114 machine_field.setEditable(false);
[8231]115 machine_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
[5564]116
[4367]117 JPanel created_pane = new JPanel();
[12119]118 JLabel created_label = new JLabel(Dictionary.get("LockFileDialog.Date"));
[4367]119 created_label.setPreferredSize(LABEL_SIZE);
[12119]120
[5536]121 JTextField created_field = new JTextField(getValue("Date"));
122 created_field.setEditable(false);
[8231]123 created_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
[5564]124
[12119]125 JLabel central_label = new JLabel(Dictionary.get("LockFileDialog.Lockfile_Message_Two"));
126
[4367]127 JPanel button_pane = new JPanel();
[12119]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
[4367]132 // Connection
133 ok_button.addActionListener(new MyActionListener());
134 cancel_button.addActionListener(new MyActionListener());
[5564]135
[4367]136 // Layout
137 icon_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,10));
[4293]138
[5673]139 title_pane.setLayout(new BorderLayout());
140 title_pane.add(title_one_label, BorderLayout.NORTH);
141 title_pane.add(title_two_textarea, BorderLayout.CENTER);
[4293]142
[4367]143 upper_pane.setLayout(new BorderLayout());
144 upper_pane.add(icon_label, BorderLayout.WEST);
145 upper_pane.add(title_pane, BorderLayout.CENTER);
[4293]146
[4367]147 name_pane.setLayout(new BorderLayout());
148 name_pane.add(name_label, BorderLayout.WEST);
149 name_pane.add(name_field, BorderLayout.CENTER);
[4293]150
[4367]151 person_pane.setLayout(new BorderLayout());
152 person_pane.add(person_label, BorderLayout.WEST);
153 person_pane.add(person_field, BorderLayout.CENTER);
[4293]154
[4367]155 machine_pane.setLayout(new BorderLayout());
156 machine_pane.add(machine_label, BorderLayout.WEST);
157 machine_pane.add(machine_field, BorderLayout.CENTER);
[4293]158
[4367]159 created_pane.setLayout(new BorderLayout());
160 created_pane.add(created_label, BorderLayout.WEST);
161 created_pane.add(created_field, BorderLayout.CENTER);
[4293]162
[4367]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);
[4293]169
[4367]170 button_pane.setLayout(new GridLayout(1,2,5,0));
171 button_pane.add(ok_button);
172 button_pane.add(cancel_button);
[4293]173
[4367]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);
[5564]179
[4367]180 // Display
[5564]181 if (parent != null) {
[4367]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 }
[4293]190
[4367]191 public int getChoice() {
[4459]192 setVisible(true);
[4367]193 return choice;
194 }
[4293]195
[4367]196 private String getValue(String name) {
197 String value = "";
198 if(document != null) {
199 try {
[8015]200 Element value_element = (Element) XMLTools.getNodeFromNamed(document.getDocumentElement(), name);
201 value = XMLTools.getValue(value_element);
[4367]202 }
203 catch (Exception error) {
204 }
205 }
206 else {
[5593]207 value = Dictionary.get("LockFileDialog.Error");
[4367]208 }
209 return value;
210 }
[4293]211
[4367]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 }
[4293]224}
Note: See TracBrowser for help on using the repository browser.