p3j.gui.panels.matrices
Class GridBehaviourAdapter

java.lang.Object
  extended by p3j.gui.panels.matrices.GridBehaviourAdapter
All Implemented Interfaces:
ActionListener, EventListener

public class GridBehaviourAdapter
extends Object
implements ActionListener

An adapter to integrate Copy/Paste-Behaviour to JGrid. Implements 'fast' navigation and selection by pressing CTRL + Arrow or CTRL + SHIFT + Arrow. Implements clipboard operations to deliver a user-friendly UI. Inspired by code from Nils O. Sel(ao)sdal (see http://groups.google.com/group/comp .lang.java.gui/browse_frm/thread/2289d2f55aaed5ad /3665b8ac63e4656a?tvc=1&q=copy+paste+excel+nach+jtable#3665b8ac63e4656a) Created on January 10, 2007

Author:
Christina Bohk, Roland Ewald

Field Summary
static String ACTION_COMMAND_DOWN
          The action command for 'down'.
static String ACTION_COMMAND_LEFT
          The action command for 'left'
static String ACTION_COMMAND_RIGHT
          The action command for 'right'.
static String ACTION_COMMAND_UP
          The action command for 'up'.
static int DIR_DOWN
          Downwards.
static int DIR_LEFT
          Left direction.
static int DIR_RIGHT
          Right direction.
static int DIR_UP
          Upwards.
static String FAST_PREFIX
          The prefix for 'fast' action commands.
static String FAST_SELECTION_CMD_PREFIX
          The prefix for 'fast' action commands on the selection.
 
Constructor Summary
GridBehaviourAdapter(net.sf.jeppers.grid.JGrid target)
          Default constructor.
 
Method Summary
 void actionPerformed(ActionEvent e)
           
protected  void copyToClipBoard(boolean cut)
          Copies or cuts selected values to clipboard.
static KeyStroke getCopyKeyStroke()
          Returns KeyStroke for copying to clipboard (CTRL + C).
static KeyStroke getCutKeyStroke()
          Returns KeyStroke for cutting to clipboard (CTRL + X).
static KeyStroke getPasteKeyStroke()
          Returns KeyStroke for pasting from clipboard (CTRL + V).
protected  String getValue(boolean modifyX, int offSet, int currentRow, int currentCol, int rowCount, int colCount)
          Gets a value from the JGrid component.
protected  void moveFast(p3j.gui.panels.matrices.Direction direction, boolean select)
          Emulates positioning when CTRIL is pressed.
protected  void pasteFromClipboard()
          Pastes from clipboard.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACTION_COMMAND_RIGHT

public static final String ACTION_COMMAND_RIGHT
The action command for 'right'.

See Also:
Constant Field Values

ACTION_COMMAND_LEFT

public static final String ACTION_COMMAND_LEFT
The action command for 'left'

See Also:
Constant Field Values

ACTION_COMMAND_UP

public static final String ACTION_COMMAND_UP
The action command for 'up'.

See Also:
Constant Field Values

ACTION_COMMAND_DOWN

public static final String ACTION_COMMAND_DOWN
The action command for 'down'.

See Also:
Constant Field Values

FAST_PREFIX

public static final String FAST_PREFIX
The prefix for 'fast' action commands.

See Also:
Constant Field Values

FAST_SELECTION_CMD_PREFIX

public static final String FAST_SELECTION_CMD_PREFIX
The prefix for 'fast' action commands on the selection.

See Also:
Constant Field Values

DIR_UP

public static final int DIR_UP
Upwards.

See Also:
Constant Field Values

DIR_RIGHT

public static final int DIR_RIGHT
Right direction.

See Also:
Constant Field Values

DIR_DOWN

public static final int DIR_DOWN
Downwards.

See Also:
Constant Field Values

DIR_LEFT

public static final int DIR_LEFT
Left direction.

See Also:
Constant Field Values
Constructor Detail

GridBehaviourAdapter

public GridBehaviourAdapter(net.sf.jeppers.grid.JGrid target)
Default constructor.

Parameters:
target - the grid of which the behaviour shall be controlled
Method Detail

getCopyKeyStroke

public static KeyStroke getCopyKeyStroke()
Returns KeyStroke for copying to clipboard (CTRL + C).

Returns:
key stroke for copy

getCutKeyStroke

public static KeyStroke getCutKeyStroke()
Returns KeyStroke for cutting to clipboard (CTRL + X).

Returns:
key stroke for cut

getPasteKeyStroke

public static KeyStroke getPasteKeyStroke()
Returns KeyStroke for pasting from clipboard (CTRL + V).

Returns:
key stroke for paste

actionPerformed

public void actionPerformed(ActionEvent e)
Specified by:
actionPerformed in interface ActionListener

copyToClipBoard

protected void copyToClipBoard(boolean cut)
Copies or cuts selected values to clipboard.

Parameters:
cut - if true, values will be cut out

pasteFromClipboard

protected void pasteFromClipboard()
Pastes from clipboard.


moveFast

protected void moveFast(p3j.gui.panels.matrices.Direction direction,
                        boolean select)
Emulates positioning when CTRIL is pressed. Used for fast selection and navigation in the JGrid. This methods walks in the given Direction until it encounters an empty field or the end of the matrix.

Parameters:
direction - the direction in which to go
select - flag to determine if passed elements shall be selected (i.e., is SHIFT also pressed?)

getValue

protected String getValue(boolean modifyX,
                          int offSet,
                          int currentRow,
                          int currentCol,
                          int rowCount,
                          int colCount)
Gets a value from the JGrid component. Checks bounds etc.

Parameters:
modifyX - flag to determine whether X is modified (true) or Y is modified (false)
offSet - either -1 or 1, depending on the direction and whether the column/row index has to be incremented or decremented to go in this direction, see Direction.getOffset()
currentRow - current row number
currentCol - current column number
rowCount - number of rows
colCount - number of columns
Returns:
String representation of next value in path


Copyright © 2012. All Rights Reserved.