source: trunk/gli/src/org/greenstone/gatherer/gui/MetaEditPrompt.java@ 5590

Last change on this file since 5590 was 5536, checked in by mdewsnip, 21 years ago

Many more tooltips and improvements to the Dictionary. Still more to come.

  • Property svn:keywords set to Author Date Id Revision
File size: 10.4 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 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.gui;
28
29import java.awt.*;
30import java.awt.event.*;
31import java.io.File;
32import javax.swing.*;
33import org.greenstone.gatherer.Dictionary;
34import org.greenstone.gatherer.Gatherer;
35import org.greenstone.gatherer.gui.SimpleMenuBar;
36import org.greenstone.gatherer.gui.ModalDialog;
37import org.greenstone.gatherer.util.Utility;
38
39/** Displays a dynamic prompt to allow the user to choose how metadata is to be added, updated or removed from target FileNodes. The prompt changes depending on the action requested, the file nodes encountered and the number of file nodes in the selection. */
40public class MetaEditPrompt
41 extends ModalDialog
42 implements ActionListener {
43
44 private int value;
45 private JButton accumulate;
46 private JButton accumulate_all;
47 private JButton cancel;
48 private JButton skip;
49 private JButton overwrite;
50 private JButton overwrite_all;
51 private JButton remove;
52 private JButton remove_all;
53 private JButton update;
54 private JButton update_all;
55
56 static private Dimension LABEL_SIZE = new Dimension(100, 25);
57 static private Dimension SIZE = new Dimension(712, 250);
58 // Generic prompt values.
59 static public int CONFIRM = 0;
60 static public int CANCEL = 1;
61 static public int SKIP = 2;
62 // Values for the different add and update action prompts.
63 static public int ACCUMULATE = 3;
64 static public int ACCUMULATE_ALL = 4;
65 static public int OVERWRITE = 5;
66 static public int OVERWRITE_ALL = 6;
67 static public int UPDATE_ONCE = 7; // Caused by SARM
68 // Values for the different remove action prompts.
69 static public int REMOVE = 8;
70 static public int REMOVE_ALL = 9;
71 // Prompt Types
72 static public String ADD_PROMPT = "MetaEditPrompt.Add_Prompt";
73 static public String REMOVE_PROMPT = "MetaEditPrompt.Remove_Prompt";
74 static public String UPDATE_PROMPT = "MetaEditPrompt.Overwrite_Prompt";
75
76 public MetaEditPrompt(String type, boolean multiple_selection, File file, String element, String current_value, String new_value) {
77 super(Gatherer.g_man, true); // Needed for modal response!
78
79 // Setup
80 this.setSize(SIZE);
81 Dictionary.setText(this, "MetaEditPrompt.Title");
82
83 if (type.equals(ADD_PROMPT)) {
84 this.setJMenuBar(new SimpleMenuBar("appendingmetadata"));
85 }
86 else if (type.equals(UPDATE_PROMPT)) {
87 this.setJMenuBar(new SimpleMenuBar("updatingmetadata"));
88 }
89 else if (type.equals(REMOVE_PROMPT)) {
90 this.setJMenuBar(new SimpleMenuBar("removingmetadata"));
91 }
92
93 // Creation
94 JPanel content_pane = (JPanel)this.getContentPane();
95 JLabel title_label = new JLabel();
96 Dictionary.setText(title_label, type);
97
98 JPanel details_pane = new JPanel();
99 JPanel filename_panel = new JPanel();
100 JLabel filename_label = new JLabel();
101 filename_label.setPreferredSize(LABEL_SIZE);
102 Dictionary.setText(filename_label, "MetaEditPrompt.File");
103 JTextField filename_field = new JTextField(Utility.trimCenter(file.getAbsolutePath(), 120));
104 filename_field.setEditable(false);
105 filename_field.setFont(Gatherer.config.getFont("general.tooltip_font", false));
106 filename_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
107 JPanel element_panel = new JPanel();
108 JLabel element_label = new JLabel();
109 element_label.setPreferredSize(LABEL_SIZE);
110 Dictionary.setText(element_label, "MetaEditPrompt.Element");
111 JTextField element_field = new JTextField(element);
112 element_field.setEditable(false);
113 element_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
114 JPanel current_value_panel = new JPanel();
115 JLabel current_value_label = new JLabel();
116 current_value_label.setPreferredSize(LABEL_SIZE);
117 Dictionary.setText(current_value_label, "MetaEditPrompt.Current_Value");
118 JTextField current_value_field = new JTextField(current_value);
119 current_value_field.setEditable(false);
120 current_value_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
121 JPanel new_value_panel = new JPanel();
122 JLabel new_value_label = new JLabel();
123 new_value_label.setPreferredSize(LABEL_SIZE);
124 Dictionary.setText(new_value_label, "MetaEditPrompt.New_Value");
125 JTextField new_value_field = new JTextField(new_value); // , (type == ADD_PROMPT || type == UPDATE_PROMPT));
126 new_value_field.setEditable(false);
127 new_value_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
128 JPanel buttons_pane = new JPanel();
129
130 accumulate = new JButton();
131 accumulate.setEnabled(type == ADD_PROMPT);
132 accumulate.setMnemonic(KeyEvent.VK_A);
133 Dictionary.setBoth(accumulate, "MetaEdit.Accumulate", "MetaEdit.Accumulate_Tooltip");
134
135 accumulate_all = new JButton();
136 accumulate_all.setEnabled(type == ADD_PROMPT && multiple_selection);
137 accumulate_all.setMnemonic(KeyEvent.VK_L);
138 Dictionary.setBoth(accumulate_all, "MetaEditPrompt.Accumulate_All", "MetaEditPrompt.Accumulate_All_Tooltip");
139
140 overwrite = new JButton();
141 overwrite.setEnabled(type == UPDATE_PROMPT);
142 overwrite.setMnemonic(KeyEvent.VK_R);
143 Dictionary.setBoth(overwrite, "MetaEdit.Overwrite", "MetaEdit.Overwrite_Tooltip");
144
145 overwrite_all = new JButton();
146 overwrite_all.setEnabled(type == UPDATE_PROMPT && multiple_selection);
147 overwrite_all.setMnemonic(KeyEvent.VK_P);
148 Dictionary.setBoth(overwrite_all, "MetaEditPrompt.Overwrite_All", "MetaEditPrompt.Overwrite_All_Tooltip");
149
150 remove = new JButton();
151 remove.setEnabled(type == REMOVE_PROMPT);
152 remove.setMnemonic(KeyEvent.VK_R);
153 Dictionary.setBoth(remove, "MetaEdit.Remove", "MetaEdit.Remove_Tooltip");
154
155 remove_all = new JButton();
156 remove_all.setEnabled(type == REMOVE_PROMPT && multiple_selection);
157 remove_all.setMnemonic(KeyEvent.VK_A);
158 Dictionary.setBoth(remove_all, "MetaEditPrompt.Remove_All", "MetaEditPrompt.Remove_All_Tooltip");
159
160 skip = new JButton();
161 skip.setEnabled(multiple_selection);
162 skip.setMnemonic(KeyEvent.VK_S);
163 Dictionary.setBoth(skip, "MetaEditPrompt.Skip", "MetaEditPrompt.Skip_Tooltip");
164
165 cancel = new JButton();
166 cancel.setMnemonic(KeyEvent.VK_C);
167 Dictionary.setBoth(cancel, "General.Cancel", "General.Cancel_Tooltip");
168
169 // Connection
170 accumulate.addActionListener(this);
171 accumulate_all.addActionListener(this);
172 cancel.addActionListener(this);
173 overwrite.addActionListener(this);
174 overwrite_all.addActionListener(this);
175 remove.addActionListener(this);
176 remove_all.addActionListener(this);
177 skip.addActionListener(this);
178
179 // Layout
180 title_label.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
181
182 filename_panel.setLayout(new BorderLayout());
183 filename_panel.add(filename_label, BorderLayout.WEST);
184 filename_panel.add(filename_field, BorderLayout.CENTER);
185
186 element_panel.setLayout(new BorderLayout());
187 element_panel.add(element_label, BorderLayout.WEST);
188 element_panel.add(element_field, BorderLayout.CENTER);
189
190 current_value_panel.setLayout(new BorderLayout());
191 current_value_panel.add(current_value_label, BorderLayout.WEST);
192 current_value_panel.add(current_value_field, BorderLayout.CENTER);
193
194 new_value_panel.setLayout(new BorderLayout());
195 new_value_panel.add(new_value_label, BorderLayout.WEST);
196 new_value_panel.add(new_value_field, BorderLayout.CENTER);
197
198 details_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
199 details_pane.setLayout(new GridLayout(4,1,0,4));
200 details_pane.add(filename_panel);
201 details_pane.add(element_panel);
202 details_pane.add(current_value_panel);
203 details_pane.add(new_value_panel);
204
205 buttons_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
206 buttons_pane.setLayout(new GridLayout(1,4,0,0));
207
208 if (type.equals(ADD_PROMPT)) {
209 buttons_pane.add(accumulate);
210 buttons_pane.add(accumulate_all);
211 }
212 else if (type.equals(UPDATE_PROMPT)) {
213 buttons_pane.add(overwrite);
214 buttons_pane.add(overwrite_all);
215 }
216 else if (type.equals(REMOVE_PROMPT)) {
217 buttons_pane.add(remove);
218 buttons_pane.add(remove_all);
219 }
220 buttons_pane.add(skip);
221 buttons_pane.add(cancel);
222
223 content_pane.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
224 content_pane.setLayout(new BorderLayout());
225 content_pane.add(title_label, BorderLayout.NORTH);
226 content_pane.add(details_pane, BorderLayout.CENTER);
227 content_pane.add(buttons_pane, BorderLayout.SOUTH);
228
229 // Position
230 Rectangle frame_bounds = Gatherer.g_man.getBounds();
231 this.setLocation(frame_bounds.x + ((frame_bounds.width - SIZE.width) / 2), frame_bounds.y + ((frame_bounds.height - SIZE.height) / 2));
232 }
233
234 public void actionPerformed(ActionEvent event) {
235 Object esrc = event.getSource();
236 if(esrc == accumulate) {
237 value = ACCUMULATE;
238 }
239 else if(esrc == accumulate_all) {
240 value = ACCUMULATE_ALL;
241 }
242 else if(esrc == cancel) {
243 value = CANCEL;
244 }
245 else if(esrc == skip) {
246 value = SKIP;
247 }
248 else if(esrc == overwrite) {
249 value = OVERWRITE;
250 }
251 else if(esrc == overwrite_all) {
252 value = OVERWRITE_ALL;
253 }
254 else if(esrc == remove) {
255 value = REMOVE;
256 }
257 else if(esrc == remove_all) {
258 value = REMOVE_ALL;
259 }
260 this.dispose();
261 }
262
263 public int display() {
264 setVisible(true);
265 return value;
266 }
267}
Note: See TracBrowser for help on using the repository browser.