Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package proj;
- import javafx.scene.layout.Pane;
- import javafx.scene.layout.StackPane;
- import javafx.scene.paint.Color;
- import javafx.scene.shape.Ellipse;
- import javafx.scene.shape.Rectangle;
- import javafx.scene.shape.Shape;
- import javafx.scene.text.Text;
- import javafx.scene.text.TextAlignment;
- import proj.Editor;
- /**
- * Created by yana on 22.02.2018.
- */
- public class TextRect extends Rectangle {
- Rectangle rect;
- final double PADDING = 10;
- public double x,y,x2,y2, w, h, center_x, center_y;
- public Text text;
- public TextRect( String t,double x, double y, double w, double h) {
- this.h = h;
- this.w = w;
- this.x= x;
- this.y = y;
- x2 = x+w;
- y2 = y+h;
- center_x = x + (x2 - x)/2;
- center_y = y + (y2 - y)/2;
- text = new Text(t);
- rect = createRect();
- setText();
- //reshape();
- }
- public Rectangle createRect() {
- rect = new Rectangle();
- rect.setFill(Color.GREENYELLOW);
- rect.setStroke(Color.YELLOW);
- rect.setX(x);
- rect.setY(y);
- //rect.setLayoutX(200);
- //rect.setTranslateX(200);
- rect.setWidth(w);
- rect.setHeight(h);
- return rect;
- }
- void changeCoords(double xx, double yy){
- x = xx;
- y = yy;
- x2 = x+w;
- y2 = y+h;
- center_x = x + (x2 - x)/2;
- center_y = y + (y2 - y)/2;
- }
- public boolean mouseIsInside(double mouseX, double mouseY){
- if (mouseX>x && mouseX<x2 && mouseY>y && mouseY<y2)
- return true;
- return false;
- }
- public void addShape(Pane canvas){canvas.getChildren().addAll(rect, text);}
- public void setText(){
- if (text.getLayoutBounds().getWidth() + 10 >= w || text.getLayoutBounds().getHeight() + 10 >= h ) {
- text.setText("");
- /*text.setText(text.getText().substring(0, text.getText().length() / 2) + "\n" +
- text.getText().substring(text.getText().length() / 2));
- text.setX(x + (w - text.getLayoutBounds().getWidth())/2); */
- }
- else
- alignText();
- }
- public void reshape(){
- text.setWrappingWidth(w/1.2);
- alignText();
- text.setTextAlignment(TextAlignment.CENTER);
- if(Editor.rectPressedEdit.text.getLayoutBounds().getHeight()+25>= Editor.rectPressedEdit.h){
- Editor.startTextEditing = false;
- Editor.rectPressedEdit.text.setText( Editor.rectPressedEdit.text.getText() + "...");
- }
- }
- private void alignText(){
- text.setX(x + (w - text.getLayoutBounds().getWidth())/2);
- text.setY(y + (h - text.getLayoutBounds().getHeight())/2 );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement