/**
     * @see javax.swing.text.GlyphView.GlyphPainter#modelToView(javax.swing.text.GlyphView, int,
     *     javax.swing.text.Position.Bias, java.awt.Shape)
     */
    @Override
    public Shape modelToView(GlyphView v, int pos, Position.Bias bias, Shape a)
        throws BadLocationException {

      sync(v);
      Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();
      int p0 = v.getStartOffset();
      int p1 = v.getEndOffset();
      TabExpander expander = v.getTabExpander();
      Segment text;

      Rectangle r = new Rectangle();
      if (pos == p1) {
        // The caller of this is left to right and borders a right to
        // left view, return our end location.
        r.setBounds(alloc.x + alloc.width, alloc.y, 0, metrics.getHeight() + VERTICAL_OFFSET);
      } else if ((pos >= p0) && (pos <= p1)) {
        // determine range to the left of the position
        text = getText(v, p0, pos);
        int width = Utilities.getTabbedTextWidth(text, metrics, alloc.x, expander, p0);
        r.setBounds(alloc.x + width, alloc.y, 0, metrics.getHeight() + VERTICAL_OFFSET);
      } else {
        throw new BadLocationException("modelToView - can't convert", p1);
      } // endif
      return r;
    }
Example #2
0
  public boolean collidesWith(Entity other) {

    me.setBounds((int) x, (int) y, sprite.getWidth(), sprite.getHeight());
    him.setBounds((int) other.x, (int) other.y, other.sprite.getWidth(), other.sprite.getHeight());

    return me.intersects(him);
  }
 public static Rectangle computeIntersection(
     final int x, final int y, final int width, final int height, final Rectangle rect) {
   auxRect.setBounds(x, y, width, height);
   Rectangle2D.intersect(auxRect, rect, rect);
   if (rect.height < 0 || rect.width < 0) {
     rect.setBounds(0, 0, 0, 0);
   }
   return rect;
 }
Example #4
0
  /**
   * @param other
   * @return true if the objects occupy the same space
   */
  public boolean collides(GameObject other) {
    me.setBounds((int) x, (int) y, (int) dx, (int) dy);
    him.setBounds((int) other.getX(), (int) other.getY(), (int) other.getDx(), (int) other.getDy());

    if (me.intersects(him) || him.intersects(me)) {
      return true;
    } else {
      return false;
    }
  }
Example #5
0
  private void repaintSelection(long indexFromBefore, long indexFromAfter) {
    if (model == null) {
      return;
    }
    // calculate area for repainting
    final int hexColumns = model.getNumberOfHexColumns();
    final int row1 = (int) (indexFromBefore / hexColumns);
    final int row2 = (int) (indexFromAfter / hexColumns);
    final int row3 = (int) (anchorSelectionIndex / hexColumns);
    final int row4 = (int) (leadSelectionIndex / hexColumns);
    final int rowFrom = min(row1, row2, row3, row4);
    final int rowTo = max(row1, row2, row3, row4);

    int colFrom, colTo;
    if (rowFrom == rowTo) {
      final int col1 = (int) (indexFromBefore % hexColumns);
      final int col2 = (int) (indexFromAfter % hexColumns);
      final int col3 = (int) (anchorSelectionIndex % hexColumns);
      final int col4 = (int) (leadSelectionIndex % hexColumns);

      colFrom = min(col1, col2, col3, col4);
      colTo = max(col1, col2, col3, col4);
    } else {
      colFrom = 0;
      colTo = hexColumns - 1;
    }

    // System.out.println("> " + colFrom + ", " + rowFrom + " -> " + colTo + ", " + rowTo);
    // repaint hex columns
    final int rowHeight = getRowHeight();
    final TableColumnModel cm = getColumnModel();
    final int offsetColumnWidth = cm.getColumn(0).getWidth();
    final int hexColumnWidth = cm.getColumn(1).getWidth();
    final int dumpColumnWidth = cm.getColumn(cm.getColumnCount() - 1).getWidth();
    // repaintRect.setBounds(offsetColumnWidth, rowHeight*rowFrom, getWidth()-offsetColumnWidth,
    // (rowTo-rowFrom+1)*rowHeight);
    // repaint(repaintRect);
    repaintRect.setBounds(
        offsetColumnWidth + colFrom * hexColumnWidth,
        rowHeight * rowFrom,
        (colTo - colFrom + 1) * hexColumnWidth,
        (rowTo - rowFrom + 1) * rowHeight);
    repaint(repaintRect);
    repaintRect.setBounds(
        getWidth() - dumpColumnWidth,
        rowHeight * rowFrom,
        dumpColumnWidth,
        (rowTo - rowFrom + 1) * rowHeight);
    repaint(repaintRect);
  }
Example #6
0
  public void initActivity(Activity.Panel actPanel) {

    this.actPanel = actPanel;

    if (formKeyboard.isVisible()) {
      formKeyboard.setVisible(false);
    }

    activityWithKeyboard = false;

    activityType = actPanel.getActivity().getShortClassName();

    // Clear data
    // WARNING: Avoid the use of fixed-length arrays!
    for (int i = 0; i < MAX_SCANNING_ZONES; i++) {
      zonePoints[i] = -1;
      for (int n = 0; n < MAX_POINTS_PER_ZONE; n++) {
        px[i][n] = 0;
        py[i][n] = 0;
        sll[i][n] = "";
      }
    }

    currentZone = 0; // Start scanning only buttons
    place = 0;
    oldActPanelRectangle.setBounds(0, 0, 0, 0);
    activityFinished = false;
    activityWithKeyboard = actPanel.getActivity().needsKeyboard();

    if (formKeyboard != null && activityWithKeyboard && showKeyboard && isScanning) {
      formKeyboard.isHorizontalScanning = false;
      formKeyboard.xPos = 0;
      formKeyboard.yPos = -1;
      formKeyboard.setVisible(true);
      formKeyboard.calcFrameSize();
      numberOfZones = 1;
      clickNumber = 1;
      currentZone = 1;
    }

    actPanel.calcScanPoints();

    if (autoAutoScan) {
      if (autoScanActivationTimer == null) {
        enableAutoScanTimer();
      }
    } else if (weAreAtTheStart) {
      if (autoScanOnStart) {
        enableAutoScan();
      } else if (directedScanOnStart) {
        enableDirectedScan();
      }
    }

    weAreAtTheStart = false;

    if (isAutoScanning) {
      startScanTimer();
    }
  }
 /**
  * Sets the bounds of this <code>Rectangle</code> to the specified <code>x</code>, <code>y</code>,
  * <code>width</code>, and <code>height</code>. This method is included for completeness, to
  * parallel the <code>setBounds</code> method of <code>Component</code>.
  *
  * @param x the x coordinate of the upper-left corner of the specified rectangle
  * @param y the y coordinate of the upper-left corner of the specified rectangle
  * @param width the new width for the <code>Dimension</code> object
  * @param height the new height for the <code>Dimension</code> object
  */
 public void setRect(double x, double y, double width, double height) {
   int x0 = (int) Math.floor(x);
   int y0 = (int) Math.floor(y);
   int x1 = (int) Math.ceil(x + width);
   int y1 = (int) Math.ceil(y + height);
   setBounds(x0, y0, x1 - x0, y1 - y0);
 }
Example #8
0
  protected Rectangle getConfigBounds(String name, Rectangle bounds) {
    String value = getConfigProperty(name + ".bounds");
    // Parse the point
    if (value != null) {
      try {
        int index = value.indexOf(',');
        int x = Integer.parseInt(value.substring(0, index).trim());
        int index2 = value.indexOf(',', index + 1);
        int y = Integer.parseInt(value.substring(index + 1, index2).trim());
        index = value.indexOf(',', index2 + 1);
        int width = Integer.parseInt(value.substring(index2 + 1, index).trim());
        int height = Integer.parseInt(value.substring(index + 1).trim());

        if (bounds == null) {
          bounds = new Rectangle(x, y, width, height);
        } else {
          bounds.setBounds(x, y, width, height);
        }
      } catch (Exception e) {
        log.log(
            Level.SEVERE,
            "could not parse bounds " + roleName + '.' + getName() + '.' + name + ": " + value,
            e);
      }
    }
    return bounds;
  }
  public Rectangle getVisualBounds(JComponent c, int type, int width, int height) {
    Rectangle bounds = new Rectangle(0, 0, width, height);
    if (type == VisuallyLayoutable.CLIP_BOUNDS) {
      return bounds;
    }

    AbstractButton b = (AbstractButton) c;

    if (type == VisuallyLayoutable.COMPONENT_BOUNDS
        && b.getBorder() != null
        && b.isBorderPainted()) {
      Border border = b.getBorder();
      if (border instanceof BackgroundBorder) {
        border = ((BackgroundBorder) border).getBackgroundBorder();
        if (border instanceof VisualMargin) {
          InsetsUtil.subtractInto(((VisualMargin) border).getVisualMargin(c), bounds);
        } else if (border instanceof QuaquaButtonBorder) {
          InsetsUtil.subtractInto(((QuaquaButtonBorder) border).getVisualMargin(c), bounds);
        }
      }
      return bounds;
    }

    String text = b.getText();
    boolean isEmpty = (text == null || text.length() == 0);
    if (isEmpty) {
      text = " ";
    }
    Icon icon = (b.isEnabled()) ? b.getIcon() : b.getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return null;
    }

    FontMetrics fm = c.getFontMetrics(c.getFont());
    Insets insets = c.getInsets(viewInsets);

    viewR.x = insets.left;
    viewR.y = insets.top;
    viewR.width = width - (insets.left + insets.right);
    viewR.height = height - (insets.top + insets.bottom);

    iconR.x = iconR.y = iconR.width = iconR.height = 0;
    textR.x = textR.y = textR.width = textR.height = 0;

    String clippedText = layoutCL(b, fm, text, icon, viewR, iconR, textR);

    Rectangle textBounds = Fonts.getPerceivedBounds(text, c.getFont(), c);
    if (isEmpty) {
      textBounds.width = 0;
    }
    int ascent = fm.getAscent();
    textR.x += textBounds.x;
    textR.width = textBounds.width;
    textR.y += ascent + textBounds.y;
    textR.height -= fm.getHeight() - textBounds.height;

    bounds.setBounds(textR);
    return bounds;
  }
Example #10
0
  @Override
  public void mouseDragged(MouseEvent e) {
    // actors.clear();

    Point mouseDraggedPoint = e.getPoint();
    int mouseDraggedWidth = (int) (mouseDraggedPoint.x - mousePressedPoint.x);
    int mouseDraggedHeight = (int) (mouseDraggedPoint.y - mousePressedPoint.y);

    // 根据玩家鼠标拖拽来变换绘制鼠标拖拽矩形的基点
    if (mouseDraggedWidth < 0 && mouseDraggedHeight < 0) {
    } else if (mouseDraggedWidth < 0) {
      mouseDraggedPoint.y -= mouseDraggedHeight;
    } else if (mouseDraggedHeight < 0) {
      mouseDraggedPoint.x -= mouseDraggedWidth;
    } else {
      mouseDraggedPoint = mousePressedPoint;
    }

    // 绘制鼠标拖拽矩形的长和宽必须是正数
    mouseDraggedWidth = Math.abs(mouseDraggedWidth);
    mouseDraggedHeight = Math.abs(mouseDraggedHeight);

    drawRouseDraggedRect.setBounds(
        mouseDraggedPoint.x, mouseDraggedPoint.y, mouseDraggedWidth, mouseDraggedHeight);
    ;
    for (Player player : players) {
      if (!player.isCollision(drawRouseDraggedRect)) {
        continue;
      }
      actors.add(player);
    }
  }
 public final void reset() {
   pathPoints.clear();
   gp.reset();
   bounds.setBounds(0, 0, 0, 0);
   largestCoord = 0;
   needClosePath = false;
 }
Example #12
0
 /**
  * Renders using the given rendering surface and area on that surface.
  *
  * @param g the rendering surface to use
  * @param allocation the allocated region to render into
  * @see View#paint
  */
 public void paint(Graphics g, Shape allocation) {
   super.paint(g, allocation);
   Rectangle alloc = allocation.getBounds();
   Rectangle clip = g.getClipBounds();
   // Since listPainter paints in the insets we have to check for the
   // case where the child is not painted because the paint region is
   // to the left of the child. This assumes the ListPainter paints in
   // the left margin.
   if ((clip.x + clip.width) < (alloc.x + getLeftInset())) {
     Rectangle childRect = alloc;
     alloc = getInsideAllocation(allocation);
     int n = getViewCount();
     int endY = clip.y + clip.height;
     for (int i = 0; i < n; i++) {
       childRect.setBounds(alloc);
       childAllocation(i, childRect);
       if (childRect.y < endY) {
         if ((childRect.y + childRect.height) >= clip.y) {
           listPainter.paint(
               g, childRect.x, childRect.y, childRect.width, childRect.height, this, i);
         }
       } else {
         break;
       }
     }
   }
 }
Example #13
0
 @Override
 public Rectangle getCellRect(int row, int column, boolean includeSpacing) {
   Rectangle cellFrame;
   TableColumn aColumn;
   cellFrame = new Rectangle();
   cellFrame.height = getRowHeight(row) + rowMargin;
   cellFrame.y = 0;
   for (int i = 0; i < row; i++) {
     cellFrame.y += getRowHeight(i) + rowMargin;
   }
   int index = 0;
   int columnMargin = getColumnModel().getColumnMargin();
   Enumeration enumeration = getColumnModel().getColumns();
   while (enumeration.hasMoreElements()) {
     aColumn = (TableColumn) enumeration.nextElement();
     cellFrame.width = aColumn.getWidth() + columnMargin;
     if (index == column) {
       break;
     }
     cellFrame.x += cellFrame.width;
     index++;
   }
   if (!(includeSpacing)) {
     Dimension spacing = getIntercellSpacing();
     cellFrame.setBounds(
         cellFrame.x + spacing.width / 2,
         cellFrame.y + spacing.height / 2,
         cellFrame.width - spacing.width,
         cellFrame.height - spacing.height);
   }
   return cellFrame;
 }
 public void setBounds(int x, int y, int width, int height) {
   if (myViewBounds != null) {
     myViewBounds.setBounds(x, y, width, height);
   } else {
     setBounds(new Point(x, y), new Dimension(width, height));
   }
 }
  /**
   * Repaints the whole component - either calls repaint() or performs an accelerated repaint
   * directly accessing component's Graphics.
   */
  public final void repaintDirtyAccel() {
    if (!isDirty()) return;
    //        if (bufferType != BUFFER_NONE && offscreenImage == null) return;

    if (!ACCEL_DISABLED && canDirectlyAccessGraphics()) {
      Graphics g = getGraphics();
      try {
        if (bufferType != BUFFER_NONE) { // Painting to an offscreen image
          Graphics offscreenGraphics = offscreenImage.getGraphics();
          try {
            paintComponent(offscreenGraphics, invalidOffscreenArea);
          } finally {
            offscreenGraphics.dispose();
          }
          g.drawImage(offscreenImage, 0, 0, null);
        } else { // Painting directly to the provided Graphics
          paintComponent(g, invalidOffscreenArea);
        }
        invalidOffscreenArea.setBounds(0, 0, 0, 0);
      } finally {
        g.dispose();
      }
    } else {
      repaintImpl(0, 0, getWidth(), getHeight());
    }
  }
Example #16
0
  /**
   * This method serves to help clients sort blocks within a page in some manner.
   *
   * @param page
   * @param topLevelBlocks
   * @requires page != null && topLevelBlocks != null
   * @modifies the location of all topLevelBlocks
   * @effects sort the topLevelBlocks and move them to an order location on the page
   */
  protected static void sortBlockStacks(Page page, Collection<RenderableBlock> topLevelBlocks) {
    blocksToArrange.clear();
    positioningBounds.setBounds(
        BUFFER_BETWEEN_BLOCKS, BUFFER_BETWEEN_BLOCKS, 0, BUFFER_BETWEEN_BLOCKS);
    // created an ordered list of blocks based on x-coordinate position
    blocksToArrange.addAll(topLevelBlocks);

    // Naively places blocks from top to bottom, left to right.
    for (RenderableBlock block : blocksToArrange) {
      Rectangle bounds = block.getStackBounds();
      if (positioningBounds.height + bounds.height > page.getJComponent().getHeight()) {
        // need to go to next column
        positioningBounds.x = positioningBounds.x + positioningBounds.width + BUFFER_BETWEEN_BLOCKS;
        positioningBounds.width = 0;
        positioningBounds.height = BUFFER_BETWEEN_BLOCKS;
      }
      block.setLocation(positioningBounds.x, positioningBounds.height);

      // sets the x and y position for when workspace is unzoomed
      block.setUnzoomedX(block.calculateUnzoomedX(positioningBounds.x));
      block.setUnzoomedY(block.calculateUnzoomedY(positioningBounds.height));
      block.moveConnectedBlocks();

      // update positioning bounds
      positioningBounds.width = Math.max(positioningBounds.width, bounds.width);
      positioningBounds.height = positioningBounds.height + bounds.height + BUFFER_BETWEEN_BLOCKS;

      if (positioningBounds.x + positioningBounds.width > page.getJComponent().getWidth()) {
        // resize page to the difference
        page.addPixelWidth(
            positioningBounds.x + positioningBounds.width - page.getJComponent().getWidth());
      }
    }
  }
Example #17
0
  private void setROI(ImagePlus image, ImageProcessor processor) {
    int[] dims = image.getDimensions();

    Rectangle rectangle = new Rectangle();
    rectangle.setBounds(dims[0], dims[1], dims[2], dims[3]);

    processor.setRoi(rectangle);
  }
 /** Calculates the area that is available for painting the display */
 private void calcInnerBounds() {
   final java.awt.Insets INSETS = getInsets();
   INNER_BOUNDS.setBounds(
       INSETS.left,
       INSETS.top,
       getWidth() - INSETS.left - INSETS.right,
       getHeight() - INSETS.top - INSETS.bottom);
 }
Example #19
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++;
    }
  }
  /**
   * Paints the View.
   *
   * @param g the rendering surface to use
   * @param a the allocated region to render into
   * @see View#paint
   */
  @Override
  public void paint(Graphics g, Shape a) {
    sync();

    Rectangle rect = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();

    Image image = getImage();
    Rectangle clip = g.getClipBounds();

    fBounds.setBounds(rect);
    paintHighlights(g, a);
    paintBorder(g, rect);
    if (clip != null) {
      g.clipRect(
          rect.x + leftInset,
          rect.y + topInset,
          rect.width - leftInset - rightInset,
          rect.height - topInset - bottomInset);
    }
    if (image != null) {
      if (!hasPixels(image)) {
        // No pixels yet, use the default
        Icon icon = (image == null) ? getNoImageIcon() : getLoadingImageIcon();

        if (icon != null) {
          icon.paintIcon(getContainer(), g, rect.x + leftInset, rect.y + topInset);
        }
      } else {
        // Draw the image
        g.drawImage(image, rect.x + leftInset, rect.y + topInset, width, height, imageObserver);
      }
    } else {
      Icon icon = getNoImageIcon();

      if (icon != null) {
        icon.paintIcon(getContainer(), g, rect.x + leftInset, rect.y + topInset);
      }
      View view = getAltView();
      // Paint the view representing the alt text, if its non-null
      if (view != null && ((state & WIDTH_FLAG) == 0 || width > DEFAULT_WIDTH)) {
        // Assume layout along the y direction
        Rectangle altRect =
            new Rectangle(
                rect.x + leftInset + DEFAULT_WIDTH,
                rect.y + topInset,
                rect.width - leftInset - rightInset - DEFAULT_WIDTH,
                rect.height - topInset - bottomInset);

        view.paint(g, altRect);
      }
    }
    if (clip != null) {
      // Reset clip.
      g.setClip(clip.x, clip.y, clip.width, clip.height);
    }
  }
 /** Disposes of the focusable tip currently displayed, if any. */
 public void possiblyDisposeOfTipWindow() {
   if (tipWindow != null) {
     tipWindow.dispose();
     tipWindow = null;
     textAreaListener.uninstall();
     tipVisibleBounds.setBounds(-1, -1, 0, 0);
     lastText = null;
     textArea.requestFocus();
   }
 }
  private boolean intersectsCursor(int x, int y, int width, int height) {
    boolean intersects = false;

    if (cursorVisible && (width > 0) && (height > 0)) {
      screenArea.setBounds(x, y, width, height);
      intersects = cursorArea.intersects(screenArea);
    }

    return intersects;
  }
 /**
  * Compute the bounds in which the user can move the mouse without the tip window disappearing.
  */
 private void computeTipVisibleBounds() {
   // Compute area that the mouse can move in without hiding the
   // tip window. Note that Java 1.4 can only detect mouse events
   // in Java windows, not globally.
   Rectangle r = tipWindow.getBounds();
   Point p = r.getLocation();
   SwingUtilities.convertPointFromScreen(p, textArea);
   r.setLocation(p);
   tipVisibleBounds.setBounds(r.x, r.y - 15, r.width, r.height + 15 * 2);
 }
Example #24
0
 public Rectangle getBounds(Rectangle rect, Graphics g) {
   rect.setBounds(x - RADIUS, y - RADIUS, 2 * RADIUS, 2 * RADIUS);
   rect.grow(2, 2);
   if (isInitial()) {
     double dx = x - RADIUS / Math.sqrt(2.0);
     double dy = y + RADIUS / Math.sqrt(2.0);
     rect.add(dx - INITARROW_LEN - 2, dy + INITARROW_LEN + 2);
   }
   return rect;
 }
Example #25
0
  public void update() {
    follow();
    centerX += speedX;
    speedX = bg.getSpeedX() * 5 + movementSpeed;
    r.setBounds(centerX - 25, centerY - 25, 50, 60);

    if (r.intersects(Robot.yellowRed)) {
      checkCollision();
    }
  }
 protected Dimension getPreferredMenuItemSize(
     JComponent comp, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap) {
   JMenu jMenu = (JMenu) comp;
   Icon icon1 = getIcon();
   Icon icon2 = getAllowedIcon();
   String text = jMenu.getText();
   Font font = jMenu.getFont();
   FontMetrics fontmetrics = jMenu.getToolkit().getFontMetrics(font);
   resetRects();
   layoutMenuItem(
       fontmetrics,
       text,
       icon1,
       icon2,
       arrowIcon,
       jMenu.getVerticalAlignment(),
       jMenu.getHorizontalAlignment(),
       jMenu.getVerticalTextPosition(),
       jMenu.getHorizontalTextPosition(),
       ourViewRect,
       ourIconRect,
       ourTextRect,
       ourAcceleratorRect,
       ourCheckIconRect,
       ourArrowIconRect,
       text != null ? defaultTextIconGap : 0,
       defaultTextIconGap);
   ourPreferredSizeRect.setBounds(ourTextRect);
   ourPreferredSizeRect =
       SwingUtilities.computeUnion(
           ourIconRect.x,
           ourIconRect.y,
           ourIconRect.width,
           ourIconRect.height,
           ourPreferredSizeRect);
   if (useCheckAndArrow()) {
     ourPreferredSizeRect.width += myMaxGutterIconWidth;
     ourPreferredSizeRect.width += defaultTextIconGap;
     ourPreferredSizeRect.width += defaultTextIconGap;
     ourPreferredSizeRect.width += ourArrowIconRect.width;
   }
   ourPreferredSizeRect.width += 2 * defaultTextIconGap;
   Insets insets = jMenu.getInsets();
   if (insets != null) {
     ourPreferredSizeRect.width += insets.left + insets.right;
     ourPreferredSizeRect.height += insets.top + insets.bottom;
   }
   if (ourPreferredSizeRect.width % 2 == 0) {
     ourPreferredSizeRect.width++;
   }
   if (ourPreferredSizeRect.height % 2 == 0) {
     ourPreferredSizeRect.height++;
   }
   return ourPreferredSizeRect.getSize();
 }
 private void resetRects() {
   ourIconRect.setBounds(ourZeroRect);
   ourTextRect.setBounds(ourZeroRect);
   ourAcceleratorRect.setBounds(ourZeroRect);
   ourCheckIconRect.setBounds(ourZeroRect);
   ourArrowIconRect.setBounds(ourZeroRect);
   ourViewRect.setBounds(0, 0, Short.MAX_VALUE, Short.MAX_VALUE);
   ourPreferredSizeRect.setBounds(ourZeroRect);
 }
Example #28
0
    private void updateDrawableRect(int compWidth, int compHeight) {
      int x = currentRect.x;
      int y = currentRect.y;
      int width = currentRect.width;
      int height = currentRect.height;

      // Make the width and height positive, if necessary.
      if (width < 0) {
        width = 0 - width;
        x = x - width + 1;
        if (x < 0) {
          width += x;
          x = 0;
        }
      }
      if (height < 0) {
        height = 0 - height;
        y = y - height + 1;
        if (y < 0) {
          height += y;
          y = 0;
        }
      }

      // The rectangle shouldn't extend past the drawing area.
      if ((x + width) > compWidth) {
        width = compWidth - x;
      }
      if ((y + height) > compHeight) {
        height = compHeight - y;
      }

      // Update rectToDraw after saving old value.
      if (rectToDraw != null) {
        previousRectDrawn.setBounds(
            rectToDraw.x, rectToDraw.y,
            rectToDraw.width, rectToDraw.height);
        rectToDraw.setBounds(x, y, width, height);
      } else {
        rectToDraw = new Rectangle(x, y, width, height);
      }
    }
 private void recomputeTotalCacheArea(int width, int height) {
   float aspect = (float) width / (float) height;
   int dim = (int) Math.sqrt(totalImagesNumber);
   int xDim = (int) (dim * aspect);
   int yDim = (int) (dim * (1.0f / aspect));
   int minWidth = Math.min(innerCacheArea.width, width);
   if (xDim < minWidth + BUFFERWIDTH) {
     xDim = minWidth + BUFFERWIDTH;
     yDim = totalImagesNumber / xDim;
   }
   fullCacheArea.setBounds(fullCacheArea.x, fullCacheArea.y, xDim, yDim);
 }
Example #30
0
  public void draw(int num, boolean mouseclick, Player human, Graphics2D g2) {
    // if weapon index is 2 then
    if (num == 2) {
      // set bounds depending if mouses are clicked  and facing left or right
      if (mouseclick == true && human.isRight == true) {
        r.setBounds(human.getPlayerX() + PLAYERDIAMETER, human.getPlayerY(), 50, 10);

      } else if (mouseclick == false && human.isRight == true) {
        r.setBounds(human.getPlayerX() + PLAYERDIAMETER, human.getPlayerY() - 50, 10, 50);

      } else if (mouseclick == false && human.isRight == false) {
        r.setBounds(human.getPlayerX() - 10, human.getPlayerY() - 50, 10, 50);

      } else if (mouseclick == true && human.isRight == false) {
        r.setBounds(human.getPlayerX() - 50, human.getPlayerY(), 50, 10);
      }
      // draw the final result
      g2.draw(r);
    } else {
      // if weapon is not 2 then set the size to 0
      r.setBounds(human.getPlayerX(), human.getPlayerY(), 0, 0);
    }
  }