From adab034091f0409e8efc90e65de32250d69b623d Mon Sep 17 00:00:00 2001 From: skylarmt Date: Wed, 1 Apr 2015 20:18:47 -0600 Subject: [PATCH] Move plugin list to a ribbon gallery --- nbproject/project.properties | 3 +- src/net/apocalypselabs/symat/Main.java | 63 +++++++----- src/net/apocalypselabs/symat/Settings.form | 96 ++++++------------- src/net/apocalypselabs/symat/Settings.java | 79 +++++---------- .../symat/plugin/LoadPlugin.java | 44 ++++++--- 5 files changed, 120 insertions(+), 165 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index 9ebefb6..b76d72d 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -34,7 +34,6 @@ endorsed.classpath= excludes= file.reference.autocomplete-2.5.4.jar=lib/autocomplete-2.5.4.jar file.reference.beautyeye_lnf.jar=lib/beautyeye_lnf.jar -file.reference.flamingo-6.3-javadoc.jar=lib/flamingo-6.3-javadoc.jar file.reference.flamingo-6.3.jar=lib/flamingo-6.3.jar file.reference.htmlcleaner-2.10.jar=lib/htmlcleaner-2.10.jar file.reference.iText-4.2.0-com.itextpdf.jar=lib/iText-4.2.0-com.itextpdf.jar @@ -57,7 +56,6 @@ jar.compress=false javac.classpath=\ ${file.reference.autocomplete-2.5.4.jar}:\ ${file.reference.beautyeye_lnf.jar}:\ - ${file.reference.flamingo-6.3-javadoc.jar}:\ ${file.reference.flamingo-6.3.jar}:\ ${file.reference.htmlcleaner-2.10.jar}:\ ${file.reference.iText-4.2.0-com.itextpdf.jar}:\ @@ -93,6 +91,7 @@ javadoc.noindex=false javadoc.nonavbar=false javadoc.notree=false javadoc.private=false +javadoc.reference.flamingo-6.3.jar=lib/flamingo-6.3-javadoc.jar javadoc.splitindex=true javadoc.use=true javadoc.version=false diff --git a/src/net/apocalypselabs/symat/Main.java b/src/net/apocalypselabs/symat/Main.java index e9fabf3..2c9313f 100644 --- a/src/net/apocalypselabs/symat/Main.java +++ b/src/net/apocalypselabs/symat/Main.java @@ -68,7 +68,9 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javafx.application.Platform; import javax.swing.ImageIcon; import javax.swing.JFileChooser; @@ -276,8 +278,17 @@ public class Main extends JRibbonFrame { */ public void loadPlugins() { pluginband = new JRibbonBand("Plugins", null); + installpluginbtn.setActionRichTooltip(new RichTooltip("Install Plugin", + "Install a plugin from a file and view plugin info.")); + installpluginbtn.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent evt) { + loadFrame(new InstallPlugin()); + } + }); pluginband.setResizePolicies((List) Arrays.asList( - new IconRibbonBandResizePolicy(pluginband.getControlPanel()))); + new CoreRibbonResizePolicies.Mirror(pluginband.getControlPanel()))); + pluginband.addCommandButton(installpluginbtn, RibbonElementPriority.TOP); File dir = new File(System.getProperty("user.home") + "\\.symat\\plugins"); dir.mkdirs(); File[] files = dir.listFiles(new FilenameFilter() { @@ -287,20 +298,29 @@ public class Main extends JRibbonFrame { } }); + Map galleryVisibleButtonCounts = new HashMap<>(); + galleryVisibleButtonCounts.put(RibbonElementPriority.LOW, 1); + galleryVisibleButtonCounts.put(RibbonElementPriority.MEDIUM, 2); + galleryVisibleButtonCounts.put(RibbonElementPriority.TOP, 2); + List>> appGalleryButtons = new ArrayList<>(); + List appGalleryButtonsList = new ArrayList<>(); for (File pl : files) { try { LoadPlugin lp = new LoadPlugin(pl); - JCommandButton b = lp.getRibbonBtn(); - pluginband.addCommandButton( - b, - RibbonElementPriority.MEDIUM); - b.setVisible(true); + appGalleryButtonsList.add(lp.getGalleryBtn()); } catch (Exception ex) { - + Debug.stacktrace(ex); + System.err.println("Error loading plugin: "+ex.getMessage()); } } + + appGalleryButtons.add(new StringValuePair>("Plugins", + appGalleryButtonsList)); + pluginband.addRibbonGallery("Plugins", appGalleryButtons, + galleryVisibleButtonCounts, 5, 3, + RibbonElementPriority.TOP); } - + /** * Reload the Ribbon tabs and all sub-components. */ @@ -321,7 +341,8 @@ public class Main extends JRibbonFrame { JRibbonBand appsband = new JRibbonBand("Apps", null); JRibbonBand webband = new JRibbonBand("Community", null); JRibbonBand collabband = new JRibbonBand("Team", null); - JRibbonBand getpluginband = new JRibbonBand("Install", null); + //JRibbonBand getpluginband = new JRibbonBand("Install", null); + loadPlugins(); shellbtn.addActionListener(new ActionListener() { @@ -376,12 +397,6 @@ public class Main extends JRibbonFrame { loadFrame(new Tasks()); } }); - installpluginbtn.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent evt) { - loadFrame(new InstallPlugin()); - } - }); shellbtn.setActionRichTooltip(new RichTooltip("Command Shell", "Open a window for running interactive commands.")); @@ -399,8 +414,6 @@ public class Main extends JRibbonFrame { "Collaborate over the Internet on projects.")); tasksbtn.setActionRichTooltip(new RichTooltip("Task List", "Manage tasks and to-do lists for projects.")); - installpluginbtn.setActionRichTooltip(new RichTooltip("Install Plugin", - "Install a plugin from a file and view plugin info.")); coreband.addCommandButton(shellbtn, RibbonElementPriority.TOP); coreband.addCommandButton(editorbtn, RibbonElementPriority.TOP); @@ -413,8 +426,6 @@ public class Main extends JRibbonFrame { collabband.addCommandButton(padsbtn, RibbonElementPriority.MEDIUM); collabband.addCommandButton(tasksbtn, RibbonElementPriority.MEDIUM); - - getpluginband.addCommandButton(installpluginbtn, RibbonElementPriority.MEDIUM); coreband.setResizePolicies((List) Arrays.asList( new CoreRibbonResizePolicies.None(coreband.getControlPanel()), @@ -428,16 +439,16 @@ public class Main extends JRibbonFrame { collabband.setResizePolicies((List) Arrays.asList( new CoreRibbonResizePolicies.None(collabband.getControlPanel()), new IconRibbonBandResizePolicy(collabband.getControlPanel()))); - getpluginband.setResizePolicies((List) Arrays.asList( - new CoreRibbonResizePolicies.None(appsband.getControlPanel()), - new IconRibbonBandResizePolicy(pluginband.getControlPanel()))); - pluginband.setResizePolicies((List) Arrays.asList( - new CoreRibbonResizePolicies.None(appsband.getControlPanel()), - new IconRibbonBandResizePolicy(pluginband.getControlPanel()))); +// getpluginband.setResizePolicies((List) Arrays.asList( +// new CoreRibbonResizePolicies.None(appsband.getControlPanel()), +// new IconRibbonBandResizePolicy(pluginband.getControlPanel()))); +// pluginband.setResizePolicies((List) Arrays.asList( +// new CoreRibbonResizePolicies.None(appsband.getControlPanel()), +// new IconRibbonBandResizePolicy(pluginband.getControlPanel()))); RibbonTask hometask = new RibbonTask("Home", coreband, appsband); RibbonTask webtask = new RibbonTask("Tools", webband, collabband); - RibbonTask plugintask = new RibbonTask("Plugins", getpluginband, pluginband); + RibbonTask plugintask = new RibbonTask("Plugins", pluginband); loadRibbonMenu(null); diff --git a/src/net/apocalypselabs/symat/Settings.form b/src/net/apocalypselabs/symat/Settings.form index f674e64..803f5d4 100644 --- a/src/net/apocalypselabs/symat/Settings.form +++ b/src/net/apocalypselabs/symat/Settings.form @@ -1,6 +1,6 @@ -
+ @@ -13,13 +13,13 @@ - + - + - + @@ -44,21 +44,21 @@ - - - - - - - - + + + + + + + + + - - - + + @@ -71,24 +71,22 @@ - + - - - - - - - - - - + + + + + + + + - + @@ -238,6 +236,7 @@ + @@ -277,7 +276,7 @@ - + @@ -288,7 +287,7 @@ - + @@ -303,44 +302,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/net/apocalypselabs/symat/Settings.java b/src/net/apocalypselabs/symat/Settings.java index c28f7fd..e069381 100644 --- a/src/net/apocalypselabs/symat/Settings.java +++ b/src/net/apocalypselabs/symat/Settings.java @@ -56,7 +56,6 @@ public class Settings extends javax.swing.JInternalFrame { */ public Settings() { initComponents(); - jPanel5.setVisible(false); setBackground(Theme.windowColor()); } @@ -84,16 +83,14 @@ public class Settings extends javax.swing.JInternalFrame { jPanel4 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); nameBox = new javax.swing.JTextField(); - jPanel5 = new javax.swing.JPanel(); - textSize = new javax.swing.JSpinner(); setClosable(true); setIconifiable(true); setTitle("Settings"); setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/net/apocalypselabs/symat/icons/settings.png"))); // NOI18N - setMaximumSize(new java.awt.Dimension(524, 274)); - setMinimumSize(new java.awt.Dimension(524, 274)); - setPreferredSize(new java.awt.Dimension(524, 274)); + setMaximumSize(new java.awt.Dimension(390, 293)); + setMinimumSize(new java.awt.Dimension(390, 293)); + setPreferredSize(new java.awt.Dimension(390, 293)); addComponentListener(new java.awt.event.ComponentAdapter() { public void componentShown(java.awt.event.ComponentEvent evt) { formComponentShown(evt); @@ -195,7 +192,8 @@ public class Settings extends javax.swing.JInternalFrame { .addContainerGap() .addComponent(quickStart) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(skipUpdates)) + .addComponent(skipUpdates) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); applyBtn.setText("Apply"); @@ -215,7 +213,7 @@ public class Settings extends javax.swing.JInternalFrame { jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup() .addComponent(jLabel1) - .addGap(0, 96, Short.MAX_VALUE)) + .addGap(0, 0, Short.MAX_VALUE)) .addComponent(nameBox) ); jPanel4Layout.setVerticalGroup( @@ -224,28 +222,7 @@ public class Settings extends javax.swing.JInternalFrame { .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(nameBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(13, Short.MAX_VALUE)) - ); - - jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Text size")); - - textSize.setModel(new javax.swing.SpinnerNumberModel(12, 8, 48, 2)); - - javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); - jPanel5.setLayout(jPanel5Layout); - jPanel5Layout.setHorizontalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addContainerGap() - .addComponent(textSize) - .addContainerGap()) - ); - jPanel5Layout.setVerticalGroup( - jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel5Layout.createSequentialGroup() - .addContainerGap() - .addComponent(textSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(0, 0, Short.MAX_VALUE)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); @@ -253,19 +230,18 @@ public class Settings extends javax.swing.JInternalFrame { layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() - .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGroup(layout.createSequentialGroup() - .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(0, 0, 0) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(applyBtn) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(saveBtn))) @@ -276,18 +252,17 @@ public class Settings extends javax.swing.JInternalFrame { .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) - .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(applyBtn) - .addComponent(saveBtn))) - .addGap(57, 57, 57)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(applyBtn) + .addComponent(saveBtn)) + .addGap(40, 40, 40)) ); pack(); @@ -313,7 +288,6 @@ public class Settings extends javax.swing.JInternalFrame { skipUpdates.setSelected( PrefStorage.getSetting("skipupdates", "").equals("yes")); nameBox.setText(PrefStorage.getSetting("author", "")); - textSize.setValue(Integer.valueOf(PrefStorage.getSetting("editfont"))); }//GEN-LAST:event_formComponentShown private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBtnActionPerformed @@ -327,7 +301,6 @@ public class Settings extends javax.swing.JInternalFrame { PrefStorage.saveSetting("quickstart", quickStart.isSelected() ? "yes" : ""); PrefStorage.saveSetting("skipupdates", skipUpdates.isSelected() ? "yes" : ""); PrefStorage.saveSetting("author", nameBox.getText()); - PrefStorage.saveSetting("editfont", String.valueOf(textSize.getValue())); PrefStorage.save(); Main.updateDisplay(); } @@ -349,13 +322,11 @@ public class Settings extends javax.swing.JInternalFrame { private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; - private javax.swing.JPanel jPanel5; private javax.swing.JTextField nameBox; private javax.swing.JCheckBox quickStart; private javax.swing.JButton saveBtn; private javax.swing.JCheckBox showRecent; private javax.swing.JCheckBox skipUpdates; - private javax.swing.JSpinner textSize; private javax.swing.JRadioButton themeDark; private javax.swing.ButtonGroup themeGroup; private javax.swing.JRadioButton themeLight; diff --git a/src/net/apocalypselabs/symat/plugin/LoadPlugin.java b/src/net/apocalypselabs/symat/plugin/LoadPlugin.java index 1e06363..05a5cce 100644 --- a/src/net/apocalypselabs/symat/plugin/LoadPlugin.java +++ b/src/net/apocalypselabs/symat/plugin/LoadPlugin.java @@ -50,43 +50,43 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; import java.io.ObjectInputStream; import net.apocalypselabs.symat.CodeRunner; import net.apocalypselabs.symat.Debug; import org.pushingpixels.flamingo.api.common.JCommandButton; +import org.pushingpixels.flamingo.api.common.JCommandToggleButton; import org.pushingpixels.flamingo.api.common.RichTooltip; import org.pushingpixels.flamingo.api.common.icon.ImageWrapperResizableIcon; import org.pushingpixels.flamingo.api.common.icon.ResizableIcon; /** * Plugin loader class. + * * @author Skylar */ public class LoadPlugin { private Plugin p = new Plugin(); - - public LoadPlugin(File f) { - try { - FileInputStream fin = new FileInputStream(f); - ObjectInputStream ois = new ObjectInputStream(fin); - p = (Plugin) ois.readObject(); - ois.close(); - } catch (Exception ex) { - Debug.stacktrace(ex); - } + + public LoadPlugin(File f) throws FileNotFoundException, IOException, ClassNotFoundException { + FileInputStream fin = new FileInputStream(f); + ObjectInputStream ois = new ObjectInputStream(fin); + p = (Plugin) ois.readObject(); + ois.close(); } - public LoadPlugin(String path) { + public LoadPlugin(String path) throws FileNotFoundException, IOException, ClassNotFoundException { this(new File(path)); } - + private ResizableIcon getRibbonIcon() { return ImageWrapperResizableIcon.getIcon( p.getIcon().getImage(), new Dimension(100, 76)); } - + public JCommandButton getRibbonBtn() { JCommandButton b = new JCommandButton(p.getTitle(), getRibbonIcon()); b.setActionRichTooltip(new RichTooltip(p.getLongTitle(), @@ -97,14 +97,28 @@ public class LoadPlugin { exec(); } }); + b.setCommandButtonKind(JCommandButton.CommandButtonKind.ACTION_ONLY); + return b; + } + + public JCommandToggleButton getGalleryBtn() { + JCommandToggleButton b = new JCommandToggleButton(p.getTitle(), getRibbonIcon()); + b.setActionRichTooltip(new RichTooltip(p.getLongTitle(), + p.getDesc())); + b.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent evt) { + exec(); + } + }); return b; } - + public void exec() { CodeRunner cr = new CodeRunner(p.getLang()); cr.evalString(p.getScript()); } - + public Plugin getPlugin() { return p; }