com.frinika.sequencer.gui
Class ItemPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.frinika.sequencer.gui.ItemPanel
All Implemented Interfaces:
Snapable, SongPositionListener, java.awt.event.ComponentListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible
Direct Known Subclasses:
NotationEditor, PartView, PianoRollPanelAdapter

public abstract class ItemPanel
extends javax.swing.JPanel
implements SongPositionListener, java.awt.event.ComponentListener, Snapable

Basis for PianoRoll and PartView We imagine the pianoRoll/trackView to be drawn on a large "virtualScreen" such that the origins (pitch=0,beat=0) coincide with (0,0) ItemPanel provides a view of this through itemViewRect.

Author:
pjl
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  boolean altIsDown
           
protected  boolean controlIsDown
           
protected  boolean dragArmed
           
protected  Item dragItem
           
protected  int dragMode
           
protected  ToolAdapter dragViewTool
           
protected  ToolAdapter eraseTool
           
protected  boolean isChanging
           
protected  java.awt.Rectangle lastItemViewRect
           
static int OVER_ENVELOPE_GAIN
           
static int OVER_ENVELOPE_LEFT
           
static int OVER_ENVELOPE_RIGHT
           
static int OVER_ITEM_LEFT
           
static int OVER_ITEM_MIDDLE
           
static int OVER_ITEM_RIGHT
           
protected static int OVER_ITEM_TOP
           
static int OVER_NOTHING
           
protected  ProjectContainer project
           
protected  ToolAdapter rectZoomTool
           
protected  ItemScrollPane scroller
           
protected  ToolAdapter selectTool
           
protected  FrinikaSequencer sequencer
           
protected  int ticksPerBeat
           
protected  boolean timeBased
           
protected  ToolAdapter tool
           
protected  javax.swing.JToolBar toolBar
           
 double userToScreen
           
protected  ToolAdapter writeTool
           
protected  int xAnchor
           
protected  int yAnchor
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
protected ItemPanel(ProjectContainer project, ItemScrollPane scroller, boolean hasTimeLine, boolean canScrollY, double ticksToScreen, boolean sampleBased)
           
 
Method Summary
 void armDrag(java.awt.Point p, Item item)
           
abstract  void clientAddToSelection(Item item)
           
abstract  void clientClearSelection()
          Clears all items from the ItemPanels selection
abstract  void clientNotifySelectionChange()
           
abstract  void clientRemoveFromSelection(Item item)
           
 void componentHidden(java.awt.event.ComponentEvent arg0)
           
 void componentMoved(java.awt.event.ComponentEvent arg0)
           
 void componentResized(java.awt.event.ComponentEvent arg0)
           
 void componentShown(java.awt.event.ComponentEvent arg0)
           
 void copyImageToScreen(java.awt.Graphics g)
           
abstract  void dragTo(java.awt.Point p)
           
abstract  void endDrag()
          This will be called when the mouse is released from a dragging operation
abstract  void erase(Item item)
           
 void feedBack(Item item)
           
 void followSong(boolean b)
           
abstract  int getHoverStateAt(java.awt.Point p)
           
 ProjectContainer getProjectContainer()
           
 ItemScrollPane getScroller()
           
abstract  double getSnapQuantization()
           
 ToolAdapter getTool(java.lang.String name)
          Get the tool associated with name.
 java.lang.String getToolTipText(java.awt.event.MouseEvent event)
           
 java.awt.Rectangle getVirtualScreenRect()
           
 ExtendingRangeModel getXRangeModel()
           
 javax.swing.DefaultBoundedRangeModel getYRangeModel()
           
 void ignorePartWarp(boolean b)
           
 boolean isFollowSong()
           
 boolean isRightButtonPressed()
           
abstract  boolean isSnapQuantized()
           
abstract  Item itemAt(java.awt.Point p)
           
 void map(java.awt.Point point)
           
 int mapX(int x)
           
 void notifyTickPosition(long tick)
          This method is called each time a new tick is played by the sequencer.
 void paintComponent(java.awt.Graphics g)
           
protected abstract  void paintImageImpl(java.awt.Rectangle clipRect, java.awt.Graphics2D g)
           
protected abstract  void paintImageImplLabel(java.awt.Graphics2D graphics)
          override this to draw on top of screen
protected  void paintImages()
          paint the itemImage and timeLineImage.
 void paintTimeImpl(int xClip, int widthClip, java.awt.Graphics g1)
           
 void paintTimeImplUser(int xClip, int widthClip, java.awt.Graphics g1)
           
 boolean pointInTimeLine(int y)
           
protected  void rebuildXScrollBars()
           
 void rectZoomFinished()
           
 void repaintItems()
          flag reconstruction the image of the notes and request a repaint
 boolean requiresNotificationOnEachTick()
          Your implementation should return true if your listener requires to be notified for each and every tick.
abstract  void rightButtonPressedOnItem(int x, int y)
           
 void scaleX(double fact)
          This is called when the scale of painoRoll to screen mapping changes the sub class must workpout the new postion of all items.
 long screenToTickAbs(int x, boolean quantizeMe)
          Convert virtual screen x to a tick.
 long screenToTickAbs(int x, boolean quantizeMe, boolean drumMode)
          Convert virtual screen x to a tick.
 long screenToTickRel(int x, int dx, boolean quantizeMe)
          Convert delta on the virtual screen to a tick with optional quntization
protected  void scrollItemImageX()
           
protected  void scrollItemImageY()
           
 void scrollRectToVisible(java.awt.Rectangle r)
           
 boolean scrollToContain(int x)
           
 java.awt.Point scrollToContian(java.awt.Point p)
           
abstract  void selectInRect(java.awt.Rectangle rect, boolean shift)
          Add items in the rectangle to the ItemPanels selection.
 void setAltState(boolean b)
           
 void setControlState(boolean b)
          method to let the ItemPanel know the state of the control key Look at controlIsDown field.
 void setDirty()
          Force a complete redraw on next repaint();
 void setDragMode(int mode)
           
abstract  void setFocus(Item item)
           
 void setIgnoreRepaints(boolean yes)
           
 void setRightButton(boolean buttonState)
           
abstract  void setSnapQuantization(double quant)
           
abstract  void setSnapQuantized(boolean b)
           
abstract  void setTimeAtX(int x)
           
 void setTool(java.lang.String name)
           
 void setToolBar(ItemRollToolBar bar)
           
 void setX(int xNew)
          Sets the x cordinate of the viewport on the items space.
 void setY(int yNew)
           
 double userToScreen(double userTIme)
          Convert time or tick to virtual screen x
 void writeDraggedAt(java.awt.Point p)
          Notififiction that mouse has been drag during after a writeTool press.
protected abstract  void writePressedAt(java.awt.Point p)
           
protected abstract  void writeReleasedAt(java.awt.Point p)
           
 void zoomIn()
           
 void zoomOut()
           
 void zoomToRect(java.awt.Rectangle rect)
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OVER_NOTHING

public static final int OVER_NOTHING
See Also:
Constant Field Values

OVER_ITEM_MIDDLE

public static final int OVER_ITEM_MIDDLE
See Also:
Constant Field Values

OVER_ITEM_RIGHT

public static final int OVER_ITEM_RIGHT
See Also:
Constant Field Values

OVER_ITEM_LEFT

public static final int OVER_ITEM_LEFT
See Also:
Constant Field Values

OVER_ITEM_TOP

protected static final int OVER_ITEM_TOP
See Also:
Constant Field Values

OVER_ENVELOPE_LEFT

public static final int OVER_ENVELOPE_LEFT
See Also:
Constant Field Values

OVER_ENVELOPE_RIGHT

public static final int OVER_ENVELOPE_RIGHT
See Also:
Constant Field Values

OVER_ENVELOPE_GAIN

public static final int OVER_ENVELOPE_GAIN
See Also:
Constant Field Values

lastItemViewRect

protected java.awt.Rectangle lastItemViewRect

ticksPerBeat

protected int ticksPerBeat

userToScreen

public double userToScreen

timeBased

protected boolean timeBased

toolBar

protected javax.swing.JToolBar toolBar

xAnchor

protected int xAnchor

yAnchor

protected int yAnchor

scroller

protected ItemScrollPane scroller

sequencer

protected FrinikaSequencer sequencer

dragArmed

protected boolean dragArmed

dragMode

protected int dragMode

project

protected ProjectContainer project

selectTool

protected ToolAdapter selectTool

eraseTool

protected ToolAdapter eraseTool

writeTool

protected ToolAdapter writeTool

dragViewTool

protected ToolAdapter dragViewTool

rectZoomTool

protected ToolAdapter rectZoomTool

tool

protected ToolAdapter tool

dragItem

protected Item dragItem

controlIsDown

protected boolean controlIsDown

altIsDown

protected boolean altIsDown

isChanging

protected boolean isChanging
Constructor Detail

ItemPanel

protected ItemPanel(ProjectContainer project,
                    ItemScrollPane scroller,
                    boolean hasTimeLine,
                    boolean canScrollY,
                    double ticksToScreen,
                    boolean sampleBased)
Method Detail

getToolTipText

public java.lang.String getToolTipText(java.awt.event.MouseEvent event)
Overrides:
getToolTipText in class javax.swing.JComponent

getScroller

public ItemScrollPane getScroller()

componentHidden

public void componentHidden(java.awt.event.ComponentEvent arg0)
Specified by:
componentHidden in interface java.awt.event.ComponentListener

componentMoved

public void componentMoved(java.awt.event.ComponentEvent arg0)
Specified by:
componentMoved in interface java.awt.event.ComponentListener

componentResized

public void componentResized(java.awt.event.ComponentEvent arg0)
Specified by:
componentResized in interface java.awt.event.ComponentListener

componentShown

public void componentShown(java.awt.event.ComponentEvent arg0)
Specified by:
componentShown in interface java.awt.event.ComponentListener

writePressedAt

protected abstract void writePressedAt(java.awt.Point p)

writeReleasedAt

protected abstract void writeReleasedAt(java.awt.Point p)

dragTo

public abstract void dragTo(java.awt.Point p)

endDrag

public abstract void endDrag()
This will be called when the mouse is released from a dragging operation


getVirtualScreenRect

public java.awt.Rectangle getVirtualScreenRect()

itemAt

public abstract Item itemAt(java.awt.Point p)

mapX

public int mapX(int x)

map

public void map(java.awt.Point point)
Parameters:
point -

notifyTickPosition

public void notifyTickPosition(long tick)
Description copied from interface: SongPositionListener
This method is called each time a new tick is played by the sequencer. Note that this method should return as soon as possible (immediately).

Specified by:
notifyTickPosition in interface SongPositionListener

scrollToContain

public boolean scrollToContain(int x)

copyImageToScreen

public void copyImageToScreen(java.awt.Graphics g)

paintImageImpl

protected abstract void paintImageImpl(java.awt.Rectangle clipRect,
                                       java.awt.Graphics2D g)

paintImages

protected void paintImages()
paint the itemImage and timeLineImage. Notes:is it worth doing copyArea if we have a wide static window ? Maybe for the user scroll ?


paintImageImplLabel

protected abstract void paintImageImplLabel(java.awt.Graphics2D graphics)
override this to draw on top of screen

Parameters:
graphics -

paintTimeImpl

public void paintTimeImpl(int xClip,
                          int widthClip,
                          java.awt.Graphics g1)

paintTimeImplUser

public void paintTimeImplUser(int xClip,
                              int widthClip,
                              java.awt.Graphics g1)

scaleX

public void scaleX(double fact)
This is called when the scale of painoRoll to screen mapping changes the sub class must workpout the new postion of all items.


screenToTickAbs

public long screenToTickAbs(int x,
                            boolean quantizeMe)
Convert virtual screen x to a tick. with optional quantization Do not use this if x is a delta quantity

Parameters:
x -
Returns:

screenToTickAbs

public long screenToTickAbs(int x,
                            boolean quantizeMe,
                            boolean drumMode)
Convert virtual screen x to a tick. with optional quantization if (drumMode) quantize using round not truncate Do not use this if x is a delta quantity

Parameters:
x -
Returns:

screenToTickRel

public long screenToTickRel(int x,
                            int dx,
                            boolean quantizeMe)
Convert delta on the virtual screen to a tick with optional quntization

Parameters:
x - reference point to deduce bar boundaries
dx - screen delta to convert
Returns:

getSnapQuantization

public abstract double getSnapQuantization()
Specified by:
getSnapQuantization in interface Snapable

isSnapQuantized

public abstract boolean isSnapQuantized()

scrollItemImageX

protected void scrollItemImageX()

scrollItemImageY

protected void scrollItemImageY()

scrollRectToVisible

public void scrollRectToVisible(java.awt.Rectangle r)
Overrides:
scrollRectToVisible in class javax.swing.JComponent

scrollToContian

public java.awt.Point scrollToContian(java.awt.Point p)

clientClearSelection

public abstract void clientClearSelection()
Clears all items from the ItemPanels selection


selectInRect

public abstract void selectInRect(java.awt.Rectangle rect,
                                  boolean shift)
Add items in the rectangle to the ItemPanels selection.


setIgnoreRepaints

public void setIgnoreRepaints(boolean yes)

setX

public void setX(int xNew)
Sets the x cordinate of the viewport on the items space.

Parameters:
xNew -

setY

public void setY(int yNew)

userToScreen

public double userToScreen(double userTIme)
Convert time or tick to virtual screen x

Parameters:
userTIme -
Returns:

zoomIn

public void zoomIn()

zoomOut

public void zoomOut()

zoomToRect

public void zoomToRect(java.awt.Rectangle rect)

rebuildXScrollBars

protected void rebuildXScrollBars()

setRightButton

public void setRightButton(boolean buttonState)

isRightButtonPressed

public boolean isRightButtonPressed()
Returns:
Returns the rightButtonPressed.

followSong

public void followSong(boolean b)
Parameters:
b - if true panel will auto scroll to follow sequencer songPosition.

isFollowSong

public boolean isFollowSong()

setTimeAtX

public abstract void setTimeAtX(int x)

requiresNotificationOnEachTick

public boolean requiresNotificationOnEachTick()
Description copied from interface: SongPositionListener
Your implementation should return true if your listener requires to be notified for each and every tick. Otherwise (which is in most cases) return false. WARNING: If you return true on this method, you MUST return absolutely immediately everytime. Otherwise it may result in a halting song.

Specified by:
requiresNotificationOnEachTick in interface SongPositionListener
Returns:

pointInTimeLine

public boolean pointInTimeLine(int y)

setToolBar

public void setToolBar(ItemRollToolBar bar)

armDrag

public void armDrag(java.awt.Point p,
                    Item item)

rightButtonPressedOnItem

public abstract void rightButtonPressedOnItem(int x,
                                              int y)

clientAddToSelection

public abstract void clientAddToSelection(Item item)

clientRemoveFromSelection

public abstract void clientRemoveFromSelection(Item item)

erase

public abstract void erase(Item item)

repaintItems

public void repaintItems()
flag reconstruction the image of the notes and request a repaint


paintComponent

public void paintComponent(java.awt.Graphics g)
Overrides:
paintComponent in class javax.swing.JComponent

rectZoomFinished

public void rectZoomFinished()

getHoverStateAt

public abstract int getHoverStateAt(java.awt.Point p)

setDragMode

public void setDragMode(int mode)

getProjectContainer

public ProjectContainer getProjectContainer()

setTool

public void setTool(java.lang.String name)

getTool

public ToolAdapter getTool(java.lang.String name)
Get the tool associated with name.

Parameters:
name -
Returns:

writeDraggedAt

public void writeDraggedAt(java.awt.Point p)
Notififiction that mouse has been drag during after a writeTool press. Default to ignoring it

Parameters:
p -

setSnapQuantization

public abstract void setSnapQuantization(double quant)
Specified by:
setSnapQuantization in interface Snapable

feedBack

public void feedBack(Item item)

setSnapQuantized

public abstract void setSnapQuantized(boolean b)

setControlState

public void setControlState(boolean b)
method to let the ItemPanel know the state of the control key Look at controlIsDown field.


setDirty

public void setDirty()
Force a complete redraw on next repaint();


setFocus

public abstract void setFocus(Item item)

ignorePartWarp

public void ignorePartWarp(boolean b)

clientNotifySelectionChange

public abstract void clientNotifySelectionChange()

getXRangeModel

public ExtendingRangeModel getXRangeModel()

getYRangeModel

public javax.swing.DefaultBoundedRangeModel getYRangeModel()

setAltState

public void setAltState(boolean b)