示例#1
0
  /**
   * Spusti se pri zmacknuti tlacitka. Pokud je pod mysi obraz figury, zjisti, zda se muze pohnout
   * (pokud ano, upravi ho pro tahnuti, nastavi ho do figLabel) a zobrazi kontextovou napovedu.
   */
  private void eCatcherMousePressed(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_eCatcherMousePressed
    if (figLabel != null || finished) {
      return;
    }
    BoardSquare bsquare = (BoardSquare) eCatcher.getComponentAt(evt.getPoint());

    JPanel fsquare = (JPanel) figurePan.getComponent(bsquare.getIndex());
    sourceBSquare = bsquare;
    Point defLocation = fsquare.getLocation();
    xAdjustment = (int) defLocation.getX() - evt.getX();
    yAdjustment = (int) defLocation.getY() - evt.getY();
    if (fsquare.getComponentCount() == 0) {
      return;
    }
    figLabel = (JLabel) fsquare.getComponent(0);

    setFocus(gui.getFocus(bsquare.getColumn(), bsquare.getRow()));
    if (!gui.canMove(bsquare.getColumn(), bsquare.getRow())) {
      figLabel = null;
      return;
    }
    fsquare.remove(figLabel);
    boardPane.add(figLabel, 0);
    figLabel.setLocation(evt.getX() + xAdjustment, evt.getY() + yAdjustment);
    figLabel.setSize(figLabel.getWidth(), figLabel.getHeight());
  } // GEN-LAST:event_eCatcherMousePressed
示例#2
0
  // Cette fonction pourrait etre optimisee en calculant le deplacement directement
  // Pas besoin de boucler
  void LightCalendar_MousePress(java.awt.event.MouseEvent event) {
    int x = 1;
    int y = drawMonthName ? 2 * (fm.getHeight() + 2) : (fm.getHeight());
    int w = getSize().width - 2;
    int h = getSize().height - y + 5;

    Rectangle r = new Rectangle(x, y, w, h);

    if (r.contains(event.getPoint())) {
      int caseWidth = w / 7;
      int caseHeight = h / 7;

      Calendar cal = Calendar.getInstance();
      cal.setTime(dateDebutMois);

      int nbJoursVides = cal.get(Calendar.DAY_OF_WEEK) - 1;
      int iJoursVides = 0;
      // int iJour = 1;

      Cases:
      for (int iRow = 0; iRow < 6; iRow++) {
        for (int iCol = 0; iCol < 7; iCol++) {
          // int day = cal.get( Calendar.DATE );
          if (iJoursVides < nbJoursVides) iJoursVides++;
          else if (cal.get(Calendar.MONTH) == mois) {
            int xCase = 1 + (iCol * caseWidth);
            int yCase = y + (iRow * caseHeight);
            Rectangle rCase = new Rectangle(xCase, yCase + 5, caseWidth, caseHeight);

            if (rCase.contains(event.getPoint())) {
              selectedDate = cal.getTime();
              selectedRow = iRow;
              selectedCol = iCol;
              parent.currentDate = selectedDate;
              repaint();
              break Cases;
            }

            cal.add(Calendar.DATE, 1);
          }
        }
      }
    }
  }
示例#3
0
 /**
  * Spousti se pri uvolneni tlacitka mysi. Pokud byl tazen obraz figury, vyhodnoti tah a bud jej
  * potvrdi a ukonci tah hrace nebo zamitne a vrati obraz figury na puvodni pozici.
  */
 private void eCatcherMouseReleased(
     java.awt.event.MouseEvent evt) { // GEN-FIRST:event_eCatcherMouseReleased
   removeFocus();
   if (figLabel == null) {
     return;
   }
   figLabel.setVisible(false);
   boardPane.remove(figLabel);
   BoardSquare bsquare = (BoardSquare) eCatcher.getComponentAt(evt.getPoint());
   if (bsquare == null
       || !gui.move(
           sourceBSquare.getColumn(),
           sourceBSquare.getRow(),
           bsquare.getColumn(),
           bsquare.getRow())) {
     ((JPanel) figurePan.getComponent(sourceBSquare.getIndex())).add(figLabel);
     figLabel.setVisible(true);
   }
   figLabel = null;
 } // GEN-LAST:event_eCatcherMouseReleased