/*
This file is part of the software framework JStatCom,
a library for building applications for data based analysis.
Copyright (C) 2000-2005 Markus Kraetzig
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
package com.jstatcom.model;
import java.net.URL;
import javax.swing.Icon;
import javax.swing.ImageIcon;
/**
* This enumeration contains all existing JSCData types. If new
* data types are to be added, this class needs to be extended.
*
* @author Markus Kraetzig
*/
public abstract class JSCTypes {
private final String name;
private Icon icon = null;
/**
* Contains a single Double. Represented by
* JSCNumber.
*/
public static final JSCTypes NUMBER = new JSCTypes("NUMBER") {
public JSCData valueOfEmpty(String name) {
return new JSCNumber(name);
}
};
/**
* Contains a single Integer. Represented by
* JSCInt.
*/
public static final JSCTypes INT = new JSCTypes("INT") {
public JSCData valueOfEmpty(String name) {
return new JSCInt(name);
}
};
/**
* Contains a single String. Represented by
* JSCString.
*/
public static final JSCTypes STRING = new JSCTypes("STRING") {
public JSCData valueOfEmpty(String name) {
return new JSCString(name);
}
};
/**
* Contains an m x n double array. Represented by
* JSCNArray.
*/
public static final JSCTypes NARRAY = new JSCTypes("NARRAY") {
public JSCData valueOfEmpty(String name) {
return new JSCNArray(name);
}
};
/**
* Contains an m x n String array. Represented by
* JSCSArray.
*/
public static final JSCTypes SARRAY = new JSCTypes("SARRAY") {
public JSCData valueOfEmpty(String name) {
return new JSCSArray(name);
}
};
/**
* Contains an single TSDate. Represented by
* JSCDate.
*/
public static final JSCTypes DATE = new JSCTypes("DATE") {
public JSCData valueOfEmpty(String name) {
return new JSCDate(name);
}
};
/**
* Contains an single TSDateRange. Represented by
* JSCDRange.
*/
public static final JSCTypes DRANGE = new JSCTypes("DRANGE") {
public JSCData valueOfEmpty(String name) {
return new JSCDRange(name);
}
};
/**
* Contains an single arbitrary Object. Represented by
* JSCVoid.
*/
public static final JSCTypes VOID = new JSCTypes("VOID") {
public JSCData valueOfEmpty(String name) {
return new JSCVoid(name);
}
};
/**
* Contains an single arbitrary Object. Represented by
* JSCMap.
*/
public static final JSCTypes MAP = new JSCTypes("MAP") {
public JSCData valueOfEmpty(String name) {
return new JSCMap(name);
}
};
/**
* JSCTypes constructor.
*/
protected JSCTypes(String name) {
this.name = name;
}
/**
* Override prevention method to enforce a.equals(b) if and
* only if a==b.
*
* @param o
* object to compare with
* @return true if equal, false otherwise
*/
public final boolean equals(Object o) {
return super.equals(o);
}
/**
* Gets the respective icon that visualizes the type.
*
* @return icon for visualization of this type
*/
public Icon getIcon() {
if (icon == null) {
URL loc = getClass().getResource(
"/images/" + name.toLowerCase() + ".gif");
icon = (loc != null) ? new ImageIcon(loc) : null;
}
return icon;
}
/**
* Override prevention method invokes super method.
*
* @return hash code
*/
public final int hashCode() {
return super.hashCode();
}
/**
* Gets string representation of this object.
*
* @return a string
*/
public final String toString() {
return name;
}
/**
* Gets an empty JSCData instance for the specified type.
* Must be implemented by JSCTypes.
*
* @param name
* the name of the new instance
* @return instance of the respective type with isEmpty == true
*/
public abstract JSCData valueOfEmpty(String name);
}
Ads help maintain this website.