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

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

Changed dictionary get()s to have the whole key.

  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 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(712, 250);
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 = "MetaEditPrompt.Add_Prompt";
72 static public String REMOVE_PROMPT = "MetaEditPrompt.Remove_Prompt";
73 static public String UPDATE_PROMPT = "MetaEditPrompt.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(), 120));
91 filename_field.setFont(Gatherer.config.getFont("general.tooltip_font", false));
92 filename_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
93 JPanel element_panel = new JPanel();
94 JLabel element_label = new JLabel(get("MetaEditPrompt.Element"));
95 element_label.setPreferredSize(LABEL_SIZE);
96 TextFieldLabel element_field = new TextFieldLabel(element);
97 element_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
98 JPanel current_value_panel = new JPanel();
99 JLabel current_value_label = new JLabel(get("MetaEditPrompt.Current_Value"));
100 current_value_label.setPreferredSize(LABEL_SIZE);
101 TextFieldLabel current_value_field = new TextFieldLabel(current_value);
102 current_value_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
103 JPanel new_value_panel = new JPanel();
104 JLabel new_value_label = new JLabel(get("MetaEditPrompt.New_Value"));
105 new_value_label.setPreferredSize(LABEL_SIZE);
106 TextFieldLabel new_value_field = new TextFieldLabel(new_value, (type == ADD_PROMPT || type == UPDATE_PROMPT));
107 new_value_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
108 JPanel buttons_pane = new JPanel();
109 accumulate = new JButton(get("MetaEditPrompt.Accumulate"));
110 accumulate.setEnabled(type == ADD_PROMPT);
111 accumulate.setMnemonic(KeyEvent.VK_A);
112 accumulate_all = new JButton(get("MetaEditPrompt.Accumulate_All"));
113 accumulate_all.setEnabled(type == ADD_PROMPT && multiple_selection);
114 accumulate_all.setMnemonic(KeyEvent.VK_L);
115 cancel = new JButton(get("MetaEditPrompt.Cancel"));
116 cancel.setMnemonic(KeyEvent.VK_C);
117 skip = new JButton(get("MetaEditPrompt.Skip"));
118 skip.setEnabled(multiple_selection);
119 skip.setMnemonic(KeyEvent.VK_S);
120 overwrite = new JButton(get("MetaEditPrompt.Overwrite"));
121 overwrite.setEnabled(type == UPDATE_PROMPT);
122 overwrite.setMnemonic(KeyEvent.VK_R);
123 overwrite_all = new JButton(get("MetaEditPrompt.Overwrite_All"));
124 overwrite_all.setEnabled(type == UPDATE_PROMPT && multiple_selection);
125 overwrite_all.setMnemonic(KeyEvent.VK_P);
126 remove = new JButton(get("MetaEditPrompt.Remove"));
127 remove.setEnabled(type == REMOVE_PROMPT);
128 remove.setMnemonic(KeyEvent.VK_R);
129 remove_all = new JButton(get("MetaEditPrompt.Remove_All"));
130 remove_all.setEnabled(type == REMOVE_PROMPT && multiple_selection);
131 remove_all.setMnemonic(KeyEvent.VK_A);
132
133 // Connection
134 accumulate.addActionListener(this);
135 accumulate_all.addActionListener(this);
136 cancel.addActionListener(this);
137 overwrite.addActionListener(this);
138 overwrite_all.addActionListener(this);
139 remove.addActionListener(this);
140 remove_all.addActionListener(this);
141 skip.addActionListener(this);
142
143 // Layout
144 title_label.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
145
146 filename_panel.setLayout(new BorderLayout());
147 filename_panel.add(filename_label, BorderLayout.WEST);
148 filename_panel.add(filename_field, BorderLayout.CENTER);
149
150 element_panel.setLayout(new BorderLayout());
151 element_panel.add(element_label, BorderLayout.WEST);
152 element_panel.add(element_field, BorderLayout.CENTER);
153
154 current_value_panel.setLayout(new BorderLayout());
155 current_value_panel.add(current_value_label, BorderLayout.WEST);
156 current_value_panel.add(current_value_field, BorderLayout.CENTER);
157
158 new_value_panel.setLayout(new BorderLayout());
159 new_value_panel.add(new_value_label, BorderLayout.WEST);
160 new_value_panel.add(new_value_field, BorderLayout.CENTER);
161
162 details_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
163 details_pane.setLayout(new GridLayout(4,1,0,4));
164 details_pane.add(filename_panel);
165 details_pane.add(element_panel);
166 details_pane.add(current_value_panel);
167 details_pane.add(new_value_panel);
168
169 buttons_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2));
170 buttons_pane.setLayout(new GridLayout(2,4,0,0));
171 buttons_pane.add(accumulate);
172 buttons_pane.add(overwrite);
173 buttons_pane.add(remove);
174 buttons_pane.add(skip);
175 buttons_pane.add(accumulate_all);
176 buttons_pane.add(overwrite_all);
177 buttons_pane.add(remove_all);
178 buttons_pane.add(cancel);
179
180 content_pane.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
181 content_pane.setLayout(new BorderLayout());
182 content_pane.add(title_label, BorderLayout.NORTH);
183 content_pane.add(details_pane, BorderLayout.CENTER);
184 content_pane.add(buttons_pane, BorderLayout.SOUTH);
185
186 // Position
187 Rectangle frame_bounds = Gatherer.g_man.getBounds();
188 this.setLocation(frame_bounds.x + ((frame_bounds.width - SIZE.width) / 2), frame_bounds.y + ((frame_bounds.height - SIZE.height) / 2));
189 }
190
191 public void actionPerformed(ActionEvent event) {
192 Object esrc = event.getSource();
193 if(esrc == accumulate) {
194 value = ACCUMULATE;
195 }
196 else if(esrc == accumulate_all) {
197 value = ACCUMULATE_ALL;
198 }
199 else if(esrc == cancel) {
200 value = CANCEL;
201 }
202 else if(esrc == skip) {
203 value = SKIP;
204 }
205 else if(esrc == overwrite) {
206 value = OVERWRITE;
207 }
208 else if(esrc == overwrite_all) {
209 value = OVERWRITE_ALL;
210 }
211 else if(esrc == remove) {
212 value = REMOVE;
213 }
214 else if(esrc == remove_all) {
215 value = REMOVE_ALL;
216 }
217 this.dispose();
218 }
219
220 public int display() {
221 setVisible(true);
222 return value;
223 }
224
225 private String get(String key) {
226 return Gatherer.dictionary.get(key);
227 }
228}
Note: See TracBrowser for help on using the repository browser.