Changeset 2817 in josm for trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java
- Timestamp:
- 2010-01-11T21:06:49+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java
r2745 r2817 23 23 import javax.swing.JScrollPane; 24 24 import javax.swing.JTabbedPane; 25 import javax.swing.SwingUtilities; 25 26 26 27 import org.openstreetmap.josm.Main; 28 import org.openstreetmap.josm.plugins.PluginDownloadTask; 27 29 import org.openstreetmap.josm.plugins.PluginHandler; 30 import org.openstreetmap.josm.plugins.PluginInformation; 28 31 import org.openstreetmap.josm.tools.BugReportExceptionHandler; 29 32 import org.openstreetmap.josm.tools.GBC; … … 47 50 public final JPanel map = createPreferenceTab("map", I18n.tr("Map Settings"), I18n.tr("Settings for the map projection and data interpretation.")); 48 51 public final JPanel audio = createPreferenceTab("audio", I18n.tr("Audio Settings"), I18n.tr("Settings for the audio player and audio markers.")); 52 public final JPanel plugins = createPreferenceTab("plugin", tr("Plugins"), tr("Configure available plugins."), false); 49 53 50 54 public final javax.swing.JTabbedPane displaycontent = new javax.swing.JTabbedPane(); … … 95 99 } 96 100 101 protected PluginPreference getPluginPreference() { 102 for (PreferenceSetting setting: settings) { 103 if (setting instanceof PluginPreference) 104 return (PluginPreference) setting; 105 } 106 return null; 107 } 108 97 109 public void savePreferences() { 98 boolean requiresRestart = false; 99 for (PreferenceSetting setting : settings) 100 { 101 if(setting.ok()) { 102 requiresRestart = true; 110 111 // create a task for downloading plugins if the user has activated, yet not downloaded, 112 // new plugins 113 // 114 final PluginPreference preference = getPluginPreference(); 115 final List<PluginInformation> toDownload = preference.getPluginsScheduledForUpdateOrDownload(); 116 final PluginDownloadTask task; 117 if (! toDownload.isEmpty()) { 118 task = new PluginDownloadTask(this, toDownload, tr("Download plugins")); 119 } else { 120 task = null; 121 } 122 123 // this is the task which will run *after* the plugins are downloaded 124 // 125 final Runnable continuation = new Runnable() { 126 public void run() { 127 boolean requiresRestart = false; 128 if (task != null && !task.isCanceled()) { 129 if (!task.getDownloadedPlugins().isEmpty()) { 130 requiresRestart = true; 131 } 132 } 133 134 for (PreferenceSetting setting : settings) { 135 if (setting.ok()) { 136 requiresRestart = true; 137 } 138 } 139 140 // build the messages. We only display one message, including the status 141 // information from the plugin download task and - if necessary - a hint 142 // to restart JOSM 143 // 144 StringBuffer sb = new StringBuffer(); 145 sb.append("<html>"); 146 if (task != null && !task.isCanceled()) { 147 sb.append(PluginPreference.buildDownloadSummary(task)); 148 } 149 if (requiresRestart) { 150 sb.append(tr("You have to restart JOSM for some settings to take effect.")); 151 } 152 sb.append("</html>"); 153 154 // display the message, if necessary 155 // 156 if ((task != null && !task.isCanceled()) || requiresRestart) { 157 JOptionPane.showMessageDialog( 158 Main.parent, 159 sb.toString(), 160 tr("Warning"), 161 JOptionPane.WARNING_MESSAGE 162 ); 163 } 164 Main.parent.repaint(); 103 165 } 104 } 105 if (requiresRestart) { 106 JOptionPane.showMessageDialog( 107 Main.parent, 108 tr("You have to restart JOSM for some settings to take effect."), 109 tr("Warning"), 110 JOptionPane.WARNING_MESSAGE 166 }; 167 168 if (task != null) { 169 // if we have to launch a plugin download task we do it asynchronously, followed 170 // by the remaining "save preferences" activites run on the Swing EDT. 171 // 172 Main.worker.submit(task); 173 Main.worker.submit( 174 new Runnable() { 175 public void run() { 176 SwingUtilities.invokeLater(continuation); 177 } 178 } 111 179 ); 112 } 113 Main.parent.repaint(); 180 } else { 181 // no need for asynchronous activities. Simply run the remaining "save preference" 182 // activities on this thread (we are already on the Swing EDT 183 // 184 continuation.run(); 185 } 114 186 } 115 187
Note:
See TracChangeset
for help on using the changeset viewer.