PageRenderTime 128ms CodeModel.GetById 114ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 263 lines | 114 code | 25 blank | 124 comment | 4 complexity | 71ec47be51249c12798fb4bdf2a30317 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 */
 37// even though this class is called AbstractOptionPane, it is not really
 38// abstract, since BufferOptions uses an instance of it to lay out its
 39// components.
 40public class AbstractOptionPane extends JPanel implements OptionPane
 41{
 42	//{{{ AbstractOptionPane constructor
 43	/**
 44	 * Creates a new option pane.
 45	 * @param name The internal name. The option pane's label is set to the
 46	 * value of the property named <code>options.<i>name</i>.label</code>.
 47	 */
 48	public AbstractOptionPane(String name)
 49	{
 50		this.name = name;
 51		setLayout(gridBag = new GridBagLayout());
 52	} //}}}
 53
 54	//{{{ getName() method
 55	/**
 56	 * Returns the internal name of this option pane. The option pane's label
 57	 * is set to the value of the property named
 58	 * <code>options.<i>name</i>.label</code>.
 59	 */
 60	public String getName()
 61	{
 62		return name;
 63	} //}}}
 64
 65	//{{{ getComponent() method
 66	/**
 67	 * Returns the component that should be displayed for this option pane.
 68	 * Because this class extends Component, it simply returns "this".
 69	 */
 70	public Component getComponent()
 71	{
 72		return this;
 73	} //}}}
 74
 75	//{{{ init() method
 76	public void init()
 77	{
 78		if(!initialized)
 79		{
 80			initialized = true;
 81			_init();
 82		}
 83	} //}}}
 84
 85	//{{{ save() method
 86	public void save()
 87	{
 88		if(initialized)
 89			_save();
 90	} //}}}
 91
 92	//{{{ addComponent() method
 93	/**
 94	 * Adds a labeled component to the option pane. Components are
 95	 * added in a vertical fashion, one per row. The label is
 96	 * displayed to the left of the component.
 97	 * @param label The label
 98	 * @param comp The component
 99	 */
100	public void addComponent(String label, Component comp)
101	{
102		JLabel l = new JLabel(label);
103		l.setBorder(new EmptyBorder(0,0,0,12));
104		addComponent(l,comp,GridBagConstraints.BOTH);
105	} //}}}
106
107	//{{{ addComponent() method
108	/**
109	 * Adds a labeled component to the option pane. Components are
110	 * added in a vertical fashion, one per row. The label is
111	 * displayed to the left of the component.
112	 * @param label The label
113	 * @param comp The component
114	 * @param fill Fill parameter to GridBagConstraints for the right
115	 * component
116	 */
117	public void addComponent(String label, Component comp, int fill)
118	{
119		JLabel l = new JLabel(label);
120		l.setBorder(new EmptyBorder(0,0,0,12));
121		addComponent(l,comp,fill);
122	} //}}}
123
124	//{{{ addComponent() method
125	/**
126	 * Adds a labeled component to the option pane. Components are
127	 * added in a vertical fashion, one per row. The label is
128	 * displayed to the left of the component.
129	 * @param comp1 The label
130	 * @param comp2 The component
131	 *
132	 * @since jEdit 4.1pre3
133	 */
134	public void addComponent(Component comp1, Component comp2)
135	{
136		addComponent(comp1,comp2,GridBagConstraints.BOTH);
137	} //}}}
138
139	//{{{ addComponent() method
140	/**
141	 * Adds a labeled component to the option pane. Components are
142	 * added in a vertical fashion, one per row. The label is
143	 * displayed to the left of the component.
144	 * @param comp1 The label
145	 * @param comp2 The component
146	 * @param fill Fill parameter to GridBagConstraints for the right
147	 * component
148	 *
149	 * @since jEdit 4.1pre3
150	 */
151	public void addComponent(Component comp1, Component comp2, int fill)
152	{
153		GridBagConstraints cons = new GridBagConstraints();
154		cons.gridy = y++;
155		cons.gridheight = 1;
156		cons.gridwidth = 1;
157		cons.weightx = 0.0f;
158		cons.insets = new Insets(1,0,1,0);
159		cons.fill = GridBagConstraints.BOTH;
160
161		gridBag.setConstraints(comp1,cons);
162		add(comp1);
163
164		cons.fill = fill;
165		cons.gridx = 1;
166		cons.weightx = 1.0f;
167		gridBag.setConstraints(comp2,cons);
168		add(comp2);
169	} //}}}
170
171	//{{{ addComponent() method
172	/**
173	 * Adds a component to the option pane. Components are
174	 * added in a vertical fashion, one per row.
175	 * @param comp The component
176	 */
177	public void addComponent(Component comp)
178	{
179		GridBagConstraints cons = new GridBagConstraints();
180		cons.gridy = y++;
181		cons.gridheight = 1;
182		cons.gridwidth = cons.REMAINDER;
183		cons.fill = GridBagConstraints.NONE;
184		cons.anchor = GridBagConstraints.WEST;
185		cons.weightx = 1.0f;
186		cons.insets = new Insets(1,0,1,0);
187
188		gridBag.setConstraints(comp,cons);
189		add(comp);
190	} //}}}
191
192	//{{{ addSeparator() method
193	/**
194	 * Adds a separator component.
195	 * @param label The separator label property
196	 * @since jEdit 2.6pre2
197	 */
198	public void addSeparator(String label)
199	{
200		if(y != 0)
201			addComponent(Box.createVerticalStrut(6));
202
203		Box box = new Box(BoxLayout.X_AXIS);
204		Box box2 = new Box(BoxLayout.Y_AXIS);
205		box2.add(Box.createGlue());
206		box2.add(new JSeparator(JSeparator.HORIZONTAL));
207		box2.add(Box.createGlue());
208		box.add(box2);
209		JLabel l = new JLabel(jEdit.getProperty(label));
210		l.setMaximumSize(l.getPreferredSize());
211		box.add(l);
212		Box box3 = new Box(BoxLayout.Y_AXIS);
213		box3.add(Box.createGlue());
214		box3.add(new JSeparator(JSeparator.HORIZONTAL));
215		box3.add(Box.createGlue());
216		box.add(box3);
217
218		GridBagConstraints cons = new GridBagConstraints();
219		cons.gridy = y++;
220		cons.gridheight = 1;
221		cons.gridwidth = cons.REMAINDER;
222		cons.fill = GridBagConstraints.BOTH;
223		cons.anchor = GridBagConstraints.WEST;
224		cons.weightx = 1.0f;
225		cons.insets = new Insets(1,0,1,0);
226
227		gridBag.setConstraints(box,cons);
228		add(box);
229	} //}}}
230
231	//{{{ Protected members
232	/**
233	 * Has the option pane been initialized?
234	 */
235	protected boolean initialized;
236
237	/**
238	 * The layout manager.
239	 */
240	protected GridBagLayout gridBag;
241
242	/**
243	 * The number of components already added to the layout manager.
244	 */
245	protected int y;
246
247	/**
248	 * This method should create the option pane's GUI.
249	 */
250	protected void _init() {}
251
252	/**
253	 * Called when the options dialog's "ok" button is clicked.
254	 * This should save any properties being edited in this option
255	 * pane.
256	 */
257	protected void _save() {}
258	//}}}
259
260	//{{{ Private members
261	private String name;
262	//}}}
263}