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

Last change on this file since 4448 was 4427, checked in by kjdon, 21 years ago

the modal dialog now is one of our special ModalDialogs which only block the parent, enabling the use of help files while the dialog is open. A SimpleMenuBar with help on it has been added to the dialog.

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