Exemple #1
0
  @Override
  public void keyPressed(KeyEvent ke) {
    // System.out.println("key pressed:"+ke.getKeyCode());
    if (ke.isControlDown()) {
      if (ke.getKeyCode() == 67) { // Ctrl+c = copy
        menu.copy();
      } else if (ke.getKeyCode() == 88) { // Ctrl+x = cut
        menu.copy();
        menu.delete();
      } else if (ke.getKeyCode() == 86) { // Ctrl+v = paste
        menu.paste();
      } else if (ke.getKeyCode() == 79) { // Ctrl+o = open
        menu.open();
      } else if (ke.getKeyCode() == 83) { // Ctrl+s = save
        menu.save();
      }
    }

    if (ke.getKeyCode() == 38) { // Up key
      for (Bead bead : multiSelect) {
        if (bead.getTrack() > 1) {
          bead.setTrack(bead.getTrack() - 1);
          bead.setLocation(bead.getX(), bead.getY() - beadPlayer1.TRACKHEIGHT);
        }
      }
    } else if (ke.getKeyCode() == 40) { // Down key
      for (Bead bead : multiSelect) {
        if (bead.getTrack() < 8) {
          bead.setTrack(bead.getTrack() + 1);
          bead.setLocation(bead.getX(), bead.getY() + beadPlayer1.TRACKHEIGHT);
        }
      }
    } else if (ke.getKeyCode() == 37) { // Left key
      for (Bead bead : multiSelect) {
        if (bead.getX() > 55) bead.setLocation(bead.getX() - beadPlayer1.BEADHEIGHT, bead.getY());
      }
    } else if (ke.getKeyCode() == 39) { // Right key
      for (Bead bead : multiSelect) {
        if (bead.getX() < 1000) bead.setLocation(bead.getX() + beadPlayer1.BEADHEIGHT, bead.getY());
      }
    } else if (ke.getKeyCode() == 127 || ke.getKeyCode() == 8) { // delete/backspace key
      menu.delete();
    }
  }
Exemple #2
0
 public void refreshBeadPanel() {
   Bead tmpBead = new Bead();
   tmpBead.setSize(55, 55);
   beadPanelText.add(tmpBead);
   tmpBead.setLocation(20, 15);
   tmpBead.setOpaque(false);
   activeBead = tmpBead;
   beadPanel.repaint();
   prevBead = tmpBead;
 }
Exemple #3
0
  private void beadPlayer1MouseReleased(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_beadPlayer1MouseReleased
    endBead =
        beadPlayer1.getBeadAt(
            evt.getX(), evt.getY(), beadPlayer1.page); // Check if there is a bead in the end.

    if (evt.getButton() == MouseEvent.BUTTON1) {
      if (dragStatus && isActualDrag(evt.getX(), evt.getY())) {
        if (activeBead != null) {
          if (endBead == null) {
            if (activeBead.connectedTo
                == null) { // If there is no bead, and A is not connected, create one.
              if (!activeBead.playable) {
                remove(activeBead); // Remove bead panel glitch
              } else {
                endBead = new Bead();
                endBead.setSize(55, 55);
                endBead.setIntensity(activeBead.getIntensity());
                endBead.setFrequency(activeBead.getFrequency());
                endBead.setConnection(activeBead);
                endBead.vibcompUI = this;

                Bead leftPossible =
                    beadPlayer1.getBeadAt(evt.getX() - 27, evt.getY(), beadPlayer1.page);
                Bead rightPossible =
                    beadPlayer1.getBeadAt(evt.getX() + 27, evt.getY(), beadPlayer1.page);
                if (leftPossible == null) { // If there exists no bead on the point's left
                  if (rightPossible == null) {
                    beadPlayer1.setBead(evt.getX(), evt.getY(), endBead);
                  } else { // There is a bead on its right.
                    beadPlayer1.setBead(rightPossible.getX() - 27, evt.getY(), endBead);
                  }
                } else if (rightPossible
                    == null) { // There is a Bead on the left of clicked position.
                  beadPlayer1.setBead(leftPossible.getX() + 80, evt.getY(), endBead);
                }
                activeBead = endBead;
              }
            } else { // Moving a connected Bead.
              int x = evt.getX();
              int y = evt.getY();

              if (x < 27) { // keep bead within page bounds
                x = 27;
              } else if (x > 1072) {
                x = 1072;
              }
              if (y < 0) {
                y = 0;
              } else if (y > 540) {
                y = 540;
              }
              int yLoc = (beadPlayer1.getTrackAt(y) - 1) * beadPlayer1.TRACKHEIGHT + 5;
              activeBead.setTrack(beadPlayer1.getTrackAt(y));

              Bead leftPossible = beadPlayer1.getBeadAt(x - 27, y, beadPlayer1.page);
              Bead rightPossible = beadPlayer1.getBeadAt(x + 27, y, beadPlayer1.page);
              if (leftPossible == null) { // If there exists no bead on the point's left
                if (rightPossible == null) {
                  activeBead.setLocation(x - 27, yLoc);
                } else { // There is a bead on its right.
                  activeBead.setLocation(rightPossible.getX() - 55, yLoc);
                }
              } else if (rightPossible
                  == null) { // There is a Bead on the left of clicked position.
                activeBead.setLocation(leftPossible.getX() + 55, yLoc);
              }
            }
          } else {
            /*if endbead is not null;*/
            /* do nothing*/

          }
        } else {
          JOptionPane.showMessageDialog(null, "There is no active Bead!");
        }
      }
      dragStatus = false;
      multiSelect.add(activeBead);
    }
  } // GEN-LAST:event_beadPlayer1MouseReleased