public class Word extends java.lang.Object implements java.lang.Comparable<Word>
Each Word object has a word String, and its associated weight, and it's constructed
with these two things.
Word[] to pass
to the WordCram (rather than using something like WordCram.fromWebPage(String)),
you can specify how a Word should be rendered: set a Word's font, size, etc:
Word w = new Word("texty", 20);
w.setFont(createFont("myFontName", 1));
w.setAngle(radians(45));
Any values set on a Word will override the corresponding component (WordColorer,
WordAngler, etc) - it won't even be called for that word.
Word strawberry = new Word("strawberry", 10);
strawberry.setProperty("isFruit", true);
Word pea = new Word("pea", 10);
pea.setProperty("isFruit", false);
new WordCram(this)
.fromWords(new Word[] { strawberry, pea })
.withColorer(new WordColorer() {
public int colorFor(Word w) {
if (w.getProperty("isFruit") == true) {
return color(255, 0, 0);
}
else {
return color(0, 200, 0);
}
}
});
| Constructor and Description |
|---|
Word(java.lang.String word,
float weight) |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Word w)
Compares Words based on weight only.
|
java.lang.Object |
getProperty(java.lang.String propertyName)
Get a property value from this Word, for a WordColorer, a WordPlacer, etc.
|
float |
getRenderedAngle()
Get the angle the Word was rendered at: either the value passed to setAngle(), or the value returned from the WordAngler.
|
int |
getRenderedColor()
Get the color the Word was rendered in: either the value passed to setColor(), or the value returned from the WordColorer.
|
processing.core.PFont |
getRenderedFont()
Get the font the Word was rendered in: either the value passed to setFont(), or the value returned from the WordFonter.
|
float |
getRenderedHeight()
Gets the height, in pixels, of the java.awt.Shape that will be rendered for
this Word, based on the Font, Angle, and Size for this Word.
|
processing.core.PVector |
getRenderedPlace()
Get the final place the Word was rendered at, or null if it couldn't be placed.
|
float |
getRenderedSize()
Get the size the Word was rendered at: either the value passed to setSize(), or the value returned from the WordSizer.
|
float |
getRenderedWidth()
Gets the width, in pixels, of the java.awt.Shape that will be rendered for
this Word, based on the Font, Angle, and Size for this Word.
|
processing.core.PVector |
getTargetPlace()
Get the place the Word was supposed to be rendered at: either the value passed to setPlace(),
or the value returned from the WordPlacer.
|
Word |
setAngle(float angle)
Set the angle this Word should be rendered at - WordCram won't even call the WordAngler.
|
Word |
setColor(int color)
Set the color this Word should be rendered in - WordCram won't call the WordColorer.
|
Word |
setFont(processing.core.PFont font)
Set the font this Word should be rendered in - WordCram won't call the WordFonter.
|
Word |
setPlace(float x,
float y)
Set the place this Word should be rendered at - WordCram won't call the WordPlacer.
|
Word |
setPlace(processing.core.PVector place)
Set the place this Word should be rendered at - WordCram won't call the WordPlacer.
|
Word |
setProperty(java.lang.String propertyName,
java.lang.Object propertyValue)
Set a property on this Word, to be used by a WordColorer, a WordPlacer, etc, down the line.
|
Word |
setSize(float size)
Set the size this Word should be rendered at - WordCram won't even call the WordSizer.
|
java.lang.String |
toString()
Displays the word, and its weight (in parentheses).
|
boolean |
wasPlaced()
Indicates whether the Word was placed successfully.
|
boolean |
wasSkipped()
Indicates whether the Word was skipped.
|
java.lang.Integer |
wasSkippedBecause()
Tells you why this Word was skipped.
|
public Word setSize(float size)
public Word setAngle(float angle)
public Word setFont(processing.core.PFont font)
public Word setColor(int color)
public Word setPlace(processing.core.PVector place)
public Word setPlace(float x, float y)
public float getRenderedSize()
public float getRenderedAngle()
public processing.core.PFont getRenderedFont()
public int getRenderedColor()
public processing.core.PVector getTargetPlace()
public processing.core.PVector getRenderedPlace()
public boolean wasPlaced()
wasSkipped() and wasSkippedBecause()).public boolean wasSkipped()
wasSkippedBecause()public java.lang.Integer wasSkippedBecause()
WordCram.WAS_OVER_MAX_NUMBER_OF_WORDS, WordCram.SHAPE_WAS_TOO_SMALL,
or WordCram.NO_SPACE.
If the word was successfully placed, or WordCram hasn't
gotten to this word yet, this will return null.public java.lang.Object getProperty(java.lang.String propertyName)
propertyName - null, if it's not there.public Word setProperty(java.lang.String propertyName, java.lang.Object propertyValue)
propertyName - propertyValue - public java.lang.String toString()
new Word("hello", 1.3).toString() will return "hello (0.3)".toString in class java.lang.Objectpublic int compareTo(Word w)
compareTo in interface java.lang.Comparable<Word>public float getRenderedWidth()
getRenderedHeight()public float getRenderedHeight()
getRenderedWidth()