From 52fc1b1521fbc994d756f658e23ab413d3ccf49f Mon Sep 17 00:00:00 2001 From: skylarmt Date: Fri, 3 Apr 2015 00:42:30 -0600 Subject: [PATCH] Plugin bug hotfix --- .../apocalypselabs/symat/InstallPlugin.java | 13 +++++-- src/net/apocalypselabs/symat/Main.java | 34 ++++++++++++------- .../apocalypselabs/symat/PackagePlugin.java | 4 --- .../symat/plugin/LoadPlugin.java | 28 ++++++++++----- 4 files changed, 52 insertions(+), 27 deletions(-) diff --git a/src/net/apocalypselabs/symat/InstallPlugin.java b/src/net/apocalypselabs/symat/InstallPlugin.java index cbe883e..ee89257 100644 --- a/src/net/apocalypselabs/symat/InstallPlugin.java +++ b/src/net/apocalypselabs/symat/InstallPlugin.java @@ -250,10 +250,11 @@ public class InstallPlugin extends javax.swing.JInternalFrame { return; } try { + String fsep = System.getProperty("file.separator"); Files.copy(f, new File( System.getProperty("user.home") - + "\\.symat\\plugins\\" + + fsep + ".symat" + fsep + "plugins" + fsep + f.getName())); Main.maingui.reloadRibbon(); JOptionPane.showInternalMessageDialog(this, @@ -263,7 +264,15 @@ public class InstallPlugin extends javax.swing.JInternalFrame { } catch (IOException ex) { Debug.stacktrace(ex); JOptionPane.showInternalMessageDialog(this, - "Error: could not copy plugin file: " + ex.getMessage(), + "Error: could not install plugin file: " + ex.getMessage(), + "Error", + JOptionPane.ERROR_MESSAGE); + } catch (IllegalArgumentException ex) { + Debug.stacktrace(ex); + JOptionPane.showInternalMessageDialog(this, + "Error: could not install plugin file." + + "\nIs a plugin with the same name already " + + "installed?\n(" + ex.getMessage() + ")", "Error", JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { diff --git a/src/net/apocalypselabs/symat/Main.java b/src/net/apocalypselabs/symat/Main.java index 2c9313f..3c73c4e 100644 --- a/src/net/apocalypselabs/symat/Main.java +++ b/src/net/apocalypselabs/symat/Main.java @@ -115,7 +115,7 @@ public class Main extends JRibbonFrame { /** * Version number, for updates and //needs in scripts */ - public static final double APP_CODE = 19; + public static final double APP_CODE = 20; /** * Base URL for building API calls */ @@ -289,7 +289,8 @@ public class Main extends JRibbonFrame { pluginband.setResizePolicies((List) Arrays.asList( new CoreRibbonResizePolicies.Mirror(pluginband.getControlPanel()))); pluginband.addCommandButton(installpluginbtn, RibbonElementPriority.TOP); - File dir = new File(System.getProperty("user.home") + "\\.symat\\plugins"); + String fsep = System.getProperty("file.separator"); + File dir = new File(System.getProperty("user.home") + fsep + ".symat" + fsep + "plugins"); dir.mkdirs(); File[] files = dir.listFiles(new FilenameFilter() { @Override @@ -304,18 +305,21 @@ public class Main extends JRibbonFrame { galleryVisibleButtonCounts.put(RibbonElementPriority.TOP, 2); List>> appGalleryButtons = new ArrayList<>(); List appGalleryButtonsList = new ArrayList<>(); - for (File pl : files) { - try { - LoadPlugin lp = new LoadPlugin(pl); - appGalleryButtonsList.add(lp.getGalleryBtn()); - } catch (Exception ex) { - Debug.stacktrace(ex); - System.err.println("Error loading plugin: "+ex.getMessage()); + if (files != null) { + for (File pl : files) { + LoadPlugin lp; + try { + lp = new LoadPlugin(pl); + appGalleryButtonsList.add(lp.getGalleryBtn()); + } catch (Exception ex) { + Debug.stacktrace(ex); + System.err.println("Error loading plugin " + pl.getName() + ": " + ex.getMessage()); + } } } - appGalleryButtons.add(new StringValuePair>("Plugins", - appGalleryButtonsList)); + appGalleryButtons.add(new StringValuePair<>("Plugins", + appGalleryButtonsList)); pluginband.addRibbonGallery("Plugins", appGalleryButtons, galleryVisibleButtonCounts, 5, 3, RibbonElementPriority.TOP); @@ -343,7 +347,13 @@ public class Main extends JRibbonFrame { JRibbonBand collabband = new JRibbonBand("Team", null); //JRibbonBand getpluginband = new JRibbonBand("Install", null); - loadPlugins(); + try { + loadPlugins(); + } catch (Exception ex) { + JOptionPane.showMessageDialog(this, + "An error occurred while loading plugins: " + + ex.getMessage()); + } shellbtn.addActionListener(new ActionListener() { @Override diff --git a/src/net/apocalypselabs/symat/PackagePlugin.java b/src/net/apocalypselabs/symat/PackagePlugin.java index 48ebd5d..1a985c0 100644 --- a/src/net/apocalypselabs/symat/PackagePlugin.java +++ b/src/net/apocalypselabs/symat/PackagePlugin.java @@ -48,8 +48,6 @@ package net.apocalypselabs.symat; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFileChooser; @@ -375,8 +373,6 @@ public class PackagePlugin extends javax.swing.JInternalFrame { p.setIcon(icon); if (p.getTitle().equals("") || p.getAuthor().equals("") - || p.getLongTitle().equals("") - || p.getDesc().equals("") || p.getPackage().equals("") || p.getVersion().equals("") || p.getScript().equals("") diff --git a/src/net/apocalypselabs/symat/plugin/LoadPlugin.java b/src/net/apocalypselabs/symat/plugin/LoadPlugin.java index 05a5cce..3bb2aa3 100644 --- a/src/net/apocalypselabs/symat/plugin/LoadPlugin.java +++ b/src/net/apocalypselabs/symat/plugin/LoadPlugin.java @@ -55,6 +55,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import net.apocalypselabs.symat.CodeRunner; import net.apocalypselabs.symat.Debug; +import net.apocalypselabs.symat.Main; import org.pushingpixels.flamingo.api.common.JCommandButton; import org.pushingpixels.flamingo.api.common.JCommandToggleButton; import org.pushingpixels.flamingo.api.common.RichTooltip; @@ -82,15 +83,22 @@ public class LoadPlugin { } private ResizableIcon getRibbonIcon() { - return ImageWrapperResizableIcon.getIcon( - p.getIcon().getImage(), - new Dimension(100, 76)); + try { + ResizableIcon ico = ImageWrapperResizableIcon.getIcon( + p.getIcon().getImage(), + new Dimension(100, 76)); + return ico; + } catch (Exception ex) { + return Main.getRibbonIcon("plugin"); + } } public JCommandButton getRibbonBtn() { - JCommandButton b = new JCommandButton(p.getTitle(), getRibbonIcon()); - b.setActionRichTooltip(new RichTooltip(p.getLongTitle(), - p.getDesc())); + JCommandButton b = new JCommandButton((p.getTitle().equals("") ? "Untitled" : p.getTitle()), getRibbonIcon()); + if (!p.getLongTitle().equals("")) { + b.setActionRichTooltip(new RichTooltip(p.getLongTitle(), + (p.getDesc().equals("") ? " " : p.getDesc()))); + } b.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { @@ -102,9 +110,11 @@ public class LoadPlugin { } public JCommandToggleButton getGalleryBtn() { - JCommandToggleButton b = new JCommandToggleButton(p.getTitle(), getRibbonIcon()); - b.setActionRichTooltip(new RichTooltip(p.getLongTitle(), - p.getDesc())); + JCommandToggleButton b = new JCommandToggleButton((p.getTitle().equals("") ? "Untitled" : p.getTitle()), getRibbonIcon()); + if (!p.getLongTitle().equals("")) { + b.setActionRichTooltip(new RichTooltip(p.getLongTitle(), + (p.getDesc().equals("") ? " " : p.getDesc()))); + } b.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) {