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
private void beadPlayer1MousePressed( java.awt.event.MouseEvent evt) { // GEN-FIRST:event_beadPlayer1MousePressed /** * 2015-05-13 * * <p>Update note. If a bead is already Connected to something, then the user can "Drag" to move * around the note. * * <p>One can overlap if s/he clicked on "offset margin" */ point1 = evt.getPoint(); Bead tmpBead = beadPlayer1.getBeadAt(point1.x, point1.y, beadPlayer1.page); if (evt.getButton() == MouseEvent.BUTTON1) // Left click { if (evt.isAltDown()) { if (isBeadPanelEmpty()) { refreshBeadPanel(); beadPanelText.setVisible(true); activeBead.vibcompUI = this; Bead leftPossible = beadPlayer1.getBeadAt(point1.x - 27, point1.y, beadPlayer1.page); Bead rightPossible = beadPlayer1.getBeadAt(point1.x + 27, point1.y, beadPlayer1.page); if (leftPossible == null) { // If there exists no bead on the point's left if (rightPossible == null) { beadPlayer1.setBead(point1.x + 80, point1.y, activeBead); } else { // There is a bead on its right. beadPlayer1.setBead(rightPossible.getX() - 27, point1.y, activeBead); } } else if (rightPossible == null) { // There is a Bead on the left of clicked position. beadPlayer1.setBead(leftPossible.getX() + 80, point1.y, activeBead); } } } if (activeBead != null) { if (tmpBead == null) { // Create one beadPanelText.setVisible(true); activeBead.vibcompUI = this; Bead leftPossible = beadPlayer1.getBeadAt(point1.x - 27, point1.y, beadPlayer1.page); Bead rightPossible = beadPlayer1.getBeadAt(point1.x + 27, point1.y, beadPlayer1.page); if (leftPossible == null) { // If there exists no bead on the point's left if (rightPossible == null) { beadPlayer1.setBead(point1.x, point1.y, activeBead); } else { // There is a bead on its right. beadPlayer1.setBead(rightPossible.getX() - 27, point1.y, activeBead); } } else if (rightPossible == null) { // There is a Bead on the left of clicked position. beadPlayer1.setBead(leftPossible.getX() + 80, point1.y, activeBead); } } else { // There already is a bead at the location if (!activeBead.playable) { remove(activeBead); // Remove bead panel glitch } else { activeBead = tmpBead; } } // set slider positions intensitySlider.setValue(activeBead.getIntensity()); frequencySlider.setValue(activeBead.getFrequency()); // multi select if (evt.isShiftDown() || shiftOn) { if (multiSelect.contains(activeBead)) multiSelect.remove(activeBead); else multiSelect.add(activeBead); } else { multiSelect.clear(); } } else if (beadPlayer1.beads.isEmpty()) { JOptionPane.showMessageDialog( null, "Please click 'New Bead' to create a Bead, then Click on then click on the canvas"); } else if (activeBead == null && tmpBead != null) { activeBead = tmpBead; } } if (evt.getButton() == MouseEvent.BUTTON3 || evt.getClickCount() == 2) { // Right click or double click if (tmpBead != null) { if (multiSelect.size() == 1) multiSelect.clear(); multiSelect.add(tmpBead); activeBead = tmpBead; } menu.show(evt.getComponent(), evt.getX(), evt.getY()); } } // GEN-LAST:event_beadPlayer1MousePressed