home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Languages Suite
/
ProgLangD.iso
/
VCAFE.3.0A
/
Main.bin
/
JDateMaskedFieldStyleEditor.java
< prev
next >
Wrap
Text File
|
1998-12-09
|
5KB
|
147 lines
/*
* @(#JDateMaskedFieldStyleEditor.java
*
* Copyright (c) 1998 Symantec Corporation. All Rights Reserved.
*
*/
// package statement
package com.symantec.itools.swing;
import java.beans.*;
import com.symantec.itools.swing.*;
import java.util.*;
import java.text.DateFormat;
/**
* Property editor for setting the formatting style of JDateMaskedField.
*
* @author Vasudev J. Rao
* @version 1.0
*/
public class JDateMaskedFieldStyleEditor extends PropertyEditorSupport {
// static variables
//private static BRLEditorsResourceLoader loader;
//private static ResourceBundle bundle;
//static {
//loader = BRLEditorsResourceLoader.getInstance();
//bundle = loader.getBundle();
//}
/**
* return the property value as a text
*
* @return the value as text
*/
public String getAsText() {
Integer value = (Integer)getValue();
int intValue = value.intValue();
String text = null;
if ( intValue == DateFormat.DEFAULT ) {
text = JDateMaskedField.DEFAULT_STYLE_STRING;
}
else if ( intValue == DateFormat.FULL ) {
text = JDateMaskedField.FULL_STYLE_STRING;
}
else if ( intValue == DateFormat.LONG ) {
text = JDateMaskedField.LONG_STYLE_STRING;
}
else if ( intValue == DateFormat.MEDIUM ) {
text = JDateMaskedField.MEDIUM_STYLE_STRING;
}
else if ( intValue == DateFormat.SHORT ) {
text = JDateMaskedField.SHORT_STYLE_STRING;
}
else {
text = "Illegal Value" ;
}
return text;
}
/**
* getTags() method
*
* @return array of tags
*/
public String[] getTags() {
String[] tags = new String[ JDateMaskedField.NUMBER_OF_STYLES ];
tags[0] = new String( JDateMaskedField.DEFAULT_STYLE_STRING );
tags[1] = new String( JDateMaskedField.FULL_STYLE_STRING );
tags[2] = new String( JDateMaskedField.LONG_STYLE_STRING );
tags[3] = new String( JDateMaskedField.MEDIUM_STYLE_STRING );
tags[4] = new String( JDateMaskedField.SHORT_STYLE_STRING );
return tags;
}
/**
* setAsText() method
*
* @param text set to String
*/
public void setAsText( String text ) throws IllegalArgumentException {
int type = 0 ;
if ( text.equals ( JDateMaskedField.DEFAULT_STYLE_STRING ) ) {
type = DateFormat.DEFAULT;
}
else if ( text.equals ( JDateMaskedField.FULL_STYLE_STRING ) ) {
type = DateFormat.FULL;
}
else if ( text.equals ( JDateMaskedField.LONG_STYLE_STRING ) ) {
type = DateFormat.LONG;
}
else if ( text.equals ( JDateMaskedField.MEDIUM_STYLE_STRING ) ) {
type = DateFormat.MEDIUM;
}
else if ( text.equals ( JDateMaskedField.SHORT_STYLE_STRING ) ) {
type = DateFormat.SHORT;
}
else {
type = DateFormat.LONG;
}
setValue( new Integer( type ) );
}
/**
* This method is intended for use when generating Java code to set
* the value of the property. It should return a fragment of Java code
* that can be used to initialize a variable with the current property
* value.
* <p>
* Example results are "2", "new Color(127,127,34)", "Color.orange", etc.
*
* @return A fragment of Java code representing an initializer for the
* current value.
*/
public String getJavaInitializationString() {
StringBuffer buf = new StringBuffer();
Integer value = (Integer)getValue();
int intValue = value.intValue();
buf.append ("java.text.DateFormat").append ("." );
if ( intValue == DateFormat.DEFAULT ) {
buf.append ( JDateMaskedField.DEFAULT_STYLE_STRING ) ;
}
else if ( intValue == DateFormat.FULL ) {
buf.append ( JDateMaskedField.FULL_STYLE_STRING );
}
else if ( intValue == DateFormat.LONG ) {
buf.append (JDateMaskedField.LONG_STYLE_STRING );
}
else if ( intValue == DateFormat.MEDIUM ) {
buf.append (JDateMaskedField.MEDIUM_STYLE_STRING );
}
else if ( intValue == DateFormat.SHORT ) {
buf.append (JDateMaskedField.SHORT_STYLE_STRING );
}
else {
buf .append ( JDateMaskedField.LONG_STYLE_STRING );
}
return buf.toString();
}
}