[6318] | 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.*;
|
---|
[8231] | 42 | import org.greenstone.gatherer.Configuration;
|
---|
[6318] | 43 | import org.greenstone.gatherer.Dictionary;
|
---|
| 44 | import 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 | */
|
---|
| 50 | final 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. */
|
---|
[9856] | 64 | final static private Dimension SIZE = new Dimension(400, 300);
|
---|
[6318] | 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"));
|
---|
[7246] | 89 | if (editable) {
|
---|
[12119] | 90 | setTitle(Dictionary.get("General.Edit"));
|
---|
[7246] | 91 | } else {
|
---|
[12119] | 92 | setTitle(Dictionary.get("General.View"));
|
---|
[7246] | 93 | }
|
---|
[6318] | 94 | // Create
|
---|
| 95 | text = new JTextArea(value);
|
---|
| 96 | text.setCaretPosition(value.length());
|
---|
| 97 | text.setEditable(editable);
|
---|
| 98 | text.setLineWrap(true);
|
---|
| 99 | text.setWrapStyleWord(false);
|
---|
[7246] | 100 | if (editable) {
|
---|
[12119] | 101 | text.setToolTipText(Dictionary.get("EnrichPane.Value_Field_Tooltip"));
|
---|
[7246] | 102 | } else {
|
---|
[12119] | 103 | text.setToolTipText(Dictionary.get("EnrichPane.Value_Field_Tooltip_Uneditable"));
|
---|
[7246] | 104 | }
|
---|
[6318] | 105 |
|
---|
[12119] | 106 | cancel = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Pure_Cancel_Tooltip"));
|
---|
| 107 |
|
---|
| 108 | ok = new GLIButton(Dictionary.get("General.OK"), Dictionary.get("General.OK_Tooltip"));
|
---|
| 109 |
|
---|
[6318] | 110 |
|
---|
| 111 | // Listeners
|
---|
| 112 | cancel.addActionListener(this);
|
---|
| 113 | ok.addActionListener(this);
|
---|
| 114 |
|
---|
| 115 | // Layout
|
---|
| 116 | JPanel button_pane = new JPanel();
|
---|
| 117 | button_pane.setLayout(new GridLayout(1,2));
|
---|
| 118 | if(editable) {
|
---|
| 119 | button_pane.add(ok);
|
---|
| 120 | button_pane.add(cancel);
|
---|
| 121 | }
|
---|
| 122 | else {
|
---|
| 123 | button_pane.add(new JPanel());
|
---|
| 124 | button_pane.add(ok);
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | JPanel content_pane = (JPanel) getContentPane();
|
---|
| 128 | content_pane.setLayout(new BorderLayout());
|
---|
| 129 | content_pane.add(new JScrollPane(text), BorderLayout.CENTER);
|
---|
| 130 | content_pane.add(button_pane, BorderLayout.SOUTH);
|
---|
| 131 |
|
---|
[8231] | 132 | Dimension screen_size = Configuration.screen_size;
|
---|
[6318] | 133 | setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
|
---|
| 134 | setVisible(true);
|
---|
| 135 | return result;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
[7246] | 138 | /** Specify if this text dialog should be editable or readonly
|
---|
| 139 | * @param editable true to allow editing, false otherwise
|
---|
| 140 | */
|
---|
| 141 | public void setEditable(boolean editable) {
|
---|
[6318] | 142 | if(text == null) {
|
---|
| 143 | this.editable = editable;
|
---|
| 144 | }
|
---|
| 145 | else {
|
---|
| 146 | text.setEditable(editable);
|
---|
| 147 | }
|
---|
| 148 | }
|
---|
| 149 | }
|
---|