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

Last change on this file since 8257 was 8243, checked in by mdewsnip, 20 years ago

Removed all occurrences of classes explicitly importing other classes in the same package.

  • Property svn:keywords set to Author Date Id Revision
File size: 9.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.Configuration;
34import org.greenstone.gatherer.Dictionary;
35import org.greenstone.gatherer.Gatherer;
36import org.greenstone.gatherer.util.Utility;
37
38/** 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. */
39public class MetaEditPrompt
40 extends ModalDialog
41 implements ActionListener {
42
43 private int value;
44 private JButton accumulate;
45 private JButton accumulate_all;
46 private JButton cancel;
47 private JButton skip;
48 private JButton overwrite;
49 private JButton overwrite_all;
50 private JButton remove;
51 private JButton remove_all;
52 private JButton update;
53 private JButton update_all;
54
55 static private Dimension SIZE = new Dimension(712, 250);
56 // Generic prompt values.
57 static public int CONFIRM = 0;
58 static public int CANCEL = 1;
59 static public int SKIP = 2;
60 // Values for the different add and update action prompts.
61 static public int ACCUMULATE = 3;
62 static public int ACCUMULATE_ALL = 4;
63 static public int OVERWRITE = 5;
64 static public int OVERWRITE_ALL = 6;
65 static public int UPDATE_ONCE = 7; // Caused by SARM
66 // Values for the different remove action prompts.
67 static public int REMOVE = 8;
68 static public int REMOVE_ALL = 9;
69 // Prompt Types
70 static public String ADD_PROMPT = "MetaEditPrompt.Add_Prompt";
71 static public String REMOVE_PROMPT = "MetaEditPrompt.Remove_Prompt";
72 static public String UPDATE_PROMPT = "MetaEditPrompt.Overwrite_Prompt";
73
74 public MetaEditPrompt(String type, boolean multiple_selection, File file, String element, String current_value, String new_value) {
75 super(Gatherer.g_man, true); // Needed for modal response!
76
77 // Setup
78 this.setSize(SIZE);
79 Dictionary.setText(this, "MetaEditPrompt.Title");
80
81 if (type.equals(ADD_PROMPT)) {
82 this.setJMenuBar(new SimpleMenuBar("appendingmetadata"));
83 }
84 else if (type.equals(UPDATE_PROMPT)) {
85 this.setJMenuBar(new SimpleMenuBar("updatingmetadata"));
86 }
87 else if (type.equals(REMOVE_PROMPT)) {
88 this.setJMenuBar(new SimpleMenuBar("removingmetadata"));
89 }
90
91 // Creation
92 JPanel content_pane = (JPanel)this.getContentPane();
93 JLabel title_label = new JLabel();
94 Dictionary.setText(title_label, type);
95
96 JPanel details_pane = new JPanel();
97
98 JPanel labels_panel = new JPanel();
99 JPanel fields_panel = new JPanel();
100
101 JLabel filename_label = new JLabel();
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(Configuration.getFont("general.tooltip_font", false));
106 filename_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
107
108 JLabel element_label = new JLabel();
109 Dictionary.setText(element_label, "MetaEditPrompt.Element");
110 JTextField element_field = new JTextField(element);
111 element_field.setEditable(false);
112 element_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
113
114 JLabel current_value_label = new JLabel();
115 Dictionary.setText(current_value_label, "MetaEditPrompt.Current_Value");
116 JTextField current_value_field = new JTextField(current_value);
117 current_value_field.setEditable(false);
118 current_value_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
119
120 JLabel new_value_label = new JLabel();
121 Dictionary.setText(new_value_label, "MetaEditPrompt.New_Value");
122 JTextField new_value_field = new JTextField(new_value); // , (type == ADD_PROMPT || type == UPDATE_PROMPT));
123 new_value_field.setEditable(false);
124 new_value_field.setBackground(Configuration.getColor("coloring.collection_tree_background", false));
125
126 JPanel buttons_pane = new JPanel();
127
128 accumulate = new GLIButton();
129 accumulate.setEnabled(type == ADD_PROMPT);
130 accumulate.setMnemonic(KeyEvent.VK_A);
131 Dictionary.setBoth(accumulate, "MetaEdit.Accumulate", "MetaEdit.Accumulate_Tooltip");
132
133 accumulate_all = new GLIButton();
134 accumulate_all.setEnabled(type == ADD_PROMPT && multiple_selection);
135 accumulate_all.setMnemonic(KeyEvent.VK_L);
136 Dictionary.setBoth(accumulate_all, "MetaEditPrompt.Accumulate_All", "MetaEditPrompt.Accumulate_All_Tooltip");
137
138 overwrite = new GLIButton();
139 overwrite.setEnabled(type == UPDATE_PROMPT);
140 overwrite.setMnemonic(KeyEvent.VK_R);
141 Dictionary.setBoth(overwrite, "MetaEdit.Overwrite", "MetaEdit.Overwrite_Tooltip");
142
143 overwrite_all = new GLIButton();
144 overwrite_all.setEnabled(type == UPDATE_PROMPT && multiple_selection);
145 overwrite_all.setMnemonic(KeyEvent.VK_P);
146 Dictionary.setBoth(overwrite_all, "MetaEditPrompt.Overwrite_All", "MetaEditPrompt.Overwrite_All_Tooltip");
147
148 remove = new GLIButton();
149 remove.setEnabled(type == REMOVE_PROMPT);
150 remove.setMnemonic(KeyEvent.VK_R);
151 Dictionary.setBoth(remove, "MetaEdit.Remove", "MetaEdit.Remove_Tooltip");
152
153 remove_all = new GLIButton();
154 remove_all.setEnabled(type == REMOVE_PROMPT && multiple_selection);
155 remove_all.setMnemonic(KeyEvent.VK_A);
156 Dictionary.setBoth(remove_all, "MetaEditPrompt.Remove_All", "MetaEditPrompt.Remove_All_Tooltip");
157
158 skip = new GLIButton();
159 skip.setEnabled(multiple_selection);
160 skip.setMnemonic(KeyEvent.VK_S);
161 Dictionary.setBoth(skip, "MetaEditPrompt.Skip", "MetaEditPrompt.Skip_Tooltip");
162
163 cancel = new GLIButton();
164 cancel.setMnemonic(KeyEvent.VK_C);
165 Dictionary.setBoth(cancel, "General.Cancel", "General.Cancel_Tooltip");
166
167 // Connection
168 accumulate.addActionListener(this);
169 accumulate_all.addActionListener(this);
170 cancel.addActionListener(this);
171 overwrite.addActionListener(this);
172 overwrite_all.addActionListener(this);
173 remove.addActionListener(this);
174 remove_all.addActionListener(this);
175 skip.addActionListener(this);
176
177 // Layout
178 title_label.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
179
180 labels_panel.setLayout (new GridLayout(4,1,5,5));
181 labels_panel.add(filename_label);
182 labels_panel.add(element_label);
183 labels_panel.add(current_value_label);
184 labels_panel.add(new_value_label);
185
186 fields_panel.setLayout (new GridLayout(4,1,5,5));
187 fields_panel.add(filename_field);
188 fields_panel.add(element_field);
189 fields_panel.add(current_value_field);
190 fields_panel.add(new_value_field);
191
192 details_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
193 details_pane.setLayout(new BorderLayout(5,0));
194 details_pane.add(labels_panel, BorderLayout.WEST);
195 details_pane.add(fields_panel, BorderLayout.CENTER);
196
197 buttons_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
198 buttons_pane.setLayout(new GridLayout(1,4,0,0));
199
200 if (type.equals(ADD_PROMPT)) {
201 buttons_pane.add(accumulate);
202 buttons_pane.add(accumulate_all);
203 }
204 else if (type.equals(UPDATE_PROMPT)) {
205 buttons_pane.add(overwrite);
206 buttons_pane.add(overwrite_all);
207 }
208 else if (type.equals(REMOVE_PROMPT)) {
209 buttons_pane.add(remove);
210 buttons_pane.add(remove_all);
211 }
212 buttons_pane.add(skip);
213 buttons_pane.add(cancel);
214
215 content_pane.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
216 content_pane.setLayout(new BorderLayout());
217 content_pane.add(title_label, BorderLayout.NORTH);
218 content_pane.add(details_pane, BorderLayout.CENTER);
219 content_pane.add(buttons_pane, BorderLayout.SOUTH);
220
221 // Position
222 Rectangle frame_bounds = Gatherer.g_man.getBounds();
223 this.setLocation(frame_bounds.x + ((frame_bounds.width - SIZE.width) / 2), frame_bounds.y + ((frame_bounds.height - SIZE.height) / 2));
224 }
225
226 public void actionPerformed(ActionEvent event) {
227 Object esrc = event.getSource();
228 if(esrc == accumulate) {
229 value = ACCUMULATE;
230 }
231 else if(esrc == accumulate_all) {
232 value = ACCUMULATE_ALL;
233 }
234 else if(esrc == cancel) {
235 value = CANCEL;
236 }
237 else if(esrc == skip) {
238 value = SKIP;
239 }
240 else if(esrc == overwrite) {
241 value = OVERWRITE;
242 }
243 else if(esrc == overwrite_all) {
244 value = OVERWRITE_ALL;
245 }
246 else if(esrc == remove) {
247 value = REMOVE;
248 }
249 else if(esrc == remove_all) {
250 value = REMOVE_ALL;
251 }
252 this.dispose();
253 }
254
255 public int display() {
256 setVisible(true);
257 return value;
258 }
259}
Note: See TracBrowser for help on using the repository browser.