[.home.]
[.hacks.]
[.java.]

Class MultiColumnList

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--Awt
                          |
                          +--MultiColumnList
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.AdjustmentListener, java.util.EventListener, java.awt.event.FocusListener, java.awt.image.ImageObserver, java.awt.ItemSelectable, java.awt.event.KeyListener, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable

public class MultiColumnList
extends Awt

(#)MultiColumnList.java

Version:
3.2 19-Mar-2004

A widget for displaying Strings in rows and colums. Allows sorting, resizing and modifying the colums visible. Currently only single row selection is supportet
Author:
Holger Pfaff
See Also:
Serialized Form

Field Summary
protected  boolean adjustable
          user adjustable ?
protected  int borderw
          border width around titles & col separators
protected  int[] cpos
          column x positions
protected  float[] cwidth
          proportional column widths (sum = 1.0)
protected  int dragcol
          column being resized (-1 for none)
protected  java.awt.Image image
          backing image for flickerfree drawing
protected  java.util.Vector[] items
          items per column (arraysize = no. of cols)
protected  long lastclick
          last mouse click time (to enable doubleclick)
protected  int minVisibleCols
          minimal no. of rows that must be visible
protected  int minVisibleRows
          to determine minimal space required
protected  int moc
          mouse over column
protected  java.awt.Scrollbar scrollbar
          scrollbar at the right side
protected  int selrow
          selected row (-1 for no selection)
protected  boolean showLines
          show lines ?
protected  boolean showTitle
          show title ?
protected  int sortcol
          column being sorted (-1 for unsorted)
protected  boolean sortign
          sort ignore case ?
protected  boolean sortrev
          sort normal or reversed ?
protected  int[] spos
          sorted positions
protected  java.lang.String[] titles
          titles per column (arraysize = no. of cols)
protected  int[] uniquecols
          columns that should be unique
protected  int visibleCols
          no. of currently visible rows
 
Fields inherited from class Awt
actionListener, Background, bg, big, bim, Black, BlueMask, Bold, Bolditalic, borderDepth, borderType, BOTTOM, Brighter, Bulk, BULK, C, Center, CENTER, ColorMask, componentStates, Darker, E, East, EFFECT_MASK, Esc, FILL, Flat, FontMask, fonts, FontSize0, FontSizeMask, Foreground, GreenMask, Href, HREF, Hrefend, innerInsets, insets, Italic, itemListener, jvendor, jversion, Larger, LEFT, minimumDimension, MISC_MASK, Monospaced, N, NE, None, NONE, North, NorthEast, NorthWest, Null, NW, Plain, POSITION_MASK, Raised, RAISED, RedMask, RIGHT, S, SansSerif, SE, Serif, Smaller, South, SouthEast, SouthWest, Sunken, SUNKEN, SW, Tab0, TabMask, TabSizeMask, TOP, Uline, ULINE, W, West, White
 
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
MultiColumnList(java.lang.String[] tls, int visCols, int minVisCols, int minVisRows)
          Creates a new scrolling list.
 
Method Summary
 void addItem(java.lang.String item)
          Add a item row to the list with just one col
 void addItem(java.lang.String[] item)
          Add a item row to the list
 void addItems(java.lang.String[] items)
          several rows to the list with just one col
 void addItems(java.lang.String[][] items)
          Add several rows to the list
 void addNotify()
          override Awt.addNotify()
 void adjustmentValueChanged(java.awt.event.AdjustmentEvent e)
          implement java.awt.event.AdjustmentListener
 void clear()
          Remove everything from the list
 void deleteItem(int row)
          Remove one row from the list
 void deleteItem(java.lang.String item)
          Remove one row from the list (matching only first col)
 void deleteItem(java.lang.String item, int col)
          Remove one row from the list matching in col
 boolean equalsItem(java.lang.String[] item, int row, int[] cols)
          See if item[] equals a specific row
 int findItem(java.lang.String item)
          Find an item in column 0 - return row on succes ot -1 otherwis
 int findItem(java.lang.String[] item, int[] cols)
          Find an item in specific columns - return row on succes ot -1 otherwise
 int findItem(java.lang.String item, int col)
          Find an item in a specific column - return row on succes ot -1 otherwise
 int getColumnCount()
          Return the column count
 java.lang.String[] getItem(int row)
          Returns the contents of a given row (all cols)
 java.lang.String getItem(int row, int col)
          Returns the contents of a given cell
 java.lang.String[] getItem(int row, int[] col)
          Returns the contents of a given row (selected cols)
 int getItemCount()
          Return the item count
 java.lang.String[][] getItems()
          Returns the all content
 java.lang.String[] getItems(int col)
          gets the contents of one given col as string array
 java.lang.String[][] getItems(int[] col)
          Gets the contents of given cols as string array
 int getSelectedIndex()
          Return the selected row
 java.lang.String[] getSelectedItem()
          Return the selected item
 java.lang.Object[] getSelectedObjects()
          implement ItemSelectable()
 int getSortColumn()
          which column to sort ?
 java.lang.String[] getTitles()
          get all column titles
 int[] getUniqueColumns()
          which columns are unique ?
 int getVisibleCols()
          how many columns are currently visible?
 float[] getWidths()
          get the proportional widths of each column
 boolean isAdjustable()
          can this lists columns be adjusted by user ?
 boolean isShowTitle()
          is a title shown ?
 boolean isSortReverse()
          reverse sort set ?
 boolean isValidColumn(int col)
          check if a column is valid
 boolean isValidRow(int row)
          check if a row is valid
 void keyPressed(java.awt.event.KeyEvent e)
          implement java.awt.event.KeyListener
 void keyTyped(java.awt.event.KeyEvent e)
          implement java.awt.event.KeyListener
 void makeVisible()
          Make sure selected item is visble
 java.awt.Dimension measure()
          calculate required sizes
 void mouseDragged(java.awt.event.MouseEvent e)
          implement java.awt.event.MouseListener actively update screen while mouse drags column separator
 void mouseExited(java.awt.event.MouseEvent e)
          implement java.awt.event.MouseListener
 void mouseMoved(java.awt.event.MouseEvent e)
          implement java.awt.event.MouseListener Check if mouse is over a column separator & change cursor
 void mousePressed(java.awt.event.MouseEvent e)
          implement java.awt.event.MouseListener
 void paint(java.awt.Graphics g)
          Overwirte paint to do the actual artwork ;-)
 void removeAll()
          Remove everything from the list
 void setAdjustable(boolean adjustable)
          Turns on or off the user's ability to adjust column widths
 void setBounds(int x, int y, int w, int h)
          Called by the system when this component gets resized - intercept to do some layout
 void setItem(int row, int col, java.lang.String value)
          Sets the contents of a given cell
 void setSelectedIndex(int sel)
          Set the selected row to index
 void setShowTitle(boolean showTitle)
          show or hide a title
 void setSortColumn(int sc)
          set column to sort
 void setSortReverse(boolean sortrev)
          set sort direction
 void setUniqueColumns(int[] uc)
          set unique columns
 void setVisibleCols(int cols)
          set number of visible columns
 void setWidths(float[] w)
          Set the proportional widths of each column
 
Methods inherited from class Awt
addActionListener, addItemListener, Array2Insets, bold, bolditalic, brighter, centerWindow, Color2Esc, darker, dim, doHref, doMeasure, drawCaption, drawCaption, drawLine, drawRectangle, drawString, drawString, drawTriangle, error, exHref, exString, focusGained, focusLost, getAppletContext, getBG, getBGImage, getBGParent, getBGParentImage, getBorderDepth, getBorderRectangle, getBorderType, getColor, getColor, getFont, getFont, getFont, getInnerInsets, getInnerRectangle, getInsets, getMetrics, getMinimumSize, getMode, getPosition, getPreferredSize, getRectangle, getTab, getTopComponent, invalidate, isBulk, isEffect, isFill, isHref, isMSJVM, isNS4JVM, isRaised, isSunken, isUline, italic, keyReleased, larger, loadImage, loadImageFromArchive, loadImageFromStream, loadImageFromURL, makeBim, measureCaption, measureString, monospaced, mouseClicked, mouseEntered, mouseReleased, notifyActionListeners, notifyItemListeners, paintBackground, paintBackground, paintBim, paintBorder, plain, refresh, refresh, refreshAll, removeActionListener, removeItemListener, sansserif, serif, setBackground, setBG, setBGIfNull, setBorderDepth, setBorderType, setBorderType, setEnabled, setFont, setFont, setForeground, setInnerInsets, setInsets, setVisible, smaller, tile, tile, update, waitForImage
 
Methods inherited from class java.awt.Panel
getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getListeners, getMaximumSize, insets, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, 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, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

titles

protected java.lang.String[] titles
titles per column (arraysize = no. of cols)


items

protected java.util.Vector[] items
items per column (arraysize = no. of cols)


showTitle

protected boolean showTitle
show title ?


showLines

protected boolean showLines
show lines ?


adjustable

protected boolean adjustable
user adjustable ?


sortrev

protected boolean sortrev
sort normal or reversed ?


sortign

protected boolean sortign
sort ignore case ?


minVisibleRows

protected int minVisibleRows
to determine minimal space required


minVisibleCols

protected int minVisibleCols
minimal no. of rows that must be visible


visibleCols

protected int visibleCols
no. of currently visible rows


selrow

protected int selrow
selected row (-1 for no selection)


sortcol

protected int sortcol
column being sorted (-1 for unsorted)


dragcol

protected int dragcol
column being resized (-1 for none)


uniquecols

protected int[] uniquecols
columns that should be unique


borderw

protected int borderw
border width around titles & col separators


moc

protected int moc
mouse over column


lastclick

protected long lastclick
last mouse click time (to enable doubleclick)


cwidth

protected float[] cwidth
proportional column widths (sum = 1.0)


cpos

protected int[] cpos
column x positions


spos

protected int[] spos
sorted positions


scrollbar

protected java.awt.Scrollbar scrollbar
scrollbar at the right side


image

protected java.awt.Image image
backing image for flickerfree drawing

Constructor Detail

MultiColumnList

public MultiColumnList(java.lang.String[] tls,
                       int visCols,
                       int minVisCols,
                       int minVisRows)
Creates a new scrolling list. The number of cols is equal to t.length. The number of initially visible cols is specified via visibleCols.

Method Detail

addItem

public void addItem(java.lang.String[] item)
Add a item row to the list

Parameters:
item - row to add

addItem

public void addItem(java.lang.String item)
Add a item row to the list with just one col

Parameters:
item - row to add

addItems

public void addItems(java.lang.String[][] items)
Add several rows to the list


addItems

public void addItems(java.lang.String[] items)
several rows to the list with just one col


deleteItem

public void deleteItem(int row)
Remove one row from the list


deleteItem

public void deleteItem(java.lang.String item)
Remove one row from the list (matching only first col)

Parameters:
item - row to remove

deleteItem

public void deleteItem(java.lang.String item,
                       int col)
Remove one row from the list matching in col

Parameters:
item - item to find
col - col to search in

clear

public void clear()
Remove everything from the list


removeAll

public void removeAll()
Remove everything from the list

Overrides:
removeAll in class java.awt.Container

getItem

public java.lang.String[] getItem(int row)
Returns the contents of a given row (all cols)

Parameters:
row - row to return

getItem

public java.lang.String[] getItem(int row,
                                  int[] col)
Returns the contents of a given row (selected cols)

Parameters:
row - row to return
col - cols to return

getItem

public java.lang.String getItem(int row,
                                int col)
Returns the contents of a given cell

Parameters:
row - row of item to return
col - col of item to return

getItems

public java.lang.String[] getItems(int col)
gets the contents of one given col as string array

Parameters:
col - col to return

getItems

public java.lang.String[][] getItems(int[] col)
Gets the contents of given cols as string array

Parameters:
col - cols to return

getItems

public java.lang.String[][] getItems()
Returns the all content


setItem

public void setItem(int row,
                    int col,
                    java.lang.String value)
Sets the contents of a given cell

Parameters:
row - row of cell to set
col - col of cell to set
value - value to set

getSelectedItem

public java.lang.String[] getSelectedItem()
Return the selected item


getSelectedIndex

public int getSelectedIndex()
Return the selected row


setSelectedIndex

public void setSelectedIndex(int sel)
Set the selected row to index

Parameters:
sel - row to select

equalsItem

public boolean equalsItem(java.lang.String[] item,
                          int row,
                          int[] cols)
See if item[] equals a specific row

Parameters:
item - each array elem represents one column
row - row to compare with
cols - cols of row to compare with item

findItem

public int findItem(java.lang.String item)
Find an item in column 0 - return row on succes ot -1 otherwis

Parameters:
item - item to find

findItem

public int findItem(java.lang.String item,
                    int col)
Find an item in a specific column - return row on succes ot -1 otherwise

Parameters:
item - item to find
col - col to search in

findItem

public int findItem(java.lang.String[] item,
                    int[] cols)
Find an item in specific columns - return row on succes ot -1 otherwise

Parameters:
item - item to find - each array elem represents one column
cols - cols to search in

getItemCount

public int getItemCount()
Return the item count


getColumnCount

public int getColumnCount()
Return the column count


isValidRow

public boolean isValidRow(int row)
check if a row is valid

Parameters:
row - row to check

isValidColumn

public boolean isValidColumn(int col)
check if a column is valid

Parameters:
col - col to check

getWidths

public float[] getWidths()
get the proportional widths of each column


setWidths

public void setWidths(float[] w)
Set the proportional widths of each column


isAdjustable

public boolean isAdjustable()
can this lists columns be adjusted by user ?


setAdjustable

public void setAdjustable(boolean adjustable)
Turns on or off the user's ability to adjust column widths

Parameters:
adjustable - Can adjust or not?

isShowTitle

public boolean isShowTitle()
is a title shown ?


setShowTitle

public void setShowTitle(boolean showTitle)
show or hide a title

Parameters:
showTitle - show or not?

getUniqueColumns

public int[] getUniqueColumns()
which columns are unique ?


setUniqueColumns

public void setUniqueColumns(int[] uc)
set unique columns

Parameters:
uc - array of unique columns

isSortReverse

public boolean isSortReverse()
reverse sort set ?


setSortReverse

public void setSortReverse(boolean sortrev)
set sort direction

Parameters:
sortrev - true=sort reverse false=sort normal

getSortColumn

public int getSortColumn()
which column to sort ?


setSortColumn

public void setSortColumn(int sc)
set column to sort

Parameters:
sc - sort column; -1 for none

getVisibleCols

public int getVisibleCols()
how many columns are currently visible?


setVisibleCols

public void setVisibleCols(int cols)
set number of visible columns

Parameters:
cols - how many columns should be visible

getTitles

public java.lang.String[] getTitles()
get all column titles


setBounds

public void setBounds(int x,
                      int y,
                      int w,
                      int h)
Called by the system when this component gets resized - intercept to do some layout

Overrides:
setBounds in class Awt
Parameters:
x - x-position
y - y-position
w - width
h - height

paint

public void paint(java.awt.Graphics g)
Overwirte paint to do the actual artwork ;-)

Overrides:
paint in class Awt
Parameters:
g - Graphics object to use

makeVisible

public void makeVisible()
Make sure selected item is visble


getSelectedObjects

public java.lang.Object[] getSelectedObjects()
implement ItemSelectable()

Specified by:
getSelectedObjects in interface java.awt.ItemSelectable
Overrides:
getSelectedObjects in class Awt

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
implement java.awt.event.MouseListener

Specified by:
mouseExited in interface java.awt.event.MouseListener
Overrides:
mouseExited in class Awt

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
implement java.awt.event.MouseListener Check if mouse is over a column separator & change cursor

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Overrides:
mouseMoved in class Awt

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
implement java.awt.event.MouseListener actively update screen while mouse drags column separator

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Overrides:
mouseDragged in class Awt

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
implement java.awt.event.MouseListener

Specified by:
mousePressed in interface java.awt.event.MouseListener
Overrides:
mousePressed in class Awt

adjustmentValueChanged

public void adjustmentValueChanged(java.awt.event.AdjustmentEvent e)
implement java.awt.event.AdjustmentListener

Specified by:
adjustmentValueChanged in interface java.awt.event.AdjustmentListener
Overrides:
adjustmentValueChanged in class Awt

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
implement java.awt.event.KeyListener

Specified by:
keyTyped in interface java.awt.event.KeyListener
Overrides:
keyTyped in class Awt

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
implement java.awt.event.KeyListener

Specified by:
keyPressed in interface java.awt.event.KeyListener
Overrides:
keyPressed in class Awt

measure

public java.awt.Dimension measure()
calculate required sizes

Overrides:
measure in class Awt

addNotify

public void addNotify()
override Awt.addNotify()

Overrides:
addNotify in class Awt

[.home.]
[.hacks.]
[.java.]