PageRenderTime 51ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/Sessions/sessions/SessionsOptionPane.java

#
Java | 206 lines | 147 code | 34 blank | 25 comment | 8 complexity | 7ddb24cbbfd148fa0e871bb6a3baec1b 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. * SessionsOptionPane.java - plugin options pane for Sessions plugin
  3. * Copyright (c) 2000,2001 Dirk Moebius
  4. *
  5. * :tabSize=4:indentSize=4:noTabs=false:maxLineLen=0:
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. package sessions;
  22. import java.awt.event.ActionEvent;
  23. import java.awt.event.ActionListener;
  24. import javax.swing.Box;
  25. import javax.swing.BoxLayout;
  26. import javax.swing.ButtonGroup;
  27. import javax.swing.JCheckBox;
  28. import javax.swing.JLabel;
  29. import javax.swing.JPanel;
  30. import javax.swing.JRadioButton;
  31. import javax.swing.JSpinner;
  32. import javax.swing.SpinnerNumberModel;
  33. import org.gjt.sp.jedit.jEdit;
  34. import org.gjt.sp.jedit.AbstractOptionPane;
  35. /**
  36. * This is the option pane that jEdit displays for Session plugin's options.
  37. */
  38. public class SessionsOptionPane extends AbstractOptionPane implements ActionListener
  39. {
  40. private JCheckBox bAutoSave;
  41. private JCheckBox bAskSave;
  42. private JCheckBox bCloseAll;
  43. private JCheckBox bShowToolBar;
  44. private JRadioButton bShowBelowToolBar;
  45. private JRadioButton bShowJEditToolBar;
  46. private JRadioButton bShowInsideBufferList;
  47. private JCheckBox bShowTitle;
  48. private JCheckBox bChangeFSBDirectory;
  49. private JCheckBox bShowSessionNameInTitleBar;
  50. private JCheckBox bShowSessionPrefixInTitleBar;
  51. private SpinnerNumberModel maxSessionListSizeModel;
  52. private JSpinner maxSessionListSize;
  53. public SessionsOptionPane()
  54. {
  55. super("sessions");
  56. }
  57. public void _init()
  58. {
  59. bAutoSave = new JCheckBox(
  60. jEdit.getProperty("options.sessions.switcher.autoSave"),
  61. jEdit.getBooleanProperty("sessions.switcher.autoSave", true)
  62. );
  63. bAutoSave.addActionListener(this);
  64. boolean askSave = jEdit.getBooleanProperty("sessions.switcher.askSave", false);
  65. bAskSave = new JCheckBox(jEdit.getProperty("options.sessions.switcher.askSave"), askSave);
  66. bAskSave.setEnabled(bAutoSave.isSelected());
  67. bCloseAll = new JCheckBox(
  68. jEdit.getProperty("options.sessions.switcher.closeAll"),
  69. jEdit.getBooleanProperty("sessions.switcher.closeAll", true)
  70. );
  71. bShowToolBar = new JCheckBox(
  72. jEdit.getProperty("options.sessions.switcher.showToolBar"),
  73. jEdit.getBooleanProperty("sessions.switcher.showToolBar", false)
  74. );
  75. bShowToolBar.addActionListener(this);
  76. boolean showJEditToolBar = jEdit.getBooleanProperty("sessions.switcher.showJEditToolBar", false);
  77. boolean showInsideBufferList = jEdit.getBooleanProperty("sessions.switcher.showInsideBufferList", false);
  78. boolean showBelowToolBar = !(showJEditToolBar || showInsideBufferList);
  79. bShowJEditToolBar = new JRadioButton(jEdit.getProperty("options.sessions.switcher.showJEditToolBar"), showJEditToolBar);
  80. bShowJEditToolBar.setEnabled(bShowToolBar.isSelected());
  81. bShowInsideBufferList = new JRadioButton(jEdit.getProperty("options.sessions.switcher.showInsideBufferList"), showInsideBufferList);
  82. bShowInsideBufferList.setEnabled(bShowToolBar.isSelected() && isBufferListAvailable());
  83. bShowBelowToolBar = new JRadioButton(jEdit.getProperty("options.sessions.switcher.showBelowToolBar"), showBelowToolBar);
  84. bShowBelowToolBar.setEnabled(bShowToolBar.isSelected());
  85. ButtonGroup group = new ButtonGroup();
  86. group.add(bShowJEditToolBar);
  87. group.add(bShowInsideBufferList);
  88. group.add(bShowBelowToolBar);
  89. bShowTitle = new JCheckBox(
  90. jEdit.getProperty("options.sessions.switcher.showTitle"),
  91. jEdit.getBooleanProperty("sessions.switcher.showTitle", true)
  92. );
  93. bShowTitle.setEnabled(bShowToolBar.isSelected());
  94. bChangeFSBDirectory = new JCheckBox(
  95. jEdit.getProperty("options.sessions.switcher.changeFSBDirectory"),
  96. jEdit.getBooleanProperty("sessions.switcher.changeFSBDirectory", false)
  97. );
  98. bShowSessionNameInTitleBar = new JCheckBox(
  99. jEdit.getProperty("options.sessions.switcher.showSessionNameInTitleBar"),
  100. jEdit.getBooleanProperty("sessions.switcher.showSessionNameInTitleBar", true)
  101. );
  102. bShowSessionNameInTitleBar.addActionListener(this);
  103. bShowSessionPrefixInTitleBar = new JCheckBox(
  104. jEdit.getProperty("options.sessions.switcher.showSessionPrefixInTitleBar"),
  105. jEdit.getBooleanProperty("sessions.switcher.showSessionPrefixInTitleBar", true)
  106. );
  107. // Max list size for session switcher combo
  108. Box maxSessListSizePanel = new Box(BoxLayout.X_AXIS);
  109. maxSessListSizePanel.add(new JLabel(
  110. jEdit.getProperty("options.sessions.switcher.maxListSize.label"))
  111. );
  112. Integer maxListSize =
  113. jEdit.getIntegerProperty("options.sessions.switcher.maxListSize", 8);
  114. maxSessionListSizeModel = new SpinnerNumberModel(
  115. maxListSize,
  116. new Integer(5),
  117. new Integer(50),
  118. new Integer(1)
  119. );
  120. maxSessionListSize = new JSpinner(maxSessionListSizeModel);
  121. maxSessionListSize.setMaximumSize(maxSessionListSize.getPreferredSize());
  122. maxSessListSizePanel.add(maxSessionListSize);
  123. maxSessListSizePanel.add(maxSessListSizePanel.createHorizontalGlue());
  124. addComponent(bAutoSave);
  125. addComponent(" ", bAskSave);
  126. addComponent(bCloseAll);
  127. addComponent(bShowToolBar);
  128. addComponent(" ", bShowBelowToolBar);
  129. addComponent(" ", bShowJEditToolBar);
  130. addComponent(" ", bShowInsideBufferList);
  131. addComponent(" ", bShowTitle);
  132. addComponent(" ", maxSessListSizePanel);
  133. addComponent(bChangeFSBDirectory);
  134. addComponent(bShowSessionNameInTitleBar);
  135. addComponent(" ", bShowSessionPrefixInTitleBar);
  136. }
  137. public void _save()
  138. {
  139. jEdit.setBooleanProperty("sessions.switcher.autoSave", bAutoSave.isSelected());
  140. jEdit.setBooleanProperty("sessions.switcher.askSave", bAskSave.isSelected());
  141. jEdit.setBooleanProperty("sessions.switcher.closeAll", bCloseAll.isSelected());
  142. jEdit.setBooleanProperty("sessions.switcher.showToolBar", bShowToolBar.isSelected());
  143. jEdit.setBooleanProperty("sessions.switcher.showJEditToolBar", bShowJEditToolBar.isSelected());
  144. jEdit.setBooleanProperty("sessions.switcher.showInsideBufferList", bShowInsideBufferList.isSelected());
  145. jEdit.setBooleanProperty("sessions.switcher.showTitle", bShowTitle.isSelected());
  146. jEdit.setBooleanProperty("sessions.switcher.changeFSBDirectory", bChangeFSBDirectory.isSelected());
  147. jEdit.setBooleanProperty("sessions.switcher.showSessionNameInTitleBar", bShowSessionNameInTitleBar.isSelected());
  148. jEdit.setBooleanProperty("sessions.switcher.showSessionPrefixInTitleBar", bShowSessionPrefixInTitleBar.isSelected());
  149. jEdit.setIntegerProperty("options.sessions.switcher.maxListSize", (Integer)maxSessionListSizeModel.getNumber());
  150. }
  151. public void actionPerformed(ActionEvent e)
  152. {
  153. if (e.getSource() == bShowToolBar)
  154. {
  155. bShowBelowToolBar.setEnabled(bShowToolBar.isSelected());
  156. bShowJEditToolBar.setEnabled(bShowToolBar.isSelected());
  157. bShowInsideBufferList.setEnabled(bShowToolBar.isSelected() && isBufferListAvailable());
  158. bShowTitle.setEnabled(bShowToolBar.isSelected());
  159. bShowSessionPrefixInTitleBar.setEnabled(bShowSessionNameInTitleBar.isSelected());
  160. }
  161. else if (e.getSource() == bAutoSave)
  162. {
  163. bAskSave.setEnabled(bAutoSave.isSelected());
  164. bAskSave.setSelected(false);
  165. }
  166. }
  167. private boolean isBufferListAvailable()
  168. {
  169. // FIXME: is it sufficient to check only first view?!?
  170. return SessionsPlugin.isBufferListAvailable(jEdit.getFirstView());
  171. }
  172. }