PageRenderTime 146ms CodeModel.GetById 24ms RepoModel.GetById 7ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/org/gjt/sp/jedit/options/PluginManagerOptionPane.java

#
Java | 267 lines | 189 code | 40 blank | 38 comment | 19 complexity | 136e8ba00a6802a65d6592924a671b7e 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. * PluginManagerOptionPane.java - Plugin options panel
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2003 Kris Kopicki
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit.options;
  23. import javax.swing.*;
  24. import javax.swing.border.*;
  25. import java.awt.*;
  26. import java.awt.event.*;
  27. import java.util.*;
  28. import org.gjt.sp.jedit.*;
  29. import org.gjt.sp.jedit.gui.*;
  30. import org.gjt.sp.jedit.io.VFSManager;
  31. import org.gjt.sp.jedit.pluginmgr.*;
  32. import org.gjt.sp.util.*;
  33. public class PluginManagerOptionPane extends AbstractOptionPane
  34. {
  35. //{{{ Constructor
  36. public PluginManagerOptionPane()
  37. {
  38. super("plugin-manager");
  39. } //}}}
  40. //{{{ _init() method
  41. protected void _init()
  42. {
  43. setLayout(new BorderLayout());
  44. locationLabel = new JLabel(jEdit.getProperty(
  45. "options.plugin-manager.location"));
  46. mirrorLabel = new JLabel(jEdit.getProperty(
  47. "options.plugin-manager.mirror"));
  48. if(jEdit.getSettingsDirectory() != null)
  49. {
  50. settingsDir = new JRadioButton(jEdit.getProperty(
  51. "options.plugin-manager.settings-dir"));
  52. settingsDir.setToolTipText(MiscUtilities.constructPath(
  53. jEdit.getSettingsDirectory(),"jars"));
  54. }
  55. appDir = new JRadioButton(jEdit.getProperty(
  56. "options.plugin-manager.app-dir"));
  57. appDir.setToolTipText(MiscUtilities.constructPath(
  58. jEdit.getJEditHome(),"jars"));
  59. miraList = new JList(miraModel = new MirrorModel());
  60. miraList.setSelectionModel(new SingleSelectionModel());
  61. /* Download mirror */
  62. add(BorderLayout.NORTH,mirrorLabel);
  63. add(BorderLayout.CENTER,new JScrollPane(miraList));
  64. JPanel buttonPanel = new JPanel();
  65. buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.Y_AXIS));
  66. buttonPanel.add(Box.createVerticalStrut(6));
  67. /* Update mirror list */
  68. JButton updateMirrors = new JButton(jEdit.getProperty(
  69. "options.plugin-manager.updateMirrors"));
  70. updateMirrors.addActionListener(new ActionHandler());
  71. buttonPanel.add(updateMirrors);
  72. buttonPanel.add(Box.createVerticalStrut(6));
  73. /* Download source */
  74. downloadSource = new JCheckBox(jEdit.getProperty(
  75. "options.plugin-manager.downloadSource"));
  76. downloadSource.setSelected(jEdit.getBooleanProperty("plugin-manager.downloadSource"));
  77. buttonPanel.add(downloadSource);
  78. buttonPanel.add(Box.createVerticalStrut(6));
  79. /* Delete downloaded files */
  80. deleteDownloads = new JCheckBox(jEdit.getProperty(
  81. "options.plugin-manager.deleteDownloads"));
  82. deleteDownloads.setSelected(jEdit.getBooleanProperty("plugin-manager.deleteDownloads"));
  83. buttonPanel.add(deleteDownloads);
  84. buttonPanel.add(Box.createVerticalStrut(6));
  85. /* Install location */
  86. locGrp = new ButtonGroup();
  87. if(jEdit.getSettingsDirectory() != null)
  88. locGrp.add(settingsDir);
  89. locGrp.add(appDir);
  90. JPanel locPanel = new JPanel();
  91. locPanel.setBorder(new EmptyBorder(3,12,0,0));
  92. locPanel.setLayout(new BoxLayout(locPanel,BoxLayout.Y_AXIS));
  93. if(jEdit.getSettingsDirectory() != null)
  94. {
  95. locPanel.add(settingsDir);
  96. locPanel.add(Box.createVerticalStrut(3));
  97. }
  98. locPanel.add(appDir);
  99. buttonPanel.add(locationLabel);
  100. buttonPanel.add(locPanel);
  101. buttonPanel.add(Box.createGlue());
  102. add(BorderLayout.SOUTH,buttonPanel);
  103. if (jEdit.getBooleanProperty("plugin-manager.installUser")
  104. && jEdit.getSettingsDirectory() != null)
  105. settingsDir.setSelected(true);
  106. else
  107. appDir.setSelected(true);
  108. } //}}}
  109. //{{{ _save() method
  110. protected void _save()
  111. {
  112. jEdit.setBooleanProperty("plugin-manager.installUser",
  113. settingsDir != null && settingsDir.isSelected());
  114. jEdit.setBooleanProperty("plugin-manager.downloadSource",downloadSource.isSelected());
  115. jEdit.setBooleanProperty("plugin-manager.deleteDownloads",deleteDownloads.isSelected());
  116. if(miraList.getSelectedIndex() != -1)
  117. {
  118. String currentMirror = miraModel.getID(miraList.getSelectedIndex());
  119. String previousMirror = jEdit.getProperty("plugin-manager.mirror.id");
  120. if (!previousMirror.equals(currentMirror))
  121. {
  122. jEdit.setProperty("plugin-manager.mirror.id",currentMirror);
  123. // Insert code to update the plugin managers list here later
  124. }
  125. }
  126. } //}}}
  127. //{{{ Private members
  128. //{{{ Instance variables
  129. private JLabel locationLabel;
  130. private JLabel mirrorLabel;
  131. private ButtonGroup locGrp;
  132. private JRadioButton settingsDir;
  133. private JRadioButton appDir;
  134. private JCheckBox downloadSource;
  135. private JCheckBox deleteDownloads;
  136. private MirrorModel miraModel;
  137. private JList miraList;
  138. //}}}
  139. //}}}
  140. //{{{ MirrorModel class
  141. class MirrorModel extends AbstractListModel
  142. {
  143. private ArrayList mirrors;
  144. public MirrorModel()
  145. {
  146. mirrors = new ArrayList();
  147. }
  148. public String getID(int index)
  149. {
  150. return ((MirrorList.Mirror)mirrors.get(index)).id;
  151. }
  152. public int getSize()
  153. {
  154. return mirrors.size();
  155. }
  156. public Object getElementAt(int index)
  157. {
  158. MirrorList.Mirror mirror = (MirrorList.Mirror)mirrors.get(index);
  159. if(mirror.id.equals(MirrorList.Mirror.NONE))
  160. return jEdit.getProperty("options.plugin-manager.none");
  161. else
  162. return mirror.continent+": "+mirror.description+" ("+mirror.location+")";
  163. }
  164. public void setList(ArrayList mirrors)
  165. {
  166. this.mirrors = mirrors;
  167. fireContentsChanged(this,0,mirrors.size() - 1);
  168. }
  169. } //}}}
  170. //{{{ SingleSelectionModel class
  171. class SingleSelectionModel extends DefaultListSelectionModel
  172. {
  173. public SingleSelectionModel()
  174. {
  175. super();
  176. setSelectionMode(SINGLE_SELECTION);
  177. }
  178. public void removeSelectionInterval(int index0, int index1) {}
  179. } //}}}
  180. //{{{ ActionHandler class
  181. class ActionHandler implements ActionListener
  182. {
  183. public void actionPerformed(ActionEvent evt)
  184. {
  185. VFSManager.runInWorkThread(new DownloadMirrorsThread());
  186. }
  187. } //}}}
  188. //{{{ DownloadMirrorsThread class
  189. class DownloadMirrorsThread extends WorkRequest
  190. {
  191. public void run()
  192. {
  193. setStatus(jEdit.getProperty("options.plugin-manager.workthread"));
  194. setProgressMaximum(1);
  195. setProgressValue(0);
  196. final ArrayList mirrors = new ArrayList();
  197. try
  198. {
  199. mirrors.addAll(new MirrorList().mirrors);
  200. }
  201. catch (Exception ex)
  202. {
  203. Log.log(Log.ERROR,this,ex);
  204. GUIUtilities.error(PluginManagerOptionPane.this,
  205. "ioerror",new String[] { ex.toString() });
  206. }
  207. SwingUtilities.invokeLater(new Runnable()
  208. {
  209. public void run()
  210. {
  211. miraModel.setList(mirrors);
  212. String id = jEdit.getProperty("plugin-manager.mirror.id");
  213. int size = miraModel.getSize();
  214. for (int i=0; i < size; i++)
  215. {
  216. if (size == 1 || miraModel.getID(i).equals(id))
  217. {
  218. miraList.setSelectedIndex(i);
  219. break;
  220. }
  221. }
  222. }
  223. });
  224. setProgressValue(1);
  225. }
  226. } //}}}
  227. }