Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. package proj;
  2.  
  3.  
  4. import javafx.scene.layout.Pane;
  5. import javafx.scene.layout.StackPane;
  6. import javafx.scene.paint.Color;
  7. import javafx.scene.shape.Ellipse;
  8. import javafx.scene.shape.Rectangle;
  9. import javafx.scene.shape.Shape;
  10. import javafx.scene.text.Text;
  11. import javafx.scene.text.TextAlignment;
  12. import proj.Editor;
  13.  
  14. /**
  15. * Created by yana on 22.02.2018.
  16. */
  17. public class TextRect extends Rectangle {
  18. Rectangle rect;
  19. final double PADDING = 10;
  20. public double x,y,x2,y2, w, h, center_x, center_y;
  21. public Text text;
  22.  
  23.  
  24. public TextRect( String t,double x, double y, double w, double h) {
  25. this.h = h;
  26. this.w = w;
  27. this.x= x;
  28. this.y = y;
  29. x2 = x+w;
  30. y2 = y+h;
  31. center_x = x + (x2 - x)/2;
  32. center_y = y + (y2 - y)/2;
  33. text = new Text(t);
  34. rect = createRect();
  35. setText();
  36. //reshape();
  37. }
  38.  
  39. public Rectangle createRect() {
  40. rect = new Rectangle();
  41. rect.setFill(Color.GREENYELLOW);
  42. rect.setStroke(Color.YELLOW);
  43. rect.setX(x);
  44. rect.setY(y);
  45. //rect.setLayoutX(200);
  46. //rect.setTranslateX(200);
  47. rect.setWidth(w);
  48. rect.setHeight(h);
  49.  
  50. return rect;
  51. }
  52.  
  53. void changeCoords(double xx, double yy){
  54. x = xx;
  55. y = yy;
  56. x2 = x+w;
  57. y2 = y+h;
  58. center_x = x + (x2 - x)/2;
  59. center_y = y + (y2 - y)/2;
  60. }
  61. public boolean mouseIsInside(double mouseX, double mouseY){
  62. if (mouseX>x && mouseX<x2 && mouseY>y && mouseY<y2)
  63. return true;
  64. return false;
  65.  
  66. }
  67.  
  68. public void addShape(Pane canvas){canvas.getChildren().addAll(rect, text);}
  69.  
  70.  
  71.  
  72. public void setText(){
  73.  
  74. if (text.getLayoutBounds().getWidth() + 10 >= w || text.getLayoutBounds().getHeight() + 10 >= h ) {
  75. text.setText("");
  76. /*text.setText(text.getText().substring(0, text.getText().length() / 2) + "\n" +
  77. text.getText().substring(text.getText().length() / 2));
  78. text.setX(x + (w - text.getLayoutBounds().getWidth())/2); */
  79. }
  80. else
  81. alignText();
  82. }
  83.  
  84. public void reshape(){
  85. text.setWrappingWidth(w/1.2);
  86. alignText();
  87. text.setTextAlignment(TextAlignment.CENTER);
  88. if(Editor.rectPressedEdit.text.getLayoutBounds().getHeight()+25>= Editor.rectPressedEdit.h){
  89. Editor.startTextEditing = false;
  90. Editor.rectPressedEdit.text.setText( Editor.rectPressedEdit.text.getText() + "...");
  91.  
  92. }
  93.  
  94. }
  95.  
  96. private void alignText(){
  97. text.setX(x + (w - text.getLayoutBounds().getWidth())/2);
  98. text.setY(y + (h - text.getLayoutBounds().getHeight())/2 );
  99. }
  100.  
  101.  
  102.  
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement