jazz.widget
Class MusicPanel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--jazz.widget.MusicPanel
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class MusicPanel
extends java.awt.Panel

See Also:
Serialized Form

Inner classes inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
static int CLICK_ERROR
           
 int clickError
           
protected  java.awt.Color[][] colors
           
protected  boolean debug
           
static java.awt.Color DEFAULT_HIGHLIGHT_COLOR
           
static int DOT_SPACE
           
static int DOT_WIDTH
           
 int dotSpace
           
 int dotWidth
           
static int FLAG_HEIGHT
           
static int FLAG_OFFSET
           
static int FLAG_WIDTH
           
 int flagHeight
           
 int flagOffset
           
 int flagWidth
           
static int FLAT_SPACE
           
static int FLAT_WIDTH
           
 int flatSpace
           
 int flatWidth
           
protected  int height
           
 java.awt.Color highlightColor
           
protected  boolean isExample
           
static int LINE_HEIGHT
           
 int lineHeight
           
protected  java.awt.event.ActionListener listener
           
static int MEASURE_MARGIN
           
static int MEASURE_WIDTH
           
 int measureMargin
           
protected  java.util.Vector measures
           
static int MEASURES_PER_LINE
           
 int measuresPerLine
           
 int measureWidth
           
static int MIN_WHITE_SPACE
           
 int minWhiteSpace
           
static int NOTE_HEIGHT
           
static int NOTE_WIDTH
           
 int noteHeight
           
 int noteWidth
           
protected  int numMeasures
           
static int PIXELS_BETWEEN_FLAGS
           
 int pixelsBetweenFlags
           
protected  java.util.Vector points
           
protected  int selectedPoint
           
static int SHARP_SPACE
           
static int SHARP_WIDTH
           
 int sharpSpace
           
 int sharpWidth
           
static int STAVE_HEIGHT
           
 int staveHeight
           
static int STEM_HEIGHT
           
 int stemHeight
           
protected  java.lang.String title
           
static int TITLE_HEIGHT
           
 int titleHeight
           
protected  int width
           
static int X_MARGIN
           
 int xMargin
           
static int Y_MARGIN
           
 int yMargin
           
 
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
MusicPanel()
           
MusicPanel(int numMeasures)
           
MusicPanel(java.lang.String title, int numMeasures)
           
 
Method Summary
 void addActionListener(java.awt.event.ActionListener l)
           
protected  int calculateNoteWidth(Note note)
          Calculate the note width of a given note
protected  double calculateWhiteSpace(Measure measure)
          Calculate the amount of white space in a measure and return a multiplier indicating what percentage of the preferred white space fits in the measure.
 void drawChord(Chord chord)
          Draw an chord, but with no color highlighting
 void drawChord(Chord chord, java.awt.Color[][] colors)
          Draw a chord
protected  void drawExample()
          Called internally when painting.
 void drawExample(Measure measure)
          Draw an example, but without color highlighting
 void drawExample(Measure measure, java.awt.Color[][] colors)
          Draw an example measure.
protected  void drawFlags(jazz.widget.MusicPanel.NotePoint np, java.awt.Graphics g)
          Draw the appropriate number of flags for a note
protected  void drawFlat(jazz.widget.MusicPanel.NotePoint np, java.awt.Graphics g)
          Draws a flat sign in front of the given note
protected  void drawMeasures()
          Calculate the whitespace for a measure and then draw it, shrinking whitespace as is necessary.
 void drawMeasures(java.util.Vector measures, java.awt.Color[][] colors)
          Calculate the whitespace for a measure and then draw it, shrinking whitespace as necessary.
protected  void drawNote(jazz.widget.MusicPanel.NotePoint np)
          Draw a note in a given x position and measure Return the y value for the note
protected  void drawNoteHead(jazz.widget.MusicPanel.NotePoint np, java.awt.Graphics g)
          Draw a note head at the given coordinates
protected  void drawScore()
          Draw the staff lines and all the measures.
protected  void drawSharp(jazz.widget.MusicPanel.NotePoint np, java.awt.Graphics g)
          Draws a sharp sign in front of the given note
protected  void drawStaffLines(jazz.widget.MusicPanel.NotePoint np, java.awt.Graphics g)
          Draw Lines above or below the staff for a given note
protected  void drawStave(int numMeasures, int stave)
          Draw a row of empty measures
protected  void drawStem(jazz.widget.MusicPanel.NotePoint np, java.awt.Graphics g)
          Draw the stem for a note at the given coordinates
 void erase()
          Erase the current screen by drawing a white rectangle
protected  void fireActionEvent(java.awt.event.ActionEvent e)
           
 int getHeight()
          * Functions for manipulating different attributes * *
 java.awt.Dimension getMinimumSize()
           
 java.awt.Dimension getPreferredSize()
           
 Measure getSelectedMeasure()
          Find the selected measure, or null
 int getSelectedMeasureNum()
          Find the selected measure number
 Note getSelectedNote()
          Find the selected note
 int getSelectedNoteNum()
          Find the selected note number
 int getWidth()
           
 boolean hasGraphics()
           
 void layoutInit()
          * Functions for drawing different components * *
protected  double lineOfPitch(Pitch pitch)
          Return the line number in the stave for a given pitch.
static void main(java.lang.String[] args)
           
 int numberOfStaves()
           
 void paint(java.awt.Graphics g)
          Draw whatever we contain...
 void processClick(int x, int y)
          Return the measure and note numbers for the closest note
 void processMouseEvent(java.awt.event.MouseEvent e)
          * Utility functions for event handling * *
protected  int realX(int x)
          Translate a relative coordinate to absolute coordinates by account for margins, etc.
protected  int realY(int y)
          Return an "absolute" y - coordinate for a "relative" y-coordinate by adding in margins.
 void removeActionListener(java.awt.event.ActionListener l)
           
 void repaint()
           
 void setSelectedNote(int measureNum, int noteNum)
          Set the selected note using the measure and note number Note that the drawMeasures() or drawExample() must already be called containing the note.
 void setSelectedNote(Note note)
          Set the selected note using a reference to a specific note Note that the drawMeasures() or drawExample() must already be called containing the note.
protected  void setSelectedPoint(int pointNum)
          Internal function to set the selected point based on the point number
protected  int xOfBeat(double beat, int measure)
          Approximate the x value for a given beat accounting for margins, etc.
protected  int xOfMeasure(int measure)
          Find the x coordinate of a given measure accounting for margins, etc.
protected  int xOfStem(Note note, int x)
          Calculate the x coordinate for a note stem account for margins, etc.
protected  int yOfLine(double line, int measure)
          Calculate the y value of a line accounting for margins, etc.
protected  int yOfLine(int lineNumber, int measure)
          Calculate the y value at the top of the line account for margins, etc.
protected  int yOfMeasure(int measure)
          Find the y value for a given measure accounting for margins, etc.
protected  int yOfPitch(Pitch pitch, int measure)
          Calculate the y value of a pitch accounting for margins, etc.
protected  int yOfStave(int stave)
          Find the y value for a given stave accounting for margins, etc.
protected  int yOfStem(Pitch pitch, int measure)
          Calculate the y value at the top of the stem account for margins, etc.
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getListeners, getMaximumSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DOT_SPACE

public static int DOT_SPACE

DOT_WIDTH

public static int DOT_WIDTH

FLAG_HEIGHT

public static int FLAG_HEIGHT

FLAG_WIDTH

public static int FLAG_WIDTH

FLAG_OFFSET

public static int FLAG_OFFSET

FLAT_SPACE

public static int FLAT_SPACE

FLAT_WIDTH

public static int FLAT_WIDTH

LINE_HEIGHT

public static int LINE_HEIGHT

MEASURE_MARGIN

public static int MEASURE_MARGIN

MEASURES_PER_LINE

public static int MEASURES_PER_LINE

MEASURE_WIDTH

public static int MEASURE_WIDTH

MIN_WHITE_SPACE

public static int MIN_WHITE_SPACE

NOTE_HEIGHT

public static int NOTE_HEIGHT

NOTE_WIDTH

public static int NOTE_WIDTH

PIXELS_BETWEEN_FLAGS

public static int PIXELS_BETWEEN_FLAGS

SHARP_SPACE

public static int SHARP_SPACE

SHARP_WIDTH

public static int SHARP_WIDTH

STAVE_HEIGHT

public static int STAVE_HEIGHT

STEM_HEIGHT

public static int STEM_HEIGHT

TITLE_HEIGHT

public static int TITLE_HEIGHT

X_MARGIN

public static int X_MARGIN

Y_MARGIN

public static int Y_MARGIN

CLICK_ERROR

public static int CLICK_ERROR

DEFAULT_HIGHLIGHT_COLOR

public static java.awt.Color DEFAULT_HIGHLIGHT_COLOR

dotSpace

public int dotSpace

dotWidth

public int dotWidth

flagHeight

public int flagHeight

flagWidth

public int flagWidth

flagOffset

public int flagOffset

flatSpace

public int flatSpace

flatWidth

public int flatWidth

lineHeight

public int lineHeight

measureMargin

public int measureMargin

measuresPerLine

public int measuresPerLine

measureWidth

public int measureWidth

minWhiteSpace

public int minWhiteSpace

noteHeight

public int noteHeight

noteWidth

public int noteWidth

pixelsBetweenFlags

public int pixelsBetweenFlags

sharpSpace

public int sharpSpace

sharpWidth

public int sharpWidth

staveHeight

public int staveHeight

stemHeight

public int stemHeight

titleHeight

public int titleHeight

xMargin

public int xMargin

yMargin

public int yMargin

clickError

public int clickError

highlightColor

public java.awt.Color highlightColor

listener

protected java.awt.event.ActionListener listener

title

protected java.lang.String title

height

protected int height

width

protected int width

numMeasures

protected int numMeasures

selectedPoint

protected int selectedPoint

measures

protected java.util.Vector measures

points

protected java.util.Vector points

colors

protected java.awt.Color[][] colors

isExample

protected boolean isExample

debug

protected boolean debug
Constructor Detail

MusicPanel

public MusicPanel()

MusicPanel

public MusicPanel(java.lang.String title,
                  int numMeasures)

MusicPanel

public MusicPanel(int numMeasures)
Method Detail

getHeight

public int getHeight()
* Functions for manipulating different attributes * *
Overrides:
getHeight in class java.awt.Component

getWidth

public int getWidth()
Overrides:
getWidth in class java.awt.Component

hasGraphics

public boolean hasGraphics()

numberOfStaves

public int numberOfStaves()

layoutInit

public void layoutInit()
* Functions for drawing different components * *

paint

public void paint(java.awt.Graphics g)
Draw whatever we contain... - If there is no graphics context, do nothing - If there is no content (i.e. no measures) draw only the staves
Overrides:
paint in class java.awt.Container

erase

public void erase()
Erase the current screen by drawing a white rectangle

drawScore

protected void drawScore()
Draw the staff lines and all the measures.

drawMeasures

public void drawMeasures(java.util.Vector measures,
                         java.awt.Color[][] colors)
Calculate the whitespace for a measure and then draw it, shrinking whitespace as necessary.

drawMeasures

protected void drawMeasures()
Calculate the whitespace for a measure and then draw it, shrinking whitespace as is necessary. Note that this is called during the paint() function and is not externally visible. Magic formula for whitespace (ws) is a product of the following: - white space "shrink factor" - total drawing space measure (i.e. width - margins) - fraction of total duration that the note uses (i.e. quarter is 0.25) Finally, the actual note width is the subtracted out leaving the space.

drawChord

public void drawChord(Chord chord)
Draw an chord, but with no color highlighting

drawChord

public void drawChord(Chord chord,
                      java.awt.Color[][] colors)
Draw a chord

drawExample

public void drawExample(Measure measure)
Draw an example, but without color highlighting

drawExample

public void drawExample(Measure measure,
                        java.awt.Color[][] colors)
Draw an example measure. Note that this function does not calculate white space. Notes are placed using the minimum amount of white space.

drawExample

protected void drawExample()
Called internally when painting. Note that this function does not calculate white space. Notes are placed using the minimum amount of white space.

drawStave

protected void drawStave(int numMeasures,
                         int stave)
Draw a row of empty measures

drawNote

protected void drawNote(jazz.widget.MusicPanel.NotePoint np)
Draw a note in a given x position and measure Return the y value for the note

drawStaffLines

protected void drawStaffLines(jazz.widget.MusicPanel.NotePoint np,
                              java.awt.Graphics g)
Draw Lines above or below the staff for a given note

drawNoteHead

protected void drawNoteHead(jazz.widget.MusicPanel.NotePoint np,
                            java.awt.Graphics g)
Draw a note head at the given coordinates

drawStem

protected void drawStem(jazz.widget.MusicPanel.NotePoint np,
                        java.awt.Graphics g)
Draw the stem for a note at the given coordinates

drawSharp

protected void drawSharp(jazz.widget.MusicPanel.NotePoint np,
                         java.awt.Graphics g)
Draws a sharp sign in front of the given note

drawFlat

protected void drawFlat(jazz.widget.MusicPanel.NotePoint np,
                        java.awt.Graphics g)
Draws a flat sign in front of the given note

drawFlags

protected void drawFlags(jazz.widget.MusicPanel.NotePoint np,
                         java.awt.Graphics g)
Draw the appropriate number of flags for a note

getMinimumSize

public java.awt.Dimension getMinimumSize()
Overrides:
getMinimumSize in class java.awt.Container

getPreferredSize

public java.awt.Dimension getPreferredSize()
Overrides:
getPreferredSize in class java.awt.Container

repaint

public void repaint()
Overrides:
repaint in class java.awt.Component

calculateWhiteSpace

protected double calculateWhiteSpace(Measure measure)
Calculate the amount of white space in a measure and return a multiplier indicating what percentage of the preferred white space fits in the measure. White speace for each note then equals the percentage of beats a note lies on multiplied by the total space available for the measure.

calculateNoteWidth

protected int calculateNoteWidth(Note note)
Calculate the note width of a given note

xOfStem

protected int xOfStem(Note note,
                      int x)
Calculate the x coordinate for a note stem account for margins, etc. The passed-in x coordinate is the beginning x coordinate for the entire note.

xOfBeat

protected int xOfBeat(double beat,
                      int measure)
Approximate the x value for a given beat accounting for margins, etc. This is only an approximation!

xOfMeasure

protected int xOfMeasure(int measure)
Find the x coordinate of a given measure accounting for margins, etc.

realX

protected int realX(int x)
Translate a relative coordinate to absolute coordinates by account for margins, etc.

yOfLine

protected int yOfLine(int lineNumber,
                      int measure)
Calculate the y value at the top of the line account for margins, etc.

yOfStem

protected int yOfStem(Pitch pitch,
                      int measure)
Calculate the y value at the top of the stem account for margins, etc.

lineOfPitch

protected double lineOfPitch(Pitch pitch)
Return the line number in the stave for a given pitch. Note that e on the bottom stave is line 0.0, f is 0.5, etc.

yOfPitch

protected int yOfPitch(Pitch pitch,
                       int measure)
Calculate the y value of a pitch accounting for margins, etc.

yOfLine

protected int yOfLine(double line,
                      int measure)
Calculate the y value of a line accounting for margins, etc. Note that e on the bottom stave is line 0.0, f is 0.5, etc.

yOfMeasure

protected int yOfMeasure(int measure)
Find the y value for a given measure accounting for margins, etc.

yOfStave

protected int yOfStave(int stave)
Find the y value for a given stave accounting for margins, etc.

realY

protected int realY(int y)
Return an "absolute" y - coordinate for a "relative" y-coordinate by adding in margins.

processMouseEvent

public void processMouseEvent(java.awt.event.MouseEvent e)
* Utility functions for event handling * *
Overrides:
processMouseEvent in class java.awt.Component

processClick

public void processClick(int x,
                         int y)
Return the measure and note numbers for the closest note

getSelectedMeasureNum

public int getSelectedMeasureNum()
Find the selected measure number

setSelectedNote

public void setSelectedNote(Note note)
Set the selected note using a reference to a specific note Note that the drawMeasures() or drawExample() must already be called containing the note.

setSelectedNote

public void setSelectedNote(int measureNum,
                            int noteNum)
Set the selected note using the measure and note number Note that the drawMeasures() or drawExample() must already be called containing the note.

setSelectedPoint

protected void setSelectedPoint(int pointNum)
Internal function to set the selected point based on the point number

getSelectedMeasure

public Measure getSelectedMeasure()
Find the selected measure, or null

getSelectedNoteNum

public int getSelectedNoteNum()
Find the selected note number

getSelectedNote

public Note getSelectedNote()
Find the selected note

removeActionListener

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

addActionListener

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

fireActionEvent

protected void fireActionEvent(java.awt.event.ActionEvent e)

main

public static void main(java.lang.String[] args)