PageRenderTime 65ms CodeModel.GetById 50ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/org/gjt/sp/jedit/AbstractOptionPane.java

#
Java | 211 lines | 97 code | 23 blank | 91 comment | 2 complexity | 748593cacb5e4a168049463754d25fc9 MD5 | raw file
  1/*
  2 * AbstractOptionPane.java - Abstract option pane
  3 * :tabSize=8:indentSize=8:noTabs=false:
  4 * :folding=explicit:collapseFolds=1:
  5 *
  6 * Copyright (C) 1998, 1999, 2000, 2001, 2002 Slava Pestov
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * as published by the Free Software Foundation; either version 2
 11 * of the License, or any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 21 */
 22
 23package org.gjt.sp.jedit;
 24
 25//{{{ Imports
 26import javax.swing.border.EmptyBorder;
 27import javax.swing.*;
 28import java.awt.*;
 29//}}}
 30
 31/**
 32 * The default implementation of the option pane interface. It lays out
 33 * components in a vertical fashion.
 34 *
 35 * @see org.gjt.sp.jedit.OptionPane
 36 */
 37public abstract class AbstractOptionPane extends JPanel implements OptionPane
 38{
 39	//{{{ AbstractOptionPane constructor
 40	/**
 41	 * Creates a new option pane.
 42	 * @param name The internal name. The option pane's label is set to the
 43	 * value of the property named <code>options.<i>name</i>.label</code>.
 44	 */
 45	public AbstractOptionPane(String name)
 46	{
 47		this.name = name;
 48		setLayout(gridBag = new GridBagLayout());
 49	} //}}}
 50
 51	//{{{ getName() method
 52	/**
 53	 * Returns the internal name of this option pane. The option pane's label
 54	 * is set to the value of the property named
 55	 * <code>options.<i>name</i>.label</code>.
 56	 */
 57	public String getName()
 58	{
 59		return name;
 60	} //}}}
 61
 62	//{{{ getComponent() method
 63	/**
 64	 * Returns the component that should be displayed for this option pane.
 65	 * Because this class extends Component, it simply returns "this".
 66	 */
 67	public Component getComponent()
 68	{
 69		return this;
 70	} //}}}
 71
 72	//{{{ init() method
 73	public void init()
 74	{
 75		if(!initialized)
 76		{
 77			initialized = true;
 78			_init();
 79		}
 80	} //}}}
 81
 82	//{{{ save() method
 83	public void save()
 84	{
 85		if(initialized)
 86			_save();
 87	} //}}}
 88
 89	//{{{ Protected members
 90
 91	//{{{ Instance variables
 92	/**
 93	 * Has the option pane been initialized?
 94	 */
 95	protected boolean initialized;
 96
 97	/**
 98	 * The layout manager.
 99	 */
100	protected GridBagLayout gridBag;
101
102	/**
103	 * The number of components already added to the layout manager.
104	 */
105	protected int y;
106	//}}}
107
108	/**
109	 * This method should create the option pane's GUI.
110	 */
111	protected void _init() {}
112
113	/**
114	 * Called when the options dialog's "ok" button is clicked.
115	 * This should save any properties being edited in this option
116	 * pane.
117	 */
118	protected void _save() {}
119
120	//{{{ addComponent() method
121	/**
122	 * Adds a labeled component to the option pane. Components are
123	 * added in a vertical fashion, one per row. The label is
124	 * displayed to the left of the component.
125	 * @param label The label
126	 * @param comp The component
127	 */
128	public void addComponent(String label, Component comp)
129	{
130		GridBagConstraints cons = new GridBagConstraints();
131		cons.gridy = y++;
132		cons.gridheight = 1;
133		cons.gridwidth = 1;
134		cons.weightx = 0.0f;
135		cons.insets = new Insets(1,0,1,0);
136		cons.fill = GridBagConstraints.BOTH;
137
138		JLabel l = new JLabel(label,SwingConstants.RIGHT);
139		l.setBorder(new EmptyBorder(0,0,0,12));
140		gridBag.setConstraints(l,cons);
141		add(l);
142
143		cons.gridx = 1;
144		cons.weightx = 1.0f;
145		gridBag.setConstraints(comp,cons);
146		add(comp);
147	} //}}}
148
149	//{{{ addComponent() method
150	/**
151	 * Adds a component to the option pane. Components are
152	 * added in a vertical fashion, one per row.
153	 * @param comp The component
154	 */
155	public void addComponent(Component comp)
156	{
157		GridBagConstraints cons = new GridBagConstraints();
158		cons.gridy = y++;
159		cons.gridheight = 1;
160		cons.gridwidth = cons.REMAINDER;
161		cons.fill = GridBagConstraints.NONE;
162		cons.anchor = GridBagConstraints.WEST;
163		cons.weightx = 1.0f;
164		cons.insets = new Insets(1,0,1,0);
165
166		gridBag.setConstraints(comp,cons);
167		add(comp);
168	} //}}}
169
170	//{{{ addSeparator() method
171	/**
172	 * Adds a separator component.
173	 * @param label The separator label property
174	 * @since jEdit 2.6pre2
175	 */
176	public void addSeparator(String label)
177	{
178		Box box = new Box(BoxLayout.X_AXIS);
179		Box box2 = new Box(BoxLayout.Y_AXIS);
180		box2.add(Box.createGlue());
181		box2.add(new JSeparator(JSeparator.HORIZONTAL));
182		box2.add(Box.createGlue());
183		box.add(box2);
184		JLabel l = new JLabel(jEdit.getProperty(label));
185		l.setMaximumSize(l.getPreferredSize());
186		box.add(l);
187		Box box3 = new Box(BoxLayout.Y_AXIS);
188		box3.add(Box.createGlue());
189		box3.add(new JSeparator(JSeparator.HORIZONTAL));
190		box3.add(Box.createGlue());
191		box.add(box3);
192
193		GridBagConstraints cons = new GridBagConstraints();
194		cons.gridy = y++;
195		cons.gridheight = 1;
196		cons.gridwidth = cons.REMAINDER;
197		cons.fill = GridBagConstraints.BOTH;
198		cons.anchor = GridBagConstraints.WEST;
199		cons.weightx = 1.0f;
200		cons.insets = new Insets(1,0,1,0);
201
202		gridBag.setConstraints(box,cons);
203		add(box);
204	} //}}}
205
206	//}}}
207
208	//{{{ Private members
209	private String name;
210	//}}}
211}