PageRenderTime 102ms CodeModel.GetById 80ms app.highlight 8ms RepoModel.GetById 12ms app.codeStats 0ms

/bundles/plugins-trunk/Sessions/sessions/DefaultSessionPropertyPane.java

#
Java | 115 lines | 68 code | 25 blank | 22 comment | 4 complexity | a9b9b66b92f1a601988eec5575e042a0 MD5 | raw file
  1/*
  2 * DefaultSessionPropertyPane.java
  3 * Copyright (c) 2001 Dirk Moebius
  4 *
  5 * :tabSize=4:indentSize=4:noTabs=false:maxLineLen=0:
  6 *
  7 * This program is free software; you can redistribute it and/or
  8 * modify it under the terms of the GNU General Public License
  9 * as published by the Free Software Foundation; either version 2
 10 * of the License, or any later version.
 11 *
 12 * This program is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 15 * GNU General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU General Public License
 18 * along with this program; if not, write to the Free Software
 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 20 */
 21
 22
 23package sessions;
 24
 25
 26import java.awt.FlowLayout;
 27import java.awt.event.ActionEvent;
 28import java.awt.event.ActionListener;
 29import javax.swing.JButton;
 30import javax.swing.JComboBox;
 31import javax.swing.JFileChooser;
 32import javax.swing.JPanel;
 33import javax.swing.JTextField;
 34import javax.swing.UIManager;
 35import org.gjt.sp.jedit.jEdit;
 36import org.gjt.sp.jedit.Mode;
 37
 38
 39public class DefaultSessionPropertyPane extends SessionPropertyPane
 40	implements ActionListener
 41{
 42
 43	public DefaultSessionPropertyPane(Session session)
 44	{
 45		super(session);
 46	}
 47
 48
 49	public String getIdentifier()
 50	{
 51		return "plugin.sessions.sessionproperties.default";
 52	}
 53
 54
 55	public String getLabel()
 56	{
 57		return jEdit.getProperty("sessions.sessionproperties.default.label");
 58	}
 59
 60
 61	public void _init()
 62	{
 63		// "Base directory:"
 64		JPanel dirPanel = new JPanel();
 65		dirPanel.add(
 66			tBasedir = new JTextField(session.getProperty(Session.BASE_DIRECTORY, ""), 20));
 67
 68		dirPanel.add(
 69			bBrowse = new JButton(UIManager.getIcon("FileView.directoryIcon")));
 70		bBrowse.setMargin(new java.awt.Insets(0,0,0,0));
 71		bBrowse.addActionListener(this);
 72		addComponent(dirPanel);
 73
 74		// "Preferred mode:"
 75		cMode = new JComboBox(getModeNames());
 76		cMode.setEditable(false);
 77		cMode.setSelectedItem(session.getProperty("mode", jEdit.getProperty("buffer.defaultMode")));
 78		addComponent("sessions.sessionproperties.default.mode", cMode);
 79	}
 80
 81
 82	public void _save()
 83	{
 84		session.setProperty(Session.BASE_DIRECTORY, tBasedir.getText());
 85		session.setProperty("mode", cMode.getSelectedItem() != null
 86			? cMode.getSelectedItem().toString()
 87			: jEdit.getProperty("buffer.defaultMode"));
 88	}
 89
 90
 91	private String[] getModeNames()
 92	{
 93		Mode[] modes = jEdit.getModes();
 94		String[] modeNames = new String[modes.length];
 95		for(int i = 0; i < modes.length; ++i)
 96			modeNames[i] = modes[i].getName();
 97		return modeNames;
 98	}
 99
100
101	public void actionPerformed(ActionEvent evt)
102	{
103		JFileChooser chooser = new javax.swing.JFileChooser();
104		chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
105
106		if(chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
107			tBasedir.setText(chooser.getSelectedFile().getPath());
108	}
109
110
111	private JTextField tBasedir;
112	private JButton bBrowse;
113	private JComboBox cMode;
114
115}