Whitespace
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@1104 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -85,8 +85,7 @@ public class ColorPository implements Serializable
|
|||||||
public HashIntMap<ColorRecord> colors = new HashIntMap<ColorRecord>();
|
public HashIntMap<ColorRecord> colors = new HashIntMap<ColorRecord>();
|
||||||
|
|
||||||
/** Used when parsing the color definitions. */
|
/** Used when parsing the color definitions. */
|
||||||
public void addColor (ColorRecord record)
|
public void addColor (ColorRecord record) {
|
||||||
{
|
|
||||||
// validate the color id
|
// validate the color id
|
||||||
if (record.colorId > 127) {
|
if (record.colorId > 127) {
|
||||||
log.warning("Refusing to add color record; colorId > 127",
|
log.warning("Refusing to add color record; colorId > 127",
|
||||||
@@ -133,14 +132,12 @@ public class ColorPository implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a random starting id from the entries in this class. */
|
/** Returns a random starting id from the entries in this class. */
|
||||||
public ColorRecord randomStartingColor ()
|
public ColorRecord randomStartingColor () {
|
||||||
{
|
|
||||||
return randomStartingColor(RandomUtil.rand);
|
return randomStartingColor(RandomUtil.rand);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a random starting id from the entries in this class. */
|
/** Returns a random starting id from the entries in this class. */
|
||||||
public ColorRecord randomStartingColor (Random rand)
|
public ColorRecord randomStartingColor (Random rand) {
|
||||||
{
|
|
||||||
// figure out our starter ids if we haven't already
|
// figure out our starter ids if we haven't already
|
||||||
if (_starters == null) {
|
if (_starters == null) {
|
||||||
ArrayList<ColorRecord> list = Lists.newArrayList();
|
ArrayList<ColorRecord> list = Lists.newArrayList();
|
||||||
@@ -164,23 +161,19 @@ public class ColorPository implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the default ColorRecord defined for this color class, or
|
* Get the default ColorRecord defined for this color class, or null if none.
|
||||||
* null if none.
|
|
||||||
*/
|
*/
|
||||||
public ColorRecord getDefault ()
|
public ColorRecord getDefault () {
|
||||||
{
|
|
||||||
return colors.get(defaultId);
|
return colors.get(defaultId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// from interface Comparable<ClassRecord>
|
// from interface Comparable<ClassRecord>
|
||||||
public int compareTo (ClassRecord other)
|
public int compareTo (ClassRecord other) {
|
||||||
{
|
|
||||||
return name.compareTo(other.name);
|
return name.compareTo(other.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString ()
|
public String toString () {
|
||||||
{
|
|
||||||
return "[id=" + classId + ", name=" + name + ", source=#" +
|
return "[id=" + classId + ", name=" + name + ", source=#" +
|
||||||
Integer.toString(source.getRGB() & 0xFFFFFF, 16) +
|
Integer.toString(source.getRGB() & 0xFFFFFF, 16) +
|
||||||
", range=" + StringUtil.toString(range) +
|
", range=" + StringUtil.toString(range) +
|
||||||
@@ -223,16 +216,14 @@ public class ColorPository implements Serializable
|
|||||||
* to identify a colorization record. This value will always be a positive integer that
|
* to identify a colorization record. This value will always be a positive integer that
|
||||||
* fits into 16 bits.
|
* fits into 16 bits.
|
||||||
*/
|
*/
|
||||||
public int getColorPrint ()
|
public int getColorPrint () {
|
||||||
{
|
|
||||||
return ((cclass.classId << 8) | colorId);
|
return ((cclass.classId << 8) | colorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the data in this record configured as a colorization instance.
|
* Returns the data in this record configured as a colorization instance.
|
||||||
*/
|
*/
|
||||||
public Colorization getColorization ()
|
public Colorization getColorization () {
|
||||||
{
|
|
||||||
// if (_zation == null) {
|
// if (_zation == null) {
|
||||||
// _zation = new Colorization(getColorPrint(), cclass.source,
|
// _zation = new Colorization(getColorPrint(), cclass.source,
|
||||||
// cclass.range, offsets);
|
// cclass.range, offsets);
|
||||||
@@ -242,14 +233,12 @@ public class ColorPository implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
// from interface Comparable<ColorRecord>
|
// from interface Comparable<ColorRecord>
|
||||||
public int compareTo (ColorRecord other)
|
public int compareTo (ColorRecord other) {
|
||||||
{
|
|
||||||
return name.compareTo(other.name);
|
return name.compareTo(other.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString ()
|
public String toString () {
|
||||||
{
|
|
||||||
return "[id=" + colorId + ", name=" + name +
|
return "[id=" + colorId + ", name=" + name +
|
||||||
", offsets=" + StringUtil.toString(offsets) + ", starter=" + starter + "]";
|
", offsets=" + StringUtil.toString(offsets) + ", starter=" + starter + "]";
|
||||||
}
|
}
|
||||||
@@ -270,14 +259,13 @@ public class ColorPository implements Serializable
|
|||||||
return _classes.values().iterator();
|
return _classes.values().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<ClassRecord> getClasses ()
|
public Collection<ClassRecord> getClasses ()
|
||||||
{
|
{
|
||||||
return _classes.values();
|
return _classes.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array containing the records for the colors in the
|
* Returns an array containing the records for the colors in the specified class.
|
||||||
* specified class.
|
|
||||||
*/
|
*/
|
||||||
public ColorRecord[] enumerateColors (String className)
|
public ColorRecord[] enumerateColors (String className)
|
||||||
{
|
{
|
||||||
@@ -297,8 +285,7 @@ public class ColorPository implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array containing the ids of the colors in the specified
|
* Returns an array containing the ids of the colors in the specified class.
|
||||||
* class.
|
|
||||||
*/
|
*/
|
||||||
public int[] enumerateColorIds (String className)
|
public int[] enumerateColorIds (String className)
|
||||||
{
|
{
|
||||||
@@ -488,8 +475,7 @@ public class ColorPository implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads up a serialized color pository from the supplied resource
|
* Loads up a serialized color pository from the supplied resource manager.
|
||||||
* manager.
|
|
||||||
*/
|
*/
|
||||||
public static ColorPository loadColorPository (ResourceManager rmgr)
|
public static ColorPository loadColorPository (ResourceManager rmgr)
|
||||||
{
|
{
|
||||||
@@ -502,8 +488,7 @@ public class ColorPository implements Serializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads up a serialized color pository from the supplied resource
|
* Loads up a serialized color pository from the supplied resource manager.
|
||||||
* manager.
|
|
||||||
*/
|
*/
|
||||||
public static ColorPository loadColorPository (InputStream source)
|
public static ColorPository loadColorPository (InputStream source)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -47,8 +47,7 @@ public class Colorization
|
|||||||
/**
|
/**
|
||||||
* Constructs a colorization record with the specified identifier.
|
* Constructs a colorization record with the specified identifier.
|
||||||
*/
|
*/
|
||||||
public Colorization (int colorizationId, Color rootColor,
|
public Colorization (int colorizationId, Color rootColor, float[] range, float[] offsets)
|
||||||
float[] range, float[] offsets)
|
|
||||||
{
|
{
|
||||||
this.colorizationId = colorizationId;
|
this.colorizationId = colorizationId;
|
||||||
this.rootColor = rootColor;
|
this.rootColor = rootColor;
|
||||||
@@ -56,8 +55,7 @@ public class Colorization
|
|||||||
this.offsets = offsets;
|
this.offsets = offsets;
|
||||||
|
|
||||||
// compute our HSV and fixed HSV
|
// compute our HSV and fixed HSV
|
||||||
_hsv = Color.RGBtoHSB(rootColor.getRed(), rootColor.getGreen(),
|
_hsv = Color.RGBtoHSB(rootColor.getRed(), rootColor.getGreen(), rootColor.getBlue(), null);
|
||||||
rootColor.getBlue(), null);
|
|
||||||
_fhsv = toFixedHSV(_hsv, null);
|
_fhsv = toFixedHSV(_hsv, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,9 +68,8 @@ public class Colorization
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adjusts the supplied color by the offsets in this colorization,
|
* Adjusts the supplied color by the offsets in this colorization, taking the appropriate
|
||||||
* taking the appropriate measures for hue (wrapping it around) and
|
* measures for hue (wrapping it around) and saturation and value (clipping).
|
||||||
* saturation and value (clipping).
|
|
||||||
*
|
*
|
||||||
* @return the RGB value of the recolored color.
|
* @return the RGB value of the recolored color.
|
||||||
*/
|
*/
|
||||||
@@ -93,12 +90,11 @@ public class Colorization
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this colorization matches the supplied color, false
|
* Returns true if this colorization matches the supplied color, false otherwise.
|
||||||
* otherwise.
|
|
||||||
*
|
*
|
||||||
* @param hsv the HSV values for the color in question.
|
* @param hsv the HSV values for the color in question.
|
||||||
* @param fhsv the HSV values converted to fixed point via {@link
|
* @param fhsv the HSV values converted to fixed point via {@link #toFixedHSV} for the color
|
||||||
* #toFixedHSV} for the color in question.
|
* in question.
|
||||||
*/
|
*/
|
||||||
public boolean matches (float[] hsv, int[] fhsv)
|
public boolean matches (float[] hsv, int[] fhsv)
|
||||||
{
|
{
|
||||||
@@ -149,16 +145,14 @@ public class Colorization
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts floating point HSV values to a fixed point integer
|
* Converts floating point HSV values to a fixed point integer representation.
|
||||||
* representation.
|
|
||||||
*
|
*
|
||||||
* @param hsv the HSV values to be converted.
|
* @param hsv the HSV values to be converted.
|
||||||
* @param fhsv the destination array into which the fixed values will
|
* @param fhsv the destination array into which the fixed values will be stored. If this is
|
||||||
* be stored. If this is null, a new array will be created of the
|
* null, a new array will be created of the appropriate length.
|
||||||
* appropriate length.
|
|
||||||
*
|
*
|
||||||
* @return the <code>fhsv</code> parameter if it was non-null or the
|
* @return the <code>fhsv</code> parameter if it was non-null or the newly created target
|
||||||
* newly created target array.
|
* array.
|
||||||
*/
|
*/
|
||||||
public static int[] toFixedHSV (float[] hsv, int[] fhsv)
|
public static int[] toFixedHSV (float[] hsv, int[] fhsv)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ import com.threerings.media.image.ColorPository.ColorRecord;
|
|||||||
import com.threerings.tools.xml.CompiledConfigParser;
|
import com.threerings.tools.xml.CompiledConfigParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the XML color repository definition and creates a {@link
|
* Parses the XML color repository definition and creates a {@link ColorPository} instance that
|
||||||
* ColorPository} instance that reflects its contents.
|
* reflects its contents.
|
||||||
*/
|
*/
|
||||||
public class ColorPositoryParser extends CompiledConfigParser
|
public class ColorPositoryParser extends CompiledConfigParser
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -422,7 +422,7 @@ public class ResourceManager
|
|||||||
return (File.separatorChar == '/') ? path : path.replace(File.separatorChar, '/');
|
return (File.separatorChar == '/') ? path : path.replace(File.separatorChar, '/');
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.warning("Failed to determine resource path [file=" + file + "].", e);
|
log.warning("Failed to determine resource path", "file", file, e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -937,16 +937,14 @@ public class ResourceManager
|
|||||||
/** Used to unpack bundles on a separate thread. */
|
/** Used to unpack bundles on a separate thread. */
|
||||||
protected static class Unpacker extends Thread
|
protected static class Unpacker extends Thread
|
||||||
{
|
{
|
||||||
public Unpacker (List<ResourceBundle> bundles, InitObserver obs)
|
public Unpacker (List<ResourceBundle> bundles, InitObserver obs) {
|
||||||
{
|
|
||||||
_bundles = bundles;
|
_bundles = bundles;
|
||||||
_obs = obs;
|
_obs = obs;
|
||||||
_startTime = System.currentTimeMillis();
|
_startTime = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run ()
|
public void run () {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
// Tell the observer were starting
|
// Tell the observer were starting
|
||||||
if (_obs != null) {
|
if (_obs != null) {
|
||||||
@@ -998,11 +996,9 @@ public class ResourceManager
|
|||||||
protected static class ObservedResource
|
protected static class ObservedResource
|
||||||
{
|
{
|
||||||
/** The observers listening for modifications to this resource. */
|
/** The observers listening for modifications to this resource. */
|
||||||
public WeakObserverList<ModificationObserver> observers =
|
public WeakObserverList<ModificationObserver> observers = WeakObserverList.newFastUnsafe();
|
||||||
WeakObserverList.newFastUnsafe();
|
|
||||||
|
|
||||||
public ObservedResource (File file)
|
public ObservedResource (File file) {
|
||||||
{
|
|
||||||
_file = file;
|
_file = file;
|
||||||
_lastModified = file.lastModified();
|
_lastModified = file.lastModified();
|
||||||
}
|
}
|
||||||
@@ -1015,8 +1011,7 @@ public class ResourceManager
|
|||||||
* @return <code>true</code> if the list of observers is empty and the resource should be
|
* @return <code>true</code> if the list of observers is empty and the resource should be
|
||||||
* removed from the observed list, <code>false</code> if it should remain in the list.
|
* removed from the observed list, <code>false</code> if it should remain in the list.
|
||||||
*/
|
*/
|
||||||
public boolean checkForModification (String path)
|
public boolean checkForModification (String path) {
|
||||||
{
|
|
||||||
long newLastModified = _file.lastModified();
|
long newLastModified = _file.lastModified();
|
||||||
if (newLastModified > _lastModified) {
|
if (newLastModified > _lastModified) {
|
||||||
_resourceModifiedOp.init(path, _lastModified = newLastModified);
|
_resourceModifiedOp.init(path, _lastModified = newLastModified);
|
||||||
@@ -1036,15 +1031,13 @@ public class ResourceManager
|
|||||||
protected static class ResourceModifiedOp
|
protected static class ResourceModifiedOp
|
||||||
implements ObserverList.ObserverOp<ModificationObserver>
|
implements ObserverList.ObserverOp<ModificationObserver>
|
||||||
{
|
{
|
||||||
public void init (String path, long lastModified)
|
public void init (String path, long lastModified) {
|
||||||
{
|
|
||||||
_path = path;
|
_path = path;
|
||||||
_lastModified = lastModified;
|
_lastModified = lastModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited from interface ObserverOp
|
// documentation inherited from interface ObserverOp
|
||||||
public boolean apply (ModificationObserver obs)
|
public boolean apply (ModificationObserver obs) {
|
||||||
{
|
|
||||||
obs.resourceModified(_path, _lastModified);
|
obs.resourceModified(_path, _lastModified);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,18 +35,16 @@ import com.threerings.util.CompiledConfig;
|
|||||||
import com.threerings.tools.CompiledConfigTask;
|
import com.threerings.tools.CompiledConfigTask;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract base implementation of a parser that is used to compile
|
* An abstract base implementation of a parser that is used to compile configuration definitions
|
||||||
* configuration definitions into config objects for use by the client and
|
* into config objects for use by the client and server.
|
||||||
* server.
|
*
|
||||||
*
|
|
||||||
* @see CompiledConfig
|
* @see CompiledConfig
|
||||||
* @see CompiledConfigTask
|
* @see CompiledConfigTask
|
||||||
*/
|
*/
|
||||||
public abstract class CompiledConfigParser
|
public abstract class CompiledConfigParser
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Parses the supplied configuration file into a serializable
|
* Parses the supplied configuration file into a serializable configuration object.
|
||||||
* configuration object.
|
|
||||||
*/
|
*/
|
||||||
public Serializable parseConfig (File source)
|
public Serializable parseConfig (File source)
|
||||||
throws IOException, SAXException
|
throws IOException, SAXException
|
||||||
@@ -60,8 +58,7 @@ public abstract class CompiledConfigParser
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the config object instance that will be populated during
|
* Creates the config object instance that will be populated during the parsing process.
|
||||||
* the parsing process.
|
|
||||||
*/
|
*/
|
||||||
protected abstract Serializable createConfigObject ();
|
protected abstract Serializable createConfigObject ();
|
||||||
|
|
||||||
|
|||||||
@@ -30,9 +30,8 @@ import java.io.ObjectOutputStream;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to load and store compiled configuration data (generally XML files
|
* Used to load and store compiled configuration data (generally XML files that are parsed into
|
||||||
* that are parsed into Java object models and then serialized for rapid
|
* Java object models and then serialized for rapid and simple access on the client and server).
|
||||||
* and simple access on the client and server).
|
|
||||||
*/
|
*/
|
||||||
public class CompiledConfig
|
public class CompiledConfig
|
||||||
{
|
{
|
||||||
@@ -52,8 +51,7 @@ public class CompiledConfig
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializes the supplied configuration object to the specified file
|
* Serializes the supplied configuration object to the specified file path.
|
||||||
* path.
|
|
||||||
*/
|
*/
|
||||||
public static void saveConfig (File target, Serializable config)
|
public static void saveConfig (File target, Serializable config)
|
||||||
throws IOException
|
throws IOException
|
||||||
|
|||||||
Reference in New Issue
Block a user