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

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

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

Graphical user interface window for displaying objects of class ALDTableModel.

Author:
moeller

Nested Class Summary
protected  class ALDNativeArray1DDataIOSwing.ArrayConfigWindow.DataTabFileFilter
          Internal class that realizes a java.swing.filechooser.FileFilter for text files where MiToBo table data is stored.
protected  class ALDNativeArray1DDataIOSwing.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  boolean disableValueChecks
          Flag to disable entry validation checks.
private  java.lang.Class<?> elementClass
          Class that table entries should represent.
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 frame.
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
ALDNativeArray1DDataIOSwing.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<java.lang.Integer> 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 newSize)
          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, 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)
          Fills the table with specified values.
 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.


disableValueChecks

private boolean disableValueChecks
Flag to disable entry validation checks.

Note that this flag is only valid for next event appearing. While processing the event the flag is reset to false.


elementClass

private java.lang.Class<?> elementClass
Class that table entries should represent.


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 frame.


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

ALDNativeArray1DDataIOSwing.ArrayConfigWindow

public ALDNativeArray1DDataIOSwing.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<java.lang.Integer> 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 newSize)
Method to resize the reference entry list.

Existing entries are preserved as far as possible.

Parameters:
newSize - New size 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,
                                    java.lang.Class<?> cl)
Sets the specified table entry to the class default.

Parameters:
row - Row to set.
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)
Fills the table with specified values.

Parameters:
field - Field specifying type of data.
cl - Class of array entries.
value - Value to set.

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.