PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms 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
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. public abstract class AbstractOptionPane extends JPanel implements OptionPane
  35. {
  36. //{{{ AbstractOptionPane constructor
  37. /**
  38. * Creates a new option pane.
  39. * @param name The internal name. The option pane's label is set to the
  40. * value of the property named <code>options.<i>name</i>.label</code>.
  41. */
  42. public AbstractOptionPane(String name)
  43. {
  44. this.name = name;
  45. setLayout(gridBag = new GridBagLayout());
  46. } //}}}
  47. //{{{ getName() method
  48. /**
  49. * Returns the internal name of this option pane. The option pane's label
  50. * is set to the value of the property named
  51. * <code>options.<i>name</i>.label</code>.
  52. */
  53. public String getName()
  54. {
  55. return name;
  56. } //}}}
  57. //{{{ getComponent() method
  58. /**
  59. * Returns the component that should be displayed for this option pane.
  60. * Because this class extends Component, it simply returns "this".
  61. */
  62. public Component getComponent()
  63. {
  64. return this;
  65. } //}}}
  66. //{{{ init() method
  67. public void init()
  68. {
  69. if(!initialized)
  70. {
  71. initialized = true;
  72. _init();
  73. }
  74. } //}}}
  75. //{{{ save() method
  76. public void save()
  77. {
  78. if(initialized)
  79. _save();
  80. } //}}}
  81. //{{{ Protected members
  82. //{{{ Instance variables
  83. /**
  84. * Has the option pane been initialized?
  85. */
  86. protected boolean initialized;
  87. /**
  88. * The layout manager.
  89. */
  90. protected GridBagLayout gridBag;
  91. /**
  92. * The number of components already added to the layout manager.
  93. */
  94. protected int y;
  95. //}}}
  96. /**
  97. * This method should create the option pane's GUI.
  98. */
  99. protected void _init() {}
  100. /**
  101. * Called when the options dialog's "ok" button is clicked.
  102. * This should save any properties being edited in this option
  103. * pane.
  104. */
  105. protected void _save() {}
  106. //{{{ addComponent() method
  107. /**
  108. * Adds a labeled component to the option pane. Components are
  109. * added in a vertical fashion, one per row. The label is
  110. * displayed to the left of the component.
  111. * @param label The label
  112. * @param comp The component
  113. */
  114. public void addComponent(String label, Component comp)
  115. {
  116. GridBagConstraints cons = new GridBagConstraints();
  117. cons.gridy = y++;
  118. cons.gridheight = 1;
  119. cons.gridwidth = 1;
  120. cons.weightx = 0.0f;
  121. cons.insets = new Insets(1,0,1,0);
  122. cons.fill = GridBagConstraints.BOTH;
  123. JLabel l = new JLabel(label,SwingConstants.RIGHT);
  124. l.setBorder(new EmptyBorder(0,0,0,12));
  125. gridBag.setConstraints(l,cons);
  126. add(l);
  127. cons.gridx = 1;
  128. cons.weightx = 1.0f;
  129. gridBag.setConstraints(comp,cons);
  130. add(comp);
  131. } //}}}
  132. //{{{ addComponent() method
  133. /**
  134. * Adds a component to the option pane. Components are
  135. * added in a vertical fashion, one per row.
  136. * @param comp The component
  137. */
  138. public void addComponent(Component comp)
  139. {
  140. GridBagConstraints cons = new GridBagConstraints();
  141. cons.gridy = y++;
  142. cons.gridheight = 1;
  143. cons.gridwidth = cons.REMAINDER;
  144. cons.fill = GridBagConstraints.NONE;
  145. cons.anchor = GridBagConstraints.WEST;
  146. cons.weightx = 1.0f;
  147. cons.insets = new Insets(1,0,1,0);
  148. gridBag.setConstraints(comp,cons);
  149. add(comp);
  150. } //}}}
  151. //{{{ addSeparator() method
  152. /**
  153. * Adds a separator component.
  154. * @param label The separator label property
  155. * @since jEdit 2.6pre2
  156. */
  157. public void addSeparator(String label)
  158. {
  159. Box box = new Box(BoxLayout.X_AXIS);
  160. Box box2 = new Box(BoxLayout.Y_AXIS);
  161. box2.add(Box.createGlue());
  162. box2.add(new JSeparator(JSeparator.HORIZONTAL));
  163. box2.add(Box.createGlue());
  164. box.add(box2);
  165. JLabel l = new JLabel(jEdit.getProperty(label));
  166. l.setMaximumSize(l.getPreferredSize());
  167. box.add(l);
  168. Box box3 = new Box(BoxLayout.Y_AXIS);
  169. box3.add(Box.createGlue());
  170. box3.add(new JSeparator(JSeparator.HORIZONTAL));
  171. box3.add(Box.createGlue());
  172. box.add(box3);
  173. GridBagConstraints cons = new GridBagConstraints();
  174. cons.gridy = y++;
  175. cons.gridheight = 1;
  176. cons.gridwidth = cons.REMAINDER;
  177. cons.fill = GridBagConstraints.BOTH;
  178. cons.anchor = GridBagConstraints.WEST;
  179. cons.weightx = 1.0f;
  180. cons.insets = new Insets(1,0,1,0);
  181. gridBag.setConstraints(box,cons);
  182. add(box);
  183. } //}}}
  184. //}}}
  185. //{{{ Private members
  186. private String name;
  187. //}}}
  188. }