diff --git a/src/org/omegat/core/threads/PluginDownloadThread.java b/src/org/omegat/core/threads/PluginDownloadThread.java
index 0d33aaa144..b9b7bd4ef3 100644
--- a/src/org/omegat/core/threads/PluginDownloadThread.java
+++ b/src/org/omegat/core/threads/PluginDownloadThread.java
@@ -77,7 +77,7 @@ public void run() {
} else if (!checksum.equals(calculateSha256(temporaryFilePath))) {
Log.log("Checksum error of plugin file.");
} else {
- PluginInstaller.install(temporaryFilePath, true);
+ PluginInstaller.getInstance().install(temporaryFilePath, true);
}
} catch (IOException | NoSuchAlgorithmException e) {
e.printStackTrace();
diff --git a/src/org/omegat/gui/dialogs/ChoosePluginFile.java b/src/org/omegat/gui/dialogs/ChoosePluginFile.java
deleted file mode 100644
index 3cd596af70..0000000000
--- a/src/org/omegat/gui/dialogs/ChoosePluginFile.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**************************************************************************
- OmegaT - Computer Assisted Translation (CAT) tool
- with fuzzy matching, translation memory, keyword search,
- glossaries, and translation leveraging into updated projects.
-
- Copyright (C) 2021 Hiroshi Miura
- Home page: http://www.omegat.org/
- Support center: https://omegat.org/support
-
- This file is part of OmegaT.
-
- OmegaT is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- OmegaT is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
- **************************************************************************/
-
-package org.omegat.gui.dialogs;
-
-import java.io.File;
-import java.util.Locale;
-import javax.swing.JFileChooser;
-import javax.swing.filechooser.FileFilter;
-
-import org.omegat.util.OConsts;
-import org.omegat.util.OStrings;
-import org.omegat.util.Preferences;
-
-
-@SuppressWarnings("serial")
-public class ChoosePluginFile extends JFileChooser {
-
- public ChoosePluginFile () {
- super(Preferences.getPreference(Preferences.CURRENT_FOLDER));
-
- setMultiSelectionEnabled(false);
- setFileHidingEnabled(true);
- setFileSelectionMode(FILES_ONLY);
- setDialogTitle(OStrings.getString("GUI_PLUGIN_OPEN"));
- setAcceptAllFileFilterUsed(false);
- addChoosableFileFilter(new FileFilter() {
- @Override
- public String getDescription() {
- return OStrings.getString("GUI_PLUGIN_OPEN");
- }
-
- @Override
- public boolean accept(File f) {
- return isAcceptable(f);
- }
- });
- }
-
- @Override
- public boolean accept(File f) {
- if (f.isDirectory()) {
- return true;
- }
- return isAcceptable(f);
- }
-
- private boolean isAcceptable(File f) {
- if (!f.isFile()) {
- return false;
- }
- String name = f.getName().toLowerCase(Locale.ENGLISH);
- return name.endsWith(OConsts.JAR_EXTENSION) || name.endsWith(OConsts.ZIP_EXTENSION);
- }
-}
diff --git a/src/org/omegat/gui/preferences/view/PluginInfoTableModel.java b/src/org/omegat/gui/preferences/view/PluginInfoTableModel.java
index 135755e9af..9f406da7b3 100644
--- a/src/org/omegat/gui/preferences/view/PluginInfoTableModel.java
+++ b/src/org/omegat/gui/preferences/view/PluginInfoTableModel.java
@@ -25,7 +25,6 @@
package org.omegat.gui.preferences.view;
-import java.util.ArrayList;
import java.util.List;
import javax.swing.table.DefaultTableModel;
@@ -47,7 +46,7 @@ public class PluginInfoTableModel extends DefaultTableModel {
private final List listPlugins;
public PluginInfoTableModel() {
- listPlugins = new ArrayList<>(PluginInstaller.getPluginInformations().values());
+ listPlugins = PluginInstaller.getInstance().getPluginList();
}
@Override
diff --git a/src/org/omegat/gui/preferences/view/PluginsPreferencesController.java b/src/org/omegat/gui/preferences/view/PluginsPreferencesController.java
index 1338a3844c..3be6f27653 100644
--- a/src/org/omegat/gui/preferences/view/PluginsPreferencesController.java
+++ b/src/org/omegat/gui/preferences/view/PluginsPreferencesController.java
@@ -4,6 +4,7 @@
glossaries, and translation leveraging into updated projects.
Copyright (C) 2016 Aaron Madlon-Kay
+ 2022 Hiroshi Miura
Home page: http://www.omegat.org/
Support center: https://omegat.org/support
@@ -25,26 +26,21 @@
package org.omegat.gui.preferences.view;
-import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
-
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URL;
import javax.swing.JComponent;
-import javax.swing.JFileChooser;
+import javax.swing.ScrollPaneConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.table.TableRowSorter;
-import org.omegat.core.Core;
import org.omegat.core.data.PluginInformation;
import org.omegat.core.threads.PluginDownloadThread;
-import org.omegat.gui.dialogs.ChoosePluginFile;
import org.omegat.gui.preferences.BasePreferencesController;
import org.omegat.util.Log;
import org.omegat.util.OStrings;
-import org.omegat.util.PluginInstaller;
import org.omegat.util.gui.TableColumnSizer;
/**
@@ -52,7 +48,6 @@
*/
public class PluginsPreferencesController extends BasePreferencesController {
- public static final String PLUGINS_WIKI_URL = "https://sourceforge.net/p/omegat/wiki/Plugins/";
private PluginsPreferencesPanel panel;
private PluginDetailsPane pluginDetailsPane;
private PluginDetailHeader pluginDetailHeader;
@@ -130,8 +125,7 @@ final void selectRowAction(ListSelectionEvent evt) {
}
setRestartRequired(true);
});
- StringBuilder detailTextBuilder = new StringBuilder(formatDetailText(model.getItemAt(rowIndex)));
- pluginDetailsPane.setText(detailTextBuilder.toString());
+ pluginDetailsPane.setText(formatDetailText(model.getItemAt(rowIndex)));
}
}
@@ -149,7 +143,7 @@ private void initGui() {
pluginDetailsPane = new PluginDetailsPane();
panel.panelPluginDetails.add(pluginDetailHeader);
panel.panelPluginDetails.add(pluginDetailsPane);
- panel.scrollTable.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS);
+ panel.scrollTable.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
panel.scrollTable.getViewport().setViewSize(new Dimension(250, 350));
PluginInfoTableModel model = (PluginInfoTableModel) panel.tablePluginsInfo.getModel();
@@ -158,16 +152,6 @@ private void initGui() {
panel.tablePluginsInfo.getSelectionModel().addListSelectionListener(this::selectRowAction);
panel.tablePluginsInfo.setPreferredScrollableViewportSize(panel.tablePluginsInfo.getPreferredSize());
TableColumnSizer.autoSize(panel.tablePluginsInfo, 0, true);
-
- panel.installPluginsButton.setText(OStrings.getString("PREFS_PLUGINS_INSTALL_FROM_DISK"));
- panel.installPluginsButton.addActionListener(e -> {
- ChoosePluginFile choosePluginFile = new ChoosePluginFile();
- if (JFileChooser.APPROVE_OPTION == choosePluginFile.showOpenDialog(Core.getMainWindow().getApplicationFrame())) {
- if (PluginInstaller.install(choosePluginFile.getSelectedFile(), false)) {
- setRestartRequired(true);
- }
- }
- });
}
@Override
diff --git a/src/org/omegat/gui/preferences/view/PluginsPreferencesPanel.form b/src/org/omegat/gui/preferences/view/PluginsPreferencesPanel.form
index b5426a3e90..2c381a9f65 100644
--- a/src/org/omegat/gui/preferences/view/PluginsPreferencesPanel.form
+++ b/src/org/omegat/gui/preferences/view/PluginsPreferencesPanel.form
@@ -27,42 +27,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/org/omegat/gui/preferences/view/PluginsPreferencesPanel.java b/src/org/omegat/gui/preferences/view/PluginsPreferencesPanel.java
index 3b387168aa..d94da1e3d3 100644
--- a/src/org/omegat/gui/preferences/view/PluginsPreferencesPanel.java
+++ b/src/org/omegat/gui/preferences/view/PluginsPreferencesPanel.java
@@ -26,7 +26,6 @@
package org.omegat.gui.preferences.view;
import javax.swing.JPanel;
-import org.omegat.util.OStrings;
/**
* @author Aaron Madlon-Kay
@@ -48,9 +47,6 @@ public PluginsPreferencesPanel() {
// //GEN-BEGIN:initComponents
private void initComponents() {
- panelInfo = new javax.swing.JPanel();
- filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 5), new java.awt.Dimension(0, 5), new java.awt.Dimension(32767, 5));
- installPluginsButton = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
panelPluginsInfo = new javax.swing.JPanel();
scrollTable = new javax.swing.JScrollPane();
@@ -61,19 +57,6 @@ private void initComponents() {
setMinimumSize(new java.awt.Dimension(250, 200));
setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS));
- panelInfo.add(filler1);
-
- org.openide.awt.Mnemonics.setLocalizedText(installPluginsButton, OStrings.getString("PREFS_PLUGINS_INSTALL_FROM_DISK")); // NOI18N
- installPluginsButton.setAlignmentY(0.0F);
- installPluginsButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- installPluginsButtonActionPerformed(evt);
- }
- });
- panelInfo.add(installPluginsButton);
-
- add(panelInfo);
-
jPanel1.setMaximumSize(new java.awt.Dimension(65534, 600));
jPanel1.setMinimumSize(new java.awt.Dimension(200, 23));
jPanel1.setLayout(new java.awt.GridLayout(1, 2));
@@ -96,15 +79,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
add(jPanel1);
}// //GEN-END:initComponents
- private void installPluginsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_installPluginsButtonActionPerformed
- // TODO add your handling code here:
- }//GEN-LAST:event_installPluginsButtonActionPerformed
-
// Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.Box.Filler filler1;
- javax.swing.JButton installPluginsButton;
private javax.swing.JPanel jPanel1;
- private javax.swing.JPanel panelInfo;
javax.swing.JPanel panelPluginDetails;
private javax.swing.JPanel panelPluginsInfo;
javax.swing.JScrollPane scrollTable;
diff --git a/src/org/omegat/util/PluginInstaller.java b/src/org/omegat/util/PluginInstaller.java
index 0f959cec7c..a87917605e 100644
--- a/src/org/omegat/util/PluginInstaller.java
+++ b/src/org/omegat/util/PluginInstaller.java
@@ -3,7 +3,7 @@
with fuzzy matching, translation memory, keyword search,
glossaries, and translation leveraging into updated projects.
- Copyright (C) 2021 Hiroshi Miura
+ Copyright (C) 2021,2022 Hiroshi Miura
Home page: http://www.omegat.org/
Support center: https://omegat.org/support
@@ -59,18 +59,29 @@
/**
- * Plugin installer utility class.
+ * Plugin installer singleton class.
*
* @author Hiroshi Miura
*/
public final class PluginInstaller {
- private static final String LIST_URL = "https://github.com/omegat-org/omegat-plugins/releases/download/continuous-release/plugins.MF";
+ private static final String LIST_URL =
+ "https://github.com/omegat-org/omegat-plugins/releases/download/continuous-release/plugins.MF";
+
+ private List pluginInformationList;
+
+ private static class SingletonHelper {
+ private static final PluginInstaller INSTANCE = new PluginInstaller();
+ }
+
+ public static PluginInstaller getInstance() {
+ return SingletonHelper.INSTANCE;
+ }
private PluginInstaller() {
}
- public static boolean install(final File pluginFile, final boolean background) {
+ public boolean install(final File pluginFile, final boolean background) {
Path pluginJarFile;
PluginInformation info;
try {
@@ -127,7 +138,7 @@ public static boolean install(final File pluginFile, final boolean background) {
return false;
}
- private static boolean doInstall(PluginInformation currentInfo, File file) {
+ private boolean doInstall(PluginInformation currentInfo, File file) {
try {
if (currentInfo != null) {
FileUtils.forceDeleteOnExit(currentInfo.getJarFile());
@@ -147,15 +158,18 @@ private static boolean doInstall(PluginInformation currentInfo, File file) {
* It can has plugins that has already installed.
* @return Map of PluginInformation
*/
- public static Map getPluginInformations() {
- Map plugins = getInstalledPlugins();
+ public List getPluginList() {
+ if (pluginInformationList != null) {
+ return pluginInformationList;
+ }
+ Map listPlugins = getInstalledPlugins();
getPluginsList().stream()
.sorted(Comparator.comparing(PluginInformation::getClassName))
.map(info -> {
String key = info.getClassName();
PluginInformation.Status status;
String version = info.getVersion();
- PluginInformation installed = plugins.get(key);
+ PluginInformation installed = listPlugins.get(key);
if (installed == null) {
status = PluginInformation.Status.UNINSTALLED;
} else if (!installed.getVersion().equals(info.getVersion())) {
@@ -165,8 +179,9 @@ public static Map getPluginInformations() {
}
return PluginInformation.Builder.copy(info, status);
})
- .forEach(info -> plugins.put(info.getClassName(), info));
- return plugins;
+ .forEach(info -> listPlugins.put(info.getClassName(), info));
+ pluginInformationList = new ArrayList<>(listPlugins.values());
+ return pluginInformationList;
}
/**
@@ -177,7 +192,7 @@ public static Map getPluginInformations() {
* @return installed plugin jar file path.
* @throws IOException when source file is corrupted.
*/
- private static Path unpackPlugin(File sourceFile, Path targetPath) throws IOException {
+ private Path unpackPlugin(File sourceFile, Path targetPath) throws IOException {
Path target;
if (sourceFile.getName().endsWith(".jar")) {
target = targetPath.resolve(sourceFile.getName());
@@ -203,7 +218,7 @@ private static Path unpackPlugin(File sourceFile, Path targetPath) throws IOExce
* @param pluginJarFile plugin jar file
* @return PluginInformation
*/
- private static Set parsePluginJarFileManifest(File pluginJarFile) {
+ private Set parsePluginJarFileManifest(File pluginJarFile) {
Set pluginInfo = new HashSet<>();
try {
URL[] urls = new URL[1];
@@ -237,7 +252,7 @@ private static Set parsePluginJarFileManifest(File pluginJarF
* Return installed plugins.
* @return Set of PluginInformation
*/
- private static Map getInstalledPlugins() {
+ private Map getInstalledPlugins() {
Map installedPlugins = new TreeMap<>();
PluginUtils.getPluginInformations().stream()
.sorted(Comparator.comparing(PluginInformation::getClassName))
@@ -250,7 +265,7 @@ private static Map getInstalledPlugins() {
* Download plugin list from github repository.
* @return set of PluginInformation
*/
- private static List getPluginsList() {
+ private List getPluginsList() {
List pluginInfo = new ArrayList<>();
String raw_value;
try {