PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/OptionGroup.java

#
Java | 199 lines | 109 code | 22 blank | 68 comment | 9 complexity | fb1b184eddb934837f54571e62c485fe 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. * OptionGroup.java - Option pane group
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000 mike dillon
  7. * Portions copyright (C) 2003 Slava Pestov
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. package org.gjt.sp.jedit;
  24. import java.util.*;
  25. import org.gjt.sp.util.Log;
  26. /**
  27. * A set of option panes shown in one branch in the options dialog.<p>
  28. *
  29. * Plugins should not create instances of this class anymore. See
  30. * {@link EditPlugin} for information on how jEdit obtains and constructs
  31. * option pane instances.
  32. *
  33. * @author Mike Dillon
  34. * @version $Id: OptionGroup.java 4815 2003-06-27 20:02:06Z spestov $
  35. */
  36. public class OptionGroup
  37. {
  38. //{{{ OptionGroup constructor
  39. /**
  40. * Creates an option group.
  41. * @param name The internal name of the option group, used to key a
  42. * property <code>options.<i>name</i>.label</code> which is the
  43. * label displayed in the options dialog.
  44. * @see jEdit#getProperty(String)
  45. */
  46. public OptionGroup(String name)
  47. {
  48. this.name = name;
  49. label = jEdit.getProperty("options." + name + ".label");
  50. members = new Vector();
  51. } //}}}
  52. //{{{ OptionGroup constructor
  53. /**
  54. * Creates an option group.
  55. * @param label The label
  56. * @param options A whitespace-separated list of option pane names
  57. * @since jEdit 4.2pre2
  58. */
  59. public OptionGroup(String name, String label, String options)
  60. {
  61. this.name = name;
  62. this.label = label;
  63. members = new Vector();
  64. StringTokenizer st = new StringTokenizer(options);
  65. while(st.hasMoreTokens())
  66. {
  67. String pane = st.nextToken();
  68. addOptionPane(pane);
  69. }
  70. } //}}}
  71. //{{{ getName() method
  72. public String getName()
  73. {
  74. return name;
  75. } //}}}
  76. //{{{ getLabel() method
  77. /**
  78. * Returns the option group's human-readable label.
  79. * @since jEdit 4.2pre1
  80. */
  81. public String getLabel()
  82. {
  83. return label;
  84. } //}}}
  85. //{{{ addOptionGroup() method
  86. public void addOptionGroup(OptionGroup group)
  87. {
  88. insertionSort(group.getLabel(),group);
  89. } //}}}
  90. //{{{ addOptionPane() method
  91. public void addOptionPane(OptionPane pane)
  92. {
  93. String label = jEdit.getProperty("options."
  94. + pane.getName() + ".label","NO LABEL PROPERTY: "
  95. + pane.getName());
  96. insertionSort(label,pane);
  97. } //}}}
  98. //{{{ addOptionPane() method
  99. public void addOptionPane(String pane)
  100. {
  101. String label = jEdit.getProperty("options."
  102. + pane + ".label","NO LABEL PROPERTY: "
  103. + pane);
  104. insertionSort(label,pane);
  105. } //}}}
  106. //{{{ getMembers() method
  107. public Enumeration getMembers()
  108. {
  109. return members.elements();
  110. } //}}}
  111. //{{{ getMember() method
  112. public Object getMember(int index)
  113. {
  114. return (index >= 0 && index < members.size())
  115. ? members.elementAt(index) : null;
  116. } //}}}
  117. //{{{ getMemberIndex() method
  118. public int getMemberIndex(Object member)
  119. {
  120. return members.indexOf(member);
  121. } //}}}
  122. //{{{ getMemberCount() method
  123. public int getMemberCount()
  124. {
  125. return members.size();
  126. } //}}}
  127. //{{{ setSort() method
  128. /**
  129. * Sets if the members of this group should be sorted.
  130. * @since jEdit 4.2pre3
  131. */
  132. public void setSort(boolean sort)
  133. {
  134. this.sort = sort;
  135. } //}}}
  136. //{{{ Private members
  137. private String name;
  138. private String label;
  139. private Vector members;
  140. private boolean sort;
  141. //{{{ insertionSort() method
  142. private void insertionSort(String newLabel, Object newObj)
  143. {
  144. if(sort)
  145. {
  146. for(int i = 0; i < members.size(); i++)
  147. {
  148. Object obj = members.elementAt(i);
  149. String label;
  150. if(obj instanceof OptionPane)
  151. {
  152. String name = ((OptionPane)obj).getName();
  153. label = jEdit.getProperty("options."
  154. + name + ".label","NO LABEL PROPERTY: "
  155. + name);
  156. }
  157. else if(obj instanceof String)
  158. {
  159. label = jEdit.getProperty("options."
  160. + obj + ".label","NO LABEL PROPERTY: "
  161. + obj);
  162. }
  163. else if(obj instanceof OptionGroup)
  164. label = ((OptionGroup)obj).getLabel();
  165. else
  166. throw new InternalError();
  167. if(newLabel.compareTo(label) < 0)
  168. {
  169. members.insertElementAt(newObj,i);
  170. return;
  171. }
  172. }
  173. }
  174. members.addElement(newObj);
  175. } //}}}
  176. //}}}
  177. }