fr.cnes.genopus.time
Class GPDateOffsetField

java.lang.Object
  extended by fr.cnes.genius.main.GComponent
      extended by fr.cnes.genius.lowLevel.GTextField
          extended by fr.cnes.genopus.time.GPDateOffsetField
All Implemented Interfaces:
fr.cnes.genius.main.GDisplay, fr.cnes.genius.main.GListener, ActionListener, FocusListener, KeyListener, EventListener

public class GPDateOffsetField
extends fr.cnes.genius.lowLevel.GTextField
implements fr.cnes.genius.main.GListener

Class implementing a dedicated field to hold date offsets.

Author:
jjct

Nested Class Summary
static class GPDateOffsetField.GPOffsetFormat
          Date formats.
 
Nested classes/interfaces inherited from class fr.cnes.genius.lowLevel.GTextField
fr.cnes.genius.lowLevel.GTextField.GDocumentFieldFilterAbstract
 
Nested classes/interfaces inherited from class fr.cnes.genius.main.GComponent
fr.cnes.genius.main.GComponent.CopyPasteOperation, fr.cnes.genius.main.GComponent.DisplayIndicatorStatus, fr.cnes.genius.main.GComponent.ItemType, fr.cnes.genius.main.GComponent.Operation
 
Field Summary
 
Fields inherited from class fr.cnes.genius.main.GComponent
NAME_ATTRIBUTE
 
Constructor Summary
GPDateOffsetField(String widgetId, String textValue)
          Constructor.
 
Method Summary
 void after(fr.cnes.genius.main.GEvent e)
          
 void before(fr.cnes.genius.main.GEvent e)
          
 String formatOffset()
          Formats a given offset in seconds into the current format and units defined in the widget.
static String formatOffset(double offset, GPDateOffsetField.GPOffsetFormat format, fr.cnes.genius.unit.GUnit outUnit)
          Formats a given offset in seconds into the given format and converting to the given units (unit conversion is only needed if target format is fractional).
static String formatOffsetCal(double offset)
          Formats a given offset in seconds to the calendar format: [-]<DD...
static String formatOffsetFrac(double offset, fr.cnes.genius.unit.GUnit outUnit)
          Formats a given offset in seconds, converting the value to the given units and rounding to a precision of 1 nanosecond.
 GPDateOffsetField.GPOffsetFormat getCurrentFormat()
          Getter for the offset format.
 fr.cnes.genius.unit.GUnit getCurrentUnit()
          Get the current unit.
 double getOffset()
          Getter for the offset value in seconds.
static double parseOffset(String stringOffset, fr.cnes.genius.unit.GUnit inUnit)
          Parse a given offset as a real number of seconds.
static Double parseOffsetCal(String stringOffset)
          Parse a given offset in Cal1 or Cal2 format as a real number of seconds.
static Double parseOffsetFrac(String stringOffset, fr.cnes.genius.unit.GUnit inUnit)
          Parse a given offset in fraction format as a real number of seconds.
 void setCurrentFormat(GPDateOffsetField.GPOffsetFormat offsetFormat)
          Setter for the offset format.
 void setCurrentUnit(fr.cnes.genius.unit.GUnit offsetUnit)
          Setter for the offset unit.
 void setDefaultUnit(fr.cnes.genius.unit.GUnit unit)
          Set the default unit.
 void setOffset(double offset)
          Setter for the offset value in seconds.
 void setValue(String stringOffset)
          Set offset from string.
 void setWidgetId(String widgetId)
          
 
Methods inherited from class fr.cnes.genius.lowLevel.GTextField
actionPerformed, computeDefaultWidth, display, focusGained, focusLost, getCharWidth, getComponent, getJTextField, getText, keyPressed, keyReleased, keyTyped, setDocumentFilter, setEnabled, setText
 
Methods inherited from class fr.cnes.genius.main.GComponent
activateConstraintsByType, attachCopyPasteMenu, attachCopyPasteMenu, beginOfElement, beginOfElement, beginOfElement, beginOfElement, composeWidgetId, doDisplay, endOfElement, getCommentInConfigFile, getConstraint, getCurrentOperation, getDisplayIndicatorStatus, getDisplayIsModifiedIndicator, getElement, getGPanel, getGParent, getGUnitInConfigFile, getInnerDescendantConstraint, getName, getNameInConfigFile, getOperationSaveValue, getSimpleWidgetId, getStatus, getStringConstraint, getSubComponent, getWidgetId, handleCopyPasteEvent, handleProcessEventException, isCopyPasteEvent, isEnabled, isModified, launchInvalidPositionException, parseSimpleConstraint, processGEvent, setBusyCursor, setCommentInConfigFile, setConstraint, setCopyPasteMenuEnabled, setCurrentOperation, setDataForConstraintsByType, setDisplayIsModifiedIndicator, setElement, setGPanel, setGParent, setGUnitInConfigFile, setInnerDescendantConstraint, setNameAndCommentInConfigFile, setNameInConfigFile, setStatus, setStringConstraint, setToolTipText, setWidth, updateIsModifiedIndicator, writeCollection, writeCollection, writeCollection, writeCollection, writeConfigItem, writeConfigItem, writeConfigItem, writeConfigItem, writeConfigItem
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GPDateOffsetField

public GPDateOffsetField(String widgetId,
                         String textValue)
Constructor.

Parameters:
widgetId - widget identifier.
textValue - offset value as string.
Method Detail

setWidgetId

public void setWidgetId(String widgetId)

Overrides:
setWidgetId in class fr.cnes.genius.main.GComponent

setCurrentUnit

public void setCurrentUnit(fr.cnes.genius.unit.GUnit offsetUnit)
                    throws GPDateException
Setter for the offset unit.

Parameters:
offsetUnit - format in which the offset will be shown in the widget.
Throws:
GPDateException - if given unit is not available in the widget.

getCurrentUnit

public fr.cnes.genius.unit.GUnit getCurrentUnit()
Get the current unit.

Returns:
the current unit.

setDefaultUnit

public void setDefaultUnit(fr.cnes.genius.unit.GUnit unit)
Set the default unit.

Parameters:
unit - default unit.

setCurrentFormat

public void setCurrentFormat(GPDateOffsetField.GPOffsetFormat offsetFormat)
Setter for the offset format.

Parameters:
offsetFormat - format in which the offset will be shown in the widget.

getCurrentFormat

public GPDateOffsetField.GPOffsetFormat getCurrentFormat()
Getter for the offset format.

Returns:
format in which the offset is shown in the widget.

setOffset

public void setOffset(double offset)
               throws GPDateException
Setter for the offset value in seconds.

Parameters:
offset - the offset in seconds to set.
Throws:
GPDateException - if the absolute value of the offset in days is too high ( Long.MAX_VALUE )

getOffset

public double getOffset()
Getter for the offset value in seconds.

Returns:
the date offset in seconds

setValue

public void setValue(String stringOffset)
              throws GPDateException
Set offset from string.

Parameters:
stringOffset - string offset to set.
Throws:
GPDateException - if offset is in bad format

formatOffset

public static String formatOffset(double offset,
                                  GPDateOffsetField.GPOffsetFormat format,
                                  fr.cnes.genius.unit.GUnit outUnit)
                           throws GPDateException
Formats a given offset in seconds into the given format and converting to the given units (unit conversion is only needed if target format is fractional).
The allowed output formats are:

- Cal: [-]<DD...>j<HH>h<MM>m<SS>s<AAA>ms<BBB>us<CCC>ns.
- Fractional: [-]<Offset>[.<OffsetFraction>] ~<Unit>

Parameters:
offset - offset in seconds to format.
format - target format.
outUnit - target unit (only if target format is fractional).
Returns:
the formated offset.
Throws:
GPDateException - if the absolute value of the offset in days is too high ( Long.MAX_VALUE )

formatOffsetCal

public static String formatOffsetCal(double offset)
                              throws GPDateException
Formats a given offset in seconds to the calendar format: [-]<DD...>j<HH>h<MM>m<SS>s<AAA>ms<BBB>us<CCC>ns.

Parameters:
offset - offset in seconds to format.
Returns:
the formated offset.
Throws:
GPDateException - if the absolute value of the offset in days is too high ( Long.MAX_VALUE )

formatOffsetFrac

public static String formatOffsetFrac(double offset,
                                      fr.cnes.genius.unit.GUnit outUnit)
Formats a given offset in seconds, converting the value to the given units and rounding to a precision of 1 nanosecond.

Parameters:
offset - offset in seconds to format.
outUnit - output unit for the formated offset.
Returns:
the formated offset.

formatOffset

public String formatOffset()
Formats a given offset in seconds into the current format and units defined in the widget.

Returns:
the formated offset.

parseOffset

public static double parseOffset(String stringOffset,
                                 fr.cnes.genius.unit.GUnit inUnit)
                          throws GPDateException
Parse a given offset as a real number of seconds.

Parameters:
stringOffset - offset string to parse
inUnit - the time unit in which the string offset is defined (only needed for fractional format if string offset does not contain the unit)
Returns:
the offset in seconds
Throws:
GPDateException - if offset is in bad format

parseOffsetCal

public static Double parseOffsetCal(String stringOffset)
Parse a given offset in Cal1 or Cal2 format as a real number of seconds.

Parameters:
stringOffset - offset string in Cal1 or Cal2 format to parse
Returns:
the offset in seconds

parseOffsetFrac

public static Double parseOffsetFrac(String stringOffset,
                                     fr.cnes.genius.unit.GUnit inUnit)
Parse a given offset in fraction format as a real number of seconds.

Parameters:
stringOffset - offset string in fraction format (days, hours, minutes...) to parse
inUnit - the time unit in which the string offset is defined (only needed if string offset does not contain the unit)
Returns:
the offset in seconds

before

public void before(fr.cnes.genius.main.GEvent e)
            throws fr.cnes.genius.exception.GException

Specified by:
before in interface fr.cnes.genius.main.GListener
Overrides:
before in class fr.cnes.genius.lowLevel.GTextField
Throws:
fr.cnes.genius.exception.GException

after

public void after(fr.cnes.genius.main.GEvent e)
           throws GPDateException

Specified by:
after in interface fr.cnes.genius.main.GListener
Overrides:
after in class fr.cnes.genius.lowLevel.GTextField
Throws:
GPDateException


Copyright © 2017. All rights reserved.