source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/gui/RenamePrompt.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 4.5 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 this.setComponentOrientation(Dictionary.getOrientation());
53 setTitle(Dictionary.get("RenamePrompt.Title"));
54 name = collection_tree_node.getFile().getName();
55 }
56
57
58 public void actionPerformed(ActionEvent event)
59 {
60 if (event.getSource() == ok_button) {
61 name = name_textfield.getText();
62 }
63 else if (event.getSource() == cancel_button) {
64 name = null;
65 }
66 dispose();
67 }
68
69 public void keyPressed(KeyEvent e) {
70 if (e.getKeyCode() == KeyEvent.VK_ENTER) {
71 // Enter: Click the button in focus
72 Object source = e.getSource();
73 if (source instanceof AbstractButton) {
74 ((AbstractButton) source).doClick();
75 } else if (source == name_textfield) {
76 ok_button.doClick();
77 }
78 }
79 }
80
81 public void keyReleased(KeyEvent e) { }
82
83 public void keyTyped(KeyEvent e) { }
84
85
86 public String display()
87 {
88 setSize(SIZE);
89 JPanel content_pane = (JPanel) getContentPane();
90 content_pane.setComponentOrientation(Dictionary.getOrientation());
91
92 JPanel info_pane = new JPanel();
93 info_pane.setComponentOrientation(Dictionary.getOrientation());
94
95 JLabel name_label = new JLabel(Dictionary.get("RenamePrompt.Name"));
96 name_label.setComponentOrientation(Dictionary.getOrientation());
97 name_textfield = new JTextField(name);
98 name_textfield.setComponentOrientation(Dictionary.getOrientation());
99
100 JPanel button_pane = new JPanel();
101 button_pane.setComponentOrientation(Dictionary.getOrientation());
102 ok_button = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
103 cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Pure_Cancel_Tooltip"));
104
105 // Connection
106 cancel_button.addActionListener(this);
107 ok_button.addActionListener(this);
108 ok_button.addKeyListener(this);
109 name_textfield.addKeyListener(this);
110
111 // Layout
112 info_pane.setLayout(new BorderLayout(5,0));
113 info_pane.add(name_label, BorderLayout.LINE_START);
114 info_pane.add(name_textfield, BorderLayout.CENTER);
115
116 button_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
117 button_pane.setLayout(new GridLayout(1,2,0,5));
118 button_pane.add(ok_button);
119 button_pane.add(cancel_button);
120
121 content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
122 content_pane.setLayout(new BorderLayout());
123 content_pane.add(info_pane, BorderLayout.CENTER);
124 content_pane.add(button_pane, BorderLayout.SOUTH);
125
126 // Display
127 Rectangle frame_bounds = Gatherer.g_man.getBounds();
128 setLocation(frame_bounds.x + (frame_bounds.width - SIZE.width) / 2, frame_bounds.y + (frame_bounds.height - SIZE.height) / 2);
129 setVisible(true);
130 return name;
131 }
132}
Note: See TracBrowser for help on using the repository browser.