示例#1
1
 static void rand() // 중복되지 않는 랜덤 숫자배열 두개 만들기
     {
   int su = 0; // 난수 발생시 저장할 변수
   boolean bDash = false; // 중복여부 확인
   for (int i = 0; i < 75; i++) {
     bDash = true;
     while (bDash) // 난수발생, 중복 학인
     {
       su = (int) (Math.random() * 75) + 1; // 판 크기+10개(상대가 못맞출 수도 있게)의 난수 입력
       bDash = false;
       for (int j = 0; j < i; j++) {
         if (numArr1[j] == su) {
           bDash = true; // 중복이 있으면 멈추고 while문을 다시 수행(랜덤값을 다시 줌)
           break;
         }
       }
     }
     numArr1[i] = su;
   }
   for (int i = 0; i < 75; i++) {
     bDash = true;
     while (bDash) // 난수발생, 중복 학인
     {
       su = (int) (Math.random() * 75) + 1; // 판 크기+10개(상대가 못맞출 수도 있게)의 난수 입력
       bDash = false;
       for (int j = 0; j < i; j++) {
         if (numArr2[j] == su) {
           bDash = true; // 중복이 있으면 멈추고 while문을 다시 수행(랜덤값을 다시 줌)
           break;
         }
       }
     }
     numArr2[i] = su;
   }
 }
  /** Start the background thread. */
  public void start() {
    // create a random list of cities

    cities = new City[TravelingSalesman.CITY_COUNT];
    for (int i = 0; i < TravelingSalesman.CITY_COUNT; i++) {
      cities[i] =
          new City(
              (int) (Math.random() * (getBounds().width - 10)),
              (int) (Math.random() * (getBounds().height - 60)));
    }

    // create the initial chromosomes

    chromosomes = new Chromosome[TravelingSalesman.POPULATION_SIZE];
    for (int i = 0; i < TravelingSalesman.POPULATION_SIZE; i++) {
      chromosomes[i] = new Chromosome(cities);
      chromosomes[i].setCut(cutLength);
      chromosomes[i].setMutation(TravelingSalesman.MUTATION_PERCENT);
    }
    Chromosome.sortChromosomes(chromosomes, TravelingSalesman.POPULATION_SIZE);

    // start up the background thread
    started = true;
    map.update(map.getGraphics());

    generation = 0;

    if (worker != null) worker = null;
    worker = new Thread(this);
    // worker.setPriority(Thread.MIN_PRIORITY);
    worker.start();
  }
 // the following method added for LegacyTristateCheckBox
 protected void drawSquare(Component c, Graphics g, int x, int y) {
   final int w = Math.min(getIconWidth(), getIconHeight());
   final int h = Math.min(getIconWidth(), getIconHeight());
   int xMargin = w / 3;
   int yMargin = h / 3;
   g.fillRect(x + xMargin, y + yMargin, w - xMargin * 2, h - yMargin * 2);
 }
示例#4
0
 public void acceptMinimumSize(Component c) {
   Dimension minimumSize = getMinimumSize(c);
   c.setMinimumSize(
       new Dimension(
           Math.max(minimumSize.width, c.getMinimumSize().width),
           Math.max(minimumSize.height, c.getMinimumSize().height)));
 }
  /*
   *  Adjust the width of the scrollpane used by the popup
   */
  protected void popupWider(BasicComboPopup popup) {
    JList list = popup.getList();

    //  Determine the maximimum width to use:
    //  a) determine the popup preferred width
    //  b) limit width to the maximum if specified
    //  c) ensure width is not less than the scroll pane width

    int popupWidth =
        list.getPreferredSize().width
            + 5 // make sure horizontal scrollbar doesn't appear
            + getScrollBarWidth(popup, scrollPane);

    if (maximumWidth != -1) {
      popupWidth = Math.min(popupWidth, maximumWidth);
    }

    Dimension scrollPaneSize = scrollPane.getPreferredSize();
    popupWidth = Math.max(popupWidth, scrollPaneSize.width);

    //  Adjust the width

    scrollPaneSize.width = popupWidth;
    scrollPane.setPreferredSize(scrollPaneSize);
    scrollPane.setMaximumSize(scrollPaneSize);
  }
示例#6
0
  /**
   * Ensures that the specified line and offset is visible by scrolling the text area if necessary.
   *
   * @param line The line to scroll to
   * @param offset The offset in the line to scroll to
   * @return True if scrolling was actually performed, false if the line and offset was already
   *     visible
   */
  public boolean scrollTo(int line, int offset) {
    // visibleLines == 0 before the component is realized
    // we can't do any proper scrolling then, so we have
    // this hack...
    if (visibleLines == 0) {
      setFirstLine(Math.max(0, line - electricScroll));
      return true;
    }

    int newFirstLine = firstLine;
    int newHorizontalOffset = horizontalOffset;

    if (line < firstLine + electricScroll) {
      newFirstLine = Math.max(0, line - electricScroll);
    } else if (line + electricScroll >= firstLine + visibleLines) {
      newFirstLine = (line - visibleLines) + electricScroll + 1;
      if (newFirstLine + visibleLines >= getLineCount())
        newFirstLine = getLineCount() - visibleLines;
      if (newFirstLine < 0) newFirstLine = 0;
    }

    int x = _offsetToX(line, offset);
    int width = painter.getFontMetrics().charWidth('w');

    if (x < 0) {
      newHorizontalOffset = Math.min(0, horizontalOffset - x + width + 5);
    } else if (x + width >= painter.getWidth()) {
      newHorizontalOffset = horizontalOffset + (painter.getWidth() - x) - width - 5;
    }

    return setOrigin(newFirstLine, newHorizontalOffset);
  }
示例#7
0
 @NotNull
 private Dimension expandIfNecessary(@NotNull Dimension base) {
   if (base.width >= myMinWidth && base.height >= myMinHeight) {
     return base;
   }
   return new Dimension(Math.max(myMinWidth, base.width), Math.max(myMinHeight, base.height));
 }
示例#8
0
  public void paint(Graphics gg) {
    int faceSize = Math.min(getWidth() - 4, getHeight() - 4);
    if (face == null)
      face =
          new PADFaceMapped(
              Math.max(2, (getWidth() - faceSize) / 2),
              Math.max(2, (getHeight() - faceSize) / 2),
              faceSize);
    if (buffer == null) {
      im = this.createImage(getWidth(), getHeight());
      buffer = im.getGraphics();
    }
    super.paint(buffer);

    buffer.setColor(new Color(255, 255, 255, 0));
    buffer.fillRect(0, 0, im.getWidth(null), im.getHeight(null));

    face.setDimensions(
        Math.max(2, (getWidth() - faceSize) / 2),
        Math.max(2, (getHeight() - faceSize) / 2),
        faceSize);
    face.paint(buffer);

    // draw buffer to screen
    gg.drawImage(im, 0, 0, null, null);
  }
 @Override
 public Dimension getPreferredSize() {
   Dimension windowSize = DiffUtil.getDefaultDiffWindowSize();
   Dimension size = super.getPreferredSize();
   return new Dimension(
       Math.max(windowSize.width, size.width), Math.max(windowSize.height, size.height));
 }
示例#10
0
文件: TetrisUI.java 项目: kymo/tetris
 /**
  * the structure function of TetrisUI
  *
  * @param none
  */
 public TetrisUI() {
   Random rdm = new Random();
   m_blockStyle = Math.abs(rdm.nextInt()) % 7 + 1;
   cTetrisBlock = new TetrisBlock(100, 0, m_blockStyle, 0);
   //// System.out.println("block style " + m_blockStyle);
   cNextBlockDC = new DrawNextBlockComponent();
   rdm = new Random();
   // set next block style
   setBlockStyle(Math.abs(rdm.nextInt()) % 7 + 1);
   // set the next block game dc
   getNextBlockDC().setNextBlockStyle(getBlockStyle());
   m_blockGrid = new int[GRID_Y][GRID_X];
   // the param of control
   isCoordinateLock = false;
   isKeyPressed = false;
   isTransforStart = false;
   isGameStart = false;
   isGameOver = false;
   isNextReady = false;
   m_userScore = 0;
   // set text
   m_lTotalScore.setText(Integer.toString(m_userScore));
   m_bGameHalt.setEnabled(false);
   for (int j = 0; j < GRID_Y; j++) for (int k = 0; k < GRID_X; k++) m_blockGrid[j][k] = 0;
   isGameHalt = false;
 }
  /**
   * Stores the position and size of the bouncing box that would be painted for the current
   * animation index in <code>r</code> and returns <code>r</code>. Subclasses that add to the
   * painting performed in this class's implementation of <code>paintIndeterminate</code> -- to draw
   * an outline around the bouncing box, for example -- can use this method to get the location of
   * the bouncing box that was just painted. By overriding this method, you have complete control
   * over the size and position of the bouncing box, without having to reimplement <code>
   * paintIndeterminate</code>.
   *
   * @param r the Rectangle instance to be modified; may be <code>null</code>
   * @return <code>null</code> if no box should be drawn; otherwise, returns the passed-in rectangle
   *     (if non-null) or a new rectangle
   * @see #setAnimationIndex
   * @since 1.4
   */
  protected Rectangle getBox(Rectangle r) {
    int currentFrame = getAnimationIndex();
    int middleFrame = numFrames / 2;

    if (sizeChanged() || delta == 0.0 || maxPosition == 0.0) {
      updateSizes();
    }

    r = getGenericBox(r);

    if (r == null) {
      return null;
    }
    if (middleFrame <= 0) {
      return null;
    }

    // assert currentFrame >= 0 && currentFrame < numFrames
    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      if (currentFrame < middleFrame) {
        r.x = componentInnards.x + (int) Math.round(delta * (double) currentFrame);
      } else {
        r.x = maxPosition - (int) Math.round(delta * (currentFrame - middleFrame));
      }
    } else { // VERTICAL indeterminate progress bar
      if (currentFrame < middleFrame) {
        r.y = componentInnards.y + (int) Math.round(delta * currentFrame);
      } else {
        r.y = maxPosition - (int) Math.round(delta * (currentFrame - middleFrame));
      }
    }
    return r;
  }
    private void generateLookupTables() {
      mySat = new float[myWidth * myHeight];
      myHues = new float[myWidth * myHeight];
      myAlphas = new int[myWidth * myHeight];
      float radius = getRadius();

      // blend is used to create a linear alpha gradient of two extra pixels
      float blend = (radius + 2f) / radius - 1f;

      // Center of the color wheel circle
      int cx = myWidth / 2;
      int cy = myHeight / 2;

      for (int x = 0; x < myWidth; x++) {
        int kx = x - cx; // Kartesian coordinates of x
        int squarekx = kx * kx; // Square of kartesian x

        for (int y = 0; y < myHeight; y++) {
          int ky = cy - y; // Kartesian coordinates of y

          int index = x + y * myWidth;
          mySat[index] = (float) Math.sqrt(squarekx + ky * ky) / radius;
          if (mySat[index] <= 1f) {
            myAlphas[index] = 0xff000000;
          } else {
            myAlphas[index] =
                (int) ((blend - Math.min(blend, mySat[index] - 1f)) * 255 / blend) << 24;
            mySat[index] = 1f;
          }
          if (myAlphas[index] != 0) {
            myHues[index] = (float) (Math.atan2(ky, kx) / Math.PI / 2d);
          }
        }
      }
    }
  public Dimension getDocumentSize() {
    float pageViewWidth = 0;
    float pageViewHeight = 0;
    if (pagesPanel != null) {
      int currCompIndex = documentViewController.getCurrentPageIndex();
      int numComponents = pagesPanel.getComponentCount();
      if (currCompIndex >= 0 && currCompIndex < numComponents) {
        Component comp = pagesPanel.getComponent(currCompIndex);
        if (comp instanceof PageViewDecorator) {
          PageViewDecorator pvd = (PageViewDecorator) comp;
          Dimension dim = pvd.getPreferredSize();
          pageViewWidth = dim.width;
          pageViewHeight = dim.height;
        }
      }
    }
    // normalize the dimensions to a zoom level of zero.
    float currentZoom = documentViewModel.getViewZoom();
    pageViewWidth = Math.abs(pageViewWidth / currentZoom);
    pageViewHeight = Math.abs(pageViewHeight / currentZoom);

    // add any horizontal padding from layout manager
    pageViewWidth += AbstractDocumentView.horizontalSpace * 2;
    pageViewHeight += AbstractDocumentView.verticalSpace * 2;
    return new Dimension((int) pageViewWidth, (int) pageViewHeight);
  }
示例#14
0
  public void mouseClicked(MouseEvent e) {
    int x;
    int y;

    e.consume();

    if (mouseEventsEnabled) {

      x = Math.round(e.getX() / scale);
      y = Math.round(e.getY() / scale);

      // allow for the canvas margin
      y -= margin;

      // System.out.println("Mouse Click: (" + x + ", " + y + ")");

      if (e.getClickCount() < 2) {
        if (nativeSelectItem(x, y)) {
          parentFTAFrame.updateFrame();
        }
      } else {
        if (nativeSelectItem(x, y)) {
          parentFTAFrame.updateFrame();
        }

        editSelected();
        parentFTAFrame.updateFrame();
      }

      if (focusEventsEnabled) {
        // tell the main Canvas to point to this coordinate
        parentFTAFrame.setCanvasFocus(x, y);
      }
    }
  }
示例#15
0
 private long normalizeMax(long l) {
   int exp = (int) Math.log10((double) l);
   long multiple = (long) Math.pow(10.0, exp);
   int i = (int) (l / multiple);
   l = (i + 1) * multiple;
   return l;
 }
 /**
  * Computes and plots correlation functions
  *
  * @param tauMax is the maximum time for correlation functions
  */
 public void computeCorrelation(int tauMax) {
   plotFrame.clearData();
   double energyAccumulator = 0, magnetizationAccumulator = 0;
   double energySquaredAccumulator = 0, magnetizationSquaredAccumulator = 0;
   for (int t = 0; t < numberOfPoints; t++) {
     energyAccumulator += energy[t];
     magnetizationAccumulator += magnetization[t];
     energySquaredAccumulator += energy[t] * energy[t];
     magnetizationSquaredAccumulator += magnetization[t] * magnetization[t];
   }
   double averageEnergySquared = Math.pow(energyAccumulator / numberOfPoints, 2);
   double averageMagnetizationSquared = Math.pow(magnetizationAccumulator / numberOfPoints, 2);
   // compute normalization factors
   double normE = (energySquaredAccumulator / numberOfPoints) - averageEnergySquared;
   double normM = (magnetizationSquaredAccumulator / numberOfPoints) - averageMagnetizationSquared;
   for (int tau = 1; tau <= tauMax; tau++) {
     double c_MAccumulator = 0;
     double c_EAccumulator = 0;
     int counter = 0;
     for (int t = 0; t < numberOfPoints - tau; t++) {
       c_MAccumulator += magnetization[t] * magnetization[t + tau];
       c_EAccumulator += energy[t] * energy[t + tau];
       counter++;
     }
     // correlation function defined so that c(0) = 1 and c(infinity) -> 0
     plotFrame.append(0, tau, ((c_MAccumulator / counter) - averageMagnetizationSquared) / normM);
     plotFrame.append(1, tau, ((c_EAccumulator / counter) - averageEnergySquared) / normE);
   }
   plotFrame.setVisible(true);
 }
示例#17
0
  /**
   * Damages the area surrounding the caret to cause it to be repainted in a new location. If
   * paint() is reimplemented, this method should also be reimplemented. This method should update
   * the caret bounds (x, y, width, and height).
   *
   * @param r the current location of the caret
   * @see #paint
   */
  @Override
  protected synchronized void damage(final Rectangle r) {
    if (r == null || fPainting) return;

    x = r.x - 4;
    y = r.y;
    width = 10;
    height = r.height;

    // Don't damage the border area.  We can't paint a partial border, so get the
    // intersection of the caret rectangle and the component less the border, if any.
    final Rectangle caretRect = new Rectangle(x, y, width, height);
    final Border border = getComponent().getBorder();
    if (border != null) {
      final Rectangle alloc = getComponent().getBounds();
      alloc.x = alloc.y = 0;
      final Insets borderInsets = border.getBorderInsets(getComponent());
      alloc.x += borderInsets.left;
      alloc.y += borderInsets.top;
      alloc.width -= borderInsets.left + borderInsets.right;
      alloc.height -= borderInsets.top + borderInsets.bottom;
      Rectangle2D.intersect(caretRect, alloc, caretRect);
    }
    x = caretRect.x;
    y = caretRect.y;
    width = Math.max(caretRect.width, 1);
    height = Math.max(caretRect.height, 1);
    repaint();
  }
示例#18
0
  @Override
  public void actionPerformed(ActionEvent e) {

    if (firstClick) {
      firstClick = false;
      lastIcon = buttons[0][0].getIcon();
      buttons[0][0].setIcon(null);
      for (int i = 0; i < 10000; i++) {
        int zufallY = (int) ((Math.random() * YY) + 0);
        int zufallX = (int) ((Math.random() * XX) + 0);
        switchButton(zufallY, zufallX);
      }
      // ToDo: unwiederrufbare Operationen vermeiden?
      // funktion klären und abfangen
      /*while(lastButton % XX != 0)
          switchButton(lastButton-1);
      while (lastButton != "00")
          switchButton(lastButton-XX);*/

    } else {
      PuzzButton tmp = (PuzzButton) e.getSource();
      int posY = tmp.getPosY();
      int posX = tmp.getPosX();

      switchButton(posY, posX);
      if (isDone()) {
        buttons[0][0].setIcon(lastIcon);
        firstClick = true;
      }
    }
  }
示例#19
0
 private void setColumnPreferredSize() {
   for (int i = 0; i < getColumnCount(); i++) {
     TableColumn column = getColumnModel().getColumn(i);
     if (i == AbstractVcsLogTableModel.ROOT_COLUMN) { // thin stripe or nothing
       int rootWidth = myUI.getColorManager().isMultipleRoots() ? ROOT_INDICATOR_WIDTH : 0;
       // NB: all further instructions and their order are important, otherwise the minimum size
       // which is less than 15 won't be applied
       column.setMinWidth(rootWidth);
       column.setMaxWidth(rootWidth);
       column.setPreferredWidth(rootWidth);
     } else if (i
         == AbstractVcsLogTableModel
             .COMMIT_COLUMN) { // let commit message occupy as much as possible
       column.setPreferredWidth(Short.MAX_VALUE);
     } else if (i
         == AbstractVcsLogTableModel.AUTHOR_COLUMN) { // detect author with the longest name
       // to avoid querying the last row (it would lead to full graph loading)
       int maxRowsToCheck =
           Math.min(MAX_ROWS_TO_CALC_WIDTH, getRowCount() - MAX_ROWS_TO_CALC_OFFSET);
       if (maxRowsToCheck < 0) { // but if the log is small, check all of them
         maxRowsToCheck = getRowCount();
       }
       int contentWidth = calcMaxContentColumnWidth(i, maxRowsToCheck);
       column.setMinWidth(Math.min(contentWidth, MAX_DEFAULT_AUTHOR_COLUMN_WIDTH));
       column.setWidth(column.getMinWidth());
     } else if (i == AbstractVcsLogTableModel.DATE_COLUMN) { // all dates have nearly equal sizes
       Font tableFont = UIManager.getFont("Table.font");
       column.setMinWidth(
           getFontMetrics(tableFont)
               .stringWidth("mm" + DateFormatUtil.formatDateTime(new Date())));
       column.setWidth(column.getMinWidth());
     }
   }
 }
示例#20
0
  /**
   * Draws an open star with a specified number of points.<br>
   * The center of this star is specified by centerX,centerY and its size is specified by radius
   * <br>
   * (As in the radius of the circle the star would fit inside). <br>
   * Precondition: points >= 2 <br>
   * Example: <br>
   * Expo.drawStar(g,300,200,100,8); <br>
   * Draws an open star with 8 points and a radius of 100 pixels whose center is located at the
   * coordinate (300,200).
   */
  public static void drawStar(Graphics g, int centerX, int centerY, int radius, int points) {
    int halfRadius = getHalfRadius(radius, points);
    int p = points;
    points *= 2;

    int xCoord[] = new int[points];
    int yCoord[] = new int[points];

    int currentRadius;

    for (int k = 0; k < points; k++) {
      if (k % 2 == 0) currentRadius = radius;
      else currentRadius = halfRadius;

      xCoord[k] = (int) Math.round(Math.cos(twoPI * k / points - halfPI) * currentRadius) + centerX;
      yCoord[k] = (int) Math.round(Math.sin(twoPI * k / points - halfPI) * currentRadius) + centerY;
    }

    int x = (p - 5) / 2 + 1;
    if (p >= 5 && p <= 51)
      switch (p % 4) {
        case 1:
          yCoord[x] = yCoord[x + 1] = yCoord[points - x - 1] = yCoord[points - x];
          break;
        case 2:
          yCoord[x] = yCoord[x + 1] = yCoord[points - x - 1] = yCoord[points - x];
          yCoord[x + 3] = yCoord[x + 4] = yCoord[points - x - 4] = yCoord[points - x - 3];
          break;
        case 3:
          yCoord[x + 2] = yCoord[x + 3] = yCoord[points - x - 3] = yCoord[points - x - 2];
      }
    g.drawPolygon(xCoord, yCoord, points);
  }
 /**
  * Returns a list of pairs of x coordinates for visual ranges representing given logical range. If
  * <code>startOffset == endOffset</code>, a pair of equal numbers is returned, corresponding to
  * target position. Target offsets are supposed to be located on the same visual line.
  */
 private TFloatArrayList logicalRangeToVisualRanges(int startOffset, int endOffset) {
   assert startOffset <= endOffset;
   TFloatArrayList result = new TFloatArrayList();
   for (VisualLineFragmentsIterator.Fragment fragment :
       VisualLineFragmentsIterator.create(myView, startOffset, false)) {
     int minOffset = fragment.getMinOffset();
     int maxOffset = fragment.getMaxOffset();
     if (startOffset == endOffset) {
       if (startOffset >= minOffset && startOffset <= maxOffset) {
         float x = fragment.offsetToX(startOffset);
         result.add(x);
         result.add(x);
         break;
       }
     } else if (startOffset < maxOffset && endOffset > minOffset) {
       float x1 = fragment.offsetToX(Math.max(minOffset, startOffset));
       float x2 = fragment.offsetToX(Math.min(maxOffset, endOffset));
       if (x1 > x2) {
         float tmp = x1;
         x1 = x2;
         x2 = tmp;
       }
       if (result.isEmpty() || x1 > result.get(result.size() - 1)) {
         result.add(x1);
         result.add(x2);
       } else {
         result.set(result.size() - 1, x2);
       }
     }
   }
   return result;
 }
  /**
   * Scroll to the error specified by the given tree path, or do nothing if no error is specified.
   *
   * @param treePath the tree path to scroll to.
   */
  private void scrollToError(final TreePath treePath) {
    final DefaultMutableTreeNode treeNode =
        (DefaultMutableTreeNode) treePath.getLastPathComponent();
    if (treeNode == null || !(treeNode.getUserObject() instanceof ResultTreeNode)) {
      return;
    }

    final ResultTreeNode nodeInfo = (ResultTreeNode) treeNode.getUserObject();
    if (nodeInfo.getFile() == null || nodeInfo.getProblem() == null) {
      return; // no problem here :-)
    }

    final VirtualFile virtualFile = nodeInfo.getFile().getVirtualFile();
    if (virtualFile == null || !virtualFile.exists()) {
      return;
    }

    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    final FileEditor[] editor = fileEditorManager.openFile(virtualFile, true);

    if (editor.length > 0 && editor[0] instanceof TextEditor) {
      final LogicalPosition problemPos =
          new LogicalPosition(Math.max(lineFor(nodeInfo) - 1, 0), Math.max(columnFor(nodeInfo), 0));

      final Editor textEditor = ((TextEditor) editor[0]).getEditor();
      textEditor.getCaretModel().moveToLogicalPosition(problemPos);
      textEditor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
    }
  }
示例#23
0
  /**
   * Ensures that the caret is visible by scrolling the text area if necessary.
   *
   * @return True if scrolling was actually performed, false if the caret was already visible
   */
  public boolean scrollToCaret() {
    int line = getCaretLine();
    int lineStart = getLineStartOffset(line);
    int offset = Math.max(0, Math.min(getLineLength(line) - 1, getCaretPosition() - lineStart));

    return scrollTo(line, offset);
  }
示例#24
0
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and ellipse.
  *
  * @return Returns true, if the circle is inside of the image bounds.
  */
 private boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, Ellipse2D.Double ellipse) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType() &&
             ellipse.width == ellipse.height
             ) {
         
         Point2D.Double start = new Point2D.Double(ellipse.x, ellipse.y);
         Point2D.Double end = new Point2D.Double(ellipse.x + ellipse.width, ellipse.y + ellipse.height);
         t.transform(start, start);
         t.transform(end, end);
         ellipse.x = Math.min(start.x, end.x);
         ellipse.y = Math.min(start.y, end.y);
         ellipse.width = Math.abs(start.x - end.x);
         ellipse.height = Math.abs(start.y - end.y);
         
         elem.setAttribute("shape", "circle");
         elem.setAttribute("coords",
                 (int) (ellipse.x + ellipse.width / 2d)+","+
                 (int) (ellipse.y + ellipse.height / 2d)+","+
                 (int) (ellipse.width / 2d)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(ellipse.getBounds());
     } else {
         return writePolyAttributes(elem, f, (Shape) ellipse);
     }
 }
示例#25
0
 /**
  * Write the given text string in the current font, centered on (x, y) and rotated by the
  * specified number of degrees
  *
  * @param x the center x-coordinate of the text
  * @param y the center y-coordinate of the text
  * @param s the text
  * @param degrees is the number of degrees to rotate counterclockwise
  */
 public static void text(double x, double y, String s, double degrees) {
   double xs = scaleX(x);
   double ys = scaleY(y);
   offscreen.rotate(Math.toRadians(-degrees), xs, ys);
   text(x, y, s);
   offscreen.rotate(Math.toRadians(+degrees), xs, ys);
 }
示例#26
0
  // Proceso para posicionar las imagenes en el concentrece
  public void cargarImagenes() {
    int x, y = 0;
    int numero = -1;
    double x1, y1 = 0;
    ficha = new int[a][b];
    // Incializacion de la matriz entera en -1
    for (int i = 0; i < getA(); i++) {
      for (int j = 0; j < getB(); j++) {
        ficha[i][j] = -1;
      }
    }

    // Proceso de introduccion de imagenes en posiciones aleatorias para
    // obtener mas variaciones del juego
    for (int i = 0; i < getA(); i++) {
      for (int j = 0; j < getB(); j++) {
        do {
          x1 = Math.random() * getA();
          y1 = Math.random() * getB();
          x = (int) x1;
          y = (int) y1;
        } while (ficha[x][y] != -1);
        numero++;
        if (numero == getC()) {
          numero = 0;
        }
        ficha[x][y] = numero;
        parejas[i][j].setIcon(vacio);
      }
    }
  }
示例#27
0
    public int FindRandomSize(int max, int min) {

      int range = Math.abs(max - min) + 1;
      int random_number = (int) (Math.random() * range) + (min <= max ? min : max);

      return random_number;
    }
示例#28
0
    /**
     * Calculates the maximum size dimensions for the specified panal given the components in the
     * specified parent container.
     */
    public Dimension maximumLayoutSize(Container target) {
      synchronized (target.getTreeLock()) {
        Dimension dim = new Dimension(0, 0);
        int size = actions.size();
        if ((grip != null) && grip.isVisible()) {
          Dimension d = grip.getPreferredSize();
          dim.width += d.width;
          dim.width += hgap;
        }
        Component last = null;
        for (int i = 0; i < size; i++) {
          Component comp = (Component) actions.elementAt(i);
          if (comp.isVisible()) {
            Dimension d = comp.getPreferredSize();
            dim.width += d.width;
            dim.height = Math.max(dim.height, d.height);
            dim.width += hgap;
            last = comp;
          }
        }
        if (last != null) {
          Dimension prefSize = last.getPreferredSize();
          Dimension maxSize = last.getMaximumSize();
          if (prefSize != maxSize) {
            dim.width = dim.width - prefSize.width + maxSize.width;
            dim.height = Math.max(dim.height, maxSize.height);
          }
        }
        Insets insets = target.getInsets();
        dim.width += insets.left + insets.right;
        dim.height += insets.top + insets.bottom;

        return dim;
      }
    }
示例#29
0
  public Object down(Message msg) {
    Address dest = msg.getDest();
    boolean multicast = dest == null;

    if (msg.getSrc() == null) msg.setSrc(localAddress());

    if (discard_all) {
      if (dest == null || dest.equals(localAddress())) loopback(msg);
      return null;
    }

    if (!multicast && drop_down_unicasts > 0) {
      drop_down_unicasts = Math.max(0, drop_down_unicasts - 1);
      return null;
    }

    if (multicast && drop_down_multicasts > 0) {
      drop_down_multicasts = Math.max(0, drop_down_multicasts - 1);
      return null;
    }

    if (down > 0) {
      double r = Math.random();
      if (r < down) {
        if (excludeItself && dest != null && dest.equals(localAddress())) {
          if (log.isTraceEnabled()) log.trace("excluding itself");
        } else {
          log.trace("dropping message");
          num_down++;
          return null;
        }
      }
    }
    return down_prot.down(msg);
  }
示例#30
0
 public void blockgen() {
   Component temporaryLostComponent = null;
   pos[0] = 0;
   pos[1] = 1;
   rand = (int) (Math.floor(Math.random() * 7 + 1));
   centralx = 4;
   centraly = 0;
   System.out.print(rand);
   if ((b[4 + prof[pos[0]][0][rand - 1].x][prof[pos[0]][0][rand - 1].y].getBackground()
           == Color.DARK_GRAY)
       && (b[4 + prof[pos[0]][1][rand - 1].x][prof[pos[0]][1][rand - 1].y].getBackground()
           == Color.DARK_GRAY)
       && (b[4 + prof[pos[0]][2][rand - 1].x][prof[pos[0]][2][rand - 1].y].getBackground()
           == Color.DARK_GRAY)
       && (b[4 + prof[pos[0]][3][rand - 1].x][prof[pos[0]][3][rand - 1].y].getBackground()
           == Color.DARK_GRAY)) {
     b[4 + prof[pos[0]][0][rand - 1].x][prof[pos[0]][0][rand - 1].y].setBackground(rnd[rand - 1]);
     b[4 + prof[pos[0]][1][rand - 1].x][prof[pos[0]][1][rand - 1].y].setBackground(rnd[rand - 1]);
     b[4 + prof[pos[0]][2][rand - 1].x][prof[pos[0]][2][rand - 1].y].setBackground(rnd[rand - 1]);
     b[4 + prof[pos[0]][3][rand - 1].x][prof[pos[0]][3][rand - 1].y].setBackground(rnd[rand - 1]);
     go();
   } else {
     JOptionPane.showMessageDialog(
         temporaryLostComponent, "Game Over! You cleared " + rowsclrd + " rows, well done!");
     System.exit(0);
   }
 }