com.groovemanager.sampled.waveform
Class MarkableWaveFormDisplay

java.lang.Object
  extended by com.groovemanager.sampled.waveform.AbstractWaveFormDisplay
      extended by com.groovemanager.sampled.waveform.SelectableWaveFormDisplay
          extended by com.groovemanager.sampled.waveform.MarkableWaveFormDisplay
All Implemented Interfaces:
Markable, Selectable
Direct Known Subclasses:
WaveFormDisplay

public abstract class MarkableWaveFormDisplay
extends SelectableWaveFormDisplay
implements Markable

This class extends SelectableWaveFormDisplay to implement the Markable interface. The Markers are made visible and editable if wanted.

Author:
Manu Robledo

Field Summary
protected  boolean editMarkers
          Indicates whether Markers can be added, moved or removed on this WaveFormDisplay
protected  java.util.ArrayList markableListeners
          List of MarkableListeners
protected  java.util.SortedSet markers
          Set of all markers
protected static int MOUSE_TOLERANCE
           
protected  Marker selectedMarker
          The currently selected Marker if any
 
Fields inherited from class com.groovemanager.sampled.waveform.SelectableWaveFormDisplay
left, mouseDown, pos, right, selectableListeners, selStartedAt
 
Fields inherited from class com.groovemanager.sampled.waveform.AbstractWaveFormDisplay
channelSpacing, leftOffset, listeners, scrollFactor, source, topOffset, zoomFactor
 
Constructor Summary
MarkableWaveFormDisplay()
           
 
Method Summary
 void addMarkableListener(MarkableListener listener)
          Add a MarkableListener that will be notified of any changes made to this Markable instance
 void addMarker(int position, java.lang.String name)
          Add a Marker with the given name to this Markable at the given position
protected  void addMarker(Marker m)
          Internal method for adding a Marker
private  void deHighlightMarker(Marker m)
          Dehighlight the given marker to indicate this one is no more the currently selected Marker
 void deselectMarker()
          Deselect the currently selected Marker, if any
protected abstract  void drawHighlightedMarker(Marker m)
          Draw the given Marker in selected state
protected abstract  void drawMarker(Marker m)
          Draw the given Marker on the WaveFormDisplay
protected abstract  void eraseHighlightedMarker(Marker m)
          Erase the given Marker that has been drawn in selected state before
protected abstract  void eraseMarker(Marker m)
          Erase the given marker from the WaveformDisplay
 Marker getMarker(int index)
          Get the Marker at the given index
 int getMarkerCount()
          Get the current number of Markers contained in this Markable
protected  Marker getMarkerFromMousePos(int mousePos)
          Get the Marker that is nearest to the given mouse position, but only if it is not more than MOUSE_TOLERANCE pixels away.
 Marker[] getMarkers()
          Get all Markers currently assigned to this Markable
 Marker getSelectedMarker()
          Get the currently selected Marker
private  void highlightMarker(Marker m)
          Highlight the given Marker to indicate that this one is the currently selected Marker
protected  Marker identifyMarker(int position)
          Internal method for identifying a Marker by its position
protected  Marker identifyMarker(java.lang.String name)
          Internal method for identifying a Marker by its name
protected  Marker identifyMarker(java.lang.String name, int position)
          Internal method for identifying a Marker by its name and position
protected  Marker identifyMarkerIndex(int index)
          Internal method for identifying a Marker by its index
protected  void mouseDown(int realX, int realY, boolean shiftPressed, boolean ctrlPressed)
          Notification about a mouse button being pressed.
protected  void mouseMove(int realX, int realY, boolean shiftPressed, boolean ctrlPressed)
          Notification about the mouse being moved.
protected  void mouseUp(int realX, int realY, boolean shiftPressed, boolean ctrlPressed)
          Notification about a mouse button being released.
 void moveMarker(int oldPos, int newPos)
          Move a Marker from the specified position to a new position
protected  void moveMarker(Marker m, int newPos)
          Internal method for moving a amrker
 void moveMarker(java.lang.String name, int newPos)
          Move the Marker identified by the given name to the specified position
 void moveMarker(java.lang.String name, int oldPos, int newPos)
          Move the Marker identified by the given name and currently located at the given position to the a new position
 void moveMarkerIndex(int index, int newPos)
          Move the Marker at the given index to the given new position
protected  void redrawMarker(Marker m)
          Redraw the given marker
 void removeMarkableListener(MarkableListener listener)
          Remove a MarkableListener
 void removeMarker(int position)
          Remove a marker from the given position
 void removeMarker(int position, java.lang.String name)
          Remove a Marker identified by the given name and located at the given position
protected  void removeMarker(Marker m)
          Internal Method for removing a marker
 void removeMarker(java.lang.String name)
          Remove a marker identified by the given name
 void removeMarkerIndex(int index)
          Remove the Marker at the given index
 void selectMarker(int position)
          Select the Marker at the given position
protected  void selectMarker(Marker m)
          Internal method for selecting a marker
 void selectMarker(java.lang.String name)
          Select the Marker with the given name
 void selectMarker(java.lang.String name, int position)
          Select the Marker with the given name and positon
 void selectMarkerIndex(int index)
          Select the Marker at the given index
 void setEditMarkers(boolean edit)
          Specify whether the user should be able to edit (create, move or remove) Markers on this WaveformDisplay or not
 
Methods inherited from class com.groovemanager.sampled.waveform.SelectableWaveFormDisplay
addSelectableListener, drawPosition, drawSelection, erasePosition, eraseSelection, getPosition, getSelection, redrawPosition, redrawSelection, removeSelectableListener, setPosition, setSelection, showSelection
 
Methods inherited from class com.groovemanager.sampled.waveform.AbstractWaveFormDisplay
addWaveDisplayListener, calcY, dataToPixel, drawBackground, drawChannelBackground, drawChannelForeground, drawForeground, drawGlobalBackground, drawGlobalForeground, drawWave, drawWaveLine, getChannelHeight, getChannels, getChannelSpacing, getChannelTop, getDisplayHeight, getDisplayWidth, getFirstData, getLastData, getLeftOffset, getPixelFactor, getScroll, getSource, getTopOffset, getTotalLength, getUsableDisplayHeight, getUsableDisplayWidth, getVisibleWaveForm, getZoom, hasData, mouseToData, pixelToData, redraw, removeSource, removeWaveDisplayListener, scroll, scrollCenter, scrollLeft, scrollRight, setChannelSpacing, setLeftOffset, setSource, setTopOffset, showAll, showData, zoom
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

editMarkers

protected boolean editMarkers
Indicates whether Markers can be added, moved or removed on this WaveFormDisplay


markableListeners

protected java.util.ArrayList markableListeners
List of MarkableListeners


markers

protected java.util.SortedSet markers
Set of all markers


MOUSE_TOLERANCE

protected static final int MOUSE_TOLERANCE
See Also:
Constant Field Values

selectedMarker

protected Marker selectedMarker
The currently selected Marker if any

Constructor Detail

MarkableWaveFormDisplay

public MarkableWaveFormDisplay()
Method Detail

addMarkableListener

public void addMarkableListener(MarkableListener listener)
Description copied from interface: Markable
Add a MarkableListener that will be notified of any changes made to this Markable instance

Specified by:
addMarkableListener in interface Markable
Parameters:
listener - The MarkableListener to add
See Also:
Markable.addMarkableListener(com.groovemanager.sampled.waveform.MarkableListener)

addMarker

public void addMarker(int position,
                      java.lang.String name)
Description copied from interface: Markable
Add a Marker with the given name to this Markable at the given position

Specified by:
addMarker in interface Markable
Parameters:
position - The position where the Marker should be created
name - The name of the Marker
See Also:
Markable.addMarker(int, java.lang.String)

addMarker

protected void addMarker(Marker m)
Internal method for adding a Marker

Parameters:
m - The Marker to add

deHighlightMarker

private void deHighlightMarker(Marker m)
Dehighlight the given marker to indicate this one is no more the currently selected Marker

Parameters:
m - The Marker to dehighlight

deselectMarker

public void deselectMarker()
Deselect the currently selected Marker, if any


drawHighlightedMarker

protected abstract void drawHighlightedMarker(Marker m)
Draw the given Marker in selected state

Parameters:
m - The Marker to draw

drawMarker

protected abstract void drawMarker(Marker m)
Draw the given Marker on the WaveFormDisplay

Parameters:
m - The Marker to draw

eraseHighlightedMarker

protected abstract void eraseHighlightedMarker(Marker m)
Erase the given Marker that has been drawn in selected state before

Parameters:
m - The Marker to erase

eraseMarker

protected abstract void eraseMarker(Marker m)
Erase the given marker from the WaveformDisplay

Parameters:
m - The Marker to erase

getMarker

public Marker getMarker(int index)
Get the Marker at the given index

Parameters:
index - The zero-based index of the marker in question
Returns:
The Marker at the given index or null, if no Marker exists at the given index.

getMarkerCount

public int getMarkerCount()
Description copied from interface: Markable
Get the current number of Markers contained in this Markable

Specified by:
getMarkerCount in interface Markable
Returns:
The number of Markers contained in this Markable
See Also:
Markable.getMarkerCount()

getMarkerFromMousePos

protected Marker getMarkerFromMousePos(int mousePos)
Get the Marker that is nearest to the given mouse position, but only if it is not more than MOUSE_TOLERANCE pixels away.

Parameters:
mousePos - The mouse x position
Returns:
The nearest Marker to the given mouse position or null, if the nearest Marker is too far away

getMarkers

public Marker[] getMarkers()
Description copied from interface: Markable
Get all Markers currently assigned to this Markable

Specified by:
getMarkers in interface Markable
Returns:
An Array of all Markers currently assigned to this Markable
See Also:
Markable.getMarkers()

getSelectedMarker

public Marker getSelectedMarker()
Get the currently selected Marker

Returns:
The currently selected Marker or null, if no Marker is currently selected

highlightMarker

private void highlightMarker(Marker m)
Highlight the given Marker to indicate that this one is the currently selected Marker

Parameters:
m - The Marker to highlight

identifyMarker

protected Marker identifyMarker(int position)
Internal method for identifying a Marker by its position

Parameters:
position - The position of the Marker to identify
Returns:
The Marker at the given position or null, if no Marker could be found at the given position

identifyMarker

protected Marker identifyMarker(java.lang.String name)
Internal method for identifying a Marker by its name

Parameters:
name - The name of the Marker to identify
Returns:
The Marker with the given name or null, if no Marker could be found with the given name

identifyMarker

protected Marker identifyMarker(java.lang.String name,
                                int position)
Internal method for identifying a Marker by its name and position

Parameters:
name - The name of the Marker to identify
position - The position of the Marker to identify
Returns:
The Marker with the given name at the given position or null, if no Marker with the given name and position could be found

identifyMarkerIndex

protected Marker identifyMarkerIndex(int index)
Internal method for identifying a Marker by its index

Parameters:
index - The zero-based index of the Marker to be identified
Returns:
The Marker at the given index or null, if no Marker exists at the given index

mouseDown

protected void mouseDown(int realX,
                         int realY,
                         boolean shiftPressed,
                         boolean ctrlPressed)
Description copied from class: SelectableWaveFormDisplay
Notification about a mouse button being pressed. Subclasses must ensure with MouseListeners, that this method is called, when a mouse button is pressed.

Overrides:
mouseDown in class SelectableWaveFormDisplay
Parameters:
realX - The x-coordinate of where the mouse button was pressed
realY - The y-coordinate of where the mouse button was pressed
shiftPressed - true, if the Shift-Button is currently pressed, false otherwise
ctrlPressed - true, if the CTRL-Button is currently pressed, false otherwise

mouseMove

protected void mouseMove(int realX,
                         int realY,
                         boolean shiftPressed,
                         boolean ctrlPressed)
Description copied from class: SelectableWaveFormDisplay
Notification about the mouse being moved. Subclasses must ensure with MouseListeners, that this method is called, when the mouse is moved.

Overrides:
mouseMove in class SelectableWaveFormDisplay
Parameters:
realX - The x-coordinate of where the mouse was moved to
realY - The y-coordinate of where the mouse was moved to
shiftPressed - true, if the Shift-Button is currently pressed, false otherwise
ctrlPressed - true, if the CTRL-Button is currently pressed, false otherwise

mouseUp

protected void mouseUp(int realX,
                       int realY,
                       boolean shiftPressed,
                       boolean ctrlPressed)
Description copied from class: SelectableWaveFormDisplay
Notification about a mouse button being released. Subclasses must ensure with MouseListeners, that this method is called, when a mouse button is released.

Overrides:
mouseUp in class SelectableWaveFormDisplay
Parameters:
realX - The x-coordinate of where the mouse button was released
realY - The y-coordinate of where the mouse button was released
shiftPressed - true, if the Shift-Button is currently pressed, false otherwise
ctrlPressed - true, if the CTRL-Button is currently pressed, false otherwise

moveMarker

public void moveMarker(int oldPos,
                       int newPos)
Description copied from interface: Markable
Move a Marker from the specified position to a new position

Specified by:
moveMarker in interface Markable
Parameters:
oldPos - The position at which the Marker is currently positioned
newPos - The position to which the Marker should be moved
See Also:
Markable.moveMarker(int, int)

moveMarker

protected void moveMarker(Marker m,
                          int newPos)
Internal method for moving a amrker

Parameters:
m - The Marker to move
newPos - The position to move the Marker to

moveMarker

public void moveMarker(java.lang.String name,
                       int newPos)
Description copied from interface: Markable
Move the Marker identified by the given name to the specified position

Specified by:
moveMarker in interface Markable
Parameters:
name - The name of the Marker to move
newPos - The position to which the Marker should be moved
See Also:
Markable.moveMarker(java.lang.String, int)

moveMarker

public void moveMarker(java.lang.String name,
                       int oldPos,
                       int newPos)
Description copied from interface: Markable
Move the Marker identified by the given name and currently located at the given position to the a new position

Specified by:
moveMarker in interface Markable
Parameters:
name - The name of the Marker to move
oldPos - The position at which the Marker is currently located
newPos - The position to which the Marker should be moved
See Also:
Markable.moveMarker(java.lang.String, int, int)

moveMarkerIndex

public void moveMarkerIndex(int index,
                            int newPos)
Description copied from interface: Markable
Move the Marker at the given index to the given new position

Specified by:
moveMarkerIndex in interface Markable
Parameters:
index - The zero-based index of the Marker to move
newPos - The position to move the Marker to
See Also:
Markable.moveMarkerIndex(int, int)

redrawMarker

protected void redrawMarker(Marker m)
Redraw the given marker

Parameters:
m - The Marker to redraw

removeMarkableListener

public void removeMarkableListener(MarkableListener listener)
Description copied from interface: Markable
Remove a MarkableListener

Specified by:
removeMarkableListener in interface Markable
Parameters:
listener - The MarkableListener to remove
See Also:
Markable.removeMarkableListener(com.groovemanager.sampled.waveform.MarkableListener)

removeMarker

public void removeMarker(int position)
Description copied from interface: Markable
Remove a marker from the given position

Specified by:
removeMarker in interface Markable
Parameters:
position - The position from where the Marker should be removed
See Also:
Markable.removeMarker(int)

removeMarker

public void removeMarker(int position,
                         java.lang.String name)
Description copied from interface: Markable
Remove a Marker identified by the given name and located at the given position

Specified by:
removeMarker in interface Markable
Parameters:
position - The position from where the Marker should be removed
name - The name of the Marker to remove
See Also:
Markable.removeMarker(int, java.lang.String)

removeMarker

protected void removeMarker(Marker m)
Internal Method for removing a marker

Parameters:
m - The Marker to remove

removeMarker

public void removeMarker(java.lang.String name)
Description copied from interface: Markable
Remove a marker identified by the given name

Specified by:
removeMarker in interface Markable
Parameters:
name - The name of the Marker to remove
See Also:
Markable.removeMarker(java.lang.String)

removeMarkerIndex

public void removeMarkerIndex(int index)
Description copied from interface: Markable
Remove the Marker at the given index

Specified by:
removeMarkerIndex in interface Markable
Parameters:
index - The zero-based index of the Marker to remove
See Also:
Markable.removeMarkerIndex(int)

selectMarker

public void selectMarker(int position)
Select the Marker at the given position

Parameters:
position - The position of the Marker to select

selectMarker

protected void selectMarker(Marker m)
Internal method for selecting a marker

Parameters:
m - The Marker to select

selectMarker

public void selectMarker(java.lang.String name)
Select the Marker with the given name

Parameters:
name - The name of the Marker to select

selectMarker

public void selectMarker(java.lang.String name,
                         int position)
Select the Marker with the given name and positon

Parameters:
name - The name of the Marker to select
position - The position of the marker to select

selectMarkerIndex

public void selectMarkerIndex(int index)
Select the Marker at the given index

Parameters:
index - The zero-based index of the Marker to select

setEditMarkers

public void setEditMarkers(boolean edit)
Specify whether the user should be able to edit (create, move or remove) Markers on this WaveformDisplay or not

Parameters:
edit - true, if editing Markers should be possible, false otherwise