/plugins/JavaSideKick/tags/javasidekick-2-3-1/src/sidekick/java/options/JBrowseOptionPane.java

# · Java · 1007 lines · 636 code · 193 blank · 178 comment · 49 complexity · b8e590ac47760d06c4552955395396b3 MD5 · raw file

  1. /*
  2. * JBrowseOptionPane.java - JBrowse options panel
  3. *
  4. * Copyright (c) 1999-2000 George Latkiewicz, Andre Kaplan
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. package sidekick.java.options;
  21. import java.awt.BorderLayout;
  22. import java.awt.Component;
  23. import java.awt.FlowLayout;
  24. import java.awt.Font;
  25. import java.awt.GridBagConstraints;
  26. import java.awt.GridBagLayout;
  27. import java.awt.event.ActionEvent;
  28. import java.awt.event.ActionListener;
  29. import javax.swing.BorderFactory;
  30. import javax.swing.JCheckBox;
  31. import javax.swing.JComboBox;
  32. import javax.swing.JRadioButton;
  33. import javax.swing.ButtonGroup;
  34. import javax.swing.JLabel;
  35. import javax.swing.JPanel;
  36. import javax.swing.JScrollPane;
  37. import javax.swing.SwingConstants;
  38. import javax.swing.border.Border;
  39. import javax.swing.border.BevelBorder;
  40. import javax.swing.border.TitledBorder;
  41. import org.gjt.sp.jedit.AbstractOptionPane;
  42. import org.gjt.sp.util.Log;
  43. import sidekick.java.JavaParser;
  44. /**
  45. * JBrowse option pane
  46. * @author George Latkiewicz
  47. * @author Andre Kaplan
  48. * @version $Id: JBrowseOptionPane.java 1029 2006-07-21 20:00:43Z daleanson $
  49. **/
  50. public class JBrowseOptionPane extends AbstractOptionPane
  51. {
  52. // protected members inherited from AbstractOptionPane: y, gridBag
  53. // private state
  54. boolean isInitGui;
  55. boolean isInitModel;
  56. // private gui components
  57. private JPanel contents;
  58. // general options
  59. private JCheckBox cbxStatusBar;
  60. private JCheckBox cbxAutomaticParse;
  61. private JCheckBox cbxSort;
  62. private ButtonGroup bg = null;
  63. private JRadioButton rbSortByLine;
  64. private JRadioButton rbSortByName;
  65. private JRadioButton rbSortByVisibility;
  66. // filter options
  67. private JCheckBox cbxShowImports;
  68. private JCheckBox cbxShowFields;
  69. private JCheckBox cbxShowPrimitives;
  70. private JCheckBox cbxShowVariables;
  71. private JCheckBox cbxShowInitializers;
  72. private JCheckBox cbxShowGeneralizations;
  73. private JCheckBox cbxShowThrows;
  74. private JComboBox cmbTopLevelVis;
  75. private JComboBox cmbMemberVis;
  76. private int topLevelVisIndex;
  77. private int memberVisIndex;
  78. // display options
  79. private JCheckBox cbxShowArguments;
  80. private JCheckBox cbxShowArgumentNames;
  81. private JCheckBox cbxShowTypeArgs;
  82. private JCheckBox cbxShowErrors;
  83. private JCheckBox cbxShowNestedName;
  84. private JCheckBox cbxShowIconKeywords;
  85. private JCheckBox cbxShowMiscMod;
  86. private JCheckBox cbxShowIcons;
  87. private JCheckBox cbxShowLineNum;
  88. private JComboBox cmbStyle;
  89. private int styleIndex = DisplayOptions.STYLE_UML;
  90. private JCheckBox cbxVisSymbols;
  91. private JCheckBox cbxAbstractItalic;
  92. private JCheckBox cbxStaticUlined;
  93. private JCheckBox cbxTypeIsSuffixed;
  94. // Options object
  95. private GeneralOptions options = new GeneralOptions();
  96. private MutableFilterOptions filterOpt = options.getFilterOptions();
  97. private MutableDisplayOptions displayOpt = options.getDisplayOptions();
  98. // Property Accessor
  99. private PropertyAccessor props;
  100. private boolean batchUpdate = false;
  101. // Listeners
  102. private ActionListener defaultAction = null;
  103. private ActionListener updateOptionsAction = null;
  104. private ActionListener setOptionsAction = null;
  105. public JBrowseOptionPane() {
  106. this("sidekick.java");
  107. }
  108. public JBrowseOptionPane(String title) {
  109. super(title);
  110. setLayout(new BorderLayout());
  111. contents = new JPanel();
  112. contents.setLayout(gridBag = new GridBagLayout());
  113. add(new JScrollPane(contents));
  114. // It is the instantiating code's responsibility to call:
  115. // initGui(), initModel(), and setOptions() before displaying
  116. // Also either addDefaultListeners or addJBrowseListeners must be
  117. // called to allow the GUI to correctly respond to user interaction
  118. }
  119. /**
  120. * AbstractOptionPane implementation (_init and _save)
  121. **/
  122. public void _init() {
  123. this.setPropertyAccessor(new JEditPropertyAccessor());
  124. options.load(props);
  125. initGui(); // setup display from property values
  126. initModel(); // set GUI to model (as defined in Options object)
  127. }
  128. /**
  129. * AbstractOptionPane implementation (_init and _save)
  130. * The method called by the File->Plugin Options save button for
  131. * setting the JBrowse plugin options for all future sessions.
  132. * It saves the current view state to the associated property values.
  133. **/
  134. public void _save() {
  135. options.save(props);
  136. _init();
  137. }
  138. PropertyAccessor getPropertyAccessor() { return props; }
  139. void setPropertyAccessor(PropertyAccessor props) {
  140. this.props = props;
  141. }
  142. public boolean isInitGui() { return isInitGui; }
  143. public boolean isInitModel() { return isInitModel; }
  144. /**
  145. * Sets this OptionPane's options object to the state specified by the
  146. * the OptionPane's associated PropertyAccessor.
  147. **/
  148. public void load() {
  149. batchUpdate = true;
  150. options.load(props);
  151. batchUpdate = false;
  152. }
  153. /**
  154. * Setup the GUI (with no current state).
  155. * This should only be called once in the constructor for this
  156. * JBrowseOptionPane.
  157. **/
  158. private void initGui() {
  159. // -----
  160. // Title
  161. // -----
  162. JLabel titleLabel = new JLabel(
  163. props.getProperty("options." + getName() + ".panel_label") + ":",
  164. JLabel.LEFT );
  165. titleLabel.setFont(new Font("Helvetica", Font.BOLD + Font.ITALIC, 13));
  166. addComponent(titleLabel);
  167. // ---------------
  168. // General Options
  169. // ---------------
  170. JPanel generalPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 9, 0));
  171. cbxStatusBar = new JCheckBox(
  172. props.getProperty("options.sidekick.java.showStatusBar"));
  173. //generalPanel.add(cbxStatusBar);
  174. cbxAutomaticParse = new JCheckBox(
  175. props.getProperty("options.sidekick.java.automaticParse"));
  176. //generalPanel.add(cbxAutomaticParse);
  177. cbxSort = new JCheckBox(
  178. props.getProperty("options.sidekick.java.sort"));
  179. //generalPanel.add(cbxSort);
  180. addComponent(generalPanel);
  181. // --------------
  182. // Filter Options
  183. // --------------
  184. OptionPanel filterPanel = new OptionPanel();
  185. filterPanel.setBorder(this.createOptionBorder(
  186. " " + props.getProperty("options.sidekick.java.filterOptions") + " "
  187. ));
  188. JPanel attrPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
  189. /* Attributes */
  190. cbxShowFields = new JCheckBox(
  191. props.getProperty("options.sidekick.java.showAttr") + " ");
  192. attrPanel.add(cbxShowFields);
  193. /* Primitive Attributes */
  194. cbxShowPrimitives = new JCheckBox(
  195. props.getProperty("options.sidekick.java.showPrimAttr"));
  196. attrPanel.add(cbxShowPrimitives);
  197. filterPanel.addComponent(attrPanel);
  198. /* imports */
  199. cbxShowImports = new JCheckBox(
  200. props.getProperty("options.sidekick.java.showImports") + " ");
  201. filterPanel.addComponent(cbxShowImports);
  202. /* local variables */
  203. cbxShowVariables = new JCheckBox(
  204. props.getProperty("options.sidekick.java.showVariables"));
  205. filterPanel.addComponent(cbxShowVariables);
  206. /* static initializers */
  207. cbxShowInitializers = new JCheckBox(
  208. props.getProperty("options.sidekick.java.showInitializers"));
  209. filterPanel.addComponent(cbxShowInitializers);
  210. /* Generalizations */
  211. cbxShowGeneralizations = new JCheckBox(
  212. props.getProperty("options.sidekick.java.showGeneralizations") + " ");
  213. filterPanel.addComponent(cbxShowGeneralizations);
  214. /* Throws */
  215. cbxShowThrows = new JCheckBox(
  216. props.getProperty("options.sidekick.java.showThrows") + " ");
  217. filterPanel.addComponent(cbxShowThrows);
  218. /* Visibility Level */
  219. JLabel visLevelLabel = new JLabel(
  220. props.getProperty("options.sidekick.java.visLevelLabel") );
  221. filterPanel.addComponent(visLevelLabel);
  222. /* Top-Level Visibility Options */
  223. String[] topLevelVisNames = { "package", "public" };
  224. cmbTopLevelVis = new JComboBox(topLevelVisNames);
  225. filterPanel.addComponent(props.getProperty("options.sidekick.java.topLevelVis"),
  226. cmbTopLevelVis);
  227. /* Member-Level Visibility Options */
  228. String[] memberVisNames = { "private", "package", "protected", "public" };
  229. cmbMemberVis = new JComboBox(memberVisNames);
  230. filterPanel.addComponent(props.getProperty("options.sidekick.java.memberVis"),
  231. cmbMemberVis);
  232. addComponent(filterPanel);
  233. // ---------------
  234. // Display Options
  235. // ---------------
  236. OptionPanel displayPanel = new OptionPanel();
  237. displayPanel.setBorder(this.createOptionBorder(
  238. " " + props.getProperty("options.sidekick.java.displayOptions") + " "
  239. ));
  240. /* Arguments */
  241. JPanel argPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
  242. cbxShowArguments = new JCheckBox(
  243. props.getProperty("options.sidekick.java.showArgs") + " ");
  244. argPanel.add(cbxShowArguments);
  245. /* Argument Names */
  246. cbxShowArgumentNames = new JCheckBox(
  247. props.getProperty("options.sidekick.java.showArgNames"));
  248. argPanel.add(cbxShowArgumentNames);
  249. displayPanel.addComponent(argPanel);
  250. /* generics type arguments */
  251. cbxShowTypeArgs = new JCheckBox(
  252. props.getProperty("options.sidekick.java.showTypeArgs"));
  253. displayPanel.addComponent(cbxShowTypeArgs);
  254. /* qualify nested class/interface names */
  255. cbxShowNestedName = new JCheckBox(
  256. props.getProperty("options.sidekick.java.showNestedName"));
  257. displayPanel.addComponent(cbxShowNestedName);
  258. /* class/interface modifiers */
  259. cbxShowIconKeywords = new JCheckBox(
  260. props.getProperty("options.sidekick.java.showIconKeywords"));
  261. displayPanel.addComponent(cbxShowIconKeywords);
  262. /* misc. detail modifiers */
  263. cbxShowMiscMod = new JCheckBox(
  264. props.getProperty("options.sidekick.java.showMiscMod"));
  265. displayPanel.addComponent(cbxShowMiscMod);
  266. /* Icons */
  267. cbxShowIcons = new JCheckBox(
  268. props.getProperty("options.sidekick.java.showIcons"));
  269. displayPanel.addComponent(cbxShowIcons);
  270. /* Line Numbers */
  271. cbxShowLineNum = new JCheckBox(
  272. props.getProperty("options.sidekick.java.showLineNums"));
  273. displayPanel.addComponent(cbxShowLineNum);
  274. /* Sort */
  275. JPanel sortPanel = new JPanel(new BorderLayout());
  276. JPanel sortButtonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 5));
  277. rbSortByLine = new JRadioButton(props.getProperty("options.sidekick.java.sortByLine"));
  278. rbSortByLine.setActionCommand(props.getProperty("options.sidekick.java.sortByLine"));
  279. rbSortByName = new JRadioButton(props.getProperty("options.sidekick.java.sortByName"));
  280. rbSortByName.setActionCommand(props.getProperty("options.sidekick.java.sortByName"));
  281. rbSortByVisibility = new JRadioButton(props.getProperty("options.sidekick.java.sortByVisibility"));
  282. rbSortByVisibility.setActionCommand(props.getProperty("options.sidekick.java.sortByVisibility"));
  283. sortButtonPanel.add(rbSortByLine);
  284. sortButtonPanel.add(rbSortByName);
  285. sortButtonPanel.add(rbSortByVisibility);
  286. sortPanel.add(new JLabel(props.getProperty("options.sidekick.java.sortBy") + ":"), BorderLayout.WEST);
  287. sortPanel.add(sortButtonPanel, BorderLayout.CENTER);
  288. displayPanel.addComponent(sortPanel);
  289. bg = new ButtonGroup();
  290. bg.add(rbSortByLine);
  291. bg.add(rbSortByName);
  292. bg.add(rbSortByVisibility);
  293. /* show errors in ErrorList */
  294. cbxShowErrors = new JCheckBox(
  295. props.getProperty("options.sidekick.java.showErrors"));
  296. displayPanel.addComponent(cbxShowErrors);
  297. /* Display Style */
  298. String[] styleNames = {
  299. props.getProperty("options.sidekick.java.umlStyle"),
  300. props.getProperty("options.sidekick.java.javaStyle"),
  301. props.getProperty("options.sidekick.java.customStyle") };
  302. cmbStyle = new JComboBox(styleNames);
  303. displayPanel.addComponent(props.getProperty("options.sidekick.java.displayStyle"),
  304. cmbStyle);
  305. /* Custom Display Style Options */
  306. JLabel customOptionsLabel = new JLabel(
  307. props.getProperty("options.sidekick.java.customOptions"));
  308. displayPanel.addComponent(customOptionsLabel);
  309. cbxVisSymbols = new JCheckBox(
  310. props.getProperty("options.sidekick.java.custVisAsSymbol"));
  311. cbxAbstractItalic = new JCheckBox(
  312. props.getProperty("options.sidekick.java.custAbsAsItalic"));
  313. cbxStaticUlined = new JCheckBox(
  314. props.getProperty("options.sidekick.java.custStaAsUlined"));
  315. cbxTypeIsSuffixed = new JCheckBox(
  316. props.getProperty("options.sidekick.java.custTypeIsSuffixed"));
  317. displayPanel.addComponent(cbxVisSymbols);
  318. displayPanel.addComponent(cbxAbstractItalic);
  319. displayPanel.addComponent(cbxStaticUlined);
  320. displayPanel.addComponent(cbxTypeIsSuffixed);
  321. addComponent(displayPanel);
  322. addComponent(new JLabel("<html>&nbsp;&nbsp;<strong><i>" + props.getProperty("options.sidekick.java.reparseWarning")));
  323. this.addDefaultListeners();
  324. isInitGui = true;
  325. }
  326. /**
  327. * This method sets the GUI representation of the model to the state
  328. * specified by the current option object's state.
  329. **/
  330. public void initModel() {
  331. //Log.log(Log.DEBUG, this, "initModel: " + this.getName());
  332. batchUpdate = true;
  333. // General Options
  334. cbxStatusBar.getModel().setSelected( options.getShowStatusBar() );
  335. cbxAutomaticParse.getModel().setSelected( options.getAutomaticParse() );
  336. cbxSort.getModel().setSelected( options.getSort() );
  337. // Filter Options
  338. cbxShowImports.getModel().setSelected( filterOpt.getShowImports());
  339. cbxShowFields.getModel().setSelected( filterOpt.getShowFields() );
  340. cbxShowPrimitives.getModel().setSelected( filterOpt.getShowPrimitives() );
  341. cbxShowVariables.getModel().setSelected( filterOpt.getShowVariables());
  342. cbxShowInitializers.getModel().setSelected( filterOpt.getShowInitializers() );
  343. cbxShowGeneralizations.getModel().setSelected( filterOpt.getShowGeneralizations() );
  344. cbxShowThrows.getModel().setSelected( filterOpt.getShowThrows() );
  345. cmbTopLevelVis.setSelectedIndex( filterOpt.getTopLevelVisIndex() );
  346. cmbMemberVis.setSelectedIndex( filterOpt.getMemberVisIndex() );
  347. // Display Options
  348. cbxShowArguments.getModel().setSelected( displayOpt.getShowArguments() );
  349. cbxShowArgumentNames.getModel().setSelected( displayOpt.getShowArgumentNames() );
  350. cbxShowTypeArgs.getModel().setSelected( displayOpt.getShowTypeArgs() );
  351. cbxShowErrors.getModel().setSelected( displayOpt.getShowErrors());
  352. cbxShowNestedName.getModel().setSelected( displayOpt.getShowNestedName() );
  353. cbxShowIconKeywords.getModel().setSelected( displayOpt.getShowIconKeywords() );
  354. cbxShowMiscMod.getModel().setSelected( displayOpt.getShowMiscMod() );
  355. cbxShowIcons.getModel().setSelected( displayOpt.getShowIcons() );
  356. cbxShowLineNum.getModel().setSelected( displayOpt.getShowLineNum() );
  357. rbSortByLine.getModel().setSelected( rbSortByLine.getActionCommand().equals(displayOpt.getSortBy()));
  358. rbSortByName.getModel().setSelected( rbSortByName.getActionCommand().equals(displayOpt.getSortBy()));
  359. rbSortByVisibility.getModel().setSelected( rbSortByVisibility.getActionCommand().equals(displayOpt.getSortBy()));
  360. cmbStyle.setSelectedIndex(displayOpt.getStyleIndex() );
  361. cbxVisSymbols.getModel().setSelected( displayOpt.getVisSymbols() );
  362. cbxAbstractItalic.getModel().setSelected( displayOpt.getAbstractItalic() );
  363. cbxStaticUlined.getModel().setSelected( displayOpt.getStaticUlined() );
  364. cbxTypeIsSuffixed.getModel().setSelected( displayOpt.getTypeIsSuffixed() );
  365. // Set enabled/disabled on showArgumentNames, showPrimitives checkboxes
  366. if(cbxShowArguments.getModel().isSelected()) {
  367. cbxShowArgumentNames.getModel().setEnabled(true);
  368. } else {
  369. cbxShowArgumentNames.getModel().setSelected(false);
  370. cbxShowArgumentNames.getModel().setEnabled(false);
  371. }
  372. if(cbxShowFields.getModel().isSelected()) {
  373. cbxShowPrimitives.getModel().setEnabled(true);
  374. } else {
  375. cbxShowPrimitives.getModel().setSelected(false);
  376. cbxShowPrimitives.getModel().setEnabled(false);
  377. }
  378. refreshDisplayOptions(styleIndex);
  379. isInitModel = true;
  380. batchUpdate = false;
  381. }
  382. public void addDefaultListeners() {
  383. ActionListener defaultListener = this.getDefaultAction();
  384. // general options
  385. this.cbxStatusBar.addActionListener(defaultListener);
  386. this.cbxStatusBar.addActionListener(defaultListener);
  387. this.cbxAutomaticParse.addActionListener(defaultListener);
  388. this.cbxSort.addActionListener(defaultListener);
  389. // filter options
  390. this.cbxShowImports.addActionListener(defaultListener);
  391. this.cbxShowFields.addActionListener(defaultListener);
  392. this.cbxShowPrimitives.addActionListener(defaultListener);
  393. this.cbxShowVariables.addActionListener(defaultListener);
  394. this.cbxShowInitializers.addActionListener(defaultListener);
  395. this.cbxShowGeneralizations.addActionListener(defaultListener);
  396. this.cbxShowThrows.addActionListener(defaultListener);
  397. this.cmbTopLevelVis.addActionListener(defaultListener);
  398. this.cmbMemberVis.addActionListener(defaultListener);
  399. // display options
  400. this.cbxShowArguments.addActionListener(defaultListener);
  401. this.cbxShowArgumentNames.addActionListener(defaultListener);
  402. this.cbxShowTypeArgs.addActionListener(defaultListener);
  403. this.cbxShowErrors.addActionListener(defaultListener);
  404. this.cbxShowNestedName.addActionListener(defaultListener);
  405. this.cbxShowIconKeywords.addActionListener(defaultListener);
  406. this.cbxShowMiscMod.addActionListener(defaultListener);
  407. this.cbxShowIcons.addActionListener(defaultListener);
  408. this.cbxShowLineNum.addActionListener(defaultListener);
  409. rbSortByLine.addActionListener(defaultListener);
  410. rbSortByName.addActionListener(defaultListener);
  411. rbSortByVisibility.addActionListener(defaultListener);
  412. this.cmbStyle.addActionListener(defaultListener);
  413. this.cbxVisSymbols.addActionListener(defaultListener);
  414. this.cbxAbstractItalic.addActionListener(defaultListener);
  415. this.cbxStaticUlined.addActionListener(defaultListener);
  416. this.cbxTypeIsSuffixed.addActionListener(defaultListener);
  417. }
  418. public void removeDefaultListeners() {
  419. ActionListener defaultListener = this.getDefaultAction();
  420. // general options
  421. this.cbxStatusBar.removeActionListener(defaultListener);
  422. this.cbxStatusBar.removeActionListener(defaultListener);
  423. this.cbxAutomaticParse.removeActionListener(defaultListener);
  424. this.cbxSort.removeActionListener(defaultListener);
  425. // filter options
  426. this.cbxShowImports.removeActionListener(defaultListener);
  427. this.cbxShowFields.removeActionListener(defaultListener);
  428. this.cbxShowPrimitives.removeActionListener(defaultListener);
  429. this.cbxShowVariables.removeActionListener(defaultListener);
  430. this.cbxShowInitializers.removeActionListener(defaultListener);
  431. this.cbxShowGeneralizations.removeActionListener(defaultListener);
  432. this.cbxShowThrows.removeActionListener(defaultListener);
  433. this.cmbTopLevelVis.removeActionListener(defaultListener);
  434. this.cmbMemberVis.removeActionListener(defaultListener);
  435. // display options
  436. this.cbxShowArguments.removeActionListener(defaultListener);
  437. this.cbxShowArgumentNames.removeActionListener(defaultListener);
  438. this.cbxShowTypeArgs.removeActionListener(defaultListener);
  439. this.cbxShowErrors.removeActionListener(defaultListener);
  440. this.cbxShowNestedName.removeActionListener(defaultListener);
  441. this.cbxShowIconKeywords.removeActionListener(defaultListener);
  442. this.cbxShowMiscMod.removeActionListener(defaultListener);
  443. this.cbxShowIcons.removeActionListener(defaultListener);
  444. this.cbxShowLineNum.removeActionListener(defaultListener);
  445. rbSortByLine.removeActionListener(defaultListener);
  446. rbSortByName.removeActionListener(defaultListener);
  447. rbSortByVisibility.removeActionListener(defaultListener);
  448. this.cmbStyle.removeActionListener(defaultListener);
  449. this.cbxVisSymbols.removeActionListener(defaultListener);
  450. this.cbxAbstractItalic.removeActionListener(defaultListener);
  451. this.cbxStaticUlined.removeActionListener(defaultListener);
  452. this.cbxTypeIsSuffixed.removeActionListener(defaultListener);
  453. }
  454. /**
  455. * Allows this option pane to reflect any user interaction directly to
  456. * JBrowse
  457. **/
  458. public void addJBrowseListeners(JavaParser jbrowse) {
  459. // general options
  460. ActionListener statusBarOptionAction =
  461. this.createAction(jbrowse.getStatusBarOptionAction());
  462. this.cbxStatusBar.addActionListener(statusBarOptionAction);
  463. ActionListener resizeAction =
  464. this.createAction(jbrowse.getResizeAction());
  465. this.cbxStatusBar.addActionListener(resizeAction);
  466. this.cbxAutomaticParse.addActionListener(this.getDefaultAction());
  467. ActionListener sortOptionAction =
  468. this.createAction(jbrowse.getSortOptionAction());
  469. this.cbxSort.addActionListener(sortOptionAction);
  470. // filter options
  471. ActionListener filterOptionAction =
  472. this.createAction(jbrowse.getFilterOptionAction());
  473. this.cbxShowImports.addActionListener(filterOptionAction);
  474. this.cbxShowFields.addActionListener(filterOptionAction);
  475. this.cbxShowPrimitives.addActionListener(filterOptionAction);
  476. this.cbxShowVariables.addActionListener(filterOptionAction);
  477. this.cbxShowInitializers.addActionListener(filterOptionAction);
  478. this.cbxShowGeneralizations.addActionListener(filterOptionAction);
  479. this.cmbTopLevelVis.addActionListener(filterOptionAction);
  480. this.cmbMemberVis.addActionListener(filterOptionAction);
  481. // display options
  482. ActionListener displayOptionAction =
  483. this.createAction(jbrowse.getDisplayOptionAction());
  484. this.cbxShowArguments.addActionListener(displayOptionAction);
  485. this.cbxShowArgumentNames.addActionListener(displayOptionAction);
  486. this.cbxShowTypeArgs.addActionListener(displayOptionAction);
  487. this.cbxShowErrors.addActionListener(displayOptionAction);
  488. this.cbxShowThrows.addActionListener(displayOptionAction);
  489. this.cbxShowNestedName.addActionListener(displayOptionAction);
  490. this.cbxShowIconKeywords.addActionListener(displayOptionAction);
  491. this.cbxShowMiscMod.addActionListener(displayOptionAction);
  492. this.cbxShowIcons.addActionListener(displayOptionAction);
  493. this.cbxShowLineNum.addActionListener(displayOptionAction);
  494. rbSortByLine.addActionListener(displayOptionAction);
  495. rbSortByName.addActionListener(displayOptionAction);
  496. rbSortByVisibility.addActionListener(displayOptionAction);
  497. this.cmbStyle.addActionListener(displayOptionAction);
  498. this.cbxVisSymbols.addActionListener(displayOptionAction);
  499. this.cbxAbstractItalic.addActionListener(displayOptionAction);
  500. this.cbxStaticUlined.addActionListener(displayOptionAction);
  501. this.cbxTypeIsSuffixed.addActionListener(displayOptionAction);
  502. }
  503. private ActionListener getDefaultAction() {
  504. if (this.defaultAction == null) {
  505. this.defaultAction = this.createDefaultAction();
  506. }
  507. return this.defaultAction;
  508. }
  509. private ActionListener getUpdateOptionsAction() {
  510. if (this.updateOptionsAction == null) {
  511. this.updateOptionsAction = new UpdateOptionsAction();
  512. }
  513. return this.updateOptionsAction;
  514. }
  515. private ActionListener getSetOptionsAction() {
  516. if (this.setOptionsAction == null) {
  517. this.setOptionsAction = new SetOptionsAction();
  518. }
  519. return this.setOptionsAction;
  520. }
  521. private ActionListener createDefaultAction() {
  522. return this.createAction(null);
  523. }
  524. private ActionListener createAction(ActionListener jbrowseAction) {
  525. Condition batchUpdateCondition = new BatchUpdateCondition();
  526. if (jbrowseAction == null) {
  527. return (
  528. new CompoundAction(
  529. this.getUpdateOptionsAction(),
  530. new ConditionalAction(
  531. batchUpdateCondition,
  532. null,
  533. this.getSetOptionsAction()
  534. )
  535. )
  536. );
  537. } else {
  538. return (
  539. new CompoundAction(
  540. this.getUpdateOptionsAction(),
  541. new ConditionalAction(
  542. batchUpdateCondition,
  543. null,
  544. new CompoundAction(
  545. this.getSetOptionsAction(), jbrowseAction
  546. )
  547. )
  548. )
  549. );
  550. }
  551. }
  552. /**
  553. * Set the enabled and selected/index state of all the display options
  554. * that are dependant on the cmbStyle control. The state to be set to
  555. * is determined by the passed styleIndex value. This method is called
  556. * on init() and upon each change to the sytleIndex via its associated
  557. * cmbStyle JComboBox.
  558. **/
  559. private void refreshDisplayOptions(int styleIndex) {
  560. if (styleIndex == DisplayOptions.STYLE_UML) {
  561. // UML
  562. cbxVisSymbols.getModel().setSelected(true);
  563. cbxAbstractItalic.getModel().setSelected(true);
  564. cbxStaticUlined.getModel().setSelected(true);
  565. cbxTypeIsSuffixed.getModel().setSelected(true);
  566. cbxVisSymbols.getModel().setEnabled(false);
  567. cbxAbstractItalic.getModel().setEnabled(false);
  568. cbxStaticUlined.getModel().setEnabled(false);
  569. cbxTypeIsSuffixed.getModel().setEnabled(false);
  570. } else if (styleIndex == DisplayOptions.STYLE_JAVA) {
  571. // Java
  572. cbxVisSymbols.getModel().setSelected(false);
  573. cbxAbstractItalic.getModel().setSelected(false);
  574. cbxStaticUlined.getModel().setSelected(false);
  575. cbxTypeIsSuffixed.getModel().setSelected(false);
  576. cbxVisSymbols.getModel().setEnabled(false);
  577. cbxAbstractItalic.getModel().setEnabled(false);
  578. cbxStaticUlined.getModel().setEnabled(false);
  579. cbxTypeIsSuffixed.getModel().setEnabled(false);
  580. } else if (styleIndex == DisplayOptions.STYLE_CUSTOM) {
  581. // Custom
  582. cbxVisSymbols.getModel().setEnabled(true);
  583. cbxAbstractItalic.getModel().setEnabled(true);
  584. cbxStaticUlined.getModel().setEnabled(true);
  585. cbxTypeIsSuffixed.getModel().setEnabled(true);
  586. } else {
  587. // error, unknown style index
  588. }
  589. }
  590. public GeneralOptions getOptions() { return options; }
  591. /**
  592. * The method that sets the option object's state to reflect the values
  593. * specified by the current state of the JBrowseOptionPane.
  594. **/
  595. private void setOptions() {
  596. // General Options
  597. options.setShowStatusBar( cbxStatusBar.getModel().isSelected() );
  598. options.setAutomaticParse( cbxAutomaticParse.getModel().isSelected() );
  599. options.setSort( cbxSort.getModel().isSelected() );
  600. // Filter Options
  601. filterOpt.setShowImports( cbxShowImports.getModel().isSelected() );
  602. filterOpt.setShowFields( cbxShowFields.getModel().isSelected() );
  603. filterOpt.setShowPrimitives( cbxShowPrimitives.getModel().isSelected() );
  604. filterOpt.setShowVariables( cbxShowVariables.getModel().isSelected());
  605. filterOpt.setShowInitializers( cbxShowInitializers.getModel().isSelected() );
  606. filterOpt.setShowGeneralizations( cbxShowGeneralizations.getModel().isSelected() );
  607. filterOpt.setShowThrows( cbxShowThrows.getModel().isSelected() );
  608. filterOpt.setTopLevelVisIndex( topLevelVisIndex );
  609. filterOpt.setMemberVisIndex( memberVisIndex );
  610. // Display Options
  611. displayOpt.setShowArguments( cbxShowArguments.getModel().isSelected() );
  612. displayOpt.setShowArgumentNames( cbxShowArgumentNames.getModel().isSelected() );
  613. displayOpt.setShowTypeArgs( cbxShowTypeArgs.getModel().isSelected());
  614. displayOpt.setShowErrors(cbxShowErrors.getModel().isSelected());
  615. displayOpt.setShowNestedName( cbxShowNestedName.getModel().isSelected() );
  616. displayOpt.setShowIconKeywords( cbxShowIconKeywords.getModel().isSelected() );
  617. displayOpt.setShowMiscMod( cbxShowMiscMod.getModel().isSelected() );
  618. displayOpt.setShowIcons(cbxShowIcons.getModel().isSelected());
  619. displayOpt.setShowLineNum( cbxShowLineNum.getModel().isSelected() );
  620. displayOpt.setSortBy(bg.getSelection().getActionCommand());
  621. displayOpt.setStyleIndex( styleIndex );
  622. displayOpt.setVisSymbols( cbxVisSymbols.getModel().isSelected() );
  623. displayOpt.setAbstractItalic( cbxAbstractItalic.getModel().isSelected() );
  624. displayOpt.setStaticUlined( cbxStaticUlined.getModel().isSelected() );
  625. displayOpt.setTypeIsSuffixed( cbxTypeIsSuffixed.getModel().isSelected() );
  626. }
  627. /**
  628. * Adds a component to the JBrowse option pane.
  629. * <ul>
  630. * <li>Components are added in a vertical fashion, one per row</li>
  631. * <li>Components fill the horizontal space</li>
  632. * </ul>
  633. * Overrides org.gjt.sp.jedit.AbstractOptionPane#addComponent(java.awt.Component)
  634. **/
  635. public void addComponent(Component comp) {
  636. GridBagConstraints cons = new GridBagConstraints();
  637. cons.gridy = y++;
  638. cons.gridheight = 1;
  639. cons.gridwidth = cons.REMAINDER;
  640. cons.fill = GridBagConstraints.HORIZONTAL;
  641. cons.anchor = GridBagConstraints.CENTER;
  642. cons.weightx = 1.0f;
  643. gridBag.setConstraints(comp,cons);
  644. contents.add(comp);
  645. }
  646. /**
  647. * Creates the border of the option panels
  648. **/
  649. private Border createOptionBorder(String title) {
  650. Border border = BorderFactory.createCompoundBorder(
  651. BorderFactory.createTitledBorder(
  652. BorderFactory.createBevelBorder(BevelBorder.LOWERED),
  653. title, TitledBorder.CENTER, TitledBorder.TOP
  654. ),
  655. BorderFactory.createEmptyBorder(0, 3, 1, 1)
  656. );
  657. return border;
  658. }
  659. /**
  660. * Implements the option pane logic and interactions between components
  661. **/
  662. private class UpdateOptionsAction implements ActionListener {
  663. public void actionPerformed(ActionEvent evt)
  664. {
  665. Object actionSource = evt.getSource();
  666. // Filter Options
  667. if (actionSource == cbxShowFields) {
  668. if(cbxShowFields.getModel().isSelected()) {
  669. cbxShowPrimitives.getModel().setEnabled(true);
  670. } else {
  671. cbxShowPrimitives.getModel().setSelected(false);
  672. cbxShowPrimitives.getModel().setEnabled(false);
  673. }
  674. } else if (actionSource == cmbTopLevelVis) {
  675. topLevelVisIndex = cmbTopLevelVis.getSelectedIndex();
  676. } else if (actionSource == cmbMemberVis) {
  677. memberVisIndex = cmbMemberVis.getSelectedIndex();
  678. }
  679. // Display Style Options
  680. else if (actionSource == cmbStyle) {
  681. styleIndex = cmbStyle.getSelectedIndex();
  682. refreshDisplayOptions(styleIndex);
  683. } else if (actionSource == cbxShowArguments) {
  684. if(cbxShowArguments.getModel().isSelected()) {
  685. cbxShowArgumentNames.getModel().setEnabled(true);
  686. } else {
  687. cbxShowArgumentNames.getModel().setSelected(false);
  688. cbxShowArgumentNames.getModel().setEnabled(false);
  689. }
  690. }
  691. }
  692. }
  693. /**
  694. * Action to encapsulate a call to JBrowseOption.setOptions
  695. **/
  696. private class SetOptionsAction implements ActionListener {
  697. public void actionPerformed(ActionEvent evt) {
  698. JBrowseOptionPane.this.setOptions();
  699. }
  700. }
  701. private class CompoundAction implements ActionListener {
  702. private ActionListener[] listeners;
  703. public CompoundAction(ActionListener listener1,
  704. ActionListener listener2
  705. ) {
  706. this.listeners = new ActionListener[] {
  707. listener1, listener2
  708. };
  709. }
  710. public CompoundAction(ActionListener[] listeners) {
  711. this.listeners = listeners;
  712. }
  713. public void actionPerformed(ActionEvent evt) {
  714. for (int i = 0; i < this.listeners.length; i++) {
  715. if (this.listeners[i] != null) {
  716. this.listeners[i].actionPerformed(evt);
  717. }
  718. }
  719. }
  720. }
  721. /**
  722. * Condition interface
  723. **/
  724. interface Condition {
  725. boolean test();
  726. }
  727. private class BatchUpdateCondition implements Condition {
  728. public boolean test() {
  729. return JBrowseOptionPane.this.batchUpdate;
  730. }
  731. }
  732. private class ConditionalAction implements ActionListener {
  733. private Condition condition;
  734. private ActionListener trueAction;
  735. private ActionListener falseAction;
  736. public ConditionalAction(Condition condition,
  737. ActionListener trueAction,
  738. ActionListener falseAction
  739. ) {
  740. this.condition = condition;
  741. this.trueAction = trueAction;
  742. this.falseAction = falseAction;
  743. }
  744. public void actionPerformed(ActionEvent evt) {
  745. if (this.condition.test()) {
  746. if (this.trueAction != null) {
  747. this.trueAction.actionPerformed(evt);
  748. }
  749. } else {
  750. if (this.falseAction != null) {
  751. this.falseAction.actionPerformed(evt);
  752. }
  753. }
  754. }
  755. }
  756. /**
  757. * This class is used to for panels that require a gridBag layout for
  758. * placement into (for example) an OptionPane.
  759. */
  760. static class OptionPanel extends JPanel
  761. {
  762. /**
  763. * The layout manager.
  764. */
  765. protected GridBagLayout gridBag;
  766. /**
  767. * The number of components already added to the layout manager.
  768. */
  769. protected int y;
  770. /**
  771. * Creates a new option pane.
  772. * @param name The internal name
  773. */
  774. public OptionPanel() {
  775. setLayout(gridBag = new GridBagLayout());
  776. }
  777. /**
  778. * Adds a labeled component to the option pane.
  779. * @param label The label
  780. * @param comp The component
  781. */
  782. protected void addComponent(String label, Component comp) {
  783. GridBagConstraints cons = new GridBagConstraints();
  784. cons.gridy = y++;
  785. cons.gridheight = 1;
  786. cons.gridwidth = 3;
  787. cons.fill = GridBagConstraints.BOTH;
  788. cons.weightx = 1.0f;
  789. cons.gridx = 0;
  790. JLabel l = new JLabel(label,SwingConstants.RIGHT);
  791. gridBag.setConstraints(l,cons);
  792. add(l);
  793. cons.gridx = 3;
  794. cons.gridwidth = 1;
  795. gridBag.setConstraints(comp,cons);
  796. add(comp);
  797. }
  798. /**
  799. * Adds a component to the option pane.
  800. * @param comp The component
  801. */
  802. protected void addComponent(Component comp) {
  803. GridBagConstraints cons = new GridBagConstraints();
  804. cons.gridy = y++;
  805. cons.gridheight = 1;
  806. cons.gridwidth = cons.REMAINDER;
  807. cons.fill = GridBagConstraints.HORIZONTAL;
  808. cons.anchor = GridBagConstraints.WEST;
  809. cons.weightx = 1.0f;
  810. gridBag.setConstraints(comp,cons);
  811. add(comp);
  812. }
  813. }
  814. }