Newer
Older
CactusServer / src / main / java / framework / RWT / RWTLine.java
y-ota on 10 May 2018 1 KB 初うp
  1. package framework.RWT;
  2. import java.awt.Component;
  3. import java.awt.Graphics;
  4. import java.awt.Point;
  5. import java.util.ArrayList;
  6.  
  7. import javax.vecmath.Point2f;
  8.  
  9. /**
  10. * ラインです。
  11. * @author Wataru
  12. *
  13. */
  14. public class RWTLine extends RWTWidget {
  15. private float relativeX1 = 0.0f;
  16. private float relativeY1 = 0.0f;
  17. private float relativeX2 = 0.0f;
  18. private float relativeY2 = 0.0f;
  19. private int x1 = 0;
  20. private int y1 = 0;
  21. private int x2 = 0;
  22. private int y2 = 0;
  23.  
  24. /**
  25. * 場所を設定します。値は相対値です。
  26. * @param w
  27. * @param h
  28. */
  29. public void setRelativePosition(float x1, float y1, float x2, float y2) {
  30. relativeX1 = x1;
  31. relativeY1 = y1;
  32. relativeX2 = x2;
  33. relativeY2 = y2;
  34. }
  35.  
  36. @Override
  37. public void adjust(Component parent) {
  38. int sx = parent.getWidth();
  39. int sy = parent.getHeight();
  40. x1 = (int) (sx * relativeX1);
  41. y1 = (int) (sy * relativeY1);
  42. x2 = (int) (sx * relativeX2);
  43. y2 = (int) (sy * relativeY2);
  44. }
  45.  
  46. @Override
  47. public void paint(Graphics g) {
  48. g.setColor(color);
  49. g.drawLine(x1, y1, x2, y2);
  50. }
  51. // @Override
  52. // public void paint(Graphics g, ArrayList<Point> list, double scale) {
  53. // // TODO Auto-generated method stub
  54. // g.setColor(color);
  55. // g.drawLine(list.get(0).x, list.get(0).y, list.get(1).x, list.get(1).y);
  56. // }
  57.  
  58. }