jfxtras.labs.scene.control.gauge.ContentBuilder Maven / Gradle / Ivy
Show all versions of jfxtras-labs Show documentation
/**
* ContentBuilder.java
*
* Copyright (c) 2011-2015, JFXtras
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the organization nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package jfxtras.labs.scene.control.gauge;
import java.util.HashMap;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.geometry.Point2D;
import javafx.scene.shape.Rectangle;
import javafx.util.Builder;
/**
*
* @author Jose Pereda Llamas <jperedadnr>
* Created on : 09-jul-2012, 23:04:22
*/
public class ContentBuilder implements Builder {
private final HashMap properties = new HashMap<>();
/**
* To define a matrixPanel content, please indicate:
* - type: IMAGE, bmpName: file name (and path)
* - type: TEXT, txtContent: Text string, font, font fontGap
* and:
* area, origin, color, effect (and lapse), postEffect (and pause)
*
To alternate contents in the same area use order
*
* @return
*/
public static final ContentBuilder create(){
return new ContentBuilder();
}
/**
* Set the matrix LED's color
* @param MATRIX_COLOR Choose the matrix LED's color:
*
- MatrixColor.RED: there are three tones of RED: 85,170,255; BLUE and GREEN are filtered to 0.
* - MatrixColor.GREEN: there are three tones of GREEN: 85,170,255; RED and BLUE are filtered to 0.
* - MatrixColor.BLUE: there are three tones of BLUE: 85,170,255; RED and GREEN are filtered to 0.
* - MatrixColor.RGB: there are three tones of RED, BLUE AND GREEN: 85,170,255 for each one of them.
* @return
*/
public final ContentBuilder color(final Content.MatrixColor MATRIX_COLOR) {
properties.put("color", new SimpleObjectProperty<>(MATRIX_COLOR));
return this;
}
/**
* Set the content type
* @param TYPE Choose the type of the content:
* - Type.IMAGE: The content is a BMP Image
* - Type.TEXT: The content is a line of Text
* @return
*/
public final ContentBuilder type(final Content.Type TYPE) {
properties.put("type", new SimpleObjectProperty<>(TYPE));
return this;
}
/**
* Set the point of origin of the content
* @return
* @see #area(int, int, int, int)
* @see #origin(int, int)
* @param ORIGIN Insert a Point2D with the (int) X and Y coordinates, relative to the area
* in which the content is displayed, measured from the left-top of it, to the right-bottom.
*/
public final ContentBuilder origin(final Point2D ORIGIN) {
properties.put("origin", new SimpleObjectProperty<>(ORIGIN));
return this;
}
/**
* Set the point of origin of the content
* @return
* @see #area(int, int, int, int)
* @see #origin(Point2D)
* @param ORIGIN_X Insert the X coordinate, relative to the area
* in which the content is displayed, measured from the left of it, to the right.
* @param ORIGIN_Y Insert the Y coordinate, relative to the area
* in which the content is displayed, measured from the top of it, to the bottom.
*/
public final ContentBuilder origin(final int ORIGIN_X, final int ORIGIN_Y) {
properties.put("origin", new SimpleObjectProperty<>(new Point2D(ORIGIN_X,ORIGIN_Y)));
return this;
}
/**
* Set the area where the content is displayed
* @return
* @see #area(int, int, int, int)
* @param AREA Insert a Rectangle with X,Y as the left-top coordinates, and W,H as the width and height
* of the window in which the content will be displayed.
* This area should be inside the bounds of the matrixPanel and should not overlap with other areas.
*
The very same area could be used to display two different contents, check order(RotationOrder).
*/
public final ContentBuilder area(final Rectangle AREA) {
final Rectangle RECT=new Rectangle(AREA.getX(),AREA.getY(),AREA.getX()+AREA.getWidth(),AREA.getY()+AREA.getHeight());
properties.put("area", new SimpleObjectProperty<>(RECT));
return this;
}
/**
* Set the area where the content is displayed
* @return
* @see #area(Rectangle)
* @param ORIGIN_X Insert the X left coordinate of the window in which the content is displayed.
* @param ORIGIN_Y Insert the Y top coordinate of the window in which the content is displayed.
* @param END_X Insert the X rigth coordinate of the window in which the content is displayed.
* @param END_Y Insert the Y bottom coordinate of the window in which the content is displayed.
*
This window should be inside the bounds of the matrixPanel and should not overlap with other areas.
*
The very same area could be used to display two different contents, check order(RotationOrder).
*/
public final ContentBuilder area(final int ORIGIN_X, final int ORIGIN_Y, final int END_X, final int END_Y) {
properties.put("area", new SimpleObjectProperty<>(new Rectangle(ORIGIN_X,ORIGIN_Y,END_X,END_Y)));
return this;
}
/**
* Set the name of the bmp image
* see type(Content.Type Content.Type.IMAGE)
* @param BMP_NAME Options for a valid name of a BMP image, with or without ".bmp" extension:
*
- It should be already in the source (relative to matrixPanel package)
* - It should be in any of the project's jars, so /package/path/to/file must be provided
* - or a full valid path should be added to the name in case it has be loaded from an external resource
* @return
*/
public final ContentBuilder bmpName(final String BMP_NAME) {
properties.put("bmpName", new SimpleStringProperty(BMP_NAME));
return this;
}
/**
* Set the text string
* see type(Content.Type Content.Type.TEXT)
* @param TXT_CONTENT Insert the string of text to be displayed, it will be showed in one line. In case
* it is too long, a SCROLL effect is recommended.
* @return
*/
public final ContentBuilder txtContent(final String TXT_CONTENT) {
properties.put("txtContent", new SimpleStringProperty(TXT_CONTENT));
return this;
}
/**
* Set the font for the text
*see type(Content.Type Content.Type.TEXT)
* @param FONT Select the font for the text to be displayed. Several proportional dotted fonts are available,
* all of them named with the Width and Height used for each character.
* Check MatrixPanel to insert missing characters to the list.
* @return
*/
public final ContentBuilder font(final Content.MatrixFont FONT) {
properties.put("matrixFont", new SimpleObjectProperty<>(FONT));
return this;
}
/**
* Set the gap between characters
*see type(Content.Type Content.Type.TEXT)
* @param FONT_GAP Select the gap between the characters:
*
* - Gap.NULL: No space will be used between consecutive characters
* - Gap.SIMPLE: One LED will be used as gap between consecutive characters
* - Gap.DOUBLE: Two LEDs will be used as gap between consecutive characters
*
* @return
*/
public final ContentBuilder fontGap(final Content.Gap FONT_GAP) {
properties.put("fontGap", new SimpleObjectProperty<>(FONT_GAP));
return this;
}
/**
* Set the align of the text
*see type(Content.Type Content.Type.TEXT)
* @return
* @see #effect(Content.Effect)
* @param TXT_ALIGN Select how to align the string of text
*
* - Align.LEFT: Align the text to the left of the area
* - Align.CENTER: Align the text to the center of the area
* - Align.LEFT: Align the text to the right of the area
*
* In case of long string of text, to display the whole string select a Scroll effect
* opposite to the selected align.
*/
public final ContentBuilder align(final Content.Align TXT_ALIGN) {
properties.put("align", new SimpleObjectProperty<>(TXT_ALIGN));
return this;
}
/**
* Set the effect to display animated content
* @return
* @see #align(Content.Align)
* @see #lapse(Integer)
* @see #postEffect(Content.PostEffect)
* @param EFFECT Select the Effect to display animated content
*
- Effect.NONE: The content will be displayed in its area without animation effect
* - Effect.SCROLL_RIGHT, Effect.SCROLL_LEFT, Effect.SCROLL_UP, Effect.SCROLL_DOWN:
* The content will be scrolled from the outside to its final position in its area, from the right to the left,
* the left to the right, the bottom to the top, or the top to the bottom, respectively. They must be coordinated
* with the propor align of the content
* - Effect.BLINK, Effect.BLINK_10, Effect.BLINK_4: The content is displayed in its area
* and start blinking, indefinetly, ten times and stop, four times and stop, respectively
* The animation effect is repeted every lapse milliseconds.
*
To repeat the effect, choose a postEffect action.
*/
public final ContentBuilder effect(final Content.Effect EFFECT) {
properties.put("effect", new SimpleObjectProperty<>(EFFECT));
return this;
}
/**
* Set the action after the animation effect
* @return
* @see #effect(Content.Effect)
* @see #pause(Integer)
* @param POST_EFFECT Select the action after the animation effect has finished:
*
- PostEffect.STOP: the content will remain in its position.
* - PostEffect.REPEAT: the content will be animated again.
* - PostEffect.PAUSE: the content will remain in its position for a specificied time (see pause,
* then will be animated again.
*/
public final ContentBuilder postEffect(final Content.PostEffect POST_EFFECT) {
properties.put("postEffect", new SimpleObjectProperty<>(POST_EFFECT));
return this;
}
/**
* Set the pause time after the effect
* see #postEffect(Content.PostEffect Content.PostEffect.PAUSE)
* @return
* @see #order(Content.RotationOrder)
* @param PAUSE Insert the time in milliseconds that the content will be showed in its final position, before
* the selected effect starts again, or the content is replaced by other in the same area (see order).
*/
public final ContentBuilder pause(final Integer PAUSE) {
properties.put("pause", new SimpleIntegerProperty(PAUSE));
return this;
}
/**
* Set the time lapse of the animation
* @return
* @see #effect(Content.Effect)
* @param TIME_LAPSE in terms of milliseconds, is the time lapse to perform the animation effect,
* movement or blink of the whole content.
*/
public final ContentBuilder lapse(final Integer TIME_LAPSE) {
properties.put("lapse", new SimpleIntegerProperty(TIME_LAPSE));
return this;
}
/**
* Set the order in which the contents are alternatated
* @return
* @see #clear(Boolean)
* @param ORDER Select RotationOrder.Single for a unique content in its area.
* In case two different contents should be displayed alternately in the very same area, select:
* - RotationOrder.FIRST: for the first content to be displayed, with its own effect and postEffect
* (other than PostEffect.STOP)
* - RotationOrder.SECOND: for the second content to be displayed, with its own effect and postEffect
* (other than PostEffect.STOP)
*
*
* To erase the area before displaying the next content, select clear(true) to prevent mixing contents.
*
*/
public final ContentBuilder order(final Content.RotationOrder ORDER) {
properties.put("order", new SimpleObjectProperty<>(ORDER));
return this;
}
/**
* Set the option to clean the screen after the effect
* @return
* @see #order(Content.RotationOrder)
* @param CLEAR In case two different contents should be displayed alternately in the very same area, select
* if the area should be erased before displaying the next content.
*/
public final ContentBuilder clear(final Boolean CLEAR) {
properties.put("clear", new SimpleBooleanProperty(CLEAR));
return this;
}
@Override
public Content build() {
final Content CONTROL = new Content();
properties.keySet().stream().forEach((key) -> {
switch (key) {
case "color":
CONTROL.setColor(((ObjectProperty) properties.get(key)).get());
break;
case "type":
CONTROL.setType(((ObjectProperty) properties.get(key)).get());
break;
case "origin":
CONTROL.setOrigin(((ObjectProperty) properties.get(key)).get());
break;
case "area":
CONTROL.setArea(((ObjectProperty) properties.get(key)).get());
break;
case "bmpName":
CONTROL.setBmpName(((StringProperty) properties.get(key)).get());
break;
case "txtContent":
CONTROL.setTxtContent(((StringProperty) properties.get(key)).get());
break;
case "matrixFont":
CONTROL.setMatrixFont(((ObjectProperty) properties.get(key)).get());
break;
case "fontGap":
CONTROL.setFontGap(((ObjectProperty) properties.get(key)).get());
break;
case "align":
CONTROL.setTxtAlign(((ObjectProperty) properties.get(key)).get());
break;
case "effect":
CONTROL.setEffect(((ObjectProperty) properties.get(key)).get());
break;
case "postEffect":
CONTROL.setPostEffect(((ObjectProperty) properties.get(key)).get());
break;
case "pause":
CONTROL.setPause(((IntegerProperty) properties.get(key)).get());
break;
case "lapse":
CONTROL.setLapse(((IntegerProperty) properties.get(key)).get());
break;
case "order":
CONTROL.setOrder(((ObjectProperty) properties.get(key)).get());
break;
case "clear":
CONTROL.setClear(((BooleanProperty) properties.get(key)).get());
break;
}
});
return CONTROL;
}
}