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

Last change on this file since 21999 was 18370, checked in by kjdon, 15 years ago

committed code submitted by Amin Hedjazi for making the GLI right to left. I worked on this code on the rtl-gli branch, then merged the branch back to the trunk at revision 18368. The branch code was slightly different in a couple of places where it shouldn't have been. So don't use the branch code next time. Start a new branch.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 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 this.setComponentOrientation(Dictionary.getOrientation());
70 }
71
72 /** 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.
73 * @param event An <strong>ActionEvent</strong> containing information about the event.
74 */
75 public void actionPerformed(ActionEvent event) {
76 if (event.getSource() == ok) {
77 result = text.getText();
78 }
79 dispose();
80 }
81
82 /** Method to display the editing box on screen.
83 * @param value The initial text to be displayed in the editing area, as a <strong>String</strong>.
84 * @return The new value for the metadata value as a <strong>String</strong> or <i>null</i> if the user has pressed cancel.
85 */
86 public String display(String value) {
87 setModal(true);
88 setSize(SIZE);
89 setJMenuBar(new SimpleMenuBar("theenrichview"));
90 if (editable) {
91 setTitle(Dictionary.get("General.Edit"));
92 } else {
93 setTitle(Dictionary.get("General.View"));
94 }
95 // Create
96 text = new JTextArea(value);
97 text.setComponentOrientation(Dictionary.getOrientation());
98 text.setCaretPosition(value.length());
99 text.setEditable(editable);
100 text.setLineWrap(true);
101 text.setWrapStyleWord(false);
102 if (editable) {
103 text.setToolTipText(Dictionary.get("EnrichPane.Value_Field_Tooltip"));
104 } else {
105 text.setToolTipText(Dictionary.get("EnrichPane.Value_Field_Tooltip_Uneditable"));
106 }
107
108 cancel = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Pure_Cancel_Tooltip"));
109
110 ok = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
111
112
113 // Listeners
114 cancel.addActionListener(this);
115 ok.addActionListener(this);
116
117 // Layout
118 JPanel button_pane = new JPanel();
119 button_pane.setComponentOrientation(Dictionary.getOrientation());
120 button_pane.setLayout(new GridLayout(1,2));
121 if(editable) {
122 button_pane.add(ok);
123 button_pane.add(cancel);
124 }
125 else {
126 button_pane.add(new JPanel());
127 button_pane.add(ok);
128 }
129
130 JPanel content_pane = (JPanel) getContentPane();
131 content_pane.setComponentOrientation(Dictionary.getOrientation());
132 content_pane.setLayout(new BorderLayout());
133 JScrollPane scrol_tmp;
134 scrol_tmp = new JScrollPane(text);
135 scrol_tmp.setComponentOrientation(Dictionary.getOrientation());
136 content_pane.add(scrol_tmp, BorderLayout.CENTER);
137 content_pane.add(button_pane, BorderLayout.SOUTH);
138
139 Dimension screen_size = Configuration.screen_size;
140 setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
141 setVisible(true);
142 return result;
143 }
144
145 /** Specify if this text dialog should be editable or readonly
146 * @param editable true to allow editing, false otherwise
147 */
148 public void setEditable(boolean editable) {
149 if(text == null) {
150 this.editable = editable;
151 }
152 else {
153 text.setEditable(editable);
154 }
155 }
156}
Note: See TracBrowser for help on using the repository browser.