Exemplo n.º 1
0
    /** This is where the ghost image is drawn */
    public void dragOver(final DropTargetDragEvent e) {
      if ((e == null)
          || (_raGhost == null)
          || (_ptLast == null)
          || (_ptOffset == null)
          || (_imgGhost == null)
          || (_raCueLine == null)) return;
      // Even if the mouse is not moving, this method is still invoked 10 times per second
      final Point pt = e.getLocation();
      if (pt == null) return;
      if (pt.equals(_ptLast)) return;

      // Try to determine whether the user is flicking the cursor right or left
      final int nDeltaLeftRight = pt.x - _ptLast.x;
      if (((_nLeftRight > 0) && (nDeltaLeftRight < 0))
          || ((_nLeftRight < 0) && (nDeltaLeftRight > 0))) _nLeftRight = 0;
      _nLeftRight += nDeltaLeftRight;
      _ptLast = pt;
      final Graphics2D g2 = (Graphics2D) getGraphics();
      if (g2 == null) return;

      // If a drag image is not supported by the platform, then draw my own drag image
      if (!DragSource.isDragImageSupported()) {
        JDragTree.this.paintImmediately(
            _raGhost.getBounds()); // Rub out the last ghost image and cue line
        // And remember where we are about to draw the new ghost image
        _raGhost.setRect(
            pt.x - _ptOffset.x, pt.y - _ptOffset.y, _imgGhost.getWidth(), _imgGhost.getHeight());
        g2.drawImage(
            _imgGhost,
            AffineTransform.getTranslateInstance(_raGhost.getX(), _raGhost.getY()),
            null);
      } else // Just rub out the last cue line
      JDragTree.this.paintImmediately(_raCueLine.getBounds());

      final TreePath path = getClosestPathForLocation(pt.x, pt.y);
      if (!(path == _pathLast)) {
        _nLeftRight = 0; // We've moved up or down, so reset left/right movement trend
        _pathLast = path;
        _timerHover.restart();
      }

      // In any case draw (over the ghost image if necessary) a cue line indicating where a drop
      // will occur
      final Rectangle raPath = getPathBounds(path);
      _raCueLine.setRect(0, raPath.y + (int) raPath.getHeight(), getWidth(), 2);

      g2.setColor(_colorCueLine);
      g2.fill(_raCueLine);

      // And include the cue line in the area to be rubbed out next time
      _raGhost = _raGhost.createUnion(_raCueLine);

      // Do this if you want to prohibit dropping onto the drag source
      if (path.equals(_pathSource)) e.rejectDrag();
      else e.acceptDrag(e.getDropAction());
    }
  // print font info
  private void test2(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;

    int line = 1;
    for (int i = 10; i <= 24; i += 2) {
      Font font = new Font("MS ゴシック", Font.PLAIN, i);
      FontMetrics fm = super.getFontMetrics(font);
      System.out.println("*****1");
      System.out.println(fm);
      System.out.println("Leading(標準レディング (行間の間隔)):" + fm.getLeading());

      g2d.setFont(font);
      g2d.setRenderingHint(
          RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
      FontRenderContext frc = g2d.getFontRenderContext();
      TextLayout layout = new TextLayout("アンチエイリアスフォントテスト", font, frc);
      layout.draw(g2d, 0, line * 50);

      Rectangle2D bounds = layout.getBounds();
      bounds.setRect(
          bounds.getX() + 0, bounds.getY() + (line * 50), bounds.getWidth(), bounds.getHeight());
      g2d.draw(bounds);

      System.out.println("*****2" + font);
      System.out.println("有効幅  :" + layout.getAdvance());
      System.out.println("有効幅(v):" + layout.getVisibleAdvance());
      System.out.println("アセント  :" + layout.getAscent());
      System.out.println("ディセント :" + layout.getDescent());
      System.out.println("ベースライン:" + layout.getBaseline());
      System.out.println("境界   :" + layout.getBounds());
      line++;
    }
  }
  public void displayLayout() {
    Insets i = m_display.getInsets();
    int w = m_display.getWidth();
    int h = m_display.getHeight();
    int iw = i.left + i.right;
    int ih = i.top + i.bottom;
    int aw = 85;
    int ah = 15;

    m_dataB.setRect(i.left, i.top, w - iw - aw, h - ih - ah);
    m_xlabB.setRect(i.left, h - ah - i.bottom, w - iw - aw, ah - 10);
    m_ylabB.setRect(i.left, i.top, w - iw, h - ih - ah);

    m_vis.run("update");
    m_vis.run("xlabels");
  }
Exemplo n.º 4
0
  /**
   * Determine whether or not the actor is on a spike.
   *
   * @return Whether or not the actor is on a spike.
   */
  private void hitSpike() {
    if (dead) {
      return;
    }
    /*
     * Create a rectangle for comparisons.
     */
    Rectangle2D actor = new Rectangle();
    actor.setRect((int) x, (int) y + 3, width, height);

    for (myIntersectable i : myWorld.inIntersectable) {
      /*
       * Loop through world objects and check for those intersectable.
       */
      if (!i.equals(this) && i instanceof mySpike) {
        /*
         * Cast the intersectable object to paintable and create it's polygon.
         */
        myPaintable p = (myPaintable) i;
        int[] xP =
            new int[] {
              (int) p.getX(), (int) p.getX() + p.getWidth() / 2, (int) p.getX() + p.getWidth()
            };
        int[] yP =
            new int[] {
              (int) p.getY() + p.getHeight(), (int) p.getY(), (int) p.getY() + p.getHeight()
            };
        Polygon other = new Polygon(xP, yP, 3);

        if (other.intersects(actor)) {
          die();
        }
      }
    }
  }
Exemplo n.º 5
0
  private Rectangle2D getContentsBoundingBox() {
    Rectangle2D bb = null;

    for (VisualVertex v : Hierarchy.getChildrenOfType(this, VisualVertex.class)) {
      bb = BoundingBoxHelper.union(bb, v.getBoundingBox());
    }
    for (VisualVariable v : Hierarchy.getChildrenOfType(this, VisualVariable.class)) {
      bb = BoundingBoxHelper.union(bb, v.getBoundingBox());
    }
    for (VisualArc a : Hierarchy.getChildrenOfType(this, VisualArc.class)) {
      bb = BoundingBoxHelper.union(bb, a.getLabelBoundingBox());
    }
    if (bb == null) bb = contentsBB;
    else {
      bb.setRect(
          bb.getMinX() - frameDepth,
          bb.getMinY() - frameDepth,
          bb.getWidth() + 2.0 * frameDepth,
          bb.getHeight() + 2.0 * frameDepth);
    }

    if (bb == null) bb = new Rectangle2D.Double(0, 0, 1, 1);

    contentsBB = (Rectangle2D) bb.clone();

    return bb;
  }
Exemplo n.º 6
0
  @Override
  public void mouseDragged(MouseEvent e) {
    Canvas c = context.getTabbedPaneController().getCurrentTabContent();
    SelectionModel selectionModel = c.getSelectionModel();
    if (!selectionModel.prepareForMove()) {
      moved = false;
      return;
    }
    Point thisCoord = e.getPoint();
    int dx = thisCoord.x - previousPosition.x;
    int dy = thisCoord.y - previousPosition.y;
    if (selectionRec == null) {
      selectionRec = selectionModel.getSelectionBounds();
    }
    selectionRec.setRect(
        selectionRec.getX() + dx,
        selectionRec.getY() + dy,
        selectionRec.getWidth(),
        selectionRec.getHeight());
    c.setSelectionRectangleBounds(
        selectionRec.getX(),
        selectionRec.getY(),
        selectionRec.getWidth(),
        selectionRec.getHeight());

    c.setShowSelectionRectangle(true);

    c.repaint();
    previousPosition = (Point) thisCoord.clone();
    moved = true;
  }
    public void drawTextEdge(ModelImpl objectModel) {
      Renderable renderable = objectModel.getObj();
      TextDataImpl textData = (TextDataImpl) renderable.getTextData();
      if (textData != null) {
        model.colorMode.textColor(this, textData, objectModel);
        model.sizeMode.setSizeFactor2d(model.edgeSizeFactor, textData, objectModel);
        if (edgeRefresh) {
          builder.buildEdgeText((EdgeData) renderable, textData, model, currentTimeInterval);
        }
        if (textData.getSizeFactor() * renderer.getCharWidth('a') < PIXEL_LIMIT) {
          return;
        }
        String txt = textData.getLine().getText();
        Rectangle2D r = renderer.getBounds(txt);
        float posX =
            renderable.getModel().getViewportX()
                + (float) r.getWidth() / -2 * textData.getSizeFactor();
        float posY =
            renderable.getModel().getViewportY()
                + (float) r.getHeight() / -2 * textData.getSizeFactor();
        r.setRect(
            0,
            0,
            r.getWidth() / drawable.getDraggingMarkerX(),
            r.getHeight() / drawable.getDraggingMarkerY());
        textData.getLine().setBounds(r);

        renderer.draw3D(txt, posX, posY, 0, textData.getSizeFactor());
      }
    }
 private Rectangle2D decodeRect10() {
   rect.setRect(
       decodeX(1.7918661f), // x
       decodeY(1.7752526f), // y
       decodeX(1.8349283f) - decodeX(1.7918661f), // width
       decodeY(1.4217172f) - decodeY(1.7752526f)); // height
   return rect;
 }
 private Rectangle2D decodeRect8() {
   rect.setRect(
       decodeX(1.5645933f), // x
       decodeY(1.4078283f), // y
       decodeX(1.7870812f) - decodeX(1.5645933f), // width
       decodeY(1.5239899f) - decodeY(1.4078283f)); // height
   return rect;
 }
 private Rectangle2D decodeRect7() {
   rect.setRect(
       decodeX(1.4389952f), // x
       decodeY(1.7209597f), // y
       decodeX(1.7882775f) - decodeX(1.4389952f), // width
       decodeY(1.7765152f) - decodeY(1.7209597f)); // height
   return rect;
 }
 private Rectangle2D decodeRect6() {
   rect.setRect(
       decodeX(1.3684211f), // x
       decodeY(1.6111112f), // y
       decodeX(1.4210527f) - decodeX(1.3684211f), // width
       decodeY(1.7777778f) - decodeY(1.6111112f)); // height
   return rect;
 }
 private Rectangle2D decodeRect5() {
   rect.setRect(
       decodeX(1.6267943f), // x
       decodeY(1.3888888f), // y
       decodeX(1.673445f) - decodeX(1.6267943f), // width
       decodeY(1.6085858f) - decodeY(1.3888888f)); // height
   return rect;
 }
 private Rectangle2D decodeRect3() {
   rect.setRect(
       decodeX(1.2212919f), // x
       decodeY(1.6047981f), // y
       decodeX(1.270335f) - decodeX(1.2212919f), // width
       decodeY(1.3876263f) - decodeY(1.6047981f)); // height
   return rect;
 }
 private Rectangle2D decodeRect2() {
   rect.setRect(
       decodeX(1.2165072f), // x
       decodeY(1.2790405f), // y
       decodeX(1.6746411f) - decodeX(1.2165072f), // width
       decodeY(1.3876263f) - decodeY(1.2790405f)); // height
   return rect;
 }
 private Rectangle2D decodeRect6() {
   rect.setRect(
       decodeX(0.22222222f), // x
       decodeY(0.13333334f), // y
       decodeX(2.916668f) - decodeX(0.22222222f), // width
       decodeY(2.75f) - decodeY(0.13333334f)); // height
   return rect;
 }
 private Rectangle2D decodeRect4() {
   rect.setRect(
       decodeX(1.2643541f), // x
       decodeY(1.5542929f), // y
       decodeX(1.6315789f) - decodeX(1.2643541f), // width
       decodeY(1.5997474f) - decodeY(1.5542929f)); // height
   return rect;
 }
 private Rectangle2D decodeRect9() {
   rect.setRect(
       decodeX(1.3815789f), // x
       decodeY(1.6111112f), // y
       decodeX(1.4366028f) - decodeX(1.3815789f), // width
       decodeY(1.7739899f) - decodeY(1.6111112f)); // height
   return rect;
 }
 private Rectangle2D decodeRect11() {
   rect.setRect(
       decodeX(0.6f), // x
       decodeY(2.4f), // y
       decodeX(2.4f) - decodeX(0.6f), // width
       decodeY(2.6f) - decodeY(2.4f)); // height
   return rect;
 }
Exemplo n.º 19
0
  public Rectangle2D getCharVisualBounds(int index, float x, float y) {

    Rectangle2D bounds = decorator.getCharVisualBounds(this, index);
    if (x != 0 || y != 0) {
      bounds.setRect(bounds.getX() + x, bounds.getY() + y, bounds.getWidth(), bounds.getHeight());
    }
    return bounds;
  }
 void calcPos(AffineTransform w2n) {
   w2n.transform(worldPos, screenPos); // work in normalized coordinate space
   bbPos.setRect(
       screenPos.getX() + bb.getX(),
       screenPos.getY() + bb.getY(),
       bb.getWidth(),
       bb.getHeight());
 }
 private Rectangle2D decodeRect6() {
   rect.setRect(
       decodeX(2.0f), // x
       decodeY(1.0f), // y
       decodeX(2.3333333f) - decodeX(2.0f), // width
       decodeY(2.0f) - decodeY(1.0f)); // height
   return rect;
 }
 private Rectangle2D decodeRect1() {
   rect.setRect(
       decodeX(0.0f), // x
       decodeY(0.0f), // y
       decodeX(3.0f) - decodeX(0.0f), // width
       decodeY(3.0f) - decodeY(0.0f)); // height
   return rect;
 }
Exemplo n.º 23
0
  private void paintFirms(Graphics2D g2d) {

    Rectangle2D rec = new Rectangle2D.Double();
    ArrayList<Firm> firms = SleepStoneTest.firms;

    Stroke normalStroke = new BasicStroke();
    Stroke boldStroke = new BasicStroke(4f);

    g2d.setStroke(boldStroke);
    for (Firm x : firms) {
      rec.setRect(firmsPlace.get(x));
      FirmStatus status = x.getStatus();

      g2d.setColor(Color.black);

      g2d.drawString(x.getFirmName(), Math.round(rec.getMinX()), Math.round(rec.getMaxY() + 15d));

      g2d.drawString(
          Integer.toString(x.getWorkers().size()),
          Math.round(rec.getMinX()),
          Math.round(rec.getMinY() - 15d));
      // g2d.setColor(Color.RED);
      g2d.drawImage(
          firmIcon.getImage(),
          (int) rec.getX(),
          (int) rec.getY(),
          (int) rec.getWidth(),
          (int) rec.getHeight(),
          FirmStatus.getStatusColor(status),
          null);

      // draw the jobs done indicator
      if (status == FirmStatus.PRODUCING) {
        g2d.setColor(Color.black);
        g2d.setStroke(boldStroke);
        Rectangle jobsIndicator =
            new Rectangle(
                (int) rec.getMaxX() + 5,
                (int) rec.getMinY(),
                (int) (firmSpacing / 2d),
                (int) rec.getHeight());
        g2d.draw(jobsIndicator);
        float jobsToDo = x.getJobsToDo();
        float jobsDone = x.getJobsDone().availablePermits();
        float percentComplete = jobsDone / jobsToDo;
        g2d.setColor(Color.BLUE);
        jobsIndicator.setBounds(
            (int) rec.getMaxX() + 5,
            (int) rec.getMinY(),
            (int) (firmSpacing / 2d),
            (int) (((float) (rec.getHeight())) * percentComplete));
        g2d.fill(jobsIndicator);
        g2d.setStroke(normalStroke);
      }
      // index++;
    }
  }
Exemplo n.º 24
0
  private void calculateSelectedRect() {
    double startX = start.getX();
    double startY = start.getY();
    double endX = end.getX();
    double endY = end.getY();
    double swidth = endX - startX;
    double sheight = endY - startY;

    if (swidth > 0 && sheight > 0) {
      rect.setRect(startX, startY, swidth, sheight);
    } else if (swidth > 0 && sheight < 0) {
      rect.setRect(startX, endY, swidth, -sheight);
    } else if (swidth < 0 && sheight > 0) {
      rect.setRect(endX, startY, -swidth, sheight);
    } else if (swidth < 0 && sheight < 0) {
      rect.setRect(endX, endY, -swidth, -sheight);
    }
  }
Exemplo n.º 25
0
 public Rectangle2D evaluate(Rectangle2D v0, Rectangle2D v1, float fraction) {
   double x = v0.getX() + ((v1.getX() - v0.getX()) * fraction);
   double y = v0.getY() + ((v1.getY() - v0.getY()) * fraction);
   double w = v0.getWidth() + ((v1.getWidth() - v0.getWidth()) * fraction);
   double h = v0.getHeight() + ((v1.getHeight() - v0.getHeight()) * fraction);
   Rectangle2D value = (Rectangle2D) v0.clone();
   value.setRect(x, y, w, h);
   return value;
 }
Exemplo n.º 26
0
  /**
   * Draws the axis on a Java 2D graphics device (such as the screen or a printer).
   *
   * @param g2 the graphics device (<code>null</code> not permitted).
   * @param cursor the cursor location.
   * @param plotArea the area within which the axis should be drawn (<code>null</code> not
   *     permitted).
   * @param dataArea the area within which the plot is being drawn (<code>null</code> not
   *     permitted).
   * @param edge the location of the axis (<code>null</code> not permitted).
   * @param plotState collects information about the plot (<code>null</code> permitted).
   * @return the axis state (never <code>null</code>).
   */
  public AxisState draw(
      Graphics2D g2,
      double cursor,
      Rectangle2D plotArea,
      Rectangle2D dataArea,
      RectangleEdge edge,
      PlotRenderingInfo plotState) {

    // if the axis is not visible, don't draw it...
    if (!isVisible()) {
      return new AxisState(cursor);
    }

    // calculate the adjusted data area taking into account the 3D effect...
    // this assumes that there is a 3D renderer, all this 3D effect is a bit of an
    // ugly hack...
    CategoryPlot plot = (CategoryPlot) getPlot();

    Rectangle2D adjustedDataArea = new Rectangle2D.Double();
    if (plot.getRenderer() instanceof Effect3D) {
      Effect3D e3D = (Effect3D) plot.getRenderer();
      double adjustedX = dataArea.getMinX();
      double adjustedY = dataArea.getMinY();
      double adjustedW = dataArea.getWidth() - e3D.getXOffset();
      double adjustedH = dataArea.getHeight() - e3D.getYOffset();

      if (edge == RectangleEdge.LEFT || edge == RectangleEdge.BOTTOM) {
        adjustedY += e3D.getYOffset();
      } else if (edge == RectangleEdge.RIGHT || edge == RectangleEdge.TOP) {
        adjustedX += e3D.getXOffset();
      }
      adjustedDataArea.setRect(adjustedX, adjustedY, adjustedW, adjustedH);
    } else {
      adjustedDataArea.setRect(dataArea);
    }

    // draw the category labels and axis label
    AxisState state = new AxisState(cursor);
    state = drawCategoryLabels(g2, plotArea, adjustedDataArea, edge, state, plotState);
    state = drawLabel(getLabel(), g2, plotArea, dataArea, edge, state);

    return state;
  }
Exemplo n.º 27
0
 protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {
   super.drawNeedle(g2, plotArea, rotate, angle);
   if (rotate != null && plotArea != null) {
     int spacing = getSize() * 3;
     Rectangle2D newArea = new Double();
     Point2D newRotate = rotate;
     newArea.setRect(
         plotArea.getMinX() - ((double) spacing),
         plotArea.getMinY(),
         plotArea.getWidth(),
         plotArea.getHeight());
     super.drawNeedle(g2, newArea, newRotate, angle);
     newArea.setRect(
         plotArea.getMinX() + ((double) spacing),
         plotArea.getMinY(),
         plotArea.getWidth(),
         plotArea.getHeight());
     super.drawNeedle(g2, newArea, newRotate, angle);
   }
 }
Exemplo n.º 28
0
  /**
   * Check if the user is close enough the parent entity of the slot. If the user is too far away
   * the window should not be opened, and it should be closed if it was already open.
   *
   * @param x x coordinate of the user
   * @param y y coordinate of the user
   * @return <code>true</code> if the user is close enough to have the window open, <code>false
   *     </code> otherwise.
   */
  private boolean isCloseEnough(final double x, final double y) {
    final int px = (int) x;
    final int py = (int) y;

    final Rectangle2D orig = parent.getArea();
    orig.setRect(
        orig.getX() - MAX_DISTANCE,
        orig.getY() - MAX_DISTANCE,
        orig.getWidth() + MAX_DISTANCE * 2,
        orig.getHeight() + MAX_DISTANCE * 2);

    return orig.contains(px, py);
  }
Exemplo n.º 29
0
  /**
   * Called when the selection rectangle has changed, happens repeatedly when user drags the
   * selection rectangle
   *
   * @param selectRect2
   */
  public void selectionRectUpdated(Rectangle selRect) {
    boolean anythingIsSelected = false;
    for (TreeElement treeElement : treeElements) {
      double tx = treeElement.getTreeDrawer().translatePixelToTreeX(selRect.x);
      double ty = treeElement.getTreeDrawer().translatePixelToTreeY(selRect.y);
      double twidth = ((double) selRect.width / (double) treeElement.getDrawingWidth());
      double theight = ((double) selRect.height / (double) treeElement.getDrawingHeight());

      translatedRect.setRect(tx, ty, twidth, theight);
      boolean selected = treeElement.getTree().setSelectedNodes(translatedRect);
      anythingIsSelected = selected || anythingIsSelected;
    }
    display.setSomethingIsSelected(anythingIsSelected);
  }
Exemplo n.º 30
0
  protected Rectangle2D includeStrokeInBounds(Rectangle2D rect) throws SVGException {
    StyleAttribute styleAttrib = new StyleAttribute();
    if (!getStyle(styleAttrib.setName("stroke"))) return rect;

    double strokeWidth = 1;
    if (getStyle(styleAttrib.setName("stroke-width"))) strokeWidth = styleAttrib.getDoubleValue();

    rect.setRect(
        rect.getX() - strokeWidth / 2,
        rect.getY() - strokeWidth / 2,
        rect.getWidth() + strokeWidth,
        rect.getHeight() + strokeWidth);

    return rect;
  }