package org.greenstone.gatherer.gui; /** *######################################################################### * * A component of the Gatherer application, part of the Greenstone digital * library suite from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * Author: John Thompson, Greenstone Digital Library, University of Waikato * * Copyright (C) 1999 New Zealand Digital Library Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *######################################################################## */ import java.awt.*; import java.awt.event.*; import java.io.File; import javax.swing.*; import org.greenstone.gatherer.Configuration; import org.greenstone.gatherer.Gatherer; import org.greenstone.gatherer.gui.TextFieldLabel; import org.greenstone.gatherer.util.Utility; import org.greenstone.gatherer.gui.SimpleMenuBar; import org.greenstone.gatherer.gui.ModalDialog; /** 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. */ public class MetaEditPrompt extends ModalDialog implements ActionListener { private int value; private JButton accumulate; private JButton accumulate_all; private JButton cancel; private JButton skip; private JButton overwrite; private JButton overwrite_all; private JButton remove; private JButton remove_all; private JButton update; private JButton update_all; static private Dimension LABEL_SIZE = new Dimension(100, 25); static private Dimension SIZE = new Dimension(712, 250); // Generic prompt values. static public int CONFIRM = 0; static public int CANCEL = 1; static public int SKIP = 2; // Values for the different add and update action prompts. static public int ACCUMULATE = 3; static public int ACCUMULATE_ALL = 4; static public int OVERWRITE = 5; static public int OVERWRITE_ALL = 6; static public int UPDATE_ONCE = 7; // Caused by SARM // Values for the different remove action prompts. static public int REMOVE = 8; static public int REMOVE_ALL = 9; // Prompt Types static public String ADD_PROMPT = "Add_Prompt"; static public String REMOVE_PROMPT = "Remove_Prompt"; static public String UPDATE_PROMPT = "Overwrite_Prompt"; public MetaEditPrompt(String type, boolean multiple_selection, File file, String element, String current_value, String new_value) { super(Gatherer.g_man, true); // Needed for modal response! // Setup this.setSize(SIZE); this.setTitle(get("MetaEditPrompt.Title")); this.setJMenuBar(new SimpleMenuBar("6.3")); // Creation JPanel content_pane = (JPanel)this.getContentPane(); JLabel title_label = new JLabel(get("MetaEditPrompt." + type)); JPanel details_pane = new JPanel(); JPanel filename_panel = new JPanel(); JLabel filename_label = new JLabel(get("MetaEditPrompt.File")); filename_label.setPreferredSize(LABEL_SIZE); TextFieldLabel filename_field = new TextFieldLabel(Utility.trimCenter(file.getAbsolutePath(), 120)); filename_field.setFont(Gatherer.config.getFont("general.tooltip_font", false)); JPanel element_panel = new JPanel(); JLabel element_label = new JLabel(get("MetaEditPrompt.Element")); element_label.setPreferredSize(LABEL_SIZE); TextFieldLabel element_field = new TextFieldLabel(element); JPanel current_value_panel = new JPanel(); JLabel current_value_label = new JLabel(get("MetaEditPrompt.Current_Value")); current_value_label.setPreferredSize(LABEL_SIZE); TextFieldLabel current_value_field = new TextFieldLabel(current_value); JPanel new_value_panel = new JPanel(); JLabel new_value_label = new JLabel(get("MetaEditPrompt.New_Value")); new_value_label.setPreferredSize(LABEL_SIZE); TextFieldLabel new_value_field = new TextFieldLabel(new_value, (type == ADD_PROMPT || type == UPDATE_PROMPT)); JPanel buttons_pane = new JPanel(); accumulate = new JButton(get("MetaEditPrompt.Accumulate")); accumulate.setEnabled(type == ADD_PROMPT); accumulate.setMnemonic(KeyEvent.VK_A); accumulate_all = new JButton(get("MetaEditPrompt.Accumulate_All")); accumulate_all.setEnabled(type == ADD_PROMPT && multiple_selection); accumulate_all.setMnemonic(KeyEvent.VK_L); cancel = new JButton(get("MetaEditPrompt.Cancel")); cancel.setMnemonic(KeyEvent.VK_C); skip = new JButton(get("MetaEditPrompt.Skip")); skip.setEnabled(multiple_selection); skip.setMnemonic(KeyEvent.VK_S); overwrite = new JButton(get("MetaEditPrompt.Overwrite")); overwrite.setEnabled(type == UPDATE_PROMPT); overwrite.setMnemonic(KeyEvent.VK_R); overwrite_all = new JButton(get("MetaEditPrompt.Overwrite_All")); overwrite_all.setEnabled(type == UPDATE_PROMPT && multiple_selection); overwrite_all.setMnemonic(KeyEvent.VK_P); remove = new JButton(get("MetaEditPrompt.Remove")); remove.setEnabled(type == REMOVE_PROMPT); remove.setMnemonic(KeyEvent.VK_R); remove_all = new JButton(get("MetaEditPrompt.Remove_All")); remove_all.setEnabled(type == REMOVE_PROMPT && multiple_selection); remove_all.setMnemonic(KeyEvent.VK_A); // Connection accumulate.addActionListener(this); accumulate_all.addActionListener(this); cancel.addActionListener(this); overwrite.addActionListener(this); overwrite_all.addActionListener(this); remove.addActionListener(this); remove_all.addActionListener(this); skip.addActionListener(this); // Layout title_label.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); filename_panel.setLayout(new BorderLayout()); filename_panel.add(filename_label, BorderLayout.WEST); filename_panel.add(filename_field, BorderLayout.CENTER); element_panel.setLayout(new BorderLayout()); element_panel.add(element_label, BorderLayout.WEST); element_panel.add(element_field, BorderLayout.CENTER); current_value_panel.setLayout(new BorderLayout()); current_value_panel.add(current_value_label, BorderLayout.WEST); current_value_panel.add(current_value_field, BorderLayout.CENTER); new_value_panel.setLayout(new BorderLayout()); new_value_panel.add(new_value_label, BorderLayout.WEST); new_value_panel.add(new_value_field, BorderLayout.CENTER); details_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); details_pane.setLayout(new GridLayout(4,1,0,4)); details_pane.add(filename_panel); details_pane.add(element_panel); details_pane.add(current_value_panel); details_pane.add(new_value_panel); buttons_pane.setBorder(BorderFactory.createEmptyBorder(2,2,2,2)); buttons_pane.setLayout(new GridLayout(2,4,0,0)); buttons_pane.add(accumulate); buttons_pane.add(overwrite); buttons_pane.add(remove); buttons_pane.add(skip); buttons_pane.add(accumulate_all); buttons_pane.add(overwrite_all); buttons_pane.add(remove_all); buttons_pane.add(cancel); content_pane.setBorder(BorderFactory.createEmptyBorder(3,3,3,3)); content_pane.setLayout(new BorderLayout()); content_pane.add(title_label, BorderLayout.NORTH); content_pane.add(details_pane, BorderLayout.CENTER); content_pane.add(buttons_pane, BorderLayout.SOUTH); // Position Rectangle frame_bounds = Gatherer.g_man.getBounds(); this.setLocation(frame_bounds.x + ((frame_bounds.width - SIZE.width) / 2), frame_bounds.y + ((frame_bounds.height - SIZE.height) / 2)); } public void actionPerformed(ActionEvent event) { Object esrc = event.getSource(); if(esrc == accumulate) { value = ACCUMULATE; } else if(esrc == accumulate_all) { value = ACCUMULATE_ALL; } else if(esrc == cancel) { value = CANCEL; } else if(esrc == skip) { value = SKIP; } else if(esrc == overwrite) { value = OVERWRITE; } else if(esrc == overwrite_all) { value = OVERWRITE_ALL; } else if(esrc == remove) { value = REMOVE; } else if(esrc == remove_all) { value = REMOVE_ALL; } this.dispose(); } public int display() { setVisible(true); return value; } private String get(String key) { return Gatherer.dictionary.get(key); } }