This commit has an initial implementation of the Navigation feature (history - PREV and NEXT buttons), which enable users to go backwards or forward on the Palette Browser.
Change-Id: I910cd461ced3b2e69b41ec12ea840a0a8789d5ee
* Palette browser - zoom feature is now available via CTRL(+), CTRL(-) and CTRL(mousewheel).
* Palette browser is now able to load SVG icons.
+* Palette browser handles the action of going forward or backward.
Compilation
============
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015 - Marcos CARDINOT
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+
+package org.scilab.modules.xcos.palette.actions;
+
+import java.awt.event.ActionEvent;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+
+import org.scilab.modules.commons.gui.FindIconHelper;
+import org.scilab.modules.commons.gui.ScilabLAF;
+import org.scilab.modules.gui.events.callback.CommonCallBack;
+import org.scilab.modules.xcos.palette.view.PaletteManagerView;
+import org.scilab.modules.xcos.utils.XcosMessages;
+
+/**
+ * Navigation menu management.
+ * Actions 'next' and 'previous' of the palette browser.
+ * @author Marcos CARDINOT <mcardinot@gmail.com>
+ */
+public class NavigationAction extends CommonCallBack {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final String LABEL_NEXT = XcosMessages.NEXT;
+ private static final String LABEL_PREV = XcosMessages.PREVIOUS;
+ private static final String ICON_NEXT = FindIconHelper.findIcon("go-next");
+ private static final String ICON_PREV = FindIconHelper.findIcon("go-previous");
+
+ private static JButton btnNEXT;
+ private static JButton btnPREV;
+
+ /**
+ * Constructor
+ */
+ public NavigationAction() {
+ super("");
+ }
+
+ /**
+ * Create the button 'next'
+ * @return the button
+ */
+ public static JButton createButtonNext() {
+ btnNEXT = new JButton();
+ ScilabLAF.setDefaultProperties(btnNEXT);
+ btnNEXT.setIcon(new ImageIcon(ICON_NEXT));
+ btnNEXT.setToolTipText(LABEL_NEXT);
+ btnNEXT.addActionListener(getCallBack());
+ setEnabledNext(false);
+ return btnNEXT;
+ }
+
+ /**
+ * Create the button 'previous'
+ * @return the button
+ */
+ public static JButton createButtonPrev() {
+ btnPREV = new JButton();
+ ScilabLAF.setDefaultProperties(btnPREV);
+ btnPREV.setIcon(new ImageIcon(ICON_PREV));
+ btnPREV.setToolTipText(LABEL_PREV);
+ btnPREV.addActionListener(getCallBack());
+ setEnabledPrev(false);
+ return btnPREV;
+ }
+
+ /**
+ * Create a new class instance
+ * @return the instance
+ */
+ private static CommonCallBack getCallBack() {
+ CommonCallBack callback = null;
+ try {
+ callback = NavigationAction.class.getConstructor().newInstance();
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ }
+ return callback;
+ }
+
+ /**
+ * Action
+ * @param e ActionEvent
+ */
+ public void actionPerformed(ActionEvent e) {
+ Object src = e.getSource();
+ if (btnNEXT != null && src.equals(btnNEXT)) {
+ PaletteManagerView.get().getPanel().goNext();
+ } else if (btnPREV != null && src.equals(btnPREV)) {
+ PaletteManagerView.get().getPanel().goPrevious();
+ }
+ }
+
+ /**
+ * setEnabled property of the button 'next'
+ * @param enabled enabled
+ */
+ public static void setEnabledNext(boolean enabled) {
+ btnNEXT.setEnabled(enabled);
+ }
+
+ /**
+ * setEnabled property of the button 'previous'
+ * @param enabled enabled
+ */
+ public static void setEnabledPrev(boolean enabled) {
+ btnPREV.setEnabled(enabled);
+ }
+
+ @Override
+ public void callBack() {
+ }
+}
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2010 - DIGITEO - Clement DAVID
+ * Copyright (C) 2015 - Marcos CARDINOT
*
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
-import org.scilab.modules.xcos.graph.PaletteDiagram;
import org.scilab.modules.xcos.palette.PaletteBlockCtrl;
import org.scilab.modules.xcos.palette.model.Category;
import org.scilab.modules.xcos.palette.model.Custom;
}
// update
+ paletteManagerPanel.updateHistory();
nodeView.setPreferredSize(dimension);
splitPanel.setRightComponent(nodeView);
nodeView.validate();
}
-
}
import java.awt.Toolkit;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
+import java.util.ArrayList;
+import java.util.List;
import javax.swing.DropMode;
import javax.swing.JPanel;
import org.scilab.modules.xcos.graph.PaletteDiagram;
import org.scilab.modules.xcos.palette.PaletteManager;
+import org.scilab.modules.xcos.palette.actions.NavigationAction;
import org.scilab.modules.xcos.palette.listener.PaletteManagerMouseListener;
import org.scilab.modules.xcos.palette.listener.PaletteManagerTreeSelectionListener;
import org.scilab.modules.xcos.palette.listener.PaletteTreeTransferHandler;
private CustomMouseWheelListener mouseWheelListener;
private JTree tree;
private PaletteDiagram diagramInstance;
+ private List<TreePath> historyNext;
+ private List<TreePath> historyPrev;
+ private TreePath currentPath;
/**
* Default constructor
super(JSplitPane.HORIZONTAL_SPLIT);
this.controller = controller;
this.mouseWheelListener = new CustomMouseWheelListener();
+ this.historyNext = new ArrayList<TreePath>();
+ this.historyPrev = new ArrayList<TreePath>();
+ this.currentPath = null;
currentSize = XcosConstants.PaletteBlockSize.NORMAL;
fillUpContentPane();
}
}
/**
+ * Updates the history.
+ */
+ public void updateHistory() {
+ TreePath lastPath = currentPath;
+ currentPath = tree.getSelectionPath();
+
+ if (lastPath != null && !currentPath.equals(lastPath)) {
+
+ if (historyPrev.isEmpty()) {
+ historyPrev.add(lastPath);
+ } else {
+ int prevPathIdx = historyPrev.size() - 1;
+ // going backwards?
+ if (currentPath.equals(historyPrev.get(prevPathIdx))) {
+ historyNext.add(lastPath);
+ historyPrev.remove(prevPathIdx);
+ updateHistorySettings();
+ return;
+ } else {
+ // it seems to be a new path, just store it!
+ // Soon we'll check if we are just going forward
+ // or if it's really a new path!
+ historyPrev.add(lastPath);
+ }
+ }
+
+ if (!historyNext.isEmpty()) {
+ int nextPathIdx = historyNext.size() - 1;
+ // going forward?
+ if (currentPath.equals(historyNext.get(nextPathIdx))) {
+ historyNext.remove(nextPathIdx);
+ } else {
+ // it is really a new path!
+ // make sure it's on the top of the history!
+ historyNext.clear();
+ }
+ }
+ updateHistorySettings();
+ }
+ }
+
+ /**
+ * Update the status of the buttons and the history length.
+ */
+ private void updateHistorySettings() {
+ if (historyNext.size() + historyPrev.size() > XcosConstants.HISTORY_LENGTH) {
+ historyPrev.remove(0);
+ }
+ NavigationAction.setEnabledNext(historyNext.size() > 0);
+ NavigationAction.setEnabledPrev(historyPrev.size() > 0);
+ }
+
+ /**
+ * Go to the next path (history).
+ */
+ public void goNext() {
+ try {
+ tree.setSelectionPath(historyNext.get(historyNext.size() - 1));
+ } catch (ArrayIndexOutOfBoundsException err) {
+ NavigationAction.setEnabledNext(false);
+ }
+ }
+
+ /**
+ * Go to the previous path (history).
+ */
+ public void goPrevious() {
+ try {
+ tree.setSelectionPath(historyPrev.get(historyPrev.size() - 1));
+ } catch (ArrayIndexOutOfBoundsException err) {
+ NavigationAction.setEnabledPrev(false);
+ }
+ }
+
+ /**
* Implement custom mouse handling for the zoom
*/
private static final class CustomMouseWheelListener implements MouseWheelListener {
import org.scilab.modules.xcos.palette.PaletteManager;
import org.scilab.modules.xcos.palette.actions.ClosePalettesAction;
import org.scilab.modules.xcos.palette.actions.LoadAsPalAction;
+import org.scilab.modules.xcos.palette.actions.NavigationAction;
import org.scilab.modules.xcos.palette.actions.ZoomInAction;
import org.scilab.modules.xcos.palette.actions.ZoomOutAction;
import org.scilab.modules.xcos.utils.XcosMessages;
/* Create the toolbar */
final ToolBar toolbar = ScilabToolBar.createToolBar();
SwingScilabToolBar stb = (SwingScilabToolBar) toolbar.getAsSimpleToolBar();
+
stb.add(LoadAsPalAction.createButton(null));
stb.addSeparator();
+ stb.add(NavigationAction.createButtonPrev());
+ stb.add(NavigationAction.createButtonNext());
+
+ stb.addSeparator();
+
stb.add(ZoomInAction.createPushButton());
stb.add(ZoomOutAction.createPushButton());
/** Define the maximum number of char that might be represented as style */
public static final int MAX_CHAR_IN_STYLE = 24;
+ /** Define the history length */
+ public static final int HISTORY_LENGTH = 20;
+
/** the size of the palette block **/
public enum PaletteBlockSize {
/** small size **/
public static final String SAVE_BLOCK_GUI = Messages.gettext("Save block GUI");
/* Palette browser */
+ public static final String NEXT = Messages.gettext("Next");
+ public static final String PREVIOUS = Messages.gettext("Previous");
public static final String ZOOM_IN = Messages.gettext("Zoom In");
public static final String ZOOM_OUT = Messages.gettext("Zoom Out");