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

Last change on this file since 20877 was 18370, checked in by kjdon, 15 years ago

committed code submitted by Amin Hedjazi for making the GLI right to left. I worked on this code on the rtl-gli branch, then merged the branch back to the trunk at revision 18368. The branch code was slightly different in a couple of places where it shouldn't have been. So don't use the branch code next time. Start a new branch.

  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 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);
[18370]68 this.setComponentOrientation(Dictionary.getOrientation());
[4367]69 setSize(SIZE);
[5527]70 setJMenuBar(new SimpleMenuBar("openingacollection"));
[4367]71 this.self = this;
[5564]72
[9036]73 // Parse the lock file
74 document = XMLTools.parseXMLFile(lock_file);
[5564]75
[4367]76 // Creation
77 JPanel content_pane = (JPanel) getContentPane();
[18370]78 content_pane.setComponentOrientation(Dictionary.getOrientation());
[4367]79 JPanel upper_pane = new JPanel();
[18370]80 upper_pane.setComponentOrientation(Dictionary.getOrientation());
[10011]81 ImageIcon icon = JarTools.getImage("lcolicn.gif");
[4367]82 ImageIcon scaled_icon = new ImageIcon(icon.getImage().getScaledInstance(ICON_SIZE, ICON_SIZE, Image.SCALE_DEFAULT));
83 JLabel icon_label = new JLabel(scaled_icon);
[18370]84 icon_label.setComponentOrientation(Dictionary.getOrientation());
[4367]85 JPanel title_pane = new JPanel();
[18370]86 title_pane.setComponentOrientation(Dictionary.getOrientation());
[12119]87 JLabel title_one_label = new JLabel(Dictionary.get("General.Warning"));
[18370]88 title_one_label.setComponentOrientation(Dictionary.getOrientation());
[12119]89 JTextArea title_two_textarea = new JTextArea(Dictionary.get("LockFileDialog.Lockfile_Message_One"));
[18370]90 title_two_textarea.setComponentOrientation(Dictionary.getOrientation());
[5673]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);
[12119]96
[18370]97 JPanel central_pane = new JPanel();
98 central_pane.setComponentOrientation(Dictionary.getOrientation());
99
[4367]100 JPanel name_pane = new JPanel();
[18370]101 name_pane.setComponentOrientation(Dictionary.getOrientation());
[12119]102 JLabel name_label = new JLabel(Dictionary.get("LockFileDialog.Name"));
[18370]103 name_label.setComponentOrientation(Dictionary.getOrientation());
[4367]104 name_label.setPreferredSize(LABEL_SIZE);
[12119]105
[5536]106 JTextField name_field = new JTextField(name);
[18370]107 name_field.setComponentOrientation(Dictionary.getOrientation());
[5536]108 name_field.setEditable(false);
[8231]109 name_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
[5564]110
[18370]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());
[4367]116 person_label.setPreferredSize(LABEL_SIZE);
[12119]117
[5536]118 JTextField person_field = new JTextField(getValue("User"));
[18370]119 person_field.setComponentOrientation(Dictionary.getOrientation());
[5536]120 person_field.setEditable(false);
[8231]121 person_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
[5564]122
[4367]123 JPanel machine_pane = new JPanel();
[18370]124 machine_pane.setComponentOrientation(Dictionary.getOrientation());
[12119]125 JLabel machine_label = new JLabel(Dictionary.get("LockFileDialog.Machine"));
[18370]126 machine_label.setComponentOrientation(Dictionary.getOrientation());
[4367]127 machine_label.setPreferredSize(LABEL_SIZE);
[12119]128
[5536]129 JTextField machine_field = new JTextField(getValue("Machine"));
[18370]130 machine_field.setComponentOrientation(Dictionary.getOrientation());
[5536]131 machine_field.setEditable(false);
[8231]132 machine_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
[5564]133
[4367]134 JPanel created_pane = new JPanel();
[18370]135 created_pane.setComponentOrientation(Dictionary.getOrientation());
[12119]136 JLabel created_label = new JLabel(Dictionary.get("LockFileDialog.Date"));
[4367]137 created_label.setPreferredSize(LABEL_SIZE);
[18370]138 created_label.setComponentOrientation(Dictionary.getOrientation());
[12119]139
[5536]140 JTextField created_field = new JTextField(getValue("Date"));
[18370]141 created_field.setComponentOrientation(Dictionary.getOrientation());
[5536]142 created_field.setEditable(false);
[8231]143 created_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
[5564]144
[12119]145 JLabel central_label = new JLabel(Dictionary.get("LockFileDialog.Lockfile_Message_Two"));
[18370]146 central_label.setComponentOrientation(Dictionary.getOrientation());
147
[4367]148 JPanel button_pane = new JPanel();
[18370]149 button_pane.setComponentOrientation(Dictionary.getOrientation());
[12119]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
[4367]154 // Connection
155 ok_button.addActionListener(new MyActionListener());
156 cancel_button.addActionListener(new MyActionListener());
[5564]157
[4367]158 // Layout
159 icon_label.setBorder(BorderFactory.createEmptyBorder(0,0,0,10));
[4293]160
[5673]161 title_pane.setLayout(new BorderLayout());
162 title_pane.add(title_one_label, BorderLayout.NORTH);
163 title_pane.add(title_two_textarea, BorderLayout.CENTER);
[4293]164
[4367]165 upper_pane.setLayout(new BorderLayout());
[18370]166 upper_pane.add(icon_label, BorderLayout.LINE_START);
[4367]167 upper_pane.add(title_pane, BorderLayout.CENTER);
[4293]168
[4367]169 name_pane.setLayout(new BorderLayout());
[18370]170 name_pane.add(name_label, BorderLayout.LINE_START);
[4367]171 name_pane.add(name_field, BorderLayout.CENTER);
[4293]172
[4367]173 person_pane.setLayout(new BorderLayout());
[18370]174 person_pane.add(person_label, BorderLayout.LINE_START);
[4367]175 person_pane.add(person_field, BorderLayout.CENTER);
[4293]176
[4367]177 machine_pane.setLayout(new BorderLayout());
[18370]178 machine_pane.add(machine_label, BorderLayout.LINE_START);
[4367]179 machine_pane.add(machine_field, BorderLayout.CENTER);
[4293]180
[4367]181 created_pane.setLayout(new BorderLayout());
[18370]182 created_pane.add(created_label, BorderLayout.LINE_START);
[4367]183 created_pane.add(created_field, BorderLayout.CENTER);
[4293]184
[4367]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);
[4293]191
[4367]192 button_pane.setLayout(new GridLayout(1,2,5,0));
193 button_pane.add(ok_button);
194 button_pane.add(cancel_button);
[4293]195
[4367]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);
[5564]201
[4367]202 // Display
[5564]203 if (parent != null) {
[4367]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 }
[4293]212
[4367]213 public int getChoice() {
[4459]214 setVisible(true);
[4367]215 return choice;
216 }
[4293]217
[4367]218 private String getValue(String name) {
219 String value = "";
220 if(document != null) {
221 try {
[8015]222 Element value_element = (Element) XMLTools.getNodeFromNamed(document.getDocumentElement(), name);
223 value = XMLTools.getValue(value_element);
[4367]224 }
225 catch (Exception error) {
226 }
227 }
228 else {
[5593]229 value = Dictionary.get("LockFileDialog.Error");
[4367]230 }
231 return value;
232 }
[4293]233
[4367]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 }
[4293]246}
Note: See TracBrowser for help on using the repository browser.