PageRenderTime 173ms CodeModel.GetById 160ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

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

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