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