PageRenderTime 583ms CodeModel.GetById 564ms app.highlight 16ms RepoModel.GetById 0ms app.codeStats 0ms

/bundles/plugins-trunk/Console/console/options/GeneralOptionPane.java

#
Java | 207 lines | 140 code | 35 blank | 32 comment | 11 complexity | 600b0283ab9ff41b1053d6550677e53c MD5 | raw file
  1/*
  2 * GeneralOptionPane.java - General settings
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 1999, 2004 Slava Pestov
  7 * parts Copyright (C) 2010 Eric Le Lay
  8 *
  9 * This program is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU General Public License
 11 * as published by the Free Software Foundation; either version 2
 12 * of the License, or any later version.
 13 *
 14 * This program is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17 * GNU General Public License for more details.
 18 *
 19 * You should have received a copy of the GNU General Public License
 20 * along with this program; if not, write to the Free Software
 21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 22 */
 23
 24package console.options;
 25
 26//{{{ Imports
 27import java.awt.Color;
 28import java.awt.event.ActionEvent;
 29
 30import java.awt.event.ActionListener;
 31import java.util.Arrays;
 32
 33import javax.swing.JButton;
 34import javax.swing.JCheckBox;
 35import javax.swing.JColorChooser;
 36import javax.swing.JComboBox;
 37import javax.swing.JTextField;
 38
 39import org.gjt.sp.jedit.AbstractOptionPane;
 40import org.gjt.sp.jedit.MiscUtilities;
 41import org.gjt.sp.jedit.jEdit;
 42import org.gjt.sp.jedit.gui.FontSelector;
 43import org.gjt.sp.util.StandardUtilities.StringCompare;
 44import org.gjt.sp.util.StringList;
 45import org.gjt.sp.jedit.gui.HistoryModel ;
 46
 47import console.Shell;
 48import console.gui.Label;
 49//}}}
 50
 51public class GeneralOptionPane extends AbstractOptionPane
 52{
 53
 54	// {{{ data members
 55
 56	private FontSelector font;
 57	private JComboBox encoding;
 58	private JComboBox defaultShell;
 59	private JButton bgColor;
 60	private JButton plainColor;
 61	private JButton caretColor;
 62	private JButton infoColor;
 63	private JButton warningColor;
 64	private JButton errorColor;
 65	private JCheckBox showWelcomeMessage;
 66	private JTextField limit ;
 67	private JTextField limitHistory ;
 68
 69
 70	// }}}
 71
 72	//{{{ GeneralOptionPane constructor
 73	public GeneralOptionPane()
 74	{
 75		super("console.general");
 76	} //}}}
 77
 78	//{{{ _init() method
 79	protected void _init()
 80	{
 81
 82		StringList sl = new StringList(Shell.getShellNames());
 83		int idx = sl.indexOf("System");
 84		if (idx != 0) {
 85			String other = sl.get(0);
 86			sl.set(idx, other);
 87			sl.set(0, "System");
 88		}
 89		sl.add(jEdit.getProperty("options.last-selected"));
 90		defaultShell = new JComboBox(sl.toArray());
 91		String ds = jEdit.getProperty("console.shell.default", "System");
 92		defaultShell.setSelectedItem(ds);
 93		addComponent(jEdit.getProperty("options.console.general.defaultshell", "Default Shell:"),
 94			defaultShell);
 95
 96		showWelcomeMessage = new JCheckBox();
 97		showWelcomeMessage.setText(jEdit.getProperty("options.console.general.welcome"));
 98		showWelcomeMessage.setSelected(jEdit.getBooleanProperty("console.shell.info.toggle"));
 99		addComponent(showWelcomeMessage);
100
101		font = new FontSelector(jEdit.getFontProperty("console.font"));
102		addComponent(jEdit.getProperty("options.console.general.font"), font);
103
104		String[] encodings = MiscUtilities.getEncodings(true);
105		// Arrays.sort(encodings,new MiscUtilities.StringICaseCompare());
106		Arrays.sort(encodings, new StringCompare<String>(true));
107		encoding = new JComboBox(encodings);
108		encoding.setEditable(true);
109		encoding.setSelectedItem(jEdit.getProperty("console.encoding"));
110		addComponent(jEdit.getProperty("options.console.general.encoding"),
111			encoding);
112
113
114		Label limitLabel = new Label("options.console.general.charlimit");
115		limit = new JTextField(jEdit.getProperty("console.outputLimit"));
116		addComponent(limitLabel, limit);
117
118		Label limitHistoryLabel = new Label("options.console.general.historylimit");
119		limitHistory = new JTextField(jEdit.getProperty("console.historyLimit",
120			String.valueOf(HistoryModel.getDefaultMax())));
121		addComponent(limitHistoryLabel, limitHistory);
122
123
124
125		addComponent(jEdit.getProperty("options.console.general.bgColor"),
126			bgColor = createColorButton("console.bgColor"));
127		bgColor.setToolTipText(jEdit.getProperty("options.console.general.bgColor.tooltip"));
128		addComponent(jEdit.getProperty("options.console.general.plainColor"),
129			plainColor = createColorButton("console.plainColor"));
130		plainColor.setToolTipText(jEdit.getProperty("options.console.general.bgColor.tooltip"));
131		addComponent(jEdit.getProperty("options.console.general.caretColor"),
132			caretColor = createColorButton("console.caretColor"));
133		caretColor.setToolTipText(jEdit.getProperty("options.console.general.bgColor.tooltip"));
134		addComponent(jEdit.getProperty("options.console.general.infoColor"),
135			infoColor = createColorButton("console.infoColor"));
136		addComponent(jEdit.getProperty("options.console.general.warningColor"),
137			warningColor = createColorButton("console.warningColor"));
138		addComponent(jEdit.getProperty("options.console.general.errorColor"),
139			errorColor = createColorButton("console.errorColor"));
140	} //}}}
141
142	//{{{ _save() method
143	protected void _save()
144	{
145		jEdit.setBooleanProperty("console.shell.info.toggle", showWelcomeMessage.isSelected());
146
147		jEdit.setFontProperty("console.font",font.getFont());
148
149		String limitstr = limit.getText();
150		if(limitstr != null && limitstr.length() > 0)
151			jEdit.setProperty("console.outputLimit", limitstr);
152		else
153			jEdit.unsetProperty("console.outputLimit");
154
155		String limithist = limitHistory.getText();
156		if(limithist != null && limithist.length() > 0
157			&& !String.valueOf(HistoryModel.getDefaultMax()).equals(limithist))
158			jEdit.setProperty("console.historyLimit", limithist);
159		else
160			jEdit.unsetProperty("console.historyLimit");
161
162 		jEdit.setProperty("console.encoding",
163 			(String)encoding.getSelectedItem());
164
165 		jEdit.setProperty("console.shell.default",
166 			(String)defaultShell.getSelectedItem());
167
168		jEdit.setColorProperty("console.bgColor",
169			bgColor.getBackground());
170		jEdit.setColorProperty("console.plainColor",
171			plainColor.getBackground());
172		jEdit.setColorProperty("console.caretColor",
173			caretColor.getBackground());
174		jEdit.setColorProperty("console.infoColor",
175			infoColor.getBackground());
176		jEdit.setColorProperty("console.warningColor",
177			warningColor.getBackground());
178		jEdit.setColorProperty("console.errorColor",
179			errorColor.getBackground());
180
181
182	}
183	//}}}
184
185	//{{{ createColorButton() method
186	private JButton createColorButton(String property)
187	{
188		final JButton b = new JButton(" ");
189		b.setBackground(jEdit.getColorProperty(property));
190		b.addActionListener(new ActionListener()
191		{
192			public void actionPerformed(ActionEvent evt)
193			{
194				Color c = JColorChooser.showDialog(
195					GeneralOptionPane.this,
196					jEdit.getProperty("colorChooser.title"),
197					b.getBackground());
198				if(c != null)
199					b.setBackground(c);
200			}
201		});
202
203		b.setRequestFocusEnabled(false);
204		return b;
205	} //}}}
206
207}