org.rubato.composer.view2d
Class View2D

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 org.rubato.composer.view2d.View2D
All Implemented Interfaces:
java.awt.event.ComponentListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.MouseWheelListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.AncestorListener

public class View2D
extends javax.swing.JPanel
implements java.awt.event.ComponentListener, java.awt.event.MouseListener, java.awt.event.MouseWheelListener, java.awt.event.MouseMotionListener, javax.swing.event.AncestorListener

See Also:
Serialized Form

Nested Class Summary
static class View2D.DragMode
           
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
 java.awt.Cursor addCursor
           
 java.awt.Cursor infoCursor
           
 java.awt.event.ActionEvent newSelectionEvent
           
 java.awt.Cursor removeCursor
           
 java.awt.event.ActionEvent updateEvent
           
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
View2D(View2DModel model)
          Creates a new view from the given model.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener l)
           
 void addPoint(double x, double y, Denotator d)
          Adds a new data point.
 void addPoints(double[] x, double[] y)
          Adds an array of new data points, specified as two arrays of the same length.
 void addPointToSelection(double worldX, double worldY)
          Adds a new point to the current selection (world coordinates).
 void addPointToSelection(int screenX, int screenY)
          Adds a new point to the current selection (screen coordinates).
 void ancestorAdded(javax.swing.event.AncestorEvent event)
          This is called when the component is added to its parent.
 void ancestorMoved(javax.swing.event.AncestorEvent event)
           
 void ancestorRemoved(javax.swing.event.AncestorEvent event)
           
 void componentHidden(java.awt.event.ComponentEvent e)
           
 void componentMoved(java.awt.event.ComponentEvent e)
           
 void componentResized(java.awt.event.ComponentEvent e)
           
 void componentShown(java.awt.event.ComponentEvent e)
           
 void drawZoomRectangle(int x0, int y0, int x1, int y1)
          Draws a rectangle indicated the region to be zoomed into.
 Selection getCurrentSelection()
           
 View2DModel getModel()
           
 double getPointerX()
          Returns the world x-coordinate of the current pointer position.
 double getPointerY()
          Returns the world y-coordinate of the current pointer position.
 java.util.ArrayList<Point> getPoints()
           
 boolean isSelected(int i)
          Returns true iff the point number i is in the selection.
static java.awt.Cursor loadCursor(java.lang.Class<?> cls, java.lang.String name, int x, int y)
          Loads the cursor from the given file name and the given hotpoint, and returns it.
 void mouseClicked(java.awt.event.MouseEvent e)
          The most important event is mouse clicked.
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
          On mouse entering the window, the cursor must be changed to reflect the current action.
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
          Whenever the mouse is moved, the state (pointerX,pointerY) is updated, and a updateEvent is sent.
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
           
 void newSelection()
          Starts a new selection and makes it current.
 void recalcScreenCoords()
          Recomputes the screen coordinates from the world coordinates of the data and transformed points and the selections.
 void removeActionListener(java.awt.event.ActionListener l)
           
 void removeAllPoints()
          Remove all points.
 void removePointFromSelection(int screenX, int screenY)
          Removes a point from the current selection (screen coordinates).
 void setAction(Action2D action)
          Sets the current action.
 void setCurrentSelection(Selection selection)
           
 void setWindow(double xmin, double xmax, double ymin, double ymax)
          Sets the viewport of the window.
 void updatePointer(double worldX, double worldY)
           
 void zoom(double fx, double fy)
          Zooms the viewport by the given factors.
 void zoomAll()
          Sets the viewport so that everything, i.e., points and selections, is visible.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, 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, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

updateEvent

public final java.awt.event.ActionEvent updateEvent

newSelectionEvent

public final java.awt.event.ActionEvent newSelectionEvent

addCursor

public java.awt.Cursor addCursor

removeCursor

public java.awt.Cursor removeCursor

infoCursor

public java.awt.Cursor infoCursor
Constructor Detail

View2D

public View2D(View2DModel model)
Creates a new view from the given model.

Method Detail

getModel

public View2DModel getModel()

getPoints

public java.util.ArrayList<Point> getPoints()

isSelected

public boolean isSelected(int i)
Returns true iff the point number i is in the selection.


getPointerX

public double getPointerX()
Returns the world x-coordinate of the current pointer position.


getPointerY

public double getPointerY()
Returns the world y-coordinate of the current pointer position.


updatePointer

public void updatePointer(double worldX,
                          double worldY)

setWindow

public void setWindow(double xmin,
                      double xmax,
                      double ymin,
                      double ymax)
Sets the viewport of the window.


zoom

public void zoom(double fx,
                 double fy)
Zooms the viewport by the given factors. Zoom factor 1.0 means identity. Factors > 1.0 zoom in, factors < 1.0 zoom out.

Parameters:
fx - horizontal zoom factor
fy - vertical zoom factor

zoomAll

public void zoomAll()
Sets the viewport so that everything, i.e., points and selections, is visible.


setAction

public void setAction(Action2D action)
Sets the current action.


addPoint

public void addPoint(double x,
                     double y,
                     Denotator d)
Adds a new data point.

Parameters:
x - world x-coordinate
y - world y-coordinate

addPoints

public void addPoints(double[] x,
                      double[] y)
Adds an array of new data points, specified as two arrays of the same length.

Parameters:
x - array of world x-coordinates
y - array of world y-coordinates

removeAllPoints

public void removeAllPoints()
Remove all points.


recalcScreenCoords

public void recalcScreenCoords()
Recomputes the screen coordinates from the world coordinates of the data and transformed points and the selections.


newSelection

public void newSelection()
Starts a new selection and makes it current.


getCurrentSelection

public Selection getCurrentSelection()

setCurrentSelection

public void setCurrentSelection(Selection selection)

addPointToSelection

public void addPointToSelection(int screenX,
                                int screenY)
Adds a new point to the current selection (screen coordinates).

Parameters:
screenX - screen x-coordinate of the new point
screenY - screen y-coordinate of the new point

addPointToSelection

public void addPointToSelection(double worldX,
                                double worldY)
Adds a new point to the current selection (world coordinates).

Parameters:
worldX - world x-coordinate of the new point
worldY - world y-coordinate of the new point

removePointFromSelection

public void removePointFromSelection(int screenX,
                                     int screenY)
Removes a point from the current selection (screen coordinates). If the removed points was the last one, the complete selection is removed.

Parameters:
screenX - screen x-coordinate of the point to be selected
screenY - screen y-coordinate of the point to be selected

drawZoomRectangle

public void drawZoomRectangle(int x0,
                              int y0,
                              int x1,
                              int y1)
Draws a rectangle indicated the region to be zoomed into.

Parameters:
x0 - screen x-coordinate of the first corner
y0 - screen y-coordinate of the first corner
x1 - screen x-coordinate of the second corner
y1 - screen y-coordinate of the second corner

loadCursor

public static java.awt.Cursor loadCursor(java.lang.Class<?> cls,
                                         java.lang.String name,
                                         int x,
                                         int y)
Loads the cursor from the given file name and the given hotpoint, and returns it.


componentResized

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

componentMoved

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

componentShown

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

componentHidden

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

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
The most important event is mouse clicked. What is actually done depends on the current action.

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
On mouse entering the window, the cursor must be changed to reflect the current action.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseWheelMoved

public void mouseWheelMoved(java.awt.event.MouseWheelEvent e)
Specified by:
mouseWheelMoved in interface java.awt.event.MouseWheelListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Whenever the mouse is moved, the state (pointerX,pointerY) is updated, and a updateEvent is sent.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

ancestorAdded

public void ancestorAdded(javax.swing.event.AncestorEvent event)
This is called when the component is added to its parent. Until now there have been no valid screen coordinates. These must be computed.

Specified by:
ancestorAdded in interface javax.swing.event.AncestorListener

ancestorMoved

public void ancestorMoved(javax.swing.event.AncestorEvent event)
Specified by:
ancestorMoved in interface javax.swing.event.AncestorListener

ancestorRemoved

public void ancestorRemoved(javax.swing.event.AncestorEvent event)
Specified by:
ancestorRemoved in interface javax.swing.event.AncestorListener

addActionListener

public void addActionListener(java.awt.event.ActionListener l)

removeActionListener

public void removeActionListener(java.awt.event.ActionListener l)