You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
3.3 KiB
135 lines
3.3 KiB
package wow.doge.chatto.messagebuble;
|
|
|
|
import com.sandec.mdfx.MDFXNode;
|
|
|
|
import javafx.beans.InvalidationListener;
|
|
import javafx.beans.Observable;
|
|
import javafx.beans.value.ChangeListener;
|
|
import javafx.beans.value.ObservableValue;
|
|
import javafx.geometry.Insets;
|
|
import javafx.scene.Node;
|
|
import javafx.scene.control.Label;
|
|
import javafx.scene.effect.DropShadow;
|
|
import javafx.scene.paint.Color;
|
|
import javafx.scene.shape.Shape;
|
|
|
|
public class BubbledMDFXNode extends MDFXNode {
|
|
public BubbledMDFXNode(String s) {
|
|
super(s);
|
|
init();
|
|
}
|
|
|
|
private BubbleSpec bs = BubbleSpec.FACE_LEFT_CENTER;
|
|
private double pading = 5.0;
|
|
private boolean systemCall = false;
|
|
|
|
private void init() {
|
|
DropShadow ds = new DropShadow();
|
|
ds.setOffsetX(1.3);
|
|
ds.setOffsetY(1.3);
|
|
ds.setColor(Color.DARKGRAY);
|
|
setPrefSize(Label.USE_COMPUTED_SIZE, Label.USE_COMPUTED_SIZE);
|
|
shapeProperty().addListener(new ChangeListener<Shape>() {
|
|
@Override
|
|
public void changed(ObservableValue<? extends Shape> arg0, Shape arg1, Shape arg2) {
|
|
if (systemCall) {
|
|
systemCall = false;
|
|
} else {
|
|
shapeIt();
|
|
}
|
|
/*
|
|
* if(arg2.getClass().isAssignableFrom(Bubble.class)){ // i do no need to check
|
|
* for this actuall is waste of time systemCall = false; return; }else{ // not
|
|
* the required shape systemCall = true; setShape(new Bubble(bs)); System.gc();
|
|
* }
|
|
*/
|
|
|
|
}
|
|
});
|
|
|
|
heightProperty().addListener(new InvalidationListener() {
|
|
|
|
@Override
|
|
public void invalidated(Observable arg0) {
|
|
if (!systemCall)
|
|
setPrefHeight(Label.USE_COMPUTED_SIZE);
|
|
}
|
|
});
|
|
|
|
widthProperty().addListener(new InvalidationListener() {
|
|
|
|
@Override
|
|
public void invalidated(Observable observable) {
|
|
if (!systemCall)
|
|
setPrefHeight(Label.USE_COMPUTED_SIZE);
|
|
}
|
|
});
|
|
|
|
shapeIt();
|
|
}
|
|
|
|
@Override
|
|
protected void updateBounds() {
|
|
super.updateBounds();
|
|
// top right bottom left
|
|
switch (bs) {
|
|
case FACE_LEFT_BOTTOM:
|
|
setPadding(new Insets(pading, pading,
|
|
(this.getBoundsInLocal().getWidth() * ((Bubble) getShape()).drawRectBubbleIndicatorRule) / 2
|
|
+ pading,
|
|
pading));
|
|
break;
|
|
case FACE_LEFT_CENTER:
|
|
setPadding(new Insets(pading, pading, pading,
|
|
(this.getBoundsInLocal().getWidth() * ((Bubble) getShape()).drawRectBubbleIndicatorRule) / 2
|
|
+ pading));
|
|
break;
|
|
case FACE_RIGHT_BOTTOM:
|
|
setPadding(new Insets(pading,
|
|
(this.getBoundsInLocal().getWidth() * ((Bubble) getShape()).drawRectBubbleIndicatorRule) / 2
|
|
+ pading,
|
|
pading, pading));
|
|
break;
|
|
case FACE_RIGHT_CENTER:
|
|
setPadding(new Insets(pading,
|
|
(this.getBoundsInLocal().getWidth() * ((Bubble) getShape()).drawRectBubbleIndicatorRule) / 2
|
|
+ pading,
|
|
pading, pading));
|
|
break;
|
|
case FACE_TOP:
|
|
setPadding(new Insets(
|
|
(this.getBoundsInLocal().getWidth() * ((Bubble) getShape()).drawRectBubbleIndicatorRule) / 2
|
|
+ pading,
|
|
pading, pading, pading));
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
public final double getPading() {
|
|
return pading;
|
|
}
|
|
|
|
public void setPading(double pading) {
|
|
if (pading > 25.0)
|
|
return;
|
|
this.pading = pading;
|
|
}
|
|
|
|
public BubbleSpec getBubbleSpec() {
|
|
return bs;
|
|
}
|
|
|
|
public void setBubbleSpec(BubbleSpec bubbleSpec) {
|
|
this.bs = bubbleSpec;
|
|
shapeIt();
|
|
}
|
|
|
|
private final void shapeIt() {
|
|
systemCall = true;
|
|
setShape(new Bubble(bs));
|
|
System.gc();
|
|
}
|
|
}
|