Palette browser: allowing multiple selection by holding down the ctrl key 86/17086/2
Marcos CARDINOT [Fri, 21 Aug 2015 16:45:01 +0000 (17:45 +0100)]
This patch introduces a new feature to the palette browser.
Now it is able to select multiple blocks by holding down the ctrl key.

test cases:
A)
- open the palette browser
- hold down the ctrl key
- left click on some blocks
- drag the blocks to a diagram

B)
- open the palette browser
- hold down the ctrl key
- left click on some blocks
- double click any block to load all of them on the most recent diagram

C)
- open the palette browser
- hold down the ctrl key
- use the arrow keys to move the selection (hightlight)
- press SPACE key to select a block
- press ENTER to load the selected blocks on the most recent diagram

Change-Id: Iba03c2ad71cf7e894bea2804834a56ab2135881f

13 files changed:
scilab/CHANGES_5.6.X
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/PaletteBlockCtrl.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/PaletteCtrl.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteBlockKeyListener.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteBlockMouseListener.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteDragGestureListener.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteManagerTreeSelectionListener.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteMouseListener.java [new file with mode: 0644]
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/view/PaletteBlockView.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/view/PaletteManagerPanel.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/view/PaletteSearchView.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/view/PaletteView.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/utils/XcosMessages.java

index 2a2680f..a4fd270 100644 (file)
@@ -16,6 +16,7 @@ Xcos
 * Palette browser handles the action of going forward or backward.
 * Palette browser enable users to add blocks to the most recent diagram by using the ENTER key.
 * Palette browser includes a palette of blocks you have used most recently.
+* Palette browser is now able to select multiple blocks by holding down the ctrl key.
 
 * Bug #13906 fixed - It is now possible to navigate through the Palette browser with the arrow keys.
 
index 8fa50a8..4e367e3 100644 (file)
@@ -17,10 +17,7 @@ import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManag
 import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.buildCall;
 import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.synchronousScilabExec;
 
-import java.awt.Point;
-import java.awt.datatransfer.Transferable;
 import java.awt.dnd.DnDConstants;
-import java.awt.dnd.DragGestureEvent;
 import java.awt.dnd.DragGestureListener;
 import java.awt.dnd.DragSource;
 import java.awt.dnd.InvalidDnDOperationException;
@@ -28,80 +25,95 @@ import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.KeyListener;
 import java.awt.event.MouseListener;
-import java.lang.ref.WeakReference;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.InterpreterException;
 import org.scilab.modules.gui.messagebox.ScilabModalDialog;
 import org.scilab.modules.gui.messagebox.ScilabModalDialog.IconType;
-import org.scilab.modules.localization.Messages;
 import org.scilab.modules.xcos.block.BasicBlock;
 import org.scilab.modules.xcos.block.BlockFactory;
 import org.scilab.modules.xcos.block.BlockFactory.BlockInterFunction;
-import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.io.scicos.ScicosFormatException;
 import org.scilab.modules.xcos.io.scicos.ScilabDirectHandler;
 import org.scilab.modules.xcos.palette.listener.PaletteBlockKeyListener;
 import org.scilab.modules.xcos.palette.listener.PaletteBlockMouseListener;
+import org.scilab.modules.xcos.palette.listener.PaletteDragGestureListener;
 import org.scilab.modules.xcos.palette.model.PaletteBlock;
 import org.scilab.modules.xcos.palette.view.PaletteBlockView;
 import org.scilab.modules.xcos.palette.view.PaletteBlockView.StatusUI;
 import org.scilab.modules.xcos.palette.view.PaletteManagerView;
-import org.scilab.modules.xcos.utils.BlockPositioning;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
-import com.mxgraph.swing.handler.mxGraphTransferHandler;
-import com.mxgraph.swing.util.mxGraphTransferable;
-
 /**
- * A palette block is the representation of the block in the palette. All the
- * operations there are used to render, load and put (on a diagram) a block.
+ * A palette block is the representation of the block in the palette.
+ * @author Marcos CARDINOT <mcardinot@gmail.com>
+ * @author Clement DAVID
  */
 public final class PaletteBlockCtrl {
-    /**
-     * Internal graph used to render each block.
-     */
-    public static final XcosDiagram INTERNAL_GRAPH;
-    static {
-        INTERNAL_GRAPH = new XcosDiagram();
-        INTERNAL_GRAPH.installListeners();
-    }
 
-    private static final double BLOCK_DEFAULT_POSITION = 10.0;
+    private static final DragGestureListener DRAG_LISTENER = new PaletteDragGestureListener();
     private static final KeyListener KEY_LISTENER = new PaletteBlockKeyListener();
     private static final MouseListener MOUSE_LISTENER = new PaletteBlockMouseListener();
     private static final Logger LOG = Logger.getLogger(PaletteBlockCtrl.class.getName());
 
-    private static final String UNABLE_TO_LOAD_BLOCK = Messages.gettext("Unable to load block from %s .");
-    private static final String LOADING_THE_BLOCK = Messages.gettext("Loading the block") + XcosMessages.DOTS;
-
-    private static PaletteBlockCtrl previouslySelected;
-
+    private final PaletteCtrl paletteCtrl;
     private final PaletteBlock model;
     private final PaletteBlockView view;
-
-    private transient WeakReference<Transferable> transferable = new WeakReference<Transferable>(null);
+    private BasicBlock basicBlock;
+    private boolean isSelected;
 
     /**
      * Default constructor
+     * @param ctrl The palette in which it belongs
      * @param model the block data
      */
-    public PaletteBlockCtrl(PaletteBlock model) {
+    public PaletteBlockCtrl(PaletteCtrl ctrl, PaletteBlock model) {
+        this.paletteCtrl = ctrl;
         this.model = model;
         this.view = new PaletteBlockView(this);
-        installListeners(this.view);
+        this.isSelected = false;
+        this.basicBlock = null;
+
+        // add block to its parent palette
+        this.paletteCtrl.addBlock(this);
+
+        // install listeners
+        this.view.setFocusTraversalKeysEnabled(false);
+        this.view.addKeyListener(KEY_LISTENER);
+        this.view.addMouseListener(MOUSE_LISTENER);
+
+        DragSource dragSource = DragSource.getDefaultDragSource();
+        dragSource.createDefaultDragGestureRecognizer(this.getView(),
+                DnDConstants.ACTION_COPY, DRAG_LISTENER);
+    }
+
+    /**
+     * @return true if it is selected, false otherwise
+     */
+    public boolean isSelected() {
+        return isSelected;
+    }
+
+    /**
+     * @param selected The selected state to set
+     */
+    public void setSelected(boolean selected) {
+        if (selected) {
+            getView().requestFocus();
+            getView().setStatusUI(StatusUI.SELECTED);
+        } else {
+            PaletteManagerView.get().getPanel().requestFocus();
+            getView().setStatusUI(StatusUI.NON_SELECTED);
+        }
+        isSelected = selected;
     }
 
     /**
-     * @param view
-     *            The view to setup
+     * @return the parent palette (PaletteCtrl)
      */
-    private void installListeners(PaletteBlockView view) {
-        view.setFocusTraversalKeysEnabled(false);
-        view.addKeyListener(KEY_LISTENER);
-        view.addMouseListener(MOUSE_LISTENER);
-        installDnd();
+    public PaletteCtrl getPaletteCtrl() {
+        return paletteCtrl;
     }
 
     /**
@@ -119,219 +131,113 @@ public final class PaletteBlockCtrl {
     }
 
     /**
-     * This function is the only access to get the block.
-     *
-     * @return the transferable object
-     * @throws ScicosFormatException
-     *             on decoding error
+     * Get the loaded block.
+     * @return basicblock
      */
-    public synchronized Transferable getTransferable() throws ScicosFormatException {
-        Transferable transfer = transferable.get();
-        if (transfer == null) {
-            /* Load the block from the H5 file */
-            BasicBlock block;
+    public BasicBlock getBlock() {
+        if (basicBlock == null) {
             try {
-                block = loadBlock();
+                basicBlock = loadBlock();
             } catch (ScicosFormatException ex) {
-                getView().setEnabled(false);
-                throw ex;
+                ScilabModalDialog.show(PaletteManagerView.get(), ex.getMessage(),
+                        XcosMessages.XCOS_ERROR, IconType.ERROR_ICON);
             }
-            if (block == null) {
-                if (LOG.isLoggable(Level.FINEST)) {
-                    LOG.finest(String.format(UNABLE_TO_LOAD_BLOCK, getModel().getData().getEvaluatedPath()));
-                }
-                getView().setEnabled(false);
-                throw new InvalidDnDOperationException();
-            }
-            getView().setEnabled(true);
-
-            /* Render it and export it */
-            block.getGeometry().setX(BLOCK_DEFAULT_POSITION);
-            block.getGeometry().setY(BLOCK_DEFAULT_POSITION);
-
-            INTERNAL_GRAPH.addCell(block);
-            INTERNAL_GRAPH.selectAll();
-
-            BlockPositioning.updateBlockView(block);
-
-            mxGraphTransferHandler handler = ((mxGraphTransferHandler) INTERNAL_GRAPH.getAsComponent().getTransferHandler());
-            transfer = handler.createTransferable(INTERNAL_GRAPH.getAsComponent());
-            transferable = new WeakReference<Transferable>(transfer);
-
-            INTERNAL_GRAPH.removeCells();
         }
-        return transfer;
+        return basicBlock;
     }
 
     /**
      * @return the loaded block.
-     * @throws ScicosFormatException
-     *             on error
+     * @throws ScicosFormatException error
      */
-    private BasicBlock loadBlock() throws ScicosFormatException {
-        BasicBlock block;
-        if (model.getName().compareTo("TEXT_f") != 0) {
-
+    // CSOFF: MultipleStringLiterals
+    public BasicBlock loadBlock() throws ScicosFormatException {
+        BasicBlock block = null;
+        if (model.getName().compareTo("TEXT_f") == 0) {
+            block = BlockFactory.createBlock(BlockInterFunction.TEXT_f);
+        } else {
             // Load the block with a reference instance
             final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
-            if (handler == null) {
-                return null;
-            }
-
-            try {
-                synchronousScilabExec(ScilabDirectHandler.BLK + " = " + buildCall(model.getName(), "define"));
-                block = handler.readBlock();
-            } catch (InterpreterException e1) {
-                LOG.severe(e1.toString());
-                block = null;
-            } finally {
-                handler.release();
-            }
+            if (handler != null) {
+                try {
+                    synchronousScilabExec(ScilabDirectHandler.BLK + " = " + buildCall(model.getName(), "define"));
+                    block = handler.readBlock();
+                } catch (InterpreterException e1) {
+                    LOG.severe(e1.toString());
+                    block = null;
+                    getView().setEnabled(false);
+                } finally {
+                    handler.release();
+                }
 
-            // invalid block case
-            if (block == null) {
-                return null;
+                if (block != null && block.getStyle().compareTo("") == 0) {
+                    block.setStyle(block.getInterfaceFunctionName());
+                }
             }
+        }
 
-            if (block.getStyle().compareTo("") == 0) {
-                block.setStyle(block.getInterfaceFunctionName());
+        if (block == null) {
+            if (LOG.isLoggable(Level.FINEST)) {
+                LOG.finest(String.format(XcosMessages.UNABLE_TO_LOAD_BLOCK,
+                        getModel().getData().getEvaluatedPath()));
             }
+            getView().setEnabled(false);
+            throw new InvalidDnDOperationException();
         } else {
-            block = BlockFactory.createBlock(BlockInterFunction.TEXT_f);
+            getView().setEnabled(true);
         }
+
         return block;
     }
 
     /**
-     * @param callback
-     *            called after the block loading
+     * @param callback Called after the block loading
      */
     protected void loadBlock(final ActionListener callback) {
-        if (model.getName().compareTo("TEXT_f") != 0) {
-
-            // Load the block with a reference instance
-            final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
-            if (handler == null) {
-                return;
-            }
-
-            final ActionListener internalCallback = new ActionListener() {
-                @Override
-                public void actionPerformed(ActionEvent e) {
-                    try {
-                        final BasicBlock block = handler.readBlock();
-
-                        // invalid block case
-                        if (block == null) {
-                            return;
-                        }
-
-                        // update style
-                        if (block.getStyle().compareTo("") == 0) {
-                            block.setStyle(block.getInterfaceFunctionName());
-                        }
-
-                        callback.actionPerformed(new ActionEvent(block, 0, "loaded"));
-                    } catch (ScicosFormatException e1) {
-                        e1.printStackTrace();
-                    } finally {
-                        handler.release();
-                    }
-                }
-            };
-
-            try {
-                asynchronousScilabExec(internalCallback, ScilabDirectHandler.BLK + " = " + buildCall(model.getName(), "define"));
-            } catch (InterpreterException e1) {
-                LOG.severe(e1.toString());
-            } finally {
-                handler.release();
-            }
-        } else {
+        if (model.getName().compareTo("TEXT_f") == 0) {
             final BasicBlock block = BlockFactory.createBlock(BlockInterFunction.TEXT_f);
             callback.actionPerformed(new ActionEvent(block, 0, "loaded"));
+            return;
         }
-    }
 
-    /**
-     * This function load the block and render it on the hidden diagram. This
-     * can be time-consuming and each block should be cached on the caller when
-     * possible.
-     *
-     * @return a rendered block
-     */
-    public BasicBlock getBlock() {
-        try {
-            return (BasicBlock) ((mxGraphTransferable) getTransferable()).getCells()[0];
-        } catch (ScicosFormatException e) {
-            LOG.severe(e.toString());
-            return null;
+        // Load the block with a reference instance
+        final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
+        if (handler == null) {
+            return;
         }
-    }
 
-    /**
-     * @return true if it is selected, false otherwise
-     */
-    public boolean isSelected() {
-        return this == previouslySelected;
-    }
-
-    /**
-     * @param selected
-     *            the selected state to set
-     */
-    public void setSelected(boolean selected) {
-        if (selected) {
-            if (previouslySelected != null) {
-                previouslySelected.setSelected(false);
-            }
-            previouslySelected = this;
-            getView().requestFocus();
-            getView().setStatusUI(StatusUI.SELECTED);
-        } else {
-            previouslySelected = null;
-            PaletteManagerView.get().getPanel().requestFocus();
-            getView().setStatusUI(StatusUI.NON_SELECTED);
-        }
-    }
-
-    /**
-     * Install the Drag'n'Drop on this instance.
-     */
-    public void installDnd() {
-        // Install the handler for dragging nodes into a graph
-        DragGestureListener dragGestureListener = new DragGestureListener() {
+        final ActionListener internalCallback = new ActionListener() {
             @Override
-            public void dragGestureRecognized(DragGestureEvent e) {
-                if (PaletteManagerView.get() == null) {
-                    PaletteManagerView.restore(null);
-                }
-                final PaletteManagerView winView = PaletteManagerView.get();
-                final DragGestureEvent event = e;
-                final String msg = String.format(UNABLE_TO_LOAD_BLOCK, getModel().getName());
-
-                winView.setInfo(LOADING_THE_BLOCK);
+            public void actionPerformed(ActionEvent e) {
                 try {
-                    Transferable transfer = getTransferable();
+                    final BasicBlock block = handler.readBlock();
+
+                    // invalid block case
+                    if (block == null) {
+                        return;
+                    }
 
-                    if (transfer != null) {
-                        event.startDrag(null, null, new Point(), transfer, null);
-                        PaletteManagerView.get().getPanel().addRecentltyUsedBlock(model);
-                    } else {
-                        throw new InvalidDnDOperationException();
+                    // update style
+                    if (block.getStyle().compareTo("") == 0) {
+                        block.setStyle(block.getInterfaceFunctionName());
                     }
-                } catch (InvalidDnDOperationException exception) {
-                    ScilabModalDialog.show(winView, msg, XcosMessages.XCOS_ERROR, IconType.ERROR_ICON);
-                } catch (ScicosFormatException ex) {
-                    ScilabModalDialog.show(winView, ex.getMessage(), XcosMessages.XCOS_ERROR, IconType.ERROR_ICON);
+
+                    callback.actionPerformed(new ActionEvent(block, 0, "loaded"));
+                } catch (ScicosFormatException e1) {
+                    e1.printStackTrace();
                 } finally {
-                    winView.setInfo(XcosMessages.EMPTY_INFO);
+                    handler.release();
                 }
             }
-
         };
 
-        DragSource dragSource = DragSource.getDefaultDragSource();
-        dragSource.createDefaultDragGestureRecognizer(this.getView(), DnDConstants.ACTION_COPY, dragGestureListener);
+        try {
+            asynchronousScilabExec(internalCallback,
+                    ScilabDirectHandler.BLK + " = " + buildCall(model.getName(), "define"));
+        } catch (InterpreterException e1) {
+            LOG.severe(e1.toString());
+        } finally {
+            handler.release();
+        }
     }
 }
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/PaletteCtrl.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/PaletteCtrl.java
new file mode 100644 (file)
index 0000000..1d2284d
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * 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;
+
+import java.awt.Dimension;
+import java.awt.datatransfer.Transferable;
+import java.awt.event.MouseListener;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.scilab.modules.xcos.block.BasicBlock;
+import org.scilab.modules.xcos.block.BlockFactory;
+import org.scilab.modules.xcos.graph.XcosDiagram;
+import org.scilab.modules.xcos.palette.listener.PaletteMouseListener;
+import org.scilab.modules.xcos.palette.view.PaletteManagerView;
+import org.scilab.modules.xcos.palette.view.PaletteView;
+import org.scilab.modules.xcos.utils.BlockPositioning;
+import org.scilab.modules.xcos.utils.XcosConstants;
+
+import com.mxgraph.swing.handler.mxGraphTransferHandler;
+
+/**
+ * All the operations which are used to render, load and put
+ * the selected blocks on a diagram.
+ * @author Marcos Cardinot <mcardinot@gmail.com>
+ */
+public final class PaletteCtrl {
+    /**
+     * Internal graph used to render the selected blocks.
+     */
+    private static XcosDiagram internalGraph;
+    static {
+        internalGraph = new XcosDiagram();
+        internalGraph.installListeners();
+    }
+
+    private static final MouseListener MOUSE_LISTENER = new PaletteMouseListener();
+
+    private static final int BLOCKS_BY_ROW = 5;
+    private static final Dimension BLOCK_POSITION = XcosConstants.PaletteBlockSize.NORMAL.getBlockDimension();
+
+    private static final List<PaletteBlockCtrl> BLOCKS = new ArrayList<PaletteBlockCtrl>();
+    private final PaletteView view;
+
+    /**
+     * Default constructor
+     */
+    public PaletteCtrl() {
+        this.view = new PaletteView();
+
+        // install listeners
+        this.view.addMouseListener(MOUSE_LISTENER);
+    }
+
+    /**
+     * @return the view
+     */
+    public PaletteView getView() {
+        return view;
+    }
+
+    /**
+     * Clear the view
+     */
+    public void clear() {
+        BLOCKS.clear();
+        view.removeAll();
+    }
+
+    /**
+     * Deselects all blocks
+     */
+    public static void clearSelections() {
+        for (PaletteBlockCtrl block : BLOCKS) {
+            block.setSelected(false);
+        }
+    }
+
+    /**
+     * Adds a block to the view.
+     * @param ctrl PaletteBlockCtrl
+     */
+    public void addBlock(PaletteBlockCtrl ctrl) {
+        BLOCKS.add(ctrl);
+        view.add(ctrl.getView());
+    }
+
+    /**
+     * Add all the selected blocks to a XcosDiagram.
+     * @param diagram XcosDiagram
+     * @return true if some block was added
+     */
+    public boolean addSelectedBlocks(final XcosDiagram diagram) {
+        int row = 0;
+        int column = 0;
+        boolean hasNewBlocks = false;
+        for (PaletteBlockCtrl blockCtrl : BLOCKS) {
+            if (!blockCtrl.isSelected()) {
+                continue;
+            }
+
+            BasicBlock basicBlock = (BasicBlock) BlockFactory.createClone(blockCtrl.getBlock());
+            if (basicBlock == null) {
+                continue;
+            }
+
+            // add to the 'recently used blocks' panel
+            PaletteManagerView.get().getPanel().addRecentltyUsedBlock(blockCtrl.getModel());
+
+            // Render it and export it
+            final double margin = 15.0;
+            basicBlock.getGeometry().setX(margin + BLOCK_POSITION.width * column);
+            basicBlock.getGeometry().setY(margin + BLOCK_POSITION.height * row);
+            ++column;
+
+            if (column >= BLOCKS_BY_ROW) {
+                column = 0;
+                ++row;
+            }
+
+            diagram.addCell(basicBlock);
+            diagram.addSelectionCell(basicBlock);
+            BlockPositioning.updateBlockView(basicBlock);
+            hasNewBlocks = true;
+        }
+        return hasNewBlocks;
+    }
+
+    /**
+     * This function is used to get all selected blocks.
+     * @return the transferable object
+     */
+    public synchronized Transferable getTransferable() {
+        Transferable transfer = null;
+        internalGraph.removeCells();
+        if (addSelectedBlocks(internalGraph)) {
+            mxGraphTransferHandler handler = (mxGraphTransferHandler) internalGraph.getAsComponent().getTransferHandler();
+            transfer = handler.createTransferable(internalGraph.getAsComponent());
+            internalGraph.removeCells();
+        }
+        return transfer;
+    }
+}
index 4b4abed..db4f5c6 100644 (file)
 
 package org.scilab.modules.xcos.palette.listener;
 
-import java.awt.Component;
 import java.awt.event.KeyEvent;
 import java.awt.event.KeyListener;
 import java.util.List;
 
-import javax.swing.JScrollPane;
-
 import org.scilab.modules.xcos.Xcos;
-import org.scilab.modules.xcos.block.BasicBlock;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.palette.PaletteBlockCtrl;
+import org.scilab.modules.xcos.palette.PaletteCtrl;
 import org.scilab.modules.xcos.palette.view.PaletteBlockView;
+import org.scilab.modules.xcos.palette.view.PaletteBlockView.StatusUI;
 import org.scilab.modules.xcos.palette.view.PaletteManagerPanel;
-import org.scilab.modules.xcos.palette.view.PaletteManagerView;
-import org.scilab.modules.xcos.palette.view.PaletteSearchView;
 import org.scilab.modules.xcos.palette.view.PaletteView;
 import org.scilab.modules.xcos.utils.XcosConstants;
 import org.scilab.modules.xcos.utils.XcosConstants.PaletteBlockSize;
@@ -56,42 +52,44 @@ public final class PaletteBlockKeyListener implements KeyListener {
             assert size != 0;
 
             final XcosDiagram theDiagram = allDiagrams.get(size - 1);
-            BasicBlock current = control.getBlock();
-            theDiagram.addCell(current);
-
-            PaletteManagerView.get().getPanel().addRecentltyUsedBlock(control.getModel());
-            return;
-        }
+            control.getPaletteCtrl().addSelectedBlocks(theDiagram);
 
-        /** deselects block and loses focus **/
-        if (e.getKeyCode() == KeyEvent.VK_ESCAPE || e.getKeyCode() == KeyEvent.VK_TAB) {
+        /** deselects blocks and loses focus **/
+        } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE || e.getKeyCode() == KeyEvent.VK_TAB) {
+            PaletteCtrl.clearSelections();
             PaletteBlockView currentBlockView = ((PaletteBlockView) e.getSource());
-            currentBlockView.getController().setSelected(false);
             currentBlockView.transferFocusUpCycle();
-            return;
-        }
+
+        /** toggle selection **/
+        } else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
+            PaletteBlockView currentBlockView = ((PaletteBlockView) e.getSource());
+            boolean isSelected = currentBlockView.getController().isSelected();
+            if ((e.getModifiers() & KeyEvent.CTRL_MASK) == 0) {
+                PaletteCtrl.clearSelections();
+            }
+            currentBlockView.getController().setSelected(!isSelected); // toggle
+            currentBlockView.requestFocus();
 
         /** move selection (arrow keys) **/
-        int x = 0;
-        int y = 0;
-        if (e.getKeyCode() == KeyEvent.VK_DOWN) {
-            x = 0;
-            y = 1;
+        } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
+            getNextBlock(e, 0, 1);
         } else if (e.getKeyCode() == KeyEvent.VK_UP) {
-            x = 0;
-            y = -1;
+            getNextBlock(e, 0, -1);
         } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
-            x = 1;
-            y = 0;
+            getNextBlock(e, 1, 0);
         } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
-            x = -1;
-            y = 0;
-        } else {
-            // nothing to do!
-            return;
+            getNextBlock(e, -1, 0);
         }
+    }
 
-        // get position of the next block
+    /**
+     * Get the next block position and handle the selection status
+     * @param e KeyEvent
+     * @param x Initialize x
+     * @param y Initialize y
+     */
+    // CSOFF: ParameterAssignment
+    private void getNextBlock(KeyEvent e, int x, int y) {
         PaletteBlockView currentBlockView = ((PaletteBlockView) e.getSource());
         PaletteBlockSize blockSize = PaletteManagerPanel.getCurrentSize();
 
@@ -105,22 +103,29 @@ public final class PaletteBlockKeyListener implements KeyListener {
             return;
         }
 
-        // select the block
         try {
-            JScrollPane jsp = (JScrollPane) PaletteManagerView.get().getPanel().getRightComponent();
-            Component c = jsp.getViewport().getComponent(0);
-            String cName = c.getName();
-            PaletteView pview;
-            if (cName.equals("PaletteView")) {
-                pview = (PaletteView) c;
-            } else if (cName.equals("PaletteSearchView")) {
-                PaletteSearchView sview = (PaletteSearchView) c;
-                pview = (PaletteView) sview.getComponent(1);
-            } else {
-                return;
+            // gets the current palette view
+            PaletteView pview = currentBlockView.getController().getPaletteCtrl().getView();
+
+            // gets the next PaletteBlockView
+            PaletteBlockView nextBlockView = (PaletteBlockView) pview.getComponentAt(x, y);
+
+            // handle keys to decide the selection type
+            boolean ctrlIsDown = (e.getModifiers() & KeyEvent.CTRL_MASK) != 0;
+            boolean isSelected = nextBlockView.getController().isSelected();
+            if (!ctrlIsDown) {
+                PaletteCtrl.clearSelections();
+                nextBlockView.getController().setSelected(!isSelected); // toggle
+            } else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
+                nextBlockView.getController().setSelected(!isSelected); // toggle
+            } else if (!isSelected) { 
+                nextBlockView.setStatusUI(StatusUI.HOVER);
+            }
+
+            nextBlockView.requestFocus();
+            if (currentBlockView.getStatusUI().equals(StatusUI.HOVER)) {
+                currentBlockView.setStatusUI(StatusUI.NON_SELECTED);
             }
-            PaletteBlockView bview = (PaletteBlockView) pview.getComponentAt(x, y);
-            bview.getController().setSelected(true);
         } catch (ClassCastException err) {
         } catch (NullPointerException err) {
         }
index 239cde3..54aa4f0 100644 (file)
@@ -32,117 +32,135 @@ import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.gui.menuitem.ScilabMenuItem;
 import org.scilab.modules.xcos.Xcos;
 import org.scilab.modules.xcos.XcosTab;
-import org.scilab.modules.xcos.block.BasicBlock;
 import org.scilab.modules.xcos.graph.XcosDiagram;
 import org.scilab.modules.xcos.palette.PaletteBlockCtrl;
+import org.scilab.modules.xcos.palette.PaletteCtrl;
 import org.scilab.modules.xcos.palette.view.PaletteBlockView;
 import org.scilab.modules.xcos.palette.view.PaletteBlockView.StatusUI;
 import org.scilab.modules.xcos.utils.XcosMessages;
 
-/** Implement the default mouse listener for the block */
+/**
+ * Implement the default mouse listener for the block
+ * @author Marcos CARDINOT <mcardinot@gmail.com>
+ * @author Clement DAVID
+ */
 public final class PaletteBlockMouseListener implements MouseListener {
+
     /** Default constructor */
     public PaletteBlockMouseListener() {
     }
 
     /**
-     * Load and perform display update on mouse click.
-     * @param e The associated event
+     * @return opened diagrams
      */
-    @Override
-    public void mouseClicked(MouseEvent e) {
-        if ((e.getClickCount() == 1 && SwingUtilities.isRightMouseButton(e))
-                || e.isPopupTrigger() || XcosMessages.isMacOsPopupTrigger(e)) {
-            /** opens a context menu **/
-
-            ContextMenu menu = ScilabContextMenu.createContextMenu();
+    private List<XcosDiagram> getOpenedDiagrams() {
+        final List<XcosDiagram> allDiagrams = Xcos.getInstance().openedDiagrams();
+        // No diagram opened: should never happen as Xcos opens an empty
+        // diagram when it is launched
+        assert allDiagrams.size() != 0;
+        return allDiagrams;
+    }
 
-            final List<XcosDiagram> allDiagrams = Xcos.getInstance()
-                                                  .openedDiagrams();
-            final PaletteBlockCtrl control = ((PaletteBlockView) e.getSource())
-                                             .getController();
+    /**
+     * Create the context menu.
+     * @param ctrl PaletteBlockCtrl
+     * @param cmd event
+     * @return ContextMenu
+     */
+    @SuppressWarnings("serial")
+    private ContextMenu createContextMenu(final PaletteBlockCtrl ctrl, final String cmd) {
+        final List<XcosDiagram> allDiagrams = getOpenedDiagrams();
 
-            // No diagram opened: should never happen as Xcos opens an empty
-            // diagram when it is launched
-            assert allDiagrams.size() != 0;
+        ContextMenu menu = ScilabContextMenu.createContextMenu();
 
-            if (allDiagrams.size() == 1) {
-                // A single diagram opened: add to this diagram
-                MenuItem addTo = ScilabMenuItem.createMenuItem();
+        if (allDiagrams.size() == 1) {
+            // A single diagram opened: add to this diagram
+            MenuItem addTo = ScilabMenuItem.createMenuItem();
+            addTo.setText(XcosMessages.ADDTO + " " + XcosTab.get(allDiagrams.get(0)).getName());
 
-                addTo.setText(XcosMessages.ADDTO + " "
-                              + XcosTab.get(allDiagrams.get(0)).getName());
-                final XcosDiagram theDiagram = allDiagrams.get(0);
-                addTo.setCallback(new CommonCallBack(e.toString()) {
+            final XcosDiagram theDiagram = allDiagrams.get(0);
+            addTo.setCallback(new CommonCallBack(cmd) {
+                @Override
+                public void callBack() {
+                    ctrl.getPaletteCtrl().addSelectedBlocks(theDiagram);
+                }
+            });
+            menu.add(addTo);
+        } else {
+            // The user has to choose
+            Menu addTo = ScilabMenu.createMenu();
+            addTo.setText(XcosMessages.ADDTO);
+
+            for (int i = 0; i < allDiagrams.size(); i++) {
+                MenuItem diagram = ScilabMenuItem.createMenuItem();
+                final XcosDiagram theDiagram = allDiagrams.get(i);
+                diagram.setText(XcosTab.get(allDiagrams.get(i)).getName());
+                diagram.setCallback(new CommonCallBack(cmd) {
                     @Override
                     public void callBack() {
-                        BasicBlock current = control.getBlock();
-                        theDiagram.addCell(current);
+                        ctrl.getPaletteCtrl().addSelectedBlocks(theDiagram);
                     }
                 });
+                addTo.add(diagram);
+            }
+            menu.add(addTo);
+        }
 
-                menu.add(addTo);
-
-            } else {
-                // The user has to choose
-                Menu addTo = ScilabMenu.createMenu();
-
-                addTo.setText(XcosMessages.ADDTO);
-
-                for (int i = 0; i < allDiagrams.size(); i++) {
-                    MenuItem diagram = ScilabMenuItem.createMenuItem();
-                    final XcosDiagram theDiagram = allDiagrams.get(i);
-                    diagram.setText(XcosTab.get(allDiagrams.get(i)).getName());
-                    diagram.setCallback(new CommonCallBack(e.toString()) {
-                        @Override
-                        public void callBack() {
-                            BasicBlock current = control.getBlock();
-                            theDiagram.addCell(current);
-                        }
-                    });
-                    addTo.add(diagram);
+        menu.getAsSimpleContextMenu().addSeparator();
+
+        MenuItem help = ScilabMenuItem.createMenuItem();
+        help.setText("Block help");
+        help.setCallback(new CommonCallBack(cmd) {
+            @Override
+            public void callBack() {
+                try {
+                    ScilabInterpreterManagement.asynchronousScilabExec(
+                        null, "help", ctrl.getModel().getName());
+                } catch (InterpreterException e) {
+                    e.printStackTrace();
                 }
-
-                menu.add(addTo);
             }
+        });
+        menu.add(help);
 
-            menu.getAsSimpleContextMenu().addSeparator();
+        return menu;
+    }
 
-            MenuItem help = ScilabMenuItem.createMenuItem();
-            help.setText("Block help");
-            help.setCallback(new CommonCallBack(e.toString()) {
-                @Override
-                public void callBack() {
-                    try {
-                        ScilabInterpreterManagement.asynchronousScilabExec(
-                            null, "help", control.getModel().getName());
-                    } catch (InterpreterException e) {
-                        e.printStackTrace();
-                    }
-                }
-            });
-            menu.add(help);
+    /**
+     * Invoked when the mouse is clicked.
+     * @param e MouseEvent
+     */
+    @Override
+    public void mouseClicked(MouseEvent e) {
+        final PaletteBlockCtrl blockCtrl = ((PaletteBlockView) e.getSource()).getController();
+        boolean ctrlIsDown = (e.getModifiers() & MouseEvent.CTRL_MASK) != 0;
 
+        if ((e.getClickCount() == 1 && SwingUtilities.isRightMouseButton(e))
+                || e.isPopupTrigger() || XcosMessages.isMacOsPopupTrigger(e)) {
+            // open a context menu
+            ContextMenu menu = createContextMenu(blockCtrl, e.toString());
             menu.setVisible(true);
-
             ((SwingScilabContextMenu) menu.getAsSimpleContextMenu())
             .setLocation(MouseInfo.getPointerInfo().getLocation().x,
                          MouseInfo.getPointerInfo().getLocation().y);
-        } else if (e.getClickCount() == 2
-                && SwingUtilities.isLeftMouseButton(e)) {
-            /** add the current block to the most recent diagram **/
-
-            final List<XcosDiagram> allDiagrams = Xcos.getInstance()
-                    .openedDiagrams();
-            final PaletteBlockCtrl control = ((PaletteBlockView) e.getSource())
-                    .getController();
-
-            int size = allDiagrams.size();
-            assert size != 0;
-
-            final XcosDiagram theDiagram = allDiagrams.get(size - 1);
-            BasicBlock current = control.getBlock();
-            theDiagram.addCell(current);
+            if (!ctrlIsDown) {
+                PaletteCtrl.clearSelections();
+            }
+            blockCtrl.setSelected(true);
+        } else if (SwingUtilities.isLeftMouseButton(e)) {
+            if (e.getClickCount() == 1) {
+                boolean isSelected = blockCtrl.isSelected();
+                if (!ctrlIsDown) {
+                    PaletteCtrl.clearSelections();
+                }
+                blockCtrl.setSelected(!isSelected); // toggle
+            } else if (e.getClickCount() == 2) {
+                blockCtrl.setSelected(true);
+                // add the current block to the most recent diagram
+                final List<XcosDiagram> allDiagrams = getOpenedDiagrams();
+                XcosDiagram theDiagram = allDiagrams.get(allDiagrams.size() - 1);
+                blockCtrl.getPaletteCtrl().addSelectedBlocks(theDiagram);
+            }
         }
     }
 
@@ -173,13 +191,11 @@ public final class PaletteBlockMouseListener implements MouseListener {
     }
 
     /**
-     * Select on mouse press.
-     * @param e MouseEvent
+     * Not used
+     * @param e Not used
      */
     @Override
-    public void mousePressed(MouseEvent e) {
-        PaletteBlockView view = (PaletteBlockView) e.getSource();
-        view.getController().setSelected(true);
+    public void mouseReleased(MouseEvent e) {
     }
 
     /**
@@ -187,6 +203,6 @@ public final class PaletteBlockMouseListener implements MouseListener {
      * @param e Not used
      */
     @Override
-    public void mouseReleased(MouseEvent e) {
+    public void mousePressed(MouseEvent e) {
     }
 }
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteDragGestureListener.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteDragGestureListener.java
new file mode 100644 (file)
index 0000000..e519445
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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.listener;
+
+import java.awt.Point;
+import java.awt.datatransfer.Transferable;
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DragGestureListener;
+import java.awt.dnd.InvalidDnDOperationException;
+
+import org.scilab.modules.gui.messagebox.ScilabModalDialog;
+import org.scilab.modules.gui.messagebox.ScilabModalDialog.IconType;
+import org.scilab.modules.xcos.palette.PaletteBlockCtrl;
+import org.scilab.modules.xcos.palette.PaletteCtrl;
+import org.scilab.modules.xcos.palette.view.PaletteBlockView;
+import org.scilab.modules.xcos.palette.view.PaletteManagerView;
+import org.scilab.modules.xcos.utils.XcosMessages;
+
+/**
+ * Install the handler for dragging nodes into a graph.
+ * @author Marcos CARDINOT <mcardinot@gmail.com>
+ */
+public final class PaletteDragGestureListener implements DragGestureListener {
+
+    /**
+     * Default constructor
+     */
+    public PaletteDragGestureListener() {
+    }
+
+    /**
+     * @param e The associated event
+     */
+    @Override
+    public void dragGestureRecognized(DragGestureEvent e) {
+        PaletteBlockCtrl blockCtrl = ((PaletteBlockView) e.getComponent()).getController();
+        PaletteCtrl paletteCtrl = blockCtrl.getPaletteCtrl();
+
+        if (paletteCtrl == null) {
+            return;
+        }
+        blockCtrl.setSelected(true);
+
+        if (PaletteManagerView.get() == null) {
+            PaletteManagerView.restore(null);
+        }
+        final PaletteManagerView winView = PaletteManagerView.get();
+
+        winView.setInfo(XcosMessages.LOADING_BLOCKS);
+        try {
+            Transferable transfer = paletteCtrl.getTransferable();
+            if (transfer != null) {
+                e.startDrag(null, null, new Point(), transfer, null);
+            }
+        } catch (InvalidDnDOperationException exception) {
+            ScilabModalDialog.show(winView, XcosMessages.UNABLE_TO_LOAD_SELECTED_BLOCKS,
+                                   XcosMessages.XCOS_ERROR, IconType.ERROR_ICON);
+        } finally {
+            winView.setInfo(XcosMessages.EMPTY_INFO);
+        }
+    }
+}
index 406caef..b4b1670 100644 (file)
@@ -24,6 +24,7 @@ import javax.swing.event.TreeSelectionEvent;
 import javax.swing.event.TreeSelectionListener;
 
 import org.scilab.modules.xcos.palette.PaletteBlockCtrl;
+import org.scilab.modules.xcos.palette.PaletteCtrl;
 import org.scilab.modules.xcos.palette.model.Category;
 import org.scilab.modules.xcos.palette.model.Custom;
 import org.scilab.modules.xcos.palette.model.PaletteBlock;
@@ -32,7 +33,6 @@ import org.scilab.modules.xcos.palette.model.PreLoaded;
 import org.scilab.modules.xcos.palette.view.PaletteConfiguratorListView;
 import org.scilab.modules.xcos.palette.view.PaletteConfiguratorListView.PaletteListModel;
 import org.scilab.modules.xcos.palette.view.PaletteManagerPanel;
-import org.scilab.modules.xcos.palette.view.PaletteView;
 
 /**
  * Implement the tree selection listener
@@ -80,12 +80,12 @@ public class PaletteManagerTreeSelectionListener implements TreeSelectionListene
         } else if (node instanceof PreLoaded) {
             final PreLoaded palette = (PreLoaded) node;
 
-            final PaletteView view = new PaletteView();
+            final PaletteCtrl ctrl = new PaletteCtrl();
             for (PaletteBlock b : palette.getBlock()) {
-                view.add(new PaletteBlockCtrl(b).getView());
+                new PaletteBlockCtrl(ctrl, b);
             }
 
-            panel.setViewportView(view);
+            panel.setViewportView(ctrl.getView());
             nodeView = panel;
         } else if (node instanceof Custom) {
             nodeView = paletteManagerPanel.openDiagramAsPal(node);
diff --git a/scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteMouseListener.java b/scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/listener/PaletteMouseListener.java
new file mode 100644 (file)
index 0000000..d8cb333
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * 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.listener;
+
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+
+import org.scilab.modules.xcos.palette.PaletteCtrl;
+
+/**
+ * Implement the default mouse listener for the palette view
+ * @author Marcos CARDINOT <mcardinot@gmail.com>
+ */
+public final class PaletteMouseListener implements MouseListener {
+
+    /** Default constructor */
+    public PaletteMouseListener() {
+    }
+
+    /**
+     * Clear selection when mouse is pressed
+     * @param e MouseEvent
+     */
+    @Override
+    public void mousePressed(MouseEvent e) {
+        PaletteCtrl.clearSelections();
+    }
+
+    /**
+     * Invoked when the mouse enters a palette view.
+     * @param e MouseEvent
+     */
+    @Override
+    public void mouseEntered(MouseEvent e) {
+    }
+
+    /**
+     * Invoked when the mouse exits a palette view.
+     * @param e MouseEvent
+     */
+    @Override
+    public void mouseExited(MouseEvent e) {
+    }
+
+    /**
+     * Not used
+     * @param e Not used
+     */
+    @Override
+    public void mouseReleased(MouseEvent e) {
+    }
+
+    /**
+     * Not used
+     * @param e Not used
+     */
+    @Override
+    public void mouseClicked(MouseEvent e) {
+    }
+}
index 94ba82a..4291fe5 100644 (file)
@@ -40,7 +40,7 @@ public final class PaletteBlockView extends JLabel {
             .createEtchedBorder(EtchedBorder.LOWERED);
     private static final Border NON_SELECTED_BORDER = BorderFactory
             .createEmptyBorder();
-
+    private StatusUI statusUI;
     private PaletteBlockCtrl controller;
 
     /**
@@ -62,6 +62,7 @@ public final class PaletteBlockView extends JLabel {
     public PaletteBlockView(PaletteBlockCtrl controller) {
         super(controller.getModel().getName(), SwingConstants.CENTER);
         this.controller = controller;
+        setStatusUI(StatusUI.NON_SELECTED);
         ZoomAction.registerKeyAction(getActionMap(), getInputMap());
         initComponents();
     }
@@ -99,9 +100,17 @@ public final class PaletteBlockView extends JLabel {
     }
 
     /**
+     * @return border status
+     */
+    public StatusUI getStatusUI() {
+        return statusUI;
+    }
+
+    /**
      * @param status Border status
      */
     public void setStatusUI(StatusUI status) {
+        statusUI = status;
         if (status == StatusUI.SELECTED) {
             setBorder(SELECTED_BORDER);
         } else if (status == StatusUI.HOVER) {
index d19c909..4fddb69 100644 (file)
@@ -130,7 +130,7 @@ public class PaletteManagerPanel extends JSplitPane {
      */
     public void addRecentltyUsedBlock(PaletteBlock block) {
         PaletteNode currentNode = (PaletteNode) tree.getLastSelectedPathComponent();
-        if (currentNode.getName().equals(RECENTLY_USED_BLOCKS)) {
+        if (currentNode != null && currentNode.getName().equals(RECENTLY_USED_BLOCKS)) {
             return;
         }
 
@@ -171,6 +171,7 @@ public class PaletteManagerPanel extends JSplitPane {
      * Zoom
      * @param newSize new paletteblocksize enum
      */
+    // CSOFF: CyclomaticComplexity
     private void zoom(PaletteBlockSize newSize) {
         if (newSize == null || newSize == currentSize) {
             return;
index 7a42bb3..5382bad 100644 (file)
@@ -18,6 +18,7 @@ import javax.swing.BoxLayout;
 import javax.swing.JLabel;
 
 import org.scilab.modules.xcos.palette.PaletteBlockCtrl;
+import org.scilab.modules.xcos.palette.PaletteCtrl;
 import org.scilab.modules.xcos.palette.model.PaletteBlock;
 
 /**
@@ -28,7 +29,7 @@ import org.scilab.modules.xcos.palette.model.PaletteBlock;
 public class PaletteSearchView extends PaletteView {
 
     private JLabel header;
-    private PaletteView paletteview;
+    private PaletteCtrl paletteCtrl;
 
     /**
      * Default constructor
@@ -36,22 +37,23 @@ public class PaletteSearchView extends PaletteView {
     public PaletteSearchView() {
         setName("PaletteSearchView");
         this.header = new JLabel();
-        this.paletteview = new PaletteView();
+        this.paletteCtrl = new PaletteCtrl();
     }
 
     /**
      * Setup component
      */
     public void initComponents() {
-        paletteview.removeAll();
+        paletteCtrl.clear();
         removeAll();
 
+        PaletteView view = paletteCtrl.getView();
         header.setAlignmentX(Component.LEFT_ALIGNMENT);
-        paletteview.setAlignmentX(Component.LEFT_ALIGNMENT);
+        view.setAlignmentX(Component.LEFT_ALIGNMENT);
 
         setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
         add(header);
-        add(paletteview);
+        add(view);
     }
 
     /**
@@ -67,6 +69,6 @@ public class PaletteSearchView extends PaletteView {
      * @param block PaletteBlock
      */
     public void addBlock(PaletteBlock block) {
-        paletteview.add(new PaletteBlockCtrl(block).getView());
+        new PaletteBlockCtrl(paletteCtrl, block);
     }
 }
index 8dcf593..aa87ec8 100644 (file)
@@ -55,6 +55,7 @@ public class PaletteView extends JPanel implements Scrollable {
                                          XcosConstants.PALETTE_HMARGIN,
                                          XcosConstants.PALETTE_VMARGIN));
 
+        // if this panel gains focus, try to select the first block!
         setFocusable(true);
         addFocusListener(new FocusListener() {
             @Override
index ec5b961..7156b3b 100644 (file)
@@ -71,6 +71,10 @@ public final class XcosMessages {
     public static final String ZOOM_IN = Messages.gettext("Zoom In");
     public static final String ZOOM_OUT = Messages.gettext("Zoom Out");
 
+    public static final String UNABLE_TO_LOAD_BLOCK = Messages.gettext("Unable to load block from %s .");
+    public static final String UNABLE_TO_LOAD_SELECTED_BLOCKS = Messages.gettext("Unable to load the selected blocks.");
+    public static final String LOADING_BLOCKS = Messages.gettext("Loading blocks") + DOTS;
+
     /* Palette menu in palette browser */
     public static final String LOAD_AS_PAL = Messages.gettext("Load as palette") + DOTS;
     public static final String USER_DEFINED = Messages.gettext("User-Defined");
@@ -318,7 +322,9 @@ public final class XcosMessages {
      * @return true if Java 1.5 and MacOS and mouse clic and ctrl activated
      */
     public static boolean isMacOsPopupTrigger(MouseEvent e) {
-        return (SwingUtilities.isLeftMouseButton(e) && e.isControlDown() && (System.getProperty("os.name").toLowerCase().indexOf("mac") != -1) && (System
-                .getProperty("java.specification.version").equals("1.5")));
+        return (SwingUtilities.isLeftMouseButton(e)
+                && e.isControlDown()
+                && (System.getProperty("os.name").toLowerCase().indexOf("mac") != -1)
+                && (System.getProperty("java.specification.version").equals("1.5")));
     }
 }