public void mouseDragged(final MouseEvent evt) {
      Point mousePoint = evt.getPoint();
      if (resizing == 0 && MOVE != 0) {
        int x = getX() + mousePoint.x - mousePointer.x;
        int y = getY() + mousePoint.y - mousePointer.y;
        setLocation(x, y);
        repaint();
        return;
      }
      Rectangle bounds = getBounds(tempBounds);

      SwingUtilities.convertPointToScreen(mousePoint, ResizableWindow.this);
      if ((resizing & RESIZE_E) != 0) {
        bounds.width = evt.getX();
      } else if ((resizing & RESIZE_W) != 0) {
        bounds.width += bounds.x - mousePoint.x;
        bounds.x = mousePoint.x;
      }
      if ((resizing & RESIZE_S) != 0) {
        bounds.height = evt.getY();
      } else if ((resizing & RESIZE_N) != 0) {
        bounds.height += bounds.y - mousePoint.y;
        bounds.y = mousePoint.y;
      }

      if (bounds.getSize().height >= getMinimumSize().height
          && bounds.getSize().width >= getMinimumSize().width) {
        setBounds(bounds);
        validate();
        repaint();
      }

      Graphics graphics = getGraphics();
      paint(graphics);
    }
        /** @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent) */
        public void componentResized(ComponentEvent evt) {
          /* 获取目标组件 */
          Component component = evt.getComponent();

          /* 获取目标组件设置的边界和最小最大尺寸 */
          Rectangle bounds = component.getBounds();
          Dimension minSize = component.getMinimumSize();
          Dimension maxSize = component.getMaximumSize();

          /* 确定目标组件新的x轴坐标及宽度 */
          if (bounds.width < minSize.width) {
            bounds.x -= (bounds.x == m_oldBounds.x ? 0 : minSize.width - bounds.width);
            bounds.width = minSize.width;

          } else if (bounds.width > maxSize.width) {
            bounds.x += (bounds.x == m_oldBounds.x ? 0 : bounds.width - maxSize.width);
            bounds.width = maxSize.width;
          }

          /* 确定目标组件新的y轴坐标及高度 */
          if (bounds.height < minSize.height) {
            bounds.y -= (bounds.y == m_oldBounds.y ? 0 : minSize.height - bounds.height);
            bounds.height = minSize.height;

          } else if (bounds.height > maxSize.height) {
            bounds.y += (bounds.y == m_oldBounds.y ? 0 : bounds.height - maxSize.height);
            bounds.height = maxSize.height;
          }

          /* 设置目标组件的新边界 */
          component.setBounds(bounds);

          /* 保存新的边界 */
          m_oldBounds = bounds;
        }
示例#3
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());
      }
    }
  }
 public Dimension getPreferredSize() {
   Dimension ret = new Dimension();
   if (leftPage != null) {
     leftPageRect.x = 0;
     leftPageRect.y = 0;
     leftPageRect.width = pointsToPixels(leftFullPageRect.width);
     leftPageRect.height = pointsToPixels(leftFullPageRect.height);
     ret.height = leftPageRect.height;
     ret.width = leftPageRect.width;
   }
   if (rightPageRect != null) {
     rightPageRect.width = pointsToPixels(rightFullPageRect.width);
     rightPageRect.height = pointsToPixels(rightFullPageRect.height);
     if (rightPageRect.height > ret.height) {
       ret.height = rightPageRect.height;
     }
     if (leftPageRect != null) {
       rightPageRect.x = leftPageRect.width;
       ret.width += rightPageRect.width;
     } else {
       rightPageRect.x = rightPageRect.width;
       ret.width = rightPageRect.width * 2;
     }
     rightPageRect.y = 0;
   } else {
     ret.width *= 2;
   }
   ret.height += margin * 2;
   ret.width += margin * 2 + interpagemargin;
   return ret;
 }
示例#5
0
  /**
   * This borrows most of the logic from the superclass handling of update events, but changes the
   * calculation of the height for the dirty region to provide proper handling for repainting custom
   * height rows
   */
  private void handleRowUpdate(TableModelEvent e) {
    int modelColumn = e.getColumn();
    int start = e.getFirstRow();
    int end = e.getLastRow();

    Rectangle dirtyRegion;
    if (modelColumn == TableModelEvent.ALL_COLUMNS) {
      // 1 or more rows changed
      dirtyRegion =
          new Rectangle(0, start * getRowHeight(), getColumnModel().getTotalColumnWidth(), 0);
    } else {
      // A cell or column of cells has changed.
      // Unlike the rest of the methods in the JTable, the TableModelEvent
      // uses the coordinate system of the model instead of the view.
      // This is the only place in the JTable where this "reverse mapping"
      // is used.
      int column = convertColumnIndexToView(modelColumn);
      dirtyRegion = getCellRect(start, column, false);
    }

    // Now adjust the height of the dirty region
    dirtyRegion.height = 0;
    for (int row = start; row <= end; row++) {
      dirtyRegion.height +=
          getRowHeight(row); // THIS IS CHANGED TO CALCULATE THE DIRTY REGION HEIGHT CORRECTLY
    }
    repaint(dirtyRegion.x, dirtyRegion.y, dirtyRegion.width, dirtyRegion.height);
  }
  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;
  }
示例#7
0
	/**
	 * 获得图片的矩形大小
	 * 
	 * @return
	 */
	private Rectangle getCanvasDimension(JpdlModel jpdlModel) {
		Rectangle rectangle = new Rectangle();
		Rectangle rect;
		for (Node node : jpdlModel.getNodes().values()) {
			rect = node.getRectangle();
			if (rect.getMaxX() > rectangle.getMaxX()) {
				rectangle.width = (int) rect.getMaxX();
			}
			if (rect.getMaxY() > rectangle.getMaxY()) {
				rectangle.height = (int) rect.getMaxY();
			}
			for (Transition transition : node.getTransitions()) {
				List<Point> trace = transition.getLineTrace();
				for (Point point : trace) {
					if (rectangle.getMaxX() < point.x) {
						rectangle.width = point.x;
					}
					if (rectangle.getMaxY() < point.y) {
						rectangle.height = point.y;
					}
				}
			}
		}
		rectangle.width += 60;
		rectangle.height += 20;
		return rectangle;
	}
 /**
  * {@inheritDoc}
  *
  * <p>Paints a diagonal cross over the text if the comp is of type JLabel, does nothing otherwise.
  */
 @Override
 protected void doPaint(Graphics2D g, JComponent comp, int width, int height) {
   if (!(comp instanceof JLabel)) return;
   JLabel label = (JLabel) comp;
   Insets insets = label.getInsets(insetss);
   paintViewR.x = insets.left;
   paintViewR.y = insets.top;
   paintViewR.width = width - (insets.left + insets.right);
   paintViewR.height = height - (insets.top + insets.bottom);
   paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
   paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;
   SwingUtilities.layoutCompoundLabel(
       label,
       label.getFontMetrics(label.getFont()),
       label.getText(),
       null,
       label.getVerticalAlignment(),
       label.getHorizontalAlignment(),
       label.getVerticalTextPosition(),
       label.getHorizontalTextPosition(),
       paintViewR,
       paintIconR,
       paintTextR,
       label.getIconTextGap());
   doPaint(g, paintTextR);
 }
示例#9
0
  void selected(boolean selected, boolean temporary) {
    boolean changed = this.selected != selected;

    if (changed) {
      this.selected = selected;
      java.awt.Rectangle bounds = getBounds();
      if (selected) {
        bounds.x -= BORDER_E;
        bounds.width += BORDER_E + BORDER_W;
        bounds.y -= BORDER_N;
        bounds.height += BORDER_N + BORDER_S;
      } else {
        isForeground(false);
        bounds.x += BORDER_E;
        bounds.width -= BORDER_E + BORDER_W;
        bounds.y += BORDER_N;
        bounds.height -= BORDER_N + BORDER_S;
      }

      setBounds(bounds);
      if (!temporary) {
        new Events.WidgetSelectedEvent(widget, selected).raise(this);
      }
    }
  }
示例#10
0
  /** Returns the dimensions required to display the icon and label. */
  private Dimension getContentSize(AbstractButton button) {
    Rectangle scratchIconRect = new Rectangle();
    Rectangle scratchTextRect = new Rectangle();
    Rectangle scratchViewRect = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);

    FontMetrics fm = button.getFontMetrics(button.getFont());
    SwingUtilities.layoutCompoundLabel(
        fm,
        button.getText(),
        button.getIcon(),
        button.getVerticalAlignment(),
        button.getHorizontalAlignment(),
        button.getVerticalTextPosition(),
        button.getHorizontalTextPosition(),
        scratchViewRect,
        scratchIconRect,
        scratchTextRect,
        button.getIconTextGap());

    Insets textInsets = getTextPadding();
    scratchTextRect.y -= textInsets.top;
    scratchTextRect.x -= textInsets.left;
    scratchTextRect.width += textInsets.left + textInsets.right;
    scratchTextRect.height += textInsets.top + textInsets.bottom;

    Insets iconInsets = getIconPadding();
    scratchIconRect.y -= iconInsets.top;
    scratchIconRect.x -= iconInsets.left;
    scratchIconRect.width += iconInsets.left + iconInsets.right;
    scratchIconRect.height += iconInsets.top + iconInsets.bottom;

    Rectangle sum = getSum(new Rectangle[] {scratchIconRect, scratchTextRect});
    return new Dimension(sum.width, sum.height);
  }
  /** Assumes that the component innards, max position, etc. are up-to-date. */
  private Rectangle getGenericBox(Rectangle r) {
    if (r == null) {
      r = new Rectangle();
    }

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      r.width = getBoxLength(componentInnards.width, componentInnards.height);
      if (r.width < 0) {
        r = null;
      } else {
        r.height = componentInnards.height;
        r.y = componentInnards.y;
      }
      // end of HORIZONTAL

    } else { // VERTICAL progress bar
      r.height = getBoxLength(componentInnards.height, componentInnards.width);
      if (r.height < 0) {
        r = null;
      } else {
        r.width = componentInnards.width;
        r.x = componentInnards.x;
      }
    } // end of VERTICAL

    return r;
  }
示例#12
0
  private String layout(AbstractButton b, FontMetrics fm, int width, int height) {
    Insets i = b.getInsets();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    textRect.x = textRect.y = textRect.width = textRect.height = 0;
    iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;

    // layout the text and icon
    return SwingUtilities.layoutCompoundLabel(
        b,
        fm,
        b.getText(),
        b.getIcon(),
        b.getVerticalAlignment(),
        b.getHorizontalAlignment(),
        b.getVerticalTextPosition(),
        b.getHorizontalTextPosition(),
        viewRect,
        iconRect,
        textRect,
        b.getText() == null ? 0 : b.getIconTextGap());
  }
示例#13
0
 private static void resetRects(JComponent c, int height) {
   Insets insets = c.getInsets();
   viewRect.x = insets.left;
   viewRect.y = insets.top;
   viewRect.width = c.getWidth() - (insets.right + viewRect.x);
   viewRect.height = height - (insets.bottom + viewRect.y);
   textRect.x = textRect.y = textRect.width = textRect.height = 0;
   iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
 }
示例#14
0
  @Override
  public void paint(Graphics g, JComponent c) {
    JButton button = (JButton) c;
    String text = button.getText();
    Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();

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

    FontMetrics fm = g.getFontMetrics();
    paintViewInsets = c.getInsets(paintViewInsets);

    paintViewR.x = paintViewInsets.left;
    paintViewR.y = paintViewInsets.top;

    // Use inverted height &amp; width
    paintViewR.height = c.getWidth() - (paintViewInsets.left + paintViewInsets.right);
    paintViewR.width = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);

    paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
    paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;

    Graphics2D g2 = (Graphics2D) g;
    AffineTransform tr = g2.getTransform();

    if (angle == 90) {
      g2.rotate(Math.PI / 2);
      g2.translate(0, -c.getWidth());
      paintViewR.x = c.getHeight() / 2 - (int) fm.getStringBounds(text, g).getWidth() / 2;
      paintViewR.y = c.getWidth() / 2 - (int) fm.getStringBounds(text, g).getHeight() / 2;
    } else if (angle == 270) {
      g2.rotate(-Math.PI / 2);
      g2.translate(-c.getHeight(), 0);
      paintViewR.x = c.getHeight() / 2 - (int) fm.getStringBounds(text, g).getWidth() / 2;
      paintViewR.y = c.getWidth() / 2 - (int) fm.getStringBounds(text, g).getHeight() / 2;
    }

    if (icon != null) {
      icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
    }

    if (text != null) {
      int textX = paintTextR.x;
      int textY = paintTextR.y + fm.getAscent();

      if (button.isEnabled()) {
        paintText(g, c, new Rectangle(paintViewR.x, paintViewR.y, textX, textY), text);
      } else {
        paintText(g, c, new Rectangle(paintViewR.x, paintViewR.y, textX, textY), text);
      }
    }

    g2.setTransform(tr);
  }
示例#15
0
  /**
   * This paints the entire plot. It calls the draw methods of all the attached axis and data sets.
   * The order of drawing is - Axis first, data legends next, data last.
   *
   * @params g Graphics state.
   */
  public void paint(Graphics g) {
    int i;
    Graphics lg = g.create();
    Rectangle r = bounds();

    /* The r.x and r.y returned from bounds is relative to the
     ** parents space so set them equal to zero.
     */
    r.x = 0;
    r.y = 0;

    if (DefaultBackground == null) DefaultBackground = this.getBackground();
    if (DataBackground == null) DataBackground = this.getBackground();

    //        System.out.println("Graph2D paint method called!");

    if (!paintAll) return;

    r.x += borderLeft;
    r.y += borderTop;
    r.width -= borderLeft + borderRight;
    r.height -= borderBottom + borderTop;

    paintFirst(lg, r);

    if (!axis.isEmpty()) r = drawAxis(lg, r);
    else {
      if (clearAll) {
        Color c = g.getColor();
        g.setColor(DataBackground);
        g.fillRect(r.x, r.y, r.width, r.height);
        g.setColor(c);
      }
      drawFrame(lg, r.x, r.y, r.width, r.height);
    }

    paintBeforeData(lg, r);

    if (!dataset.isEmpty()) {

      datarect.x = r.x;
      datarect.y = r.y;
      datarect.width = r.width;
      datarect.height = r.height;

      for (i = 0; i < dataset.size(); i++) {
        ((DataSet) dataset.elementAt(i)).draw_data(lg, r);
      }
    }

    paintLast(lg, r);

    lg.dispose();
  }
示例#16
0
  void widgetResized() {
    java.awt.Rectangle rect = getBounds();
    rect.width = widget().getWidth();
    rect.height = widget().getHeight();

    if (selected()) {
      rect.width += BORDER_E + BORDER_W;
      rect.height += BORDER_N + BORDER_S;
    }
    super.setBounds(rect);
    revalidateInterfacePanel();
  }
示例#17
0
 /**
  * Updates painted label layout and returns clipped or full label text.
  *
  * @param label label to process
  * @param fm label font metrics
  * @param width label width
  * @param height label height
  * @return clipped or full label text
  */
 protected String layout(final E label, final FontMetrics fm, final int width, final int height) {
   final Insets insets = label.getInsets(null);
   final String text = label.getText();
   final Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();
   final Rectangle paintViewR = new Rectangle();
   paintViewR.x = insets.left;
   paintViewR.y = insets.top;
   paintViewR.width = width - (insets.left + insets.right);
   paintViewR.height = height - (insets.top + insets.bottom);
   paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
   paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;
   return layoutCL(label, fm, text, icon, paintViewR, paintIconR, paintTextR);
 }
    public void mouseDragged(MouseEvent e) {
      if (pressed) {
        Point point = e.getPoint();
        convertPointToScreen(point, e.getComponent());

        int dx = point.x - start.x;
        int dy = point.y - start.y;

        Rectangle bounds = new Rectangle(this.bounds);

        int min = 10;

        if (position == Position.N || position == Position.NE || position == Position.NW) {
          bounds.height -= dy;
          bounds.y += dy;

          if (bounds.height < min) {
            bounds.y -= min - bounds.height;
            bounds.height = min;
          }
        }
        if (position == Position.E || position == Position.NE || position == Position.SE) {
          bounds.width += dx;
          if (bounds.width < min) bounds.width = min;
        }
        if (position == Position.S || position == Position.SE || position == Position.SW) {
          bounds.height += dy;
          if (bounds.height < min) bounds.height = min;
        }
        if (position == Position.W || position == Position.SW || position == Position.NW) {
          bounds.width -= dx;
          bounds.x += dx;

          if (bounds.width < min) {
            bounds.x -= min - bounds.width;
            bounds.width = min;
          }
        }
        if (position == Position.MOVE) {
          bounds.x += dx;
          bounds.y += dy;
        }

        bounds = attraction.attract(bounds);

        setWindowBounds(bounds, position);
        updateBorder();
        invalidate();
        validate();
      }
    }
示例#19
0
  /**
   * Construct a blurred version of <tt>src</tt>, by blurring with a gaussian kernel with standard
   * Deviation of <tt>stdDev</tt> pixels.
   *
   * @param src The source image to blur
   * @param stdDevX The Standard Deviation of the Gaussian kernel in X
   * @param stdDevY The Standard Deviation of the Gaussian kernel in Y
   * @param rh Rendering hints.
   */
  public GaussianBlurRed8Bit(CachableRed src, double stdDevX, double stdDevY, RenderingHints rh) {
    super(); // Remember to call super.init()

    this.stdDevX = stdDevX;
    this.stdDevY = stdDevY;
    this.hints = rh;

    xinset = surroundPixels(stdDevX, rh);
    yinset = surroundPixels(stdDevY, rh);

    Rectangle myBounds = src.getBounds();
    myBounds.x += xinset;
    myBounds.y += yinset;
    myBounds.width -= 2 * xinset;
    myBounds.height -= 2 * yinset;
    if ((myBounds.width <= 0) || (myBounds.height <= 0)) {
      myBounds.width = 0;
      myBounds.height = 0;
    }

    ColorModel cm = fixColorModel(src);
    SampleModel sm = src.getSampleModel();
    int tw = sm.getWidth();
    int th = sm.getHeight();
    if (tw > myBounds.width) tw = myBounds.width;
    if (th > myBounds.height) th = myBounds.height;
    sm = cm.createCompatibleSampleModel(tw, th);

    init(
        src,
        myBounds,
        cm,
        sm,
        src.getTileGridXOffset() + xinset,
        src.getTileGridYOffset() + yinset,
        null);

    boolean highQuality =
        ((hints != null)
            && RenderingHints.VALUE_RENDER_QUALITY.equals(hints.get(RenderingHints.KEY_RENDERING)));

    // System.out.println("StdDev: " + stdDevX + "x" + stdDevY);
    if ((xinset != 0) && ((stdDevX < 2) || highQuality))
      convOp[0] = new ConvolveOp(makeQualityKernelX(xinset * 2 + 1));
    else dX = (int) Math.floor(DSQRT2PI * stdDevX + 0.5f);

    if ((yinset != 0) && ((stdDevY < 2) || highQuality))
      convOp[1] = new ConvolveOp(makeQualityKernelY(yinset * 2 + 1));
    else dY = (int) Math.floor(DSQRT2PI * stdDevY + 0.5f);
  }
示例#20
0
 private Rectangle unzoom(Rectangle rectangle) {
   if (zoom < 1) {
     rectangle.x *= scale;
     rectangle.y *= scale;
     rectangle.width *= scale;
     rectangle.height *= scale;
   } else if (zoom > 1) {
     rectangle.x /= scale;
     rectangle.y /= scale;
     rectangle.width /= scale;
     rectangle.height /= scale;
   }
   return rectangle;
 }
示例#21
0
  /**
   * Moves this piece to a new position on the board.
   *
   * @param newRow The destination row.
   * @param newColumn The destination column.
   * @return <code>false</code> if the destination is not a legal board position, or if the piece is
   *     already moving.
   */
  public boolean moveTo(int newRow, int newColumn) {
    if (!board.isLegalPosition(newRow, newColumn)) return false;
    if (moving) return false;
    int startX = board.columnToX(column);
    int startY = board.rowToY(row);
    int finishX = board.columnToX(newColumn);
    int finishY = board.rowToY(newRow);
    int changeInX = finishX - startX;
    int changeInY = finishY - startY;
    Rectangle oldRect = getRectangle();
    Rectangle newRect = new Rectangle(oldRect);

    // compensate for squares being slightly different sizes
    oldRect.width += 2;
    newRect.width += 2;
    oldRect.height += 2;
    newRect.height += 2;

    // Move smoothly towards new position
    moving = true;
    board.moveToTop(this);
    int deltaRow = Math.abs(row - newRow);
    int deltaColumn = Math.abs(column - newColumn);
    int distance = Math.max(deltaRow, deltaColumn) + Math.min(deltaRow, deltaColumn) / 2;
    int numberOfSteps = distance * FRAME_RATE / getSpeed();

    for (int i = 1; i <= numberOfSteps; i++) {
      oldRect.x = x;
      oldRect.y = y;
      x = startX + (i * changeInX) / numberOfSteps;
      y = startY + (i * changeInY) / numberOfSteps;
      newRect.x = x;
      newRect.y = y;
      board.getJPanel().paintImmediately(oldRect.union(newRect));
      //            redraw(oldRect.union(newRect));

      try {
        Thread.sleep(PAUSE_MS);
      } catch (InterruptedException e) {
        /* Deliberately empty */
      }
    }
    moving = false;
    if (canMoveTo(newRow, newColumn)) {
      changePosition(newRow, newColumn);
    }
    redraw(oldRect.union(newRect));
    return true;
  }
示例#22
0
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
      Rectangle borderR =
          new Rectangle(
              x + EDGE_SPACING,
              y + EDGE_SPACING,
              width - (EDGE_SPACING * 2),
              height - (EDGE_SPACING * 2));
      Insets borderInsets;
      if (border != null) {
        borderInsets = border.getBorderInsets(c);
      } else {
        borderInsets = new Insets(0, 0, 0, 0);
      }

      Rectangle rect = new Rectangle(x, y, width, height);
      Insets insets = getBorderInsets(c);
      Rectangle compR = getComponentRect(rect, insets);
      int diff;
      switch (titlePosition) {
        case ABOVE_TOP:
          diff = compR.height + TEXT_SPACING;
          borderR.y += diff;
          borderR.height -= diff;
          break;
        case TOP:
        case DEFAULT_POSITION:
          diff = insets.top / 2 - borderInsets.top - EDGE_SPACING;
          borderR.y += diff;
          borderR.height -= diff;
          break;
        case BELOW_TOP:
        case ABOVE_BOTTOM:
          break;
        case BOTTOM:
          diff = insets.bottom / 2 - borderInsets.bottom - EDGE_SPACING;
          borderR.height -= diff;
          break;
        case BELOW_BOTTOM:
          diff = compR.height + TEXT_SPACING;
          borderR.height -= diff;
          break;
      }
      border.paintBorder(c, g, borderR.x, borderR.y, borderR.width, borderR.height);
      Color col = g.getColor();
      g.setColor(c.getBackground());
      g.fillRect(compR.x, compR.y, compR.width, compR.height);
      g.setColor(col);
    }
示例#23
0
  /**
   * Paint to an offscreen graphic, e.g. a graphic for an image or svg file.
   *
   * @param g
   * @param rect
   */
  public void paintOffscreen(Graphics2D g, Rectangle rect) {

    // Get the components of the sort by X position.
    Component[] components = getComponents();
    Arrays.sort(
        components,
        new Comparator<Component>() {
          public int compare(Component component, Component component1) {
            return component.getX() - component1.getX();
          }
        });

    for (Component c : this.getComponents()) {

      if (c instanceof DataPanel) {
        Graphics2D g2d = (Graphics2D) g.create();
        Rectangle clipRect = new Rectangle(c.getBounds());
        clipRect.height = rect.height;
        g2d.setClip(clipRect);
        g2d.translate(c.getX(), 0);
        ((DataPanel) c).paintOffscreen(g2d, rect);
      }
    }
    // super.paintBorder(g);
  }
示例#24
0
 @Override
 public void run(Component c) {
   final Rectangle r = c.getBounds();
   r.width -= 64;
   r.height -= 64;
   c.setBounds(r);
 }
示例#25
0
  public TabSpawnable spawn() {
    JFrame f = new JFrame();
    f.getContentPane().setLayout(new BorderLayout());
    f.setTitle(_title);
    TabSpawnable newPanel = (TabSpawnable) clone();
    if (newPanel == null) return null; // failed to clone
    newPanel.setTitle(_title);
    if (newPanel instanceof TabToDoTarget) {
      TabToDoTarget me = (TabToDoTarget) this;
      TabToDoTarget it = (TabToDoTarget) newPanel;
      it.setTarget(me.getTarget());
    } else if (newPanel instanceof TabModelTarget) {
      TabModelTarget me = (TabModelTarget) this;
      TabModelTarget it = (TabModelTarget) newPanel;
      it.setTarget(me.getTarget());
    }
    f.getContentPane().add(newPanel, BorderLayout.CENTER);
    Rectangle bounds = getBounds();
    bounds.height += OVERLAPP * 2;
    f.setBounds(bounds);

    Point loc = new Point(0, 0);
    SwingUtilities.convertPointToScreen(loc, this);
    loc.y -= OVERLAPP;
    f.setLocation(loc);
    f.setVisible(true);

    if (_tear && (getParent() instanceof JTabbedPane)) ((JTabbedPane) getParent()).remove(this);

    return newPanel;
  }
  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);
      }
    }
  }
示例#27
0
 /**
  * Makes the given rectangle slightly larger. The given rectangle is modified and also returned.
  *
  * @param r A Rectangle to be enlarged.
  * @return The same Rectangle, after enlargement.
  */
 private static Rectangle enlarge(Rectangle r) {
   r.x -= 2;
   r.y -= 2;
   r.width += 4;
   r.height += 4;
   return r;
 }
 private static boolean snapToHeight(Rectangle bounds, Dimension size, int delta) {
   if (Math.abs(bounds.height - size.height) < delta) {
     bounds.height = size.height;
     return true;
   }
   return false;
 }
  @Override
  public void showFeedback() {
    createFeedback();

    myBounds =
        myContext.getTransformedRectangle(
            myComponent.getBounds(myContext.getArea().getFeedbackLayer()));
    myBounds.width = Math.max(myBounds.width, 0);
    myBounds.height = Math.max(myBounds.height, 0);

    int direction = myContext.getResizeDirection();

    if ((direction & Position.EAST) != 0) {
      if (!snapToWidth(myBounds, myWrapSize, SNAP_DELTA)) {
        snapToWidth(myBounds, myFillSize, SNAP_DELTA);
      }
    }
    if ((direction & Position.SOUTH) != 0) {
      if (!snapToHeight(myBounds, myWrapSize, SNAP_DELTA)) {
        snapToHeight(myBounds, myFillSize, SNAP_DELTA);
      }
    }

    myFeedback.setBounds(myBounds);

    myTextFeedback.clear();

    addTextSize(myStaticWidth, myBounds.width, myWrapSize.width, myFillSize.width);
    myTextFeedback.append(" x ", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
    addTextSize(myStaticHeight, myBounds.height, myWrapSize.height, myFillSize.height);

    myTextFeedback.locationTo(myContext.getLocation(), 15);
  }
  @Override
  public void refreshContainer() {
    if (!this.isMaximum()) {
      int height = this.getHeight();
      int pos = this.scrollPane.getVerticalScrollBar().getValue();

      this.validate();
      this.pack();

      // this.setMaximumSize(this.getPreferredSize());

      Rectangle bounds = this.getBounds();
      bounds.height = height;
      bounds.width += 32;

      int x2 =
          (int)
              Math.min(
                  bounds.getMaxX(),
                  this.getEditorInterface().getDesktopPane().getBounds().getMaxX());
      int y2 =
          (int)
              Math.min(
                  bounds.getMaxY(),
                  this.getEditorInterface().getDesktopPane().getBounds().getMaxY());

      bounds.setFrameFromDiagonal(bounds.x, bounds.y, x2, y2);

      this.setBounds(bounds);
      this.scrollPane.getVerticalScrollBar().setValue(pos);
    }
  }