de.unihalle.informatik.Alida.dataio.provider.swing
Class ALDNativeArray2DDataIOSwing.ArrayConfigWindow

java.lang.Object
  extended by de.unihalle.informatik.Alida.dataio.provider.swing.events.ALDSwingValueChangeReporter
      extended by de.unihalle.informatik.Alida.dataio.provider.swing.ALDNativeArray2DDataIOSwing.ArrayConfigWindow
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener, javax.swing.event.TableModelListener
Enclosing class:
ALDNativeArray2DDataIOSwing

private class ALDNativeArray2DDataIOSwing.ArrayConfigWindow
extends ALDSwingValueChangeReporter
implements java.awt.event.ActionListener, javax.swing.event.TableModelListener

Graphical user interface window for displaying objects of class DefaultTableModel.

Author:
moeller

Nested Class Summary
protected  class ALDNativeArray2DDataIOSwing.ArrayConfigWindow.DataTabFileFilter
          Internal class that realizes a FileFilter for text files where MiToBo table data is stored.
protected  class ALDNativeArray2DDataIOSwing.ArrayConfigWindow.TableFocusListener
          Focus listener to commit edits if table looses the focus.
 
Field Summary
protected  javax.swing.JTable dataTab
          Data table (swing tables are nicer than imageJ tables).
private  javax.swing.table.DefaultTableModel dataTabModel
          Reference object to the data.
private  ALDParameterDescriptor descriptor
          Optional descriptor for additional information on parameter.
private  java.lang.Class<?> entryClass
          Class of objects to be filled in the table.
private  java.lang.Object[][] entryRefList
          List of currently specified values (to restore entry if check fails).
private  java.io.File lastDir
          For convenience: always open last directory for saving.
private  javax.swing.JScrollPane tableScroller
          Scrollpane for table panel;
private  javax.swing.JPanel tabPanel
          Table component in window.
private  javax.swing.JFrame window
          Main window.
protected  boolean windowHasFocus
          Flag to indicate the table window has the focus.
 
Fields inherited from class de.unihalle.informatik.Alida.dataio.provider.swing.events.ALDSwingValueChangeReporter
listenerList
 
Constructor Summary
ALDNativeArray2DDataIOSwing.ArrayConfigWindow(java.lang.reflect.Field field, java.lang.Class<?> cl, java.lang.Object obj, ALDParameterDescriptor descr)
          Default constructor.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
private  void errorListToMessage(java.util.LinkedList<int[]> errorList)
          Error function displaying an error message box.
 java.lang.Object readData(java.lang.reflect.Field field, java.lang.Class<?> cl)
           
protected  void resizeTableEntries(int newRows, int newCols)
          Method to resize the reference entry list.
protected  void saveTable()
          Saves the contents of the table to a user-specified file.
protected  void setTabEntryToDefault(int row, int col, java.lang.Class<?> cl)
          Sets the specified table entry to the class default.
private  void setupTable()
          Initializes the data table window.
 void setValue(java.lang.reflect.Field field, java.lang.Class<?> cl, java.lang.Object value)
           
 void tableChanged(javax.swing.event.TableModelEvent e)
           
protected  boolean validateEntry(java.lang.Class<?> cl, java.lang.String entry)
          Checks if a string can be cast to the desired class.
 
Methods inherited from class de.unihalle.informatik.Alida.dataio.provider.swing.events.ALDSwingValueChangeReporter
addValueChangeEventListener, fireALDSwingValueChangeEvent, removeValueChangeEventListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataTab

protected javax.swing.JTable dataTab
Data table (swing tables are nicer than imageJ tables).


dataTabModel

private javax.swing.table.DefaultTableModel dataTabModel
Reference object to the data.


descriptor

private ALDParameterDescriptor descriptor
Optional descriptor for additional information on parameter.


entryClass

private java.lang.Class<?> entryClass
Class of objects to be filled in the table.


entryRefList

private java.lang.Object[][] entryRefList
List of currently specified values (to restore entry if check fails).


lastDir

private java.io.File lastDir
For convenience: always open last directory for saving.


tableScroller

private javax.swing.JScrollPane tableScroller
Scrollpane for table panel;


tabPanel

private javax.swing.JPanel tabPanel
Table component in window.


window

private javax.swing.JFrame window
Main window.


windowHasFocus

protected boolean windowHasFocus
Flag to indicate the table window has the focus.

By this multiple warnings on the same issue should be avoided. They might happen due to table change events and focus change events being triggered at the same time.

Constructor Detail

ALDNativeArray2DDataIOSwing.ArrayConfigWindow

public ALDNativeArray2DDataIOSwing.ArrayConfigWindow(java.lang.reflect.Field field,
                                                     java.lang.Class<?> cl,
                                                     java.lang.Object obj,
                                                     ALDParameterDescriptor descr)
Default constructor.

Parameters:
field - Field of array.
cl - Class of array elements.
obj - Default values.
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

errorListToMessage

private void errorListToMessage(java.util.LinkedList<int[]> errorList)
                         throws ALDDataIOProviderException
Error function displaying an error message box.

Parameters:
r - Row of table where error occured.
c - Column of table where error occured.
Throws:
ALDDataIOProviderException

readData

public java.lang.Object readData(java.lang.reflect.Field field,
                                 java.lang.Class<?> cl)
                          throws ALDDataIOProviderException
Throws:
ALDDataIOProviderException

resizeTableEntries

protected void resizeTableEntries(int newRows,
                                  int newCols)
Method to resize the reference entry list.

Existing entries are preserved as far as possible.

Parameters:
newRows - New number of rows for the table.
newCols - New number of cols for the table.

saveTable

protected void saveTable()
Saves the contents of the table to a user-specified file.

The file format is TSV, i.e. tabulator-separated values. The default ending is '.txt'. The user can select the file name through a file open dialog which pops-up on call of the function.


setTabEntryToDefault

protected void setTabEntryToDefault(int row,
                                    int col,
                                    java.lang.Class<?> cl)
Sets the specified table entry to the class default.

Parameters:
row - Row index.
col - Column index.
cl - Class of table elements.

setupTable

private void setupTable()
Initializes the data table window.


setValue

public void setValue(java.lang.reflect.Field field,
                     java.lang.Class<?> cl,
                     java.lang.Object value)

tableChanged

public void tableChanged(javax.swing.event.TableModelEvent e)
Specified by:
tableChanged in interface javax.swing.event.TableModelListener

validateEntry

protected boolean validateEntry(java.lang.Class<?> cl,
                                java.lang.String entry)
Checks if a string can be cast to the desired class.

Parameters:
cl - Target class.
entry - String under consideration.
Returns:
True if cast is possible.