Example #1
0
  public void setVisible(boolean inVisible) {
    if (inVisible) {
      super.setVisible(inVisible);
    } else {
      boolean closeWindow = true;

      // see if any child windows are open
      Frame[] frames = Frame.getFrames();

      for (int i = 0; i < frames.length; i++) {
        if (frames[i].isVisible() && frames[i] instanceof PatchWindow) {
          PatchWindow patchWindow = (PatchWindow) frames[i];

          if (patchWindow.getBankWindow() == this) {
            // this will confirm saves etc
            patchWindow.setVisible(false);

            if (patchWindow.isVisible()) {
              closeWindow = false;
              break;
            }
          }
        }
      }

      if (closeWindow) {
        if (this.bank.isModified()) {
          StringBuffer buffer = new StringBuffer();

          buffer.append("Save \"");
          buffer.append(getTitle());
          buffer.append(" before closing?");

          int response =
              JOptionPane.showConfirmDialog(
                  this, buffer.toString(), "Confirm", JOptionPane.YES_NO_CANCEL_OPTION);

          if (response == JOptionPane.YES_OPTION) {
            saveBank(false);
          } else if (response == JOptionPane.CANCEL_OPTION) {
            closeWindow = false;
          }
        }
      }

      if (closeWindow) {
        super.setVisible(false);

        // do NOT dispose() here
      }
    }
  }
Example #2
0
  public void mouseClicked(MouseEvent inEvent) {
    if (inEvent.getClickCount() == 2) {
      ControlWindow controlWindow = ControlWindow.getInstance();

      if (controlWindow.getPatchWindow() != null) {
        // close the patch window - will confirm write if dirty
        PatchWindow patchWindow = controlWindow.getPatchWindow();

        // this sets the control window's patch window to null
        // which we'll check for in a second
        patchWindow.setVisible(false);
      }

      if (controlWindow.getPatchWindow() == null) {
        if (!this.bankInProphet) {
          // allow the user to override our flag
          int response =
              ControlWindow.showConfirmDialog(
                  "Confirm",
                  "This bank is not in the Prophet. OK to open patch editing windows anyway?");

          if (response == JOptionPane.YES_OPTION) {
            setBankInProphet(true);
          }
        }

        if (this.bankInProphet) {
          int row = this.table.rowAtPoint(inEvent.getPoint());
          int column = this.table.columnAtPoint(inEvent.getPoint());

          if (row != -1 && column != -1) {
            int patchNumber = (row * kTableColumnCount) + column;

            boolean openEditor = true;

            // send a program change to the selected patch
            try {
              // enable all MIDI parameter options
              ControlWindow.getInstance().sendMidiMessage(Machine.makeEnableParametersMessage());

              // change to the right patch
              ControlWindow.getInstance().sendMidiProgramChange(patchNumber);
            } catch (Exception inException) {
              inException.printStackTrace(System.err);
              openEditor = false;
            }

            // if we had an error sending the midi, confirm the editor window open
            if (!openEditor) {
              int response =
                  JOptionPane.showConfirmDialog(
                      this,
                      "Could not send program change to Prophet. OK to open editor window?",
                      "Confirm",
                      JOptionPane.YES_NO_OPTION);

              openEditor = (response == JOptionPane.YES_OPTION);
            }

            if (openEditor) {
              try {
                Patch patch = this.bank.getPatchCopy(patchNumber);
                PatchWindow patchWindow = new PatchWindow(this, this.document, patch);
                ControlWindow.getInstance().setPatchWindow(patchWindow);
                patchWindow.setLocationRelativeTo(null);
                patchWindow.setVisible(true);
              } catch (Exception inException) {
                inException.printStackTrace(System.err);
                ControlWindow.showErrorDialog("Error", inException);
              }
            }
          }
        }
      }
    }
  }