cst.loggingTool.presentationLayer
Class DateFieldView

java.lang.Object
  extended by cst.loggingTool.presentationLayer.AbstractFieldView
      extended by cst.loggingTool.presentationLayer.DateFieldView
All Implemented Interfaces:
java.util.EventListener, javax.swing.event.ChangeListener

public class DateFieldView
extends AbstractFieldView
implements javax.swing.event.ChangeListener


 Copyright 2010 Medical Research Council Unit for Lifelong Health and Ageing
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software 
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.  
 

Version:
1.0
Author:
Kevin Garwood (kgarwood@users.sourceforge.net)

Field Summary
 
Fields inherited from class cst.loggingTool.presentationLayer.AbstractFieldView
fieldLabel, log, saveChangesMonitor, sessionProperties, userInterfaceFactory
 
Constructor Summary
DateFieldView(SessionProperties sessionProperties, java.lang.String labelText, java.lang.String toolTipText, DateFieldModel dateFieldModel)
           
 
Method Summary
 boolean commitChanges()
           
 void disableView()
           
 void enableView()
           
 void enableView(java.util.Date currentDateValue)
           
 javax.swing.JCheckBox getCheckBox()
           
 DateFieldModel getDateFieldModel()
           
 javax.swing.JPanel getDatePanel()
           
 java.lang.String getDateString()
           
 java.util.Date getDisplayedDate()
           
 java.util.Date getSavedDate()
           
 javax.swing.JFormattedTextField getTextField(javax.swing.JSpinner spinner)
          Return the formatted text field used by the editor, or null if the editor doesn't descend from JSpinner.DefaultEditor.
 void initialiseView(java.util.Date date)
           
 boolean isSelected()
           
 boolean isValidFieldValue()
           
 void restoreSavedValues()
           
 void setDateString(java.lang.String dateString)
          this method is used solely to promote testing in date validation facilities.
 void setSelected(boolean isSelected)
          test method used to programmatically set the state of a checkbox
 void stateChanged(javax.swing.event.ChangeEvent event)
           
 
Methods inherited from class cst.loggingTool.presentationLayer.AbstractFieldView
allowSaveChanges, deregisterChange, disableSaveChangesAbility, getFieldLabel, getFieldName, getParentForm, registerChange, setEnableSaveChangesTriggers, setFieldName, setParentForm
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateFieldView

public DateFieldView(SessionProperties sessionProperties,
                     java.lang.String labelText,
                     java.lang.String toolTipText,
                     DateFieldModel dateFieldModel)
Method Detail

getTextField

public javax.swing.JFormattedTextField getTextField(javax.swing.JSpinner spinner)
Return the formatted text field used by the editor, or null if the editor doesn't descend from JSpinner.DefaultEditor.


getCheckBox

public javax.swing.JCheckBox getCheckBox()

isSelected

public boolean isSelected()

setSelected

public void setSelected(boolean isSelected)
test method used to programmatically set the state of a checkbox

Parameters:
isSelected -

getDatePanel

public javax.swing.JPanel getDatePanel()

initialiseView

public void initialiseView(java.util.Date date)

enableView

public void enableView()
Specified by:
enableView in class AbstractFieldView

enableView

public void enableView(java.util.Date currentDateValue)

disableView

public void disableView()
Specified by:
disableView in class AbstractFieldView

commitChanges

public boolean commitChanges()

restoreSavedValues

public void restoreSavedValues()

getDateString

public java.lang.String getDateString()

setDateString

public void setDateString(java.lang.String dateString)
this method is used solely to promote testing in date validation facilities. DateFieldValidationUtility tests DateFieldView for various things, including whether the spinners for day month and year are set to legal date values.

Part of the tests is to set field view instances with dates which have too many days for a given month. SimpleDateFormat is used to create illegal date instances but for this to work, setLenient(...) must be set to true. However, this means SimpleDateFormat simply adds illegal days to the date it produces. For example "29-FEB-2009" will cause SimpleDateFormat to return "01-MAR-2009" - which is a legal date. To get around this, we have this method which will actually try to simulate a person choosing a specific string in each of the day, month and year spinners

Parameters:
dateString - - a date of the format "dd-MMM-yyyy"

getDisplayedDate

public java.util.Date getDisplayedDate()

getSavedDate

public java.util.Date getSavedDate()

getDateFieldModel

public DateFieldModel getDateFieldModel()

isValidFieldValue

public boolean isValidFieldValue()

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent event)
Specified by:
stateChanged in interface javax.swing.event.ChangeListener