예제 #1
0
 /** Draws the edge structure of the tree */
 public void drawEdges(Graphics2D gg) {
   gg.setPaint(Color.black);
   Enumeration nodeList = argument.getBreadthFirstTraversal().elements();
   // For each vertex...
   while (nodeList.hasMoreElements()) {
     // Get its edge list...
     TreeVertex vertex = (TreeVertex) nodeList.nextElement();
     Enumeration edges = vertex.getEdgeList().elements();
     // For each edge in the list...
     while (edges.hasMoreElements()) {
       TreeEdge edge = (TreeEdge) edges.nextElement();
       // If we have several vertices on layer 0, only draw
       // edges for layers below that
       if (!(argument.isMultiRoots() && vertex.getLayer() == 0)) {
         // If the edge has been selected with the mouse,
         // use a thick line
         if (edge.isSelected()) {
           gg.setStroke(selectStroke);
         }
         gg.draw(edge.getShape(this));
         // If we used a thick line, reset the stroke to normal
         // line for next edge.
         if (edge.isSelected()) {
           gg.setStroke(solidStroke);
         }
         TreeVertex edgeSource = edge.getDestVertex();
       }
     }
   }
 }
예제 #2
0
  // From: http://forum.java.sun.com/thread.jspa?threadID=378460&tstart=135
  void drawArrow(
      Graphics2D g2d,
      int xCenter,
      int yCenter,
      int x,
      int y,
      float stroke,
      BasicStroke drawStroke) {
    double aDir = Math.atan2(xCenter - x, yCenter - y);
    // Line can be dashed.
    g2d.setStroke(drawStroke);
    g2d.drawLine(x, y, xCenter, yCenter);
    // make the arrow head solid even if dash pattern has been specified
    g2d.setStroke(lineStroke);
    Polygon tmpPoly = new Polygon();
    int i1 = 12 + (int) (stroke * 2);
    // make the arrow head the same size regardless of the length length
    int i2 = 6 + (int) stroke;
    tmpPoly.addPoint(x, y);
    tmpPoly.addPoint(x + xCor(i1, aDir + .5), y + yCor(i1, aDir + .5));
    tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir));
    tmpPoly.addPoint(x + xCor(i1, aDir - .5), y + yCor(i1, aDir - .5));
    tmpPoly.addPoint(x, y); // arrow tip
    g2d.drawPolygon(tmpPoly);

    // Remove this line to leave arrow head unpainted:
    g2d.fillPolygon(tmpPoly);
  }
예제 #3
0
  private void drawSelection(Graphics2D g2d) {
    if (srcx != destx || srcy != desty) {
      int x1 = (srcx < destx) ? srcx : destx;
      int y1 = (srcy < desty) ? srcy : desty;
      int x2 = (srcx > destx) ? srcx : destx;
      int y2 = (srcy > desty) ? srcy : desty;

      rectSelection.x = x1;
      rectSelection.y = y1;
      rectSelection.width = (x2 - x1) + 1;
      rectSelection.height = (y2 - y1) + 1;
      if (rectSelection.width > 0 && rectSelection.height > 0) {
        g2d.drawImage(scr_img.getSubimage(x1, y1, x2 - x1 + 1, y2 - y1 + 1), null, x1, y1);
      }

      g2d.setColor(selFrameColor);
      g2d.setStroke(bs);
      g2d.draw(rectSelection);
      int cx = (x1 + x2) / 2;
      int cy = (y1 + y2) / 2;
      g2d.setColor(selCrossColor);
      g2d.setStroke(_StrokeCross);
      g2d.drawLine(cx, y1, cx, y2);
      g2d.drawLine(x1, cy, x2, cy);

      if (Screen.getNumberScreens() > 1) {
        drawScreenFrame(g2d, srcScreenId);
      }
    }
  }
예제 #4
0
  /** paint the canvas into a image file of given width and height */
  public void writeToImage(String s, int w, int h) {
    String ext;
    File f;
    try {
      ext = s.substring(s.lastIndexOf(".") + 1);
      f = new File(s);
    } catch (Exception e) {
      System.out.println(e);
      return;
    }
    if (!ext.equals("jpg") && !ext.equals("png")) {
      System.out.println("Cannot write to file: Illegal extension " + ext);
      return;
    }
    boolean opq = true;
    if (theOpaque != null) opq = theOpaque;

    BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    g2.setBackground(Color.white);
    g2.setPaint(Color.black);
    g2.setStroke(new BasicStroke(1));
    g2.setRenderingHint(
        RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    doBuffer(g2, true, new Rectangle(0, 0, w, h));
    try {
      ImageIO.write(image, ext, f);
    } catch (Exception e) {
      System.out.println(e);
    }
  }
예제 #5
0
  public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setStroke(new BasicStroke(1.0f));

    if (isOpaque()) {
      g2d.setColor(getBackground());
      g2d.fillRect(0, 0, getWidth(), getHeight());
    }

    g2d.setColor(Color.black);
    g2d.drawLine(0, frameHeight / 2, frameWidth, frameHeight / 2);
    g2d.drawLine(frameWidth / 2, 0, frameWidth / 2, frameHeight);

    for (int i = unityX; i < frameWidth / 2; i += unityX) {
      g2d.drawLine(
          frameWidth / 2 + i, frameHeight / 2 - 3, frameWidth / 2 + i, frameHeight / 2 + 3);
      g2d.drawLine(
          frameWidth / 2 - i, frameHeight / 2 - 3, frameWidth / 2 - i, frameHeight / 2 + 3);
    }

    for (int i = unityY; i < frameHeight / 2; i += unityY) {
      g2d.drawLine(
          frameWidth / 2 - 3, frameHeight / 2 + i, frameWidth / 2 + 3, frameHeight / 2 + i);
      g2d.drawLine(
          frameWidth / 2 - 3, frameHeight / 2 - i, frameWidth / 2 + 3, frameHeight / 2 - i);
    }

    g2d.setColor(Color.blue);
    function.drawFunctionToGraphic(g2d, frameWidth, frameHeight, unityX, unityY);

    paintCurrentMethodState(g2d);

    g2d.dispose();
  }
예제 #6
0
  // Scaling relative to the center of the screen
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (bufferImage == null) {
      bufferImage = createImage(getWidth(), getHeight());
      bufferg = (Graphics2D) bufferImage.getGraphics();

      updateAffineTransform();
      preSize = getSize();
    }
    bufferg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    bufferg.setTransform(new AffineTransform());
    bufferg.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
    bufferg.setColor(Color.WHITE);
    bufferg.fillRect(0, 0, getWidth(), getHeight());

    bufferg.setTransform(affineTransform);

    Graphics2D g2d = bufferg;

    if (ORIPA.doc.hasModel) {
      g2d.setStroke(Config.STROKE_CUT);
      if (Globals.modelDispMode == Constants.ModelDispMode.FILL_ALPHA) {
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
      }
      drawModel(g2d);
      g.drawImage(bufferImage, 0, 0, this);
    }
  }
예제 #7
0
  private BufferedImage createGrid() {
    if (transformCells.getScaleY() < SHOW_GRID_MIN_SCALE) {
      return null;
    }

    Point2D cellSize = getCellSizeAfterScale();
    cellWidth = round(cellSize.getX());
    cellHeight = round(cellSize.getY());

    BufferedImage image =
        new BufferedImage(
            getWidth() + 2 * (cellWidth),
            getHeight() + 2 * (cellHeight),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics2D = image.createGraphics();
    graphics2D.setColor(new Color(0, true));
    graphics2D.fillRect(0, 0, image.getWidth(), image.getHeight());

    graphics2D.setPaint(Color.YELLOW);
    graphics2D.setStroke(new BasicStroke(1));

    for (int x = 0; x < image.getWidth(); x += cellWidth) {
      graphics2D.drawLine(x, 0, x, image.getHeight());
    }
    for (int y = 0; y < image.getHeight(); y += cellHeight) {
      graphics2D.drawLine(0, y, image.getWidth(), y);
    }
    transformGrid.setToIdentity();
    calculateGridTranslation();

    graphics2D.dispose();
    return image;
  }
예제 #8
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D gfx = (Graphics2D) g;
    gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Clear screen
    gfx.setColor(Constants.BACKGROUND_COLOR);
    gfx.fillRect(0, 0, getWidth(), getHeight());
    // Render next frame
    grid.draw(gfx);
    // Trace path line
    if (tracing) {
      gfx.setColor(Constants.PATH_COLOR);
      gfx.setStroke(new BasicStroke(2));
      for (int i = 1; i < pathLine.size(); i++) {
        Coordinate p = pathLine.get(i - 1);
        Coordinate n = pathLine.get(i);
        gfx.drawLine(
            (Constants.TILESIZE + Constants.MARGIN) * p.x
                + (Constants.TILESIZE / 2)
                + Constants.MARGIN,
            (Constants.TILESIZE + Constants.MARGIN) * p.y
                + (Constants.TILESIZE / 2)
                + Constants.MARGIN,
            (Constants.TILESIZE + Constants.MARGIN) * n.x
                + (Constants.TILESIZE / 2)
                + Constants.MARGIN,
            (Constants.TILESIZE + Constants.MARGIN) * n.y
                + (Constants.TILESIZE / 2)
                + Constants.MARGIN);
      }
    }
  }
예제 #9
0
  /** This method is invoked before the rendered image of the figure is composited. */
  public void drawFigure(Graphics2D g) {
    AffineTransform savedTransform = null;
    if (get(TRANSFORM) != null) {
      savedTransform = g.getTransform();
      g.transform(get(TRANSFORM));
    }

    if (get(FILL_STYLE) != ODGConstants.FillStyle.NONE) {
      Paint paint = ODGAttributeKeys.getFillPaint(this);
      if (paint != null) {
        g.setPaint(paint);
        drawFill(g);
      }
    }

    if (get(STROKE_STYLE) != ODGConstants.StrokeStyle.NONE) {
      Paint paint = ODGAttributeKeys.getStrokePaint(this);
      if (paint != null) {
        g.setPaint(paint);
        g.setStroke(ODGAttributeKeys.getStroke(this));
        drawStroke(g);
      }
    }
    if (get(TRANSFORM) != null) {
      g.setTransform(savedTransform);
    }
  }
예제 #10
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;

    g2.setStroke(new BasicStroke(wl));
    g2.setColor(color);
    switch (type) {
      case 1:
        {
          g2.draw(new Rectangle2D.Float(wl, wl, getWidth() - 2 * wl, getHeight() - 2 * wl));
          break;
        }
      case 2:
        {
          g2.draw(new Ellipse2D.Float(wl, wl, getWidth() - 2 * wl, getHeight() - 2 * wl));
          break;
        }
      case 3:
        {
          g2.draw(
              new RoundRectangle2D.Float(
                  wl, wl, getWidth() - 2 * wl, getHeight() - 2 * wl, 10, 10));
          break;
        }
      case 4:
        {
          g2.draw(new Line2D.Float(wl, wl, getWidth(), getHeight()));
          break;
        }
    }
  }
예제 #11
0
 private void placerPostes(Graphics2D g) {
   g.setStroke(new BasicStroke());
   for (PlanSalle.Poste poste : modele.listerPostes()) {
     g.setColor(Color.gray);
     int xPoste = Parametres.posteX(poste.getPosition().getTravee(), poste.getOrientation());
     int yPoste = Parametres.posteY(poste.getPosition().getRangee(), poste.getOrientation());
     int xPersonne =
         Parametres.personneX(poste.getPosition().getTravee(), poste.getOrientation());
     int yPersonne =
         Parametres.personneY(poste.getPosition().getRangee(), poste.getOrientation());
     if (poste.getOrientation() == Orientation.NORD
         || poste.getOrientation() == Orientation.SUD) {
       g.fill3DRect(xPoste, yPoste, Parametres.LONGUEUR_POSTE, Parametres.LARGEUR_POSTE, true);
     } else {
       g.fill3DRect(xPoste, yPoste, Parametres.LARGEUR_POSTE, Parametres.LONGUEUR_POSTE, true);
     }
     g.drawOval(xPersonne, yPersonne, Parametres.LARGEUR_PERSONNE, Parametres.LARGEUR_PERSONNE);
     if (poste.peutVoir()) {
       g.setColor(Color.red);
     } else {
       g.setColor(Color.blue);
     }
     g.fillOval(xPersonne, yPersonne, 20, 20);
   }
 }
예제 #12
0
 void drawLine(Graphics g, DrawObject L) {
   if (L == null) {
     return;
   }
   if ((sequencingOn) && (L.sequenceNum != currentSequenceNumDisplay)) {
     return;
   }
   Graphics2D g2 = (Graphics2D) g;
   g2.setStroke(L.drawStroke);
   int x1 = (int) ((L.x - minX) / (maxX - minX) * (D.width - 2 * inset));
   int y1 = (int) ((L.y - minY) / (maxY - minY) * (D.height - 2.0 * inset));
   int x2 = (int) ((L.x2 - minX) / (maxX - minX) * (D.width - 2 * inset));
   int y2 = (int) ((L.y2 - minY) / (maxY - minY) * (D.height - 2.0 * inset));
   if (L.isArrow) {
     drawArrow(
         (Graphics2D) g,
         inset + x1,
         D.height - y1 - inset,
         inset + x2,
         D.height - y2 - inset,
         1.0f,
         L.drawStroke);
   } else {
     g.drawLine(inset + x1, D.height - y1 - inset, inset + x2, D.height - y2 - inset);
   }
 }
예제 #13
0
 /**
  * Draws this without refreshing steps.
  *
  * @param panel the drawing panel requesting the drawing
  * @param _g the graphics context on which to draw
  */
 public void drawMe(DrawingPanel panel, Graphics _g) {
   // position and show inspector if requested during loading
   if (inspectorX != Integer.MIN_VALUE
       && trackerPanel != null
       && trackerPanel.getTFrame() != null) {
     positionInspector();
     Runnable runner =
         new Runnable() {
           public void run() {
             showInspector = false;
             inspector.setVisible(true);
           }
         };
     if (showInspector) SwingUtilities.invokeLater(runner);
   }
   if (isVisible() && isTraceVisible()) {
     // draw trace only if fixed coords & (non-worldview or no ref frame)
     TrackerPanel tPanel = (TrackerPanel) panel;
     ImageCoordSystem coords = tPanel.getCoords(); // get active coords
     boolean isRefFrame = coords instanceof ReferenceFrame;
     if (isRefFrame) {
       coords = ((ReferenceFrame) coords).getCoords();
     }
     boolean fixed = coords.isFixedAngle() && coords.isFixedOrigin() && coords.isFixedScale();
     if (fixed && (!(tPanel instanceof WorldTView) || !isRefFrame)) {
       trace.reset();
       for (int i = 0; i < traceX.length; i++) {
         if (Double.isNaN(traceX[i])) continue;
         tracePt.setLocation(traceX[i], traceY[i]);
         java.awt.Point p = tracePt.getScreenPosition(tPanel);
         if (trace.getCurrentPoint() == null) trace.moveTo((float) p.getX(), (float) p.getY());
         else trace.lineTo((float) p.getX(), (float) p.getY());
       }
       Graphics2D g2 = (Graphics2D) _g;
       Color color = g2.getColor();
       Stroke stroke = g2.getStroke();
       g2.setColor(getFootprint().getColor());
       g2.setStroke(traceStroke);
       g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
       g2.draw(trace);
       // restore original color and stroke
       g2.setColor(color);
       g2.setStroke(stroke);
     }
   }
   super.draw(panel, _g);
 }
예제 #14
0
 /**
  * Set the radius of the pen to the given size.
  *
  * @param r the radius of the pen
  * @throws RuntimeException if r is negative
  */
 public static void setPenRadius(double r) {
   if (r < 0) throw new RuntimeException("pen radius must be positive");
   penRadius = r * DEFAULT_SIZE;
   BasicStroke stroke =
       new BasicStroke((float) penRadius, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
   // BasicStroke stroke = new BasicStroke((float) penRadius);
   offscreen.setStroke(stroke);
 }
예제 #15
0
파일: TicTac.java 프로젝트: Sykess/Eastwood
  /** PaintComponent to draw everything. */
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    setBackground(Color.WHITE);
    // If using images, use cool dragon background
    if (useImages) g.drawImage(background, 0, 0, 310, 300, null);

    // Use light gray to not overpower the background image
    g.setColor(Color.LIGHT_GRAY);
    for (int y = 1; y < ROWS; ++y)
      g.fillRoundRect(0, cellSize * y - 4, (cellSize * COLS) - 1, 8, 8, 8);
    for (int x = 1; x < COLS; ++x)
      g.fillRoundRect(cellSize * x - 4, 0, 8, (cellSize * ROWS) - 1, 8, 8);

    // Use graphics2d for when not using the images
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    for (int y = 0; y < ROWS; ++y) {
      for (int x = 0; x < COLS; ++x) {
        int x1 = x * cellSize + 16;
        int y1 = y * cellSize + 16;
        if (board[y][x] == Symbol.X) {
          // use image if set to true, otherwise use g2d
          // for thicker, better looking X's and O's
          if (useImages) g.drawImage(imageX, x1, y1, 75, 75, null);
          else {
            g2d.setColor(PURPLE);
            int x2 = (x + 1) * cellSize - 16;
            int y2 = (y + 1) * cellSize - 16;
            g2d.drawLine(x1, y1, x2, y2);
            g2d.drawLine(x2, y1, x1, y2);
          }
        } else if (board[y][x] == Symbol.O) {
          if (useImages) g.drawImage(imageO, x1, y1, 75, 75, null);
          else {
            g2d.setColor(Color.BLUE);
            g2d.drawOval(x1, y1, 70, 70);
          }
        }
      } // end for
    }

    // Set status bar based on gamestate.  If CONTINUE, show whose turn it is
    if (gameStatus == GameStatus.CONTINUE) {
      statusBar.setForeground(Color.BLACK);
      if (currentPlayer == Symbol.X) statusBar.setText("X's Turn");
      else statusBar.setText("O's Turn");
    } else if (gameStatus == GameStatus.DRAW) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("Draw! Click to play again!");
    } else if (gameStatus == GameStatus.X_WIN) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("X has won! Click to play again!");
    } else if (gameStatus == GameStatus.O_WIN) {
      statusBar.setForeground(Color.RED);
      statusBar.setText("O has won! Click to play again!");
    }
  }
예제 #16
0
 /**
  * Set the radius of the pen to the given size.
  *
  * @param r the radius of the pen
  * @throws IllegalArgumentException if r is negative
  */
 public static void setPenRadius(double r) {
   if (r < 0) throw new IllegalArgumentException("pen radius must be nonnegative");
   penRadius = r;
   float scaledPenRadius = (float) (r * DEFAULT_SIZE);
   BasicStroke stroke =
       new BasicStroke(scaledPenRadius, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
   // BasicStroke stroke = new BasicStroke(scaledPenRadius);
   offscreen.setStroke(stroke);
 }
예제 #17
0
  public void paint(Graphics g) {
    super.paint(g);

    Graphics2D g2 = (Graphics2D) g;
    int size =
        Math.min(
            MAX_SIZE,
            Math.min(
                getWidth() - imagePadding.left - imagePadding.right,
                getHeight() - imagePadding.top - imagePadding.bottom));

    g2.translate(getWidth() / 2 - size / 2, getHeight() / 2 - size / 2);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Shape shape;

    if (mode == ColorPicker.SAT || mode == ColorPicker.BRI) {
      shape = new Ellipse2D.Float(0, 0, size, size);
    } else {
      Rectangle r = new Rectangle(0, 0, size, size);
      shape = r;
    }

    if (hasFocus()) {
      PaintUtils.paintFocus(g2, shape, 5);
    }

    if (!(shape instanceof Rectangle)) {
      // paint a circular shadow
      g2.translate(2, 2);
      g2.setColor(new Color(0, 0, 0, 20));
      g2.fill(new Ellipse2D.Float(-2, -2, size + 4, size + 4));
      g2.setColor(new Color(0, 0, 0, 40));
      g2.fill(new Ellipse2D.Float(-1, -1, size + 2, size + 2));
      g2.setColor(new Color(0, 0, 0, 80));
      g2.fill(new Ellipse2D.Float(0, 0, size, size));
      g2.translate(-2, -2);
    }

    g2.drawImage(image, 0, 0, size, size, 0, 0, size, size, null);

    if (shape instanceof Rectangle) {
      Rectangle r = (Rectangle) shape;
      PaintUtils.drawBevel(g2, r);
    } else {
      g2.setColor(new Color(0, 0, 0, 120));
      g2.draw(shape);
    }

    g2.setColor(Color.white);
    g2.setStroke(new BasicStroke(1));
    g2.draw(new Ellipse2D.Float(point.x - 3, point.y - 3, 6, 6));
    g2.setColor(Color.black);
    g2.draw(new Ellipse2D.Float(point.x - 4, point.y - 4, 8, 8));

    g.translate(-imagePadding.left, -imagePadding.top);
  }
예제 #18
0
 void drawAllROIs(Graphics g) {
   RoiManager rm = RoiManager.getInstance();
   if (rm == null) {
     rm = Interpreter.getBatchModeRoiManager();
     if (rm != null && rm.getList().getItemCount() == 0) rm = null;
   }
   if (rm == null) {
     // if (showAllList!=null)
     //	overlay = showAllList;
     showAllROIs = false;
     repaint();
     return;
   }
   initGraphics(g, null, showAllColor);
   Hashtable rois = rm.getROIs();
   java.awt.List list = rm.getList();
   boolean drawLabels = rm.getDrawLabels();
   currentRoi = null;
   int n = list.getItemCount();
   if (IJ.debugMode) IJ.log("paint: drawing " + n + " \"Show All\" ROIs");
   if (labelRects == null || labelRects.length != n) labelRects = new Rectangle[n];
   if (!drawLabels) showAllList = new Overlay();
   else showAllList = null;
   if (imp == null) return;
   int currentImage = imp.getCurrentSlice();
   int channel = 0, slice = 0, frame = 0;
   boolean hyperstack = imp.isHyperStack();
   if (hyperstack) {
     channel = imp.getChannel();
     slice = imp.getSlice();
     frame = imp.getFrame();
   }
   drawNames = Prefs.useNamesAsLabels;
   for (int i = 0; i < n; i++) {
     String label = list.getItem(i);
     Roi roi = (Roi) rois.get(label);
     if (roi == null) continue;
     if (showAllList != null) showAllList.add(roi);
     if (i < 200 && drawLabels && roi == imp.getRoi()) currentRoi = roi;
     if (Prefs.showAllSliceOnly && imp.getStackSize() > 1) {
       if (hyperstack && roi.getPosition() == 0) {
         int c = roi.getCPosition();
         int z = roi.getZPosition();
         int t = roi.getTPosition();
         if ((c == 0 || c == channel) && (z == 0 || z == slice) && (t == 0 || t == frame))
           drawRoi(g, roi, drawLabels ? i : -1);
       } else {
         int position = roi.getPosition();
         if (position == 0) position = getSliceNumber(roi.getName());
         if (position == 0 || position == currentImage) drawRoi(g, roi, drawLabels ? i : -1);
       }
     } else drawRoi(g, roi, drawLabels ? i : -1);
   }
   ((Graphics2D) g).setStroke(Roi.onePixelWide);
   drawNames = false;
 }
예제 #19
0
  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = ((Graphics2D) g);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    g2d.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    g2d.setRenderingHint(
        RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
    g2d.setRenderingHint(
        RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
    g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
    g2d.setColor(Color.BLACK);
    g2d.fillRect(0, 0, getWidth(), getHeight());

    if (bufferedImage != null) {
      synchronized (LOCKER) {
        g2d.drawImage(bufferedImage, transformCells, null);
      }
    }
    // draw struct preview
    if (structurePreview != null) {
      Composite composite = g2d.getComposite();
      g2d.setComposite(compositeStructPreview);
      g2d.drawImage(structurePreview, previewTransform, null);
      g2d.setComposite(composite);
    }
    // draw grid
    if (transformCells.getScaleX() > SHOW_GRID_MIN_SCALE) {
      Composite composite = g2d.getComposite();
      g2d.setComposite(compositeGrid);
      g2d.drawImage(bufferedImageGrid, transformGrid, null);
      g2d.setComposite(composite);
    }
    // draw border for preview
    if (structurePreview != null && Math.abs(transformCells.getScaleX()) >= 0.95) {
      Shape shape = new Rectangle(0, 0, structurePreview.getWidth(), structurePreview.getHeight());
      shape = previewTransform.createTransformedShape(shape);
      g2d.setColor(Color.RED);
      g2d.draw(shape);
    }

    // draw border
    double x = transformCells.getTranslateX();
    double y = transformCells.getTranslateY();

    g2d.setColor(BORDER_COLOR);
    g2d.setStroke(new BasicStroke(BORDER_WIDTH));
    g2d.drawRect(
        round(x - BORDER_WIDTH),
        round(y - BORDER_WIDTH),
        round(getAutomatonWidth() * transformCells.getScaleX() + 2 * BORDER_WIDTH),
        round(getAutomatonHeight() * transformCells.getScaleY() + 2 * BORDER_WIDTH));
  }
예제 #20
0
  /** Draw vertices on top of the edge structure */
  public void drawNodes(Graphics2D gg) {
    Enumeration nodeList = argument.getBreadthFirstTraversal().elements();
    // Run through the traversal and draw each vertex
    // using an Ellipse2D
    // The draw point has been determined previously in
    // calcNodeCoords()
    while (nodeList.hasMoreElements()) {
      TreeVertex vertex = (TreeVertex) nodeList.nextElement();
      // Don't draw virtual nodes
      if (vertex.isVirtual()) continue;

      // If tree is incomplete and we're on the top layer, skip it
      if (argument.isMultiRoots() && vertex.getLayer() == 0) continue;

      Point corner = vertex.getDrawPoint();
      Shape node = new Ellipse2D.Float(corner.x, corner.y, NODE_DIAM, NODE_DIAM);
      vertex.setShape(node, this);

      // Fill the interior of the node with vertex's fillPaint
      gg.setPaint(vertex.fillPaint);
      gg.fill(node);

      // Draw the outline with vertex's outlinePaint; bold if selected
      gg.setPaint(vertex.outlinePaint);
      if (vertex.isSelected()) {
        gg.setStroke(selectStroke);
      } else {
        gg.setStroke(solidStroke);
      }
      gg.draw(node);

      // Draw the short label on top of the vertex
      gg.setPaint(vertex.textPaint);
      String shortLabelString = new String(vertex.getShortLabel());
      if (shortLabelString.length() == 1) {
        gg.setFont(labelFont1);
        gg.drawString(shortLabelString, corner.x + NODE_DIAM / 4, corner.y + 3 * NODE_DIAM / 4);
      } else if (shortLabelString.length() == 2) {
        gg.setFont(labelFont2);
        gg.drawString(shortLabelString, corner.x + NODE_DIAM / 5, corner.y + 3 * NODE_DIAM / 4);
      }
    }
  }
예제 #21
0
  public void paint(Graphics g) {
    System.out.println("paint");
    Graphics2D g2d = (Graphics2D) g;

    Point1 p1, p2;

    n = paintInfo.size();

    if (toolFlag == 2) g2d.clearRect(0, 0, getSize().width - 100, getSize().height - 100); // 清除

    for (int i = 0; i < n - 1; i++) {
      p1 = (Point1) paintInfo.elementAt(i);
      p2 = (Point1) paintInfo.elementAt(i + 1);
      size = new BasicStroke(p1.boarder, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);

      g2d.setColor(p1.col);
      g2d.setStroke(size);

      if (p1.tool == p2.tool) {
        switch (p1.tool) {
          case 0: // 画笔
            Line2D line1 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);
            g2d.draw(line1);
            break;

          case 1: // 橡皮
            g.clearRect(p1.x, p1.y, p1.boarder, p1.boarder);
            break;

          case 3: // 画直线
            Line2D line2 = new Line2D.Double(p1.x, p1.y, p2.x, p2.y);
            g2d.draw(line2);
            break;

          case 4: // 画圆
            Ellipse2D ellipse =
                new Ellipse2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y));
            g2d.draw(ellipse);
            break;

          case 5: // 画矩形
            Rectangle2D rect =
                new Rectangle2D.Double(p1.x, p1.y, Math.abs(p2.x - p1.x), Math.abs(p2.y - p1.y));
            g2d.draw(rect);
            break;

          case 6: // 截断,跳过
            i = i + 1;
            break;

          default:
        } // end switch
      } // end if
    } // end for
  }
예제 #22
0
  public void drawModel(Graphics2D g2d) {
    for (OriFace face : ORIPA.doc.sortedFaces) {
      if (Globals.modelDispMode == Constants.ModelDispMode.FILL_COLOR) {
        if (face.faceFront) {
          g2d.setColor(new Color(255, 200, 200));
        } else {
          g2d.setColor(new Color(200, 200, 255));
        }
        g2d.fill(face.outline);
      } else if (Globals.modelDispMode == Constants.ModelDispMode.FILL_WHITE) {
        g2d.setColor(Color.WHITE);
        g2d.fill(face.outline);
      } else if (Globals.modelDispMode == Constants.ModelDispMode.FILL_ALPHA) {
        g2d.setColor(new Color(100, 100, 100));
        g2d.fill(face.outline);
      }

      g2d.setColor(Color.BLACK);
      for (OriHalfedge he : face.halfedges) {
        if (he.pair == null) {
          g2d.setStroke(Config.MODEL_STROKE_CUT);
        } else {
          g2d.setStroke(Config.STROKE_CUT);
        }
        g2d.draw(
            new Line2D.Double(
                he.positionForDisplay.x,
                he.positionForDisplay.y,
                he.next.positionForDisplay.x,
                he.next.positionForDisplay.y));
      }
    }

    if (Globals.bDispCrossLine) {
      g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
      g2d.setStroke(Config.MODEL_STROKE_CUT);
      g2d.setColor(Color.RED);

      g2d.draw(new Line2D.Double(crossLine.p0.x, crossLine.p0.y, crossLine.p1.x, crossLine.p1.y));
    }
  }
  public void draw(Graphics2D g) {
    F.addVariable("x", a);
    double fa = F.getValue();

    // draw tangent line
    double m;
    double[] P = toCartesianPoint(0, 0);
    double[] Q = toCartesianPoint(w, 0);
    g.setStroke(new BasicStroke(3.0f));
    try {
      m = Double.parseDouble(F.evaluate(F.differentiate(F.getTopNode(), "x")).toString());
      drawLine(g, P[0], fa + m * (P[0] - a), Q[0], fa + m * (Q[0] - a), Color.gray);
      applet.setStat("Slope \u2248 ", m, Color.red);
    } catch (ParseException e) {
    } catch (Exception e) {
    }

    // draw derivative from b to c
    try {
      double start = w / 2 + (b - originX) * scale;
      double stop = w / 2 + (c - originX) * scale;
      GeneralPath path = new GeneralPath();
      F.addVariable(variable, b);
      double y = Double.parseDouble(F.evaluate(F.differentiate(F.getTopNode(), "x")).toString());
      path.moveTo(start, (float) (h / 2 - (y - originY) * scale));
      while (start < stop) {
        F.addVariable(variable, (start - w / 2) / scale + originX);
        y = Double.parseDouble(F.evaluate(F.differentiate(F.getTopNode(), "x")).toString());
        path.lineTo(start, (float) (h / 2 - (y - originY) * scale));
        start++;
      }
      g.setColor(Color.red);
      g.setStroke(curve);
      g.draw(path);
    } catch (ParseException e) {
    } catch (Exception e) {
    }
  }
예제 #24
0
 private synchronized void doBuffer(Graphics2D g2, boolean opq, Rectangle rt) {
   origTransform = g2.getTransform();
   if (opq && rt != null) g2.clearRect(rt.x, rt.y, rt.width, rt.height);
   g2.setPaint(origPaint);
   g2.setFont(origFont);
   g2.setStroke(origStroke);
   if (inBuffer) { // System.out.println("upps");
     for (int i = 0; i < a1x.size(); i++) doPaint(g2, a1x.get(i), a2x.get(i));
     origTransform = null;
     return;
   }
   for (int i = 0; i < a1.size(); i++) doPaint(g2, a1.get(i), a2.get(i));
   origTransform = null;
 }
예제 #25
0
  private void drawInputMethodUncommitedChars(Graphics2D gfx) {
    if (myInputMethodUncommitedChars != null && myInputMethodUncommitedChars.length() > 0) {
      int x = myCursor.getCoordX() * myCharSize.width;
      int y = (myCursor.getCoordY()) * myCharSize.height - 2;

      int len = (myInputMethodUncommitedChars.length()) * myCharSize.width;

      gfx.setColor(getBackground());
      gfx.fillRect(x, (myCursor.getCoordY() - 1) * myCharSize.height, len, myCharSize.height);

      gfx.setColor(getForeground());
      gfx.setFont(myNormalFont);

      gfx.drawString(myInputMethodUncommitedChars, x, y);
      Stroke saved = gfx.getStroke();
      BasicStroke dotted =
          new BasicStroke(
              1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, new float[] {0, 2, 0, 2}, 0);
      gfx.setStroke(dotted);

      gfx.drawLine(x, y, x + len, y);
      gfx.setStroke(saved);
    }
  }
예제 #26
0
 private void drawScreenFrame(Graphics2D g2d, int scrId) {
   g2d.setColor(screenFrameColor);
   g2d.setStroke(strokeScreenFrame);
   if (screenFrame == null) {
     screenFrame = Screen.getBounds(scrId);
     Rectangle ubound = scrOCP.getBounds();
     screenFrame.x -= ubound.x;
     screenFrame.y -= ubound.y;
     int sw = (int) (strokeScreenFrame.getLineWidth() / 2);
     screenFrame.x += sw;
     screenFrame.y += sw;
     screenFrame.width -= sw * 2;
     screenFrame.height -= sw * 2;
   }
   g2d.draw(screenFrame);
 }
예제 #27
0
 @Override
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g.create();
   if (getModel().isPressed()) {
     g2.translate(1, 1);
   }
   g2.setStroke(new BasicStroke(2));
   g2.setColor(Color.BLACK);
   if (getModel().isRollover()) {
     g2.setColor(Color.WHITE);
   }
   int delta = 6;
   g2.drawLine(delta, delta, getWidth() - delta - 1, getHeight() - delta - 1);
   g2.drawLine(getWidth() - delta - 1, delta, delta, getHeight() - delta - 1);
   g2.dispose();
 }
예제 #28
0
 private void tracerVisualisations(Graphics2D g) {
   float dash[] = {2f, 0f, 2f};
   BasicStroke pointilles =
       new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash, 2f);
   g.setStroke(pointilles);
   g.setColor(Color.red);
   for (PlanSalle.Poste poste : modele.listerPostes()) {
     int centreX =
         Parametres.centrePersonneX(poste.getPosition().getTravee(), poste.getOrientation());
     int centreY =
         Parametres.centrePersonneY(poste.getPosition().getRangee(), poste.getOrientation());
     for (PlanSalle.Poste posteVisible : poste.getPostesVisibles()) {
       int visibleX = Parametres.centrePositionX(posteVisible.getPosition().getTravee());
       int visibleY = Parametres.centrePositionY(posteVisible.getPosition().getRangee());
       g.drawLine(centreX, centreY, visibleX, visibleY);
     }
   }
 }
예제 #29
0
 private void quadriller(Graphics2D g) {
   float dash[] = {2f, 0f, 2f};
   BasicStroke pointilles =
       new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash, 2f);
   g.setStroke(pointilles);
   for (int i = 1; i <= Parametres.NB_TRAVEES - 1; i++) {
     g.drawLine(
         Parametres.LARGEUR_TRAVEE * i,
         0,
         Parametres.LARGEUR_TRAVEE * i,
         Parametres.NB_RANGEES * Parametres.HAUTEUR_RANGEE - 1);
   }
   for (int i = 1; i <= Parametres.NB_RANGEES - 1; i++) {
     g.drawLine(
         0,
         Parametres.HAUTEUR_RANGEE * i,
         Parametres.NB_TRAVEES * Parametres.LARGEUR_TRAVEE - 1,
         Parametres.HAUTEUR_RANGEE * i);
   }
 }
예제 #30
0
 void drawOvalOrRectangle(Graphics g, DrawObject R, boolean isRect) {
   if (R == null) {
     return;
   }
   if ((sequencingOn) && (R.sequenceNum != currentSequenceNumDisplay)) {
     return;
   }
   Graphics2D g2 = (Graphics2D) g;
   g2.setStroke(R.drawStroke);
   int x1 = (int) ((R.x - minX) / (maxX - minX) * (D.width - 2 * inset));
   int y1 = (int) ((R.y - minY) / (maxY - minY) * (D.height - 2.0 * inset));
   double x = R.x + R.width;
   double y = R.y - R.height;
   int x2 = (int) ((x - minX) / (maxX - minX) * (D.width - 2 * inset));
   int y2 = (int) ((y - minY) / (maxY - minY) * (D.height - 2.0 * inset));
   if (isRect) {
     g.drawRect(inset + x1, D.height - y1 - inset, x2 - x1, y1 - y2);
   } else {
     g.drawOval(inset + x1, D.height - y1 - inset, x2 - x1, y1 - y2);
   }
 }