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

Last change on this file since 7183 was 7155, checked in by kjdon, 20 years ago

added in a missing semi-colon - how that escaped my notice I do not know

  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 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.GLIButton;
36import org.greenstone.gatherer.gui.SimpleMenuBar;
37import org.greenstone.gatherer.gui.ModalDialog;
38import org.greenstone.gatherer.util.Utility;
39
40/** 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. */
41public class MetaEditPrompt
42 extends ModalDialog
43 implements ActionListener {
44
45 private int value;
46 private JButton accumulate;
47 private JButton accumulate_all;
48 private JButton cancel;
49 private JButton skip;
50 private JButton overwrite;
51 private JButton overwrite_all;
52 private JButton remove;
53 private JButton remove_all;
54 private JButton update;
55 private JButton update_all;
56
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
100 JPanel labels_panel = new JPanel();
101 JPanel fields_panel = new JPanel();
102
103 JLabel filename_label = new JLabel();
104 Dictionary.setText(filename_label, "MetaEditPrompt.File");
105 JTextField filename_field = new JTextField(Utility.trimCenter(file.getAbsolutePath(), 120));
106 filename_field.setEditable(false);
107 filename_field.setFont(Gatherer.config.getFont("general.tooltip_font", false));
108 filename_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
109
110 JLabel element_label = new JLabel();
111 Dictionary.setText(element_label, "MetaEditPrompt.Element");
112 JTextField element_field = new JTextField(element);
113 element_field.setEditable(false);
114 element_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
115
116 JLabel current_value_label = new JLabel();
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
122 JLabel new_value_label = new JLabel();
123 Dictionary.setText(new_value_label, "MetaEditPrompt.New_Value");
124 JTextField new_value_field = new JTextField(new_value); // , (type == ADD_PROMPT || type == UPDATE_PROMPT));
125 new_value_field.setEditable(false);
126 new_value_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
127
128 JPanel buttons_pane = new JPanel();
129
130 accumulate = new GLIButton();
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 GLIButton();
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 GLIButton();
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 GLIButton();
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 GLIButton();
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 GLIButton();
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 GLIButton();
161 skip.setEnabled(multiple_selection);
162 skip.setMnemonic(KeyEvent.VK_S);
163 Dictionary.setBoth(skip, "MetaEditPrompt.Skip", "MetaEditPrompt.Skip_Tooltip");
164
165 cancel = new GLIButton();
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 labels_panel.setLayout (new GridLayout(4,1,5,5));
183 labels_panel.add(filename_label);
184 labels_panel.add(element_label);
185 labels_panel.add(current_value_label);
186 labels_panel.add(new_value_label);
187
188 fields_panel.setLayout (new GridLayout(4,1,5,5));
189 fields_panel.add(filename_field);
190 fields_panel.add(element_field);
191 fields_panel.add(current_value_field);
192 fields_panel.add(new_value_field);
193
194 details_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
195 details_pane.setLayout(new BorderLayout(5,0));
196 details_pane.add(labels_panel, BorderLayout.WEST);
197 details_pane.add(fields_panel, BorderLayout.CENTER);
198
199 buttons_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
200 buttons_pane.setLayout(new GridLayout(1,4,0,0));
201
202 if (type.equals(ADD_PROMPT)) {
203 buttons_pane.add(accumulate);
204 buttons_pane.add(accumulate_all);
205 }
206 else if (type.equals(UPDATE_PROMPT)) {
207 buttons_pane.add(overwrite);
208 buttons_pane.add(overwrite_all);
209 }
210 else if (type.equals(REMOVE_PROMPT)) {
211 buttons_pane.add(remove);
212 buttons_pane.add(remove_all);
213 }
214 buttons_pane.add(skip);
215 buttons_pane.add(cancel);
216
217 content_pane.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
218 content_pane.setLayout(new BorderLayout());
219 content_pane.add(title_label, BorderLayout.NORTH);
220 content_pane.add(details_pane, BorderLayout.CENTER);
221 content_pane.add(buttons_pane, BorderLayout.SOUTH);
222
223 // Position
224 Rectangle frame_bounds = Gatherer.g_man.getBounds();
225 this.setLocation(frame_bounds.x + ((frame_bounds.width - SIZE.width) / 2), frame_bounds.y + ((frame_bounds.height - SIZE.height) / 2));
226 }
227
228 public void actionPerformed(ActionEvent event) {
229 Object esrc = event.getSource();
230 if(esrc == accumulate) {
231 value = ACCUMULATE;
232 }
233 else if(esrc == accumulate_all) {
234 value = ACCUMULATE_ALL;
235 }
236 else if(esrc == cancel) {
237 value = CANCEL;
238 }
239 else if(esrc == skip) {
240 value = SKIP;
241 }
242 else if(esrc == overwrite) {
243 value = OVERWRITE;
244 }
245 else if(esrc == overwrite_all) {
246 value = OVERWRITE_ALL;
247 }
248 else if(esrc == remove) {
249 value = REMOVE;
250 }
251 else if(esrc == remove_all) {
252 value = REMOVE_ALL;
253 }
254 this.dispose();
255 }
256
257 public int display() {
258 setVisible(true);
259 return value;
260 }
261}
Note: See TracBrowser for help on using the repository browser.