source: trunk/gli/src/org/greenstone/gatherer/gui/CreateShortcutPrompt.java@ 12119

Last change on this file since 12119 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: 4.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 * Author: Michael Dewsnip, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 2006 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.gui;
28
29import java.awt.*;
30import java.awt.event.*;
31import javax.swing.*;
32import java.io.*;
33import org.greenstone.gatherer.Dictionary;
34import org.greenstone.gatherer.Configuration;
35import org.greenstone.gatherer.Gatherer;
36import org.greenstone.gatherer.file.WorkspaceTree;
37
38
39public class CreateShortcutPrompt
40 extends JDialog
41 implements ActionListener, KeyListener
42{
43 /** The default size of a special mapping dialog. */
44 static final Dimension DIALOG_SIZE = new Dimension(400, 120);
45
46 private boolean cancelled = false;
47 private JButton cancel_button = null;
48 private JButton ok_button = null;
49 private JTextField name_field = null;
50
51
52 public CreateShortcutPrompt(WorkspaceTree workspace_tree, File file)
53 {
54 super(Gatherer.g_man);
55
56 setModal(true);
57 setSize(DIALOG_SIZE);
58 setTitle(Dictionary.get("MappingPrompt.Title"));
59
60 // Creation
61 JPanel content_pane = (JPanel) getContentPane();
62 JPanel center_pane = new JPanel();
63 JPanel labels_pane = new JPanel();
64 JPanel fields_pane = new JPanel();
65
66 JLabel file_label = new JLabel(Dictionary.get("MappingPrompt.File"));
67 JLabel file_field = new JLabel(file.getAbsolutePath());
68
69 JLabel name_label = new JLabel(Dictionary.get("MappingPrompt.Name"));
70 name_field = new JTextField(file.getName());
71
72 JPanel button_pane = new JPanel();
73 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
74 ok_button.setEnabled(name_field.getText().length() > 0);
75 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Cancel_Tooltip"));
76
77 // Connection
78 cancel_button.addActionListener(this);
79 ok_button.addActionListener(this);
80 name_field.addKeyListener(this);
81
82 // Layout
83 labels_pane.setLayout(new GridLayout(2,1,5,0));
84 labels_pane.add(file_label);
85 labels_pane.add(name_label);
86
87 fields_pane.setLayout(new GridLayout(2,1,5,0));
88 fields_pane.add(file_field);
89 fields_pane.add(name_field);
90
91 center_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
92 center_pane.setLayout(new BorderLayout(5,0));
93 center_pane.add(labels_pane, BorderLayout.WEST);
94 center_pane.add(fields_pane, BorderLayout.CENTER);
95
96 button_pane.setLayout(new GridLayout(1,2,5,5));
97 button_pane.add(ok_button);
98 button_pane.add(cancel_button);
99
100 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
101 content_pane.setLayout(new BorderLayout());
102 content_pane.add(center_pane, BorderLayout.CENTER);
103 content_pane.add(button_pane, BorderLayout.SOUTH);
104
105 // Display
106 Dimension screen_size = Configuration.screen_size;
107 setLocation((screen_size.width - DIALOG_SIZE.width) / 2, (screen_size.height - DIALOG_SIZE.height) / 2);
108 setVisible(true);
109
110 // If not cancelled create mapping.
111 if (!cancelled) {
112 workspace_tree.addDirectoryMapping(name_field.getText(), file);
113 }
114 }
115
116
117 public void actionPerformed(ActionEvent event)
118 {
119 if (event.getSource() == cancel_button) {
120 cancelled = true;
121 }
122 dispose();
123 }
124
125
126 public void destroy()
127 {
128 cancel_button = null;
129 ok_button = null;
130 name_field = null;
131 }
132
133
134 public void keyPressed(KeyEvent event) { }
135
136 public void keyReleased(KeyEvent event)
137 {
138 ok_button.setEnabled(name_field.getText().length() > 0);
139 }
140
141 public void keyTyped(KeyEvent event) { }
142}
Note: See TracBrowser for help on using the repository browser.