source: trunk/gli/src/org/greenstone/gatherer/gui/EditorDialog.java@ 5564

Last change on this file since 5564 was 5564, checked in by mdewsnip, 21 years ago

Many more small improvements and tooltips added. Still more to come!

  • 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 * <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 */
37package org.greenstone.gatherer.gui;
38
39import java.awt.*;
40import java.awt.event.*;
41import javax.swing.*;
42import org.greenstone.gatherer.Dictionary;
43import org.greenstone.gatherer.Gatherer;
44import org.greenstone.gatherer.gui.SimpleMenuBar;
45import org.greenstone.gatherer.gui.ModalDialog;
46
47/** A class that extends a JDialog into a editor for editing large block of text for the metadata value.
48 * @author John Thompson, Greenstone Digital Library, University of Waikato
49 * @version 2.3
50 */
51final public class EditorDialog
52 extends ModalDialog
53 implements ActionListener {
54 /** The cancel, and I don't want the text I've typed, button. */
55 private JButton cancel = null;
56 /** The ok, I'll save what I've just typed in, button. */
57 private JButton ok = null;
58 /** The area in which we type. */
59 private JTextArea text = null;
60 /** And what result should be passed back to our caller. */
61 private String result = null;
62 /** The size of the edit pop-up. */
63 final static private Dimension SIZE = new Dimension(400,425);
64
65 /** Constructor */
66 public EditorDialog() {
67 super(Gatherer.g_man);
68 }
69
70 /** Any implementation of ActionListener must include this method so we can be informed when an action has been performed on one of our target controls. In this case we generate a pop-up window to edit in.
71 * @param event An <strong>ActionEvent</strong> containing information about the event.
72 */
73 public void actionPerformed(ActionEvent event) {
74 if (event.getSource() == ok) {
75 result = text.getText();
76 }
77 dispose();
78 }
79
80 /** Method to display the editing box on screen.
81 * @param value The initial text to be displayed in the editing area, as a <strong>String</strong>.
82 * @return The new value for the metadata value as a <strong>String</strong> or <i>null</i> if the user has pressed cancel.
83 */
84 public String display(String value) {
85 setModal(true);
86 setSize(SIZE);
87 setJMenuBar(new SimpleMenuBar("theenrichview"));
88 Dictionary.setText(this, "General.Edit");
89
90 // Create
91 text = new JTextArea(value);
92 text.setCaretPosition(value.length());
93 text.setEditable(true);
94 text.setLineWrap(true);
95 text.setWrapStyleWord(true);
96 Dictionary.setTooltip(text, "MetaEdit.Value_Field_Tooltip");
97
98 cancel = new JButton();
99 cancel.setMnemonic(KeyEvent.VK_C);
100 Dictionary.setBoth(cancel, "General.Cancel", "General.Pure_Cancel_Tooltip");
101 ok = new JButton();
102 ok.setMnemonic(KeyEvent.VK_0);
103 Dictionary.setBoth(ok, "General.OK", "General.OK_Tooltip");
104
105 // Listeners
106 cancel.addActionListener(this);
107 ok.addActionListener(this);
108
109 // Layout
110 JPanel button_pane = new JPanel();
111 button_pane.setLayout(new GridLayout(1,2));
112 button_pane.add(ok);
113 button_pane.add(cancel);
114
115 JPanel content_pane = (JPanel) getContentPane();
116 content_pane.setLayout(new BorderLayout());
117 content_pane.add(new JScrollPane(text), BorderLayout.CENTER);
118 content_pane.add(button_pane, BorderLayout.SOUTH);
119
120 Dimension screen_size = Gatherer.config.screen_size;
121 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
122 setVisible(true);
123 return result;
124 }
125}
Note: See TracBrowser for help on using the repository browser.