コード例 #1
0
ファイル: Panel.java プロジェクト: aajjbb/Pixelator
 @Override
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D copy = (Graphics2D) g.create();
   if (dragging) {
     copy.drawImage(imageBuffer, 0, 0, null);
     if (objectDragging == SelectedForm.LINE) {
       Line l = (Line) objectDragged;
       copy.setColor(l.getColor());
       copy.drawLine(l.getP1().x, l.getP1().y, l.getP2().x, l.getP2().y);
     } else if (objectDragging == SelectedForm.SQUARE) {
       Square sq = (Square) objectDragged;
       copy.setColor(sq.getColor());
       copy.drawRect(
           sq.adjustRendering().x, sq.adjustRendering().y, sq.getWidth(), sq.getHeight());
     } else if (objectDragging == SelectedForm.CIRCLE) {
       Circle c = (Circle) objectDragged;
       copy.setColor(c.getColor());
       copy.drawOval(c.adjustRendering().x, c.adjustRendering().y, c.getWidth(), c.getHeight());
     } else if (objectDragging == SelectedForm.POLYLINE) {
       Polyline poly = (Polyline) objectDragged;
       copy.setColor(poly.getColor());
       poly.fill();
       int[] XIS = poly.getX();
       int[] YSP = poly.getY();
       copy.drawPolyline(XIS, YSP, poly.getN());
       copy.drawLine(
           XIS[poly.getN() - 1], YSP[poly.getN() - 1], poly.getActualX(), poly.getActualY());
     }
   } else {
     copy.drawImage(imageBuffer, 0, 0, null);
   }
   copy.dispose();
 }
コード例 #2
0
ファイル: Panel.java プロジェクト: aajjbb/Pixelator
 public void draw(SelectedForm type, Object form) {
   Graphics2D copy = imageBuffer.createGraphics();
   if (antiAliasing && type != SelectedForm.POLYLINE)
     copy.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   if (type == SelectedForm.LINE) {
     Line l = (Line) form;
     copy.setColor(l.getColor());
     copy.drawLine(l.getP1().x, l.getP1().y, l.getP2().x, l.getP2().y);
   } else if (type == SelectedForm.SQUARE) {
     Square sq = (Square) form;
     copy.setColor(sq.getColor());
     copy.drawRect(sq.adjustRendering().x, sq.adjustRendering().y, sq.getWidth(), sq.getHeight());
   } else if (type == SelectedForm.CIRCLE) {
     Circle c = (Circle) form;
     copy.setColor(c.getColor());
     copy.drawOval(c.adjustRendering().x, c.adjustRendering().y, c.getWidth(), c.getHeight());
   } else if (type == SelectedForm.ERASER) {
     Eraser e = (Eraser) form;
     e.adjustPreferedSize(e.getP1());
     copy.fillOval(e.getP1().x, e.getP1().y, e.getSize(), e.getSize());
   } else if (type == SelectedForm.CANPAINT) {
     CanPaint cp = (CanPaint) form;
     floodFill(cp.getP().x, cp.getP().y, cp.getActualColor(), cp.getReplacementColor());
   } else if (type == SelectedForm.POLYLINE) {
     Polyline poly = (Polyline) form;
     copy.setColor(poly.getColor());
     poly.fill();
     int[] XIS = poly.getX();
     int[] YSP = poly.getY();
     copy.drawPolyline(XIS, YSP, poly.getN());
   } else if (type == SelectedForm.PEN) {
     Pen pen = (Pen) form;
     copy.setColor(pen.getColor());
     copy.drawLine(pen.getP1().x, pen.getP1().y, pen.getP2().x, pen.getP2().y);
   }
   copy.dispose();
   repaint();
 }