/plugins/DirtyGutter/tags/release-0-2/src/lcm/LCMOptions.java

#
Java | 134 lines | 105 code | 10 blank | 19 comment | 9 complexity | adeda55a879370a338ba7fa90335450d MD5 | raw file

✨ Summary
  1. /*
  2. * LCMOptions - The plugin's option pane.
  3. *
  4. * Copyright (C) 2009 Shlomy Reinstein
  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 lcm;
  21. import java.awt.Component;
  22. import java.awt.Insets;
  23. import java.awt.event.ActionEvent;
  24. import java.awt.event.ActionListener;
  25. import javax.swing.JComboBox;
  26. import javax.swing.JPanel;
  27. import javax.swing.border.TitledBorder;
  28. import org.gjt.sp.jedit.AbstractOptionPane;
  29. import org.gjt.sp.jedit.ServiceManager;
  30. import org.gjt.sp.jedit.jEdit;
  31. @SuppressWarnings("serial")
  32. public class LCMOptions extends AbstractOptionPane
  33. {
  34. static public final String PROP_PREFIX = "options.LCMPlugin.";
  35. public static final String PROVIDER_SERVICE_PROP = PROP_PREFIX + "provider";
  36. private JComboBox provider;
  37. private DirtyLineProviderOptions [] providerOptions;
  38. private JPanel [] providerPanels;
  39. private JPanel currentPanel;
  40. public LCMOptions()
  41. {
  42. super("DirtyGutter");
  43. }
  44. @Override
  45. protected void _init()
  46. {
  47. String [] services = ServiceManager.getServiceNames(
  48. DirtyLineProvider.class.getCanonicalName());
  49. provider = new JComboBox(services);
  50. String selected = getProviderServiceName();
  51. for (int i = 0; i < services.length; i++)
  52. {
  53. if (services[i].equals(selected))
  54. {
  55. provider.setSelectedIndex(i);
  56. break;
  57. }
  58. }
  59. addComponent(jEdit.getProperty("messages.LCMPlugin.providers"),
  60. provider);
  61. providerOptions = new DirtyLineProviderOptions[services.length];
  62. providerPanels = new JPanel[services.length];
  63. providerChanged();
  64. provider.addActionListener(new ActionListener()
  65. {
  66. public void actionPerformed(ActionEvent e)
  67. {
  68. providerChanged();
  69. }
  70. });
  71. }
  72. private void providerChanged()
  73. {
  74. if (currentPanel != null)
  75. currentPanel.setVisible(false);
  76. int providerIndex = provider.getSelectedIndex();
  77. DirtyLineProviderOptions opts = providerOptions[providerIndex];
  78. if (opts == null)
  79. {
  80. String selectedName = provider.getSelectedItem().toString();
  81. DirtyLineProvider selProvider= (DirtyLineProvider)
  82. ServiceManager.getService(
  83. DirtyLineProvider.class.getCanonicalName(), selectedName);
  84. opts = providerOptions[providerIndex] = selProvider.getOptions();
  85. final Insets insets = new Insets(20,10,10,10);
  86. JPanel p = providerPanels[providerIndex] = new JPanel();
  87. TitledBorder border = new TitledBorder(jEdit.getProperty(
  88. "messages.LCMPlugin.providerSpecificOptions",
  89. new Object[] { selectedName }))
  90. {
  91. @Override
  92. public Insets getBorderInsets(Component c)
  93. {
  94. return insets;
  95. }
  96. };
  97. p.setBorder(border);
  98. opts.initOptions(p);
  99. addComponent(p);
  100. }
  101. currentPanel = providerPanels[providerIndex];
  102. currentPanel.setVisible(true);
  103. }
  104. @Override
  105. protected void _save()
  106. {
  107. jEdit.setProperty(PROVIDER_SERVICE_PROP,
  108. provider.getSelectedItem().toString());
  109. for (int i = 0; i < providerOptions.length; i++)
  110. {
  111. DirtyLineProviderOptions opts = providerOptions[i];
  112. if (opts != null)
  113. opts.saveOptions();
  114. }
  115. }
  116. public static String getProviderServiceName()
  117. {
  118. return jEdit.getProperty(PROVIDER_SERVICE_PROP);
  119. }
  120. public static void setProviderServiceName(String providerName)
  121. {
  122. jEdit.setProperty(PROVIDER_SERVICE_PROP, providerName);
  123. }
  124. }