Esempio n. 1
0
 private void clearPlane() {
   int black = Color.BLACK.getRGB();
   synchronized (LOCKER) {
     for (int i = 0; i < pixels.length; i++) {
       pixels[i] = black;
     }
   }
 }
Esempio n. 2
0
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   Component comp =
       super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
   if (value != null && highlight(table, value, isSelected, hasFocus, row, column)) {
     if (isSelected) {
       comp.setBackground(new Color((HIGHLIGHT_COLOR.getRGB() ^ comp.getBackground().getRGB())));
       comp.setForeground(new Color(Color.BLACK.getRGB() ^ comp.getForeground().getRGB()));
     } else {
       comp.setBackground(HIGHLIGHT_COLOR);
       comp.setForeground(Color.BLACK);
     }
   } else {
     if (!isSelected) {
       comp.setBackground(Color.WHITE);
       comp.setForeground(Color.BLACK);
     }
   }
   return comp;
 }
/** Created by Xiaxing SHI on 21/11/15. */
public class BasicPainter implements Painter, DrawingSource {
  private String name = "My Painting";
  private ColorRBG color = new ColorRBG(Color.BLACK.getRGB());
  private Pencil pencil = new Pencil(1, color);
  private Canvas canvas = new Canvas(1024, 1024);
  private boolean isAWT = true, isSVG = true;

  private ArrayList<Shape> shapes = new ArrayList<Shape>();

  @Override
  public void setName(String name) {
    if (name != null) this.name = name;
  }

  @Override
  public void setCanvasSize(int width, int height) {
    this.canvas.setWidth(width);
    this.canvas.setHeight(height);
  }

  @Override
  public void setShowInWindow(boolean isWindow) {
    this.isAWT = isWindow;
  }

  @Override
  public void setSaveAsSVG(boolean isSvg) {
    this.isSVG = isSvg;
  }

  @Override
  public void stroke(int width, Color color) {
    this.pencil = new Pencil(width, new ColorRBG((color.getRGB())));
  }

  @Override
  public void fill(Color color) {
    this.color = new ColorRBG(color.getRGB());
  }

  @Override
  public void circle(int x, int y, int r) {
    Circle c = new Circle(x, y, r);
    addToShapes(c);
  }

  @Override
  public void ellipse(int x, int y, int rx, int ry) {
    Ellipse e = new Ellipse(x, y, rx, ry);
    addToShapes(e);
  }

  @Override
  public void line(int x1, int y1, int x2, int y2) {
    Line l = new Line(x1, y1, x2, y2);
    addToShapes(l);
  }

  @Override
  public void path(LineType type, Point... points) {
    if (points.length == 0) {
      return;
    }

    Point start = points[0];
    ArrayList<PathPart> parts = new ArrayList<PathPart>();
    ArrayList<Point> pts = new ArrayList<Point>(Arrays.asList(points));
    pts.remove(0); // Remove the start point

    parts.add(new PathPart(pts, type));
    Path p = new Path(start, parts);
    addToShapes(p);
  }

  @Override
  public void path(Point start, LineType[] types, Point[][] points) {
    if (types.length != points.length) {
      return;
    }

    Path p = new Path();
    p.setStart(start);

    ArrayList<PathPart> parts = new ArrayList<PathPart>();
    for (int i = 0; i < types.length; ++i) {
      parts.add(new PathPart(types[i], points[i]));
    }
    p.setParts(parts);

    addToShapes(p);
  }

  @Override
  public void polygon(Point... points) {
    ArrayList<Point> pts = new ArrayList<Point>(Arrays.asList(points));

    Polygon p = new Polygon(pts);
    addToShapes(p);
  }

  @Override
  public void polyline(Point... points) {
    ArrayList<Point> pts = new ArrayList<Point>(Arrays.asList(points));

    Polyline p = new Polyline(pts);
    addToShapes(p);
  }

  @Override
  public void rectangle(int x, int y, int width, int height) {
    Rectangle r = new Rectangle(x, y, height, width);
    addToShapes(r);
  }

  @Override
  public void text(int x, int y, String text) {
    Text t = new Text(x, y, text);
    addToShapes(t);
  }

  @Override
  public String getName() {
    return this.name;
  }

  @Override
  public Canvas getCanvas() {
    return this.canvas;
  }

  @Override
  public ArrayList<Shape> getShapes() {
    return this.shapes;
  }

  @Override
  public boolean isShowInWindow() {
    return this.isAWT;
  }

  @Override
  public boolean isSaveAsSVG() {
    return this.isSVG;
  }

  private void addToShapes(Shape shape) {
    shape.setColor(color);
    shape.setPencil(pencil);
    shapes.add(shape);
  }
}