/** *######################################################################### * * 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. *######################################################################## */ 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 org.greenstone.gatherer.Configuration; import org.greenstone.gatherer.Dictionary; import org.greenstone.gatherer.Gatherer; import org.greenstone.gatherer.collection.BasicCollectionConfiguration; import org.greenstone.gatherer.util.StaticStrings; import org.greenstone.gatherer.util.Utility; /** A dialog which provides a straight-forward access to the currently installed collections. It also will contain the ability to continue through to the original OpenCollectionDialog if your source collection is located somewhere other than the gsdl collect folder. */ public class SimpleOpenCollectionDialog extends ModalDialog { static final public int OK_OPTION = 0; static final public int CANCEL_OPTION = 1; static final public int BROWSE_OPTION = 2; static final private Dimension SIZE = new Dimension(640,480); static final private String BLANK = "b"; static final private String DESCRIPTION = "d"; private CardLayout card_layout; private int result; private JButton advanced_button; private JButton cancel_button; private JButton open_button; private JList collection_list; private JTextArea description_textarea; private JPanel description_pane; private String filename; public SimpleOpenCollectionDialog() { super(Gatherer.g_man, "", true); setJMenuBar(new SimpleMenuBar("openingacollection")); setSize(SIZE); setTitle(Dictionary.get("OpenCollectionDialog.Title")); // Creation JPanel content_pane = (JPanel) getContentPane(); JPanel center_pane = new JPanel(); JPanel collection_list_pane = new JPanel(); JLabel collection_list_label = new JLabel(Dictionary.get("OpenCollectionDialog.Available_Collections")); collection_list = new JList(new CollectionListModel()); description_pane = new JPanel(); card_layout = new CardLayout(); JPanel blank_pane = new JPanel(); JPanel description_textarea_pane = new JPanel(); JLabel description_textarea_label = new JLabel(Dictionary.get("OpenCollectionDialog.Description")); description_textarea = new JTextArea(); JPanel button_pane = new JPanel(); open_button = new GLIButton(Dictionary.get("OpenCollectionDialog.Open"), Dictionary.get("OpenCollectionDialog.Open_Tooltip")); open_button.setEnabled(false); advanced_button = new GLIButton(Dictionary.get("OpenCollectionDialog.Browse"), Dictionary.get("OpenCollectionDialog.Browse_Tooltip")); cancel_button = new GLIButton(Dictionary.get("General.Cancel"), Dictionary.get("General.Pure_Cancel_Tooltip")); // Connection advanced_button.addActionListener(new AdvancedListener()); cancel_button.addActionListener(new CancelListener()); open_button.addActionListener(new OpenListener()); CollectionListSelectionListener clsl = new CollectionListSelectionListener(); collection_list.addListSelectionListener(clsl); collection_list.addMouseListener(clsl); clsl = null; // Layout collection_list_pane.setLayout(new BorderLayout()); collection_list_pane.add(collection_list_label, BorderLayout.NORTH); collection_list_pane.add(new JScrollPane(collection_list), BorderLayout.CENTER); description_textarea_pane.setLayout(new BorderLayout()); description_textarea_pane.add(description_textarea_label, BorderLayout.NORTH); description_textarea_pane.add(new JScrollPane(description_textarea), BorderLayout.CENTER); description_pane.setLayout(card_layout); description_pane.add(description_textarea_pane, DESCRIPTION); description_pane.add(blank_pane, BLANK); center_pane.setLayout(new GridLayout(2,1,0,5)); center_pane.add(collection_list_pane); center_pane.add(description_pane); button_pane.setLayout(new GridLayout(1,4)); button_pane.add(new JPanel()); button_pane.add(open_button); if (!Gatherer.GS3) { // Temporarily disable Browse for GS3 button_pane.add(advanced_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); Dimension screen_size = Configuration.screen_size; setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2); screen_size = null; } public void destroy() { } public int display() { setVisible(true); return result; } public String getFileName() { return this.filename; } private class AdvancedListener implements ActionListener { public void actionPerformed(ActionEvent event) { result = BROWSE_OPTION; SimpleOpenCollectionDialog.this.dispose(); } } private class CancelListener implements ActionListener { public void actionPerformed(ActionEvent event) { result = CANCEL_OPTION; SimpleOpenCollectionDialog.this.dispose(); } } private class CollectionListSelectionListener extends MouseAdapter implements ListSelectionListener { public void mouseClicked(MouseEvent event) { ///ystem.err.println("Mouse clicked"); if(event.getClickCount() >= 2) { Point location = event.getPoint(); int index = collection_list.locationToIndex(location); collection_list.setSelectedIndex(index); location = null; open_button.doClick(); } } public void valueChanged(ListSelectionEvent event) { if(collection_list.isSelectionEmpty()) { card_layout.show(description_pane, BLANK); open_button.setEnabled(false); } else { BasicCollectionConfiguration collection_configuration = (BasicCollectionConfiguration) collection_list.getSelectedValue(); description_textarea.setText(collection_configuration.getDescription()); description_textarea.setCaretPosition(0); card_layout.show(description_pane, DESCRIPTION); open_button.setEnabled(true); } } } // use this if we ever go back to viewing all colls at once /* private class GS3CollectionListModel extends AbstractListModel { private TreeSet data; public GS3CollectionListModel() { data = new TreeSet(); File sites_folder = new File(Utility.getSitesDir(Configuration.gsdl3_path)); File sites[] = sites_folder.listFiles(); for (int s=0; s