PageRenderTime 57ms CodeModel.GetById 45ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/XML/xml/options/CatalogsOptionPane.java

#
Java | 128 lines | 97 code | 18 blank | 13 comment | 11 complexity | cbbfacfae36444053ed98d13f9b7888e MD5 | raw file
  1/*
  2 * CatalogsOptionPane.java - Catalog manager options panel
  3 * Copyright (C) 2001, 2002 Slava Pestov
  4 *
  5 * The XML plugin is licensed under the GNU General Public License, with
  6 * the following exception:
  7 *
  8 * "Permission is granted to link this code with software released under
  9 * the Apache license version 1.1, for example used by the Xerces XML
 10 * parser package."
 11 */
 12
 13package xml.options;
 14
 15import javax.swing.border.EmptyBorder;
 16import javax.swing.event.*;
 17import javax.swing.*;
 18import java.awt.event.*;
 19import java.awt.*;
 20import org.gjt.sp.jedit.browser.VFSBrowser;
 21import org.gjt.sp.jedit.gui.*;
 22import org.gjt.sp.jedit.*;
 23
 24public class CatalogsOptionPane extends AbstractOptionPane
 25{
 26	public CatalogsOptionPane()
 27	{
 28		super("xml.catalogs");
 29	}
 30
 31	// protected members
 32	protected void _init()
 33	{
 34		setLayout(new BorderLayout());
 35
 36		JLabel label = new JLabel(jEdit.getProperty("options.xml.catalogs.caption"));
 37		label.setBorder(new EmptyBorder(0,0,6,0));
 38		add(BorderLayout.NORTH,label);
 39
 40		catalogListModel = new DefaultListModel();
 41		int i = 0;
 42		String catalog;
 43		while((catalog = jEdit.getProperty("xml.catalog." + i)) != null)
 44		{
 45			catalogListModel.addElement(catalog);
 46			i++;
 47		}
 48
 49		add(BorderLayout.CENTER,new JScrollPane(
 50			catalogList = new JList(catalogListModel)));
 51		catalogList.addListSelectionListener(new ListHandler());
 52
 53		JPanel buttons = new JPanel();
 54		buttons.setLayout(new BoxLayout(buttons,BoxLayout.X_AXIS));
 55		buttons.setBorder(new EmptyBorder(6,0,0,0));
 56
 57		add = new RolloverButton(GUIUtilities.loadIcon("Plus.png"));
 58		add.setToolTipText(jEdit.getProperty("options.xml.catalogs.add"));
 59		add.addActionListener(new ActionHandler());
 60		buttons.add(add);
 61		remove = new RolloverButton(GUIUtilities.loadIcon("Minus.png"));
 62		remove.setToolTipText(jEdit.getProperty("options.xml.catalogs.remove"));
 63		remove.addActionListener(new ActionHandler());
 64		buttons.add(remove);
 65		buttons.add(Box.createGlue());
 66
 67		add(BorderLayout.SOUTH,buttons);
 68
 69		updateEnabled();
 70	}
 71
 72	protected void _save()
 73	{
 74		int i;
 75		for(i = 0; i < catalogListModel.getSize(); i++)
 76		{
 77			jEdit.setProperty("xml.catalog." + i,
 78				(String)catalogListModel.getElementAt(i));
 79		}
 80
 81		jEdit.unsetProperty("xml.catalog." + i);
 82	}
 83
 84	// private members
 85	private JList catalogList;
 86	private DefaultListModel catalogListModel;
 87	private JButton add;
 88	private JButton remove;
 89
 90	private void updateEnabled()
 91	{
 92		boolean selected = (catalogList.getSelectedValue() != null);
 93		remove.setEnabled(selected);
 94	}
 95
 96	class ActionHandler implements ActionListener
 97	{
 98		public void actionPerformed(ActionEvent evt)
 99		{
100			if(evt.getSource() == add)
101			{
102				String[] files = GUIUtilities.showVFSFileDialog(
103					null,null,VFSBrowser.OPEN_DIALOG,true);
104				if(files == null)
105					return;
106
107				for(int i = 0; i < files.length; i++)
108				{
109					catalogListModel.addElement(files[i]);
110				}
111			}
112			else if(evt.getSource() == remove)
113			{
114				catalogListModel.removeElementAt(
115					catalogList.getSelectedIndex());
116				updateEnabled();
117			}
118		}
119	}
120
121	class ListHandler implements ListSelectionListener
122	{
123		public void valueChanged(ListSelectionEvent evt)
124		{
125			updateEnabled();
126		}
127	}
128}