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

Last change on this file since 4448 was 4427, checked in by kjdon, 21 years ago

the modal dialog now is one of our special ModalDialogs which only block the parent, enabling the use of help files while the dialog is open. A SimpleMenuBar with help on it has been added to the dialog.

  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1package org.greenstone.gatherer.gui;
2/**
3 *#########################################################################
4 *
5 * A component of the Gatherer application, part of the Greenstone digital
6 * library suite from the New Zealand Digital Library Project at the
7 * University of Waikato, New Zealand.
8 *
9 * <BR><BR>
10 *
11 * Author: John Thompson, Greenstone Digital Library, University of Waikato
12 *
13 * <BR><BR>
14 *
15 * Copyright (C) 1999 New Zealand Digital Library Project
16 *
17 * <BR><BR>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * <BR><BR>
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * <BR><BR>
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 *########################################################################
37 */
38import java.awt.*;
39import java.awt.event.*;
40import javax.swing.*;
41import org.greenstone.gatherer.Gatherer;
42import org.greenstone.gatherer.gui.SimpleMenuBar;
43import org.greenstone.gatherer.gui.ModalDialog;
44
45/** A class that extends a JDialog into a editor for editing large block of text for the metadata value.
46 * @author John Thompson, Greenstone Digital Library, University of Waikato
47 * @version 2.3
48 */
49final public class EditorDialog
50 extends ModalDialog
51 implements ActionListener {
52 /** The cancel, and I don't want the text I've typed, button. */
53 private JButton cancel = null;
54 /** The ok, I'll save what I've just typed in, button. */
55 private JButton ok = null;
56 /** The area in which we type. */
57 private JTextArea text = null;
58 /** And what result should be passed back to our caller. */
59 private String result = null;
60 /** The size of the edit pop-up. */
61 final static private Dimension SIZE = new Dimension(400,425);
62 /** Constructor.*/
63 public EditorDialog() {
64 super(Gatherer.g_man);
65
66 }
67 /** 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.
68 * @param event An <strong>ActionEvent</strong> containing information about the event.
69 */
70 public void actionPerformed(ActionEvent event) {
71 if(event.getSource() == ok) {
72 result = text.getText();
73 }
74 dispose();
75 }
76 /** Method to display the editing box on screen.
77 * @param value The initial text to be displayed in the editing area, as a <strong>String</strong>.
78 * @return The new value for the metadata value as a <strong>String</strong> or <i>null</i> if the user has pressed cancel.
79 */
80 public String display(String value) {
81 setModal(true);
82 setSize(SIZE);
83 setTitle(Gatherer.dictionary.get("General.Edit"));
84 setJMenuBar(new SimpleMenuBar("6.1"));
85 // Create
86 cancel = new JButton(Gatherer.dictionary.get("General.Cancel"));
87 ok = new JButton(Gatherer.dictionary.get("General.OK"));
88 text = new JTextArea(value);
89 text.setCaretPosition(value.length());
90 text.setEditable(true);
91 text.setLineWrap(true);
92 text.setWrapStyleWord(true);
93 // Listeners
94 cancel.addActionListener(this);
95 ok.addActionListener(this);
96 // Layout
97 JPanel button_pane = new JPanel();
98 button_pane.setLayout(new GridLayout(1,2));
99 button_pane.add(ok);
100 button_pane.add(cancel);
101
102 JPanel content_pane = (JPanel) getContentPane();
103 content_pane.setLayout(new BorderLayout());
104 content_pane.add(new JScrollPane(text), BorderLayout.CENTER);
105 content_pane.add(button_pane, BorderLayout.SOUTH);
106
107 Dimension screen_size = Gatherer.config.screen_size;
108 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
109 setVisible(true);
110 return result;
111 }
112}
Note: See TracBrowser for help on using the repository browser.