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

Last change on this file since 9856 was 9856, checked in by mdewsnip, 19 years ago

Major changes to the metadata value table and tree in the Enrich pane. The metadata value table now allows direct editing in the table -- hopefully much more obvious to the user. Classes involved have been untangled and are much more re-usable. Special code for replacing metadata has been added, which uses a more direct and efficient method rather than removing then adding metadata as before. And many many minor tidy-ups.

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