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