Side of Software
Marker Bar Library 1.0

sos.marker
Class Utility

java.lang.Object
  extended by sos.marker.Utility

public final class Utility
extends java.lang.Object

A collection of utility methods that aid in converting Swing component locations to marker locations.

Since:
1.0

Method Summary
static double[] listIndexToMarkerRange(javax.swing.JList list, int row)
          Converts a list row index to a range appropriate for a vertical marker bar.
static double[] listRangeToMarkerRange(javax.swing.JList list, int startIndex, int endIndex)
          Converts a list range to a range appropriate for a vertical marker bar.
static void scrollHorizontallyToMarker(javax.swing.JComponent componentToScroll, Marker marker)
          Scrolls the specific component horizontally to the relative location given by the specified marker.
static void scrollToMarker(javax.swing.JComponent componentToScroll, JMarkerBar markerBar, int markerIndex)
          Scrolls a component to the relative location given by the marker bar's marker.
static void scrollVerticallyToMarker(javax.swing.JComponent componentToScroll, Marker marker)
          Scrolls the specific component vertically to the relative location given by the specified marker.
static double[] tableIndexToMarkerRange(javax.swing.JTable table, int row, int column)
          Converts a table cell location to a range appropriate for a vertical marker bar.
static double[] tableRangeToMarkerRange(javax.swing.JTable table, int startRow, int startColumn, int endRow, int endColumn)
          Converts a table range to a range appropriate for a vertical marker bar.
static double[] textIndexToMarkerRange(javax.swing.text.JTextComponent textComponent, int index)
          Converts a text index to a range appropriate for a vertical marker bar.
static double[] textRangeToMarkerRange(javax.swing.text.JTextComponent textComponent, int startIndex, int endIndex)
          Converts text indices to a range appropriate for a vertical marker bar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

listIndexToMarkerRange

public static double[] listIndexToMarkerRange(javax.swing.JList list,
                                              int row)
Converts a list row index to a range appropriate for a vertical marker bar. Clients can use the returned locations as the start and end locations of a marker:
   double[] markerRange = Utility.listIndexToMarkerRange( list, row );
   Marker marker = new DefaultMarker( markerRange[0], markerRange[1], "Description here" );

Parameters:
list - the Swing JList for which the row position is requested
row - index of the row in the JList
Returns:
a 2-dimensional array where the first element is the starting Y location and the second element is the ending Y location, relative to the height of the list component
Throws:
java.lang.NullPointerException - if list is null

listRangeToMarkerRange

public static double[] listRangeToMarkerRange(javax.swing.JList list,
                                              int startIndex,
                                              int endIndex)
Converts a list range to a range appropriate for a vertical marker bar. Clients can use the returned locations as the start and end locations of a marker:
   double[] markerRange = Utility.listRangeToMarkerRange( list, fromRow, toRow );
   Marker marker = new DefaultMarker( markerRange[0], markerRange[1], "Description here" );

Parameters:
list - the Swing JList for which the row position is requested
startIndex - index of the row in the JList
endIndex - index of the row in the JList
Returns:
a 2-dimensional array where the first element is the starting Y location and the second element is the ending Y location, relative to the height of the list component
Throws:
java.lang.NullPointerException - if list is null

scrollHorizontallyToMarker

public static void scrollHorizontallyToMarker(javax.swing.JComponent componentToScroll,
                                              Marker marker)
Scrolls the specific component horizontally to the relative location given by the specified marker.

Parameters:
componentToScroll - component to scroll horizontally
marker - marker that provides the relative locations of where to scroll
Throws:
java.lang.NullPointerException - if componentToScroll or marker is null
See Also:
scrollVerticallyToMarker(javax.swing.JComponent, sos.marker.Marker), scrollToMarker(javax.swing.JComponent, sos.marker.JMarkerBar, int)

scrollVerticallyToMarker

public static void scrollVerticallyToMarker(javax.swing.JComponent componentToScroll,
                                            Marker marker)
Scrolls the specific component vertically to the relative location given by the specified marker.

Parameters:
componentToScroll - component to scroll vertically
marker - marker that provides the relative locations of where to scroll
Throws:
java.lang.NullPointerException - if componentToScroll or marker is null
See Also:
scrollHorizontallyToMarker(javax.swing.JComponent, sos.marker.Marker), scrollToMarker(javax.swing.JComponent, sos.marker.JMarkerBar, int)

scrollToMarker

public static void scrollToMarker(javax.swing.JComponent componentToScroll,
                                  JMarkerBar markerBar,
                                  int markerIndex)
Scrolls a component to the relative location given by the marker bar's marker. The direction of the scroll will be vertical if the marker bar is laid out vertically or horizontal if it is laid out horizontally. The marker is the one at the specified index. If the index is invalid, then no action is taken.

Clients often invoke this method in response to the click of a marker, as follows:

   markerBar.addActionListener( new ActionListener() {
     public void actionPerformed( ActionEvent event ) {
       int clickedMarkerIndex = markerBar.getClickedIndex();
       Utility.scrollToMarker( componentToScroll, markerBar, clickedMarkerIndex );
     }
   } );

Parameters:
componentToScroll - component to scroll either horizontally or vertically
markerBar - marker bar containing the marker
markerIndex - index of the marker that gives the relative location of where to scroll
Throws:
java.lang.NullPointerException - if componentToScroll or markerBar is null
See Also:
scrollHorizontallyToMarker(javax.swing.JComponent, sos.marker.Marker), scrollVerticallyToMarker(javax.swing.JComponent, sos.marker.Marker)

textIndexToMarkerRange

public static double[] textIndexToMarkerRange(javax.swing.text.JTextComponent textComponent,
                                              int index)
                                       throws javax.swing.text.BadLocationException
Converts a text index to a range appropriate for a vertical marker bar. Clients can use the returned locations as the start and end locations of a marker:
   double[] markerRange = Utility.textIndexToMarkerRange( textComponent, index );
   Marker marker = new DefaultMarker( markerRange[0], markerRange[1], "Description here" );

Parameters:
textComponent - Swing component containing the text to convert
index - index of the character for which the bounds should be fetched
Returns:
a 2-dimensional array where the first element is the starting Y location and the second element is the ending Y location, relative to the height of the text component
Throws:
javax.swing.text.BadLocationException - if index falls outside the bounds of the text
java.lang.NullPointerException - if textComponent is null

textRangeToMarkerRange

public static double[] textRangeToMarkerRange(javax.swing.text.JTextComponent textComponent,
                                              int startIndex,
                                              int endIndex)
                                       throws javax.swing.text.BadLocationException
Converts text indices to a range appropriate for a vertical marker bar. Clients can use the returned locations as the start and end locations of a marker:
   double[] markerRange = Utility.textRangeToMarkerRange( textComponent, startIndex, endIndex );
   Marker marker = new DefaultMarker( markerRange[0], markerRange[1], "Description here" );

Parameters:
textComponent - Swing component containing the text to convert
startIndex - index of the first character for which the bounds should be fetched
endIndex - index of the last character for which the bounds should be fetched
Returns:
a 2-dimensional array where the first element is the starting Y location and the second element is the ending Y location, relative to the height of the text component
Throws:
javax.swing.text.BadLocationException - if startIndex or endIndex falls outside the bounds of the text
java.lang.IllegalArgumentException - if endIndex precedes startIndex
java.lang.NullPointerException - if textComponent is null

tableIndexToMarkerRange

public static double[] tableIndexToMarkerRange(javax.swing.JTable table,
                                               int row,
                                               int column)
Converts a table cell location to a range appropriate for a vertical marker bar. Clients can use the returned locations as the start and end locations of a marker:
   double[] markerRange = Utility.tableIndexToMarkerRange( textComponent, row, column );
   Marker marker = new DefaultMarker( markerRange[0], markerRange[1], "Description here" );

Parameters:
table - Swing JTable containing the cell to convert
row - row index of the cell in the JTable
column - column index of the cell in the JTable
Returns:
a 2-dimensional array where the first element is the starting Y location and the second element is the ending Y location, relative to the height of the table
Throws:
java.lang.NullPointerException - if table is null

tableRangeToMarkerRange

public static double[] tableRangeToMarkerRange(javax.swing.JTable table,
                                               int startRow,
                                               int startColumn,
                                               int endRow,
                                               int endColumn)
Converts a table range to a range appropriate for a vertical marker bar. Clients can use the returned locations as the start and end locations of a marker:
   double[] markerRange = Utility.textRangeToMarkerRange( textComponent, startRow, startColumn, endRow, endColumn );
   Marker marker = new DefaultMarker( markerRange[0], markerRange[1], "Description here" );

Parameters:
table - Swing JTable containing the range of cells to convert
startRow - row index of the starting cell in the range
startColumn - column index of the starting cell in the range
endRow - row index of the ending cell in the range
endColumn - column index of the ending cell in the range
Returns:
a 2-dimensional array where the first element is the starting Y location and the second element is the ending Y location, relative to the height of the table
Throws:
java.lang.NullPointerException - if table is null

Side of Software
Marker Bar Library 1.0

Copyright 2009 Side of Software (SOS). All rights reserved.