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

Last change on this file since 11612 was 11612, checked in by mdewsnip, 18 years ago

Moved the MappingPrompt out of GatherPane and into it's own class called CreateShortcutPrompt.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 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 Dictionary.setText(this, "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();
67 Dictionary.setText(file_label, "MappingPrompt.File");
68 JLabel file_field = new JLabel(file.getAbsolutePath());
69
70 JLabel name_label = new JLabel();
71 Dictionary.setText(name_label, "MappingPrompt.Name");
72 name_field = new JTextField(file.getName());
73
74 JPanel button_pane = new JPanel();
75 ok_button = new GLIButton();
76 ok_button.setEnabled(name_field.getText().length() > 0);
77 ok_button.setMnemonic(KeyEvent.VK_O);
78 Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip");
79 cancel_button = new GLIButton();
80 cancel_button.setMnemonic(KeyEvent.VK_C);
81 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Cancel_Tooltip");
82
83 // Connection
84 cancel_button.addActionListener(this);
85 ok_button.addActionListener(this);
86 name_field.addKeyListener(this);
87
88 // Layout
89 labels_pane.setLayout(new GridLayout(2,1,5,0));
90 labels_pane.add(file_label);
91 labels_pane.add(name_label);
92
93 fields_pane.setLayout(new GridLayout(2,1,5,0));
94 fields_pane.add(file_field);
95 fields_pane.add(name_field);
96
97 center_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0));
98 center_pane.setLayout(new BorderLayout(5,0));
99 center_pane.add(labels_pane, BorderLayout.WEST);
100 center_pane.add(fields_pane, BorderLayout.CENTER);
101
102 button_pane.setLayout(new GridLayout(1,2,5,5));
103 button_pane.add(ok_button);
104 button_pane.add(cancel_button);
105
106 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
107 content_pane.setLayout(new BorderLayout());
108 content_pane.add(center_pane, BorderLayout.CENTER);
109 content_pane.add(button_pane, BorderLayout.SOUTH);
110
111 // Display
112 Dimension screen_size = Configuration.screen_size;
113 setLocation((screen_size.width - DIALOG_SIZE.width) / 2, (screen_size.height - DIALOG_SIZE.height) / 2);
114 setVisible(true);
115
116 // If not cancelled create mapping.
117 if (!cancelled) {
118 workspace_tree.addDirectoryMapping(name_field.getText(), file);
119 }
120 }
121
122
123 public void actionPerformed(ActionEvent event)
124 {
125 if (event.getSource() == cancel_button) {
126 cancelled = true;
127 }
128 dispose();
129 }
130
131
132 public void destroy()
133 {
134 cancel_button = null;
135 ok_button = null;
136 name_field = null;
137 }
138
139
140 public void keyPressed(KeyEvent event) { }
141
142 public void keyReleased(KeyEvent event)
143 {
144 ok_button.setEnabled(name_field.getText().length() > 0);
145 }
146
147 public void keyTyped(KeyEvent event) { }
148}
Note: See TracBrowser for help on using the repository browser.