PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package org.gjt.sp.jedit;
  23. //{{{ Imports
  24. import javax.swing.border.EmptyBorder;
  25. import javax.swing.*;
  26. import java.awt.*;
  27. //}}}
  28. /**
  29. * The default implementation of the option pane interface. It lays out
  30. * components in a vertical fashion.
  31. *
  32. * @see org.gjt.sp.jedit.OptionPane
  33. */
  34. // even though this class is called AbstractOptionPane, it is not really
  35. // abstract, since BufferOptions uses an instance of it to lay out its
  36. // components.
  37. public 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. //{{{ getName() method
  51. /**
  52. * Returns the internal name of this option pane. The option pane's label
  53. * is set to the value of the property named
  54. * <code>options.<i>name</i>.label</code>.
  55. */
  56. public String getName()
  57. {
  58. return name;
  59. } //}}}
  60. //{{{ getComponent() method
  61. /**
  62. * Returns the component that should be displayed for this option pane.
  63. * Because this class extends Component, it simply returns "this".
  64. */
  65. public Component getComponent()
  66. {
  67. return this;
  68. } //}}}
  69. //{{{ init() method
  70. public void init()
  71. {
  72. if(!initialized)
  73. {
  74. initialized = true;
  75. _init();
  76. }
  77. } //}}}
  78. //{{{ save() method
  79. public void save()
  80. {
  81. if(initialized)
  82. _save();
  83. } //}}}
  84. //{{{ addComponent() method
  85. /**
  86. * Adds a labeled component to the option pane. Components are
  87. * added in a vertical fashion, one per row. The label is
  88. * displayed to the left of the component.
  89. * @param label The label
  90. * @param comp The component
  91. */
  92. public void addComponent(String label, Component comp)
  93. {
  94. JLabel l = new JLabel(label);
  95. l.setBorder(new EmptyBorder(0,0,0,12));
  96. addComponent(l,comp,GridBagConstraints.BOTH);
  97. } //}}}
  98. //{{{ addComponent() method
  99. /**
  100. * Adds a labeled component to the option pane. Components are
  101. * added in a vertical fashion, one per row. The label is
  102. * displayed to the left of the component.
  103. * @param label The label
  104. * @param comp The component
  105. * @param fill Fill parameter to GridBagConstraints for the right
  106. * component
  107. */
  108. public void addComponent(String label, Component comp, int fill)
  109. {
  110. JLabel l = new JLabel(label);
  111. l.setBorder(new EmptyBorder(0,0,0,12));
  112. addComponent(l,comp,fill);
  113. } //}}}
  114. //{{{ addComponent() method
  115. /**
  116. * Adds a labeled component to the option pane. Components are
  117. * added in a vertical fashion, one per row. The label is
  118. * displayed to the left of the component.
  119. * @param comp1 The label
  120. * @param comp2 The component
  121. *
  122. * @since jEdit 4.1pre3
  123. */
  124. public void addComponent(Component comp1, Component comp2)
  125. {
  126. addComponent(comp1,comp2,GridBagConstraints.BOTH);
  127. } //}}}
  128. //{{{ addComponent() method
  129. /**
  130. * Adds a labeled component to the option pane. Components are
  131. * added in a vertical fashion, one per row. The label is
  132. * displayed to the left of the component.
  133. * @param comp1 The label
  134. * @param comp2 The component
  135. * @param fill Fill parameter to GridBagConstraints for the right
  136. * component
  137. *
  138. * @since jEdit 4.1pre3
  139. */
  140. public void addComponent(Component comp1, Component comp2, int fill)
  141. {
  142. GridBagConstraints cons = new GridBagConstraints();
  143. cons.gridy = y++;
  144. cons.gridheight = 1;
  145. cons.gridwidth = 1;
  146. cons.weightx = 0.0f;
  147. cons.insets = new Insets(1,0,1,0);
  148. cons.fill = GridBagConstraints.BOTH;
  149. gridBag.setConstraints(comp1,cons);
  150. add(comp1);
  151. cons.fill = fill;
  152. cons.gridx = 1;
  153. cons.weightx = 1.0f;
  154. gridBag.setConstraints(comp2,cons);
  155. add(comp2);
  156. } //}}}
  157. //{{{ addComponent() method
  158. /**
  159. * Adds a component to the option pane. Components are
  160. * added in a vertical fashion, one per row.
  161. * @param comp The component
  162. */
  163. public void addComponent(Component comp)
  164. {
  165. GridBagConstraints cons = new GridBagConstraints();
  166. cons.gridy = y++;
  167. cons.gridheight = 1;
  168. cons.gridwidth = cons.REMAINDER;
  169. cons.fill = GridBagConstraints.NONE;
  170. cons.anchor = GridBagConstraints.WEST;
  171. cons.weightx = 1.0f;
  172. cons.insets = new Insets(1,0,1,0);
  173. gridBag.setConstraints(comp,cons);
  174. add(comp);
  175. } //}}}
  176. //{{{ addSeparator() method
  177. /**
  178. * Adds a separator component.
  179. * @param label The separator label property
  180. * @since jEdit 2.6pre2
  181. */
  182. public void addSeparator(String label)
  183. {
  184. if(y != 0)
  185. addComponent(Box.createVerticalStrut(6));
  186. Box box = new Box(BoxLayout.X_AXIS);
  187. Box box2 = new Box(BoxLayout.Y_AXIS);
  188. box2.add(Box.createGlue());
  189. box2.add(new JSeparator(JSeparator.HORIZONTAL));
  190. box2.add(Box.createGlue());
  191. box.add(box2);
  192. JLabel l = new JLabel(jEdit.getProperty(label));
  193. l.setMaximumSize(l.getPreferredSize());
  194. box.add(l);
  195. Box box3 = new Box(BoxLayout.Y_AXIS);
  196. box3.add(Box.createGlue());
  197. box3.add(new JSeparator(JSeparator.HORIZONTAL));
  198. box3.add(Box.createGlue());
  199. box.add(box3);
  200. GridBagConstraints cons = new GridBagConstraints();
  201. cons.gridy = y++;
  202. cons.gridheight = 1;
  203. cons.gridwidth = cons.REMAINDER;
  204. cons.fill = GridBagConstraints.BOTH;
  205. cons.anchor = GridBagConstraints.WEST;
  206. cons.weightx = 1.0f;
  207. cons.insets = new Insets(1,0,1,0);
  208. gridBag.setConstraints(box,cons);
  209. add(box);
  210. } //}}}
  211. //{{{ Protected members
  212. /**
  213. * Has the option pane been initialized?
  214. */
  215. protected boolean initialized;
  216. /**
  217. * The layout manager.
  218. */
  219. protected GridBagLayout gridBag;
  220. /**
  221. * The number of components already added to the layout manager.
  222. */
  223. protected int y;
  224. /**
  225. * This method should create the option pane's GUI.
  226. */
  227. protected void _init() {}
  228. /**
  229. * Called when the options dialog's "ok" button is clicked.
  230. * This should save any properties being edited in this option
  231. * pane.
  232. */
  233. protected void _save() {}
  234. //}}}
  235. //{{{ Private members
  236. private String name;
  237. //}}}
  238. }