/** *######################################################################### * * 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: Katherine Don, 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. *######################################################################## */ package org.greenstone.gatherer.gui; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import org.greenstone.gatherer.Dictionary; import org.greenstone.gatherer.Gatherer; import org.greenstone.gatherer.checklist.CheckList; import org.greenstone.gatherer.checklist.Entry; import org.greenstone.gatherer.gui.GLIButton; import org.greenstone.gatherer.gui.SimpleMenuBar; import org.greenstone.gatherer.gui.ModalDialog; import org.greenstone.gatherer.cdm.ElementWrapper; import org.greenstone.gatherer.util.StaticStrings; import org.greenstone.gatherer.util.Utility; import org.w3c.dom.*; /** this class is pretty much copied from an inner class of MEM - AddSetActionListener. At some stage the two should be merged so there is only one copy of the code. */ public class NewMetaSetPrompt extends ModalDialog { private boolean cancelled = true; private JTextField name_field = null; private JTextField namespace_field = null; private JDialog self; static private Dimension size = new Dimension(400,125); static final private Dimension LABEL_SIZE = new Dimension(100,30); static final private Dimension ADD_SET_SIZE = new Dimension(400,125); public NewMetaSetPrompt() { super(Gatherer.g_man, true); this.self = this; setModal(true); setSize(size); Dictionary.setText(this, "MEM.AddSet"); // Creation JPanel content_pane = (JPanel) getContentPane(); content_pane.setBackground(Gatherer.config.getColor("coloring.collection_heading_background", false)); JPanel center_pane = new JPanel(); center_pane.setOpaque(false); JPanel name_pane = new JPanel(); name_pane.setOpaque(false); JLabel name_label = new JLabel(); name_label.setOpaque(false); name_label.setPreferredSize(LABEL_SIZE); Dictionary.setText(name_label, "MEM.Name"); name_field = new JTextField(); name_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false)); name_field.setForeground(Gatherer.config.getColor("coloring.collection_tree_foreground", false)); name_field.setSelectionColor(Gatherer.config.getColor("coloring.collection_selection_background", false)); name_field.setSelectedTextColor(Gatherer.config.getColor("coloring.collection_selection_foreground", false)); Dictionary.setTooltip(name_field, "MEM.Set_Name_Tooltip"); JPanel namespace_pane = new JPanel(); namespace_pane.setOpaque(false); JLabel namespace_label = new JLabel(); namespace_label.setOpaque(false); namespace_label.setPreferredSize(LABEL_SIZE); Dictionary.setText(namespace_label, "MEM.Namespace"); namespace_field = new JTextField(); namespace_field.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false)); namespace_field.setForeground(Gatherer.config.getColor("coloring.collection_tree_foreground", false)); namespace_field.setSelectionColor(Gatherer.config.getColor("coloring.collection_selection_background", false)); namespace_field.setSelectedTextColor(Gatherer.config.getColor("coloring.collection_selection_foreground", false)); Dictionary.setTooltip(namespace_field, "MEM.Set_Namespace_Tooltip"); JPanel button_pane = new JPanel(); button_pane.setOpaque(false); JButton ok_button = new GLIButton(); ok_button.setMnemonic(KeyEvent.VK_O); Dictionary.setBoth(ok_button, "General.OK", "General.OK_Tooltip"); ok_button.setEnabled(false); JButton cancel_button = new GLIButton(); cancel_button.setMnemonic(KeyEvent.VK_C); Dictionary.setBoth(cancel_button, "General.Cancel", "General.Pure_Cancel_Tooltip"); TextFieldEnabler ok_button_enabler = new TextFieldEnabler(ok_button); // Connection cancel_button.addActionListener(new OKButtonListener()); ok_button.addActionListener(new CancelButtonListener()); ok_button_enabler.add(name_field); ok_button_enabler.add(namespace_field); // Layout namespace_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0)); namespace_pane.setLayout(new BorderLayout()); namespace_pane.add(namespace_label, BorderLayout.WEST); namespace_pane.add(namespace_field, BorderLayout.CENTER); name_pane.setBorder(BorderFactory.createEmptyBorder(0,0,5,0)); name_pane.setLayout(new BorderLayout()); name_pane.add(name_label, BorderLayout.WEST); name_pane.add(name_field, BorderLayout.CENTER); center_pane.setLayout(new GridLayout(2,1)); center_pane.add(name_pane); center_pane.add(namespace_pane); button_pane.setLayout(new GridLayout(1,2,0,5)); button_pane.add(ok_button); button_pane.add(cancel_button); content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); content_pane.setLayout(new BorderLayout()); content_pane.add(center_pane, BorderLayout.CENTER); content_pane.add(button_pane, BorderLayout.SOUTH); setLocation((Gatherer.config.screen_size.width - ADD_SET_SIZE.width) / 2, (Gatherer.config.screen_size.height - ADD_SET_SIZE.height) / 2); setVisible(true); } public boolean isCancelled() { return cancelled; } public String getNamespace() { return namespace_field.getText(); } public String getName() { return name_field.getText(); } private class CancelButtonListener implements ActionListener { public void actionPerformed(ActionEvent event) { cancelled = true; self.dispose(); } } public class OKButtonListener implements ActionListener { public void actionPerformed(ActionEvent event) { cancelled = false; self.dispose(); } } /** Used to enable a certain target component if and only if all the registered text fields contain non-zero length strings. */ private class TextFieldEnabler implements DocumentListener { private boolean ignore = false; private Component target = null; private JTextComponent[] fields = null; public TextFieldEnabler(Component target) { super(); this.target = target; } public void add(JTextComponent field) { // Record this field as being one we depend upon if(fields == null) { fields = new JTextComponent[1]; fields[0] = field; } else { JTextComponent[] temp = new JTextComponent[fields.length + 1]; System.arraycopy(fields, 0, temp, 0, fields.length); temp[fields.length] = field; fields = temp; temp = null; } // Add the appropriate listener field.getDocument().addDocumentListener(this); } /** Gives notification that an attribute or set of attributes changed. */ public void changedUpdate(DocumentEvent e) { canEnable(); } /** Gives notification that there was an insert into the document. */ public void insertUpdate(DocumentEvent e) { canEnable(); } /** Gives notification that a portion of the document has been removed. */ public void removeUpdate(DocumentEvent e) { canEnable(); } private void canEnable() { if(!ignore) { ignore = true; boolean can_enable = true; for(int i = 0; can_enable && i < fields.length; i++) { can_enable = can_enable && (fields[i].getText().length() > 0); } target.setEnabled(can_enable); ignore = false; } } } }