source: trunk/gli/src/org/greenstone/gatherer/gui/RenamePrompt.java@ 12657

Last change on this file since 12657 was 12657, checked in by kjdon, 18 years ago

pressing Enter in the text field now closes the prompt

  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1/**
2 *############################################################################
3 * A component of the Greenstone Librarian Interface, part of the Greenstone
4 * digital library suite from the New Zealand Digital Library Project at the
5 * University of Waikato, New Zealand.
6 *
7 * Author: Michael Dewsnip, NZDL Project, University of Waikato, NZ
8 *
9 * Copyright (C) 2006 New Zealand Digital Library Project
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *############################################################################
25 */
26package org.greenstone.gatherer.gui;
27
28import java.awt.*;
29import java.awt.event.*;
30import java.io.*;
31import javax.swing.*;
32import org.greenstone.gatherer.Dictionary;
33import org.greenstone.gatherer.Gatherer;
34import org.greenstone.gatherer.collection.CollectionTreeNode;
35
36
37public class RenamePrompt
38 extends JDialog
39 implements ActionListener, KeyListener
40{
41 private JButton cancel_button;
42 private JButton ok_button;
43 private JTextField name_textfield;
44 private String name;
45
46 static final private Dimension SIZE = new Dimension(350, 100);
47
48
49 public RenamePrompt(CollectionTreeNode collection_tree_node)
50 {
51 super(Gatherer.g_man, true);
52 setTitle(Dictionary.get("RenamePrompt.Title"));
53 name = collection_tree_node.getFile().getName();
54 }
55
56
57 public void actionPerformed(ActionEvent event)
58 {
59 if (event.getSource() == ok_button) {
60 name = name_textfield.getText();
61 }
62 else if (event.getSource() == cancel_button) {
63 name = null;
64 }
65 dispose();
66 }
67
68 public void keyPressed(KeyEvent e) {
69 if (e.getKeyCode() == KeyEvent.VK_ENTER) {
70 // Enter: Click the button in focus
71 Object source = e.getSource();
72 if (source instanceof AbstractButton) {
73 ((AbstractButton) source).doClick();
74 } else if (source == name_textfield) {
75 ok_button.doClick();
76 }
77 }
78 }
79
80 public void keyReleased(KeyEvent e) { }
81
82 public void keyTyped(KeyEvent e) { }
83
84
85 public String display()
86 {
87 setSize(SIZE);
88 JPanel content_pane = (JPanel) getContentPane();
89
90 JPanel info_pane = new JPanel();
91
92 JLabel name_label = new JLabel(Dictionary.get("RenamePrompt.Name"));
93 name_textfield = new JTextField(name);
94
95 JPanel button_pane = new JPanel();
96 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
97 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Pure_Cancel_Tooltip"));
98
99 // Connection
100 cancel_button.addActionListener(this);
101 ok_button.addActionListener(this);
102 ok_button.addKeyListener(this);
103 name_textfield.addKeyListener(this);
104
105 // Layout
106 info_pane.setLayout(new BorderLayout(5,0));
107 info_pane.add(name_label, BorderLayout.WEST);
108 info_pane.add(name_textfield, BorderLayout.CENTER);
109
110 button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
111 button_pane.setLayout(new GridLayout(1,2,0,5));
112 button_pane.add(ok_button);
113 button_pane.add(cancel_button);
114
115 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
116 content_pane.setLayout(new BorderLayout());
117 content_pane.add(info_pane, BorderLayout.CENTER);
118 content_pane.add(button_pane, BorderLayout.SOUTH);
119
120 // Display
121 Rectangle frame_bounds = Gatherer.g_man.getBounds();
122 setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
123 setVisible(true);
124 return name;
125 }
126}
Note: See TracBrowser for help on using the repository browser.