Exemplo n.º 1
0
  /*
   * Uses the sequencer to play a Midi sequence from a .mid file
   * or a .txt file containing a JFugue string.
   */
  public void playMidiFile(String filePath) {

    try {

      if (filePath.equals("")) {
        // launch a file chooser (just for testing)
        final JFileChooser fc = new JFileChooser();
        int returnVal = fc.showOpenDialog(app.getMainComponent());
        if (returnVal == JFileChooser.APPROVE_OPTION) {
          filePath = fc.getSelectedFile().getAbsolutePath();
        }
      }

      String ext = filePath.substring(filePath.lastIndexOf(".") + 1);
      if (ext.equals("mid")) {
        // Load new sequence from .mid file
        tickPosition = 0;
        sequence = MidiSystem.getSequence(new File(filePath));
        playSequence(sequence, tickPosition);
      } else if (ext.equals("txt")) {
        playJFugueFromFile(new File(filePath));
      } else if (ext.equals("gm")) {
        loadSoundBank(new File(filePath));
      }

    } catch (IOException e) {
      e.printStackTrace();
    } catch (InvalidMidiDataException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  /** shows this dialog and select GeoElement geo at screen position location */
  public void setVisibleWithGeos(ArrayList<GeoElement> geos) {
    kernel.clearJustCreatedGeosInViews();

    setViewActive(true);

    if (kernel.getConstruction().getGeoSetConstructionOrder().size() < MAX_GEOS_FOR_EXPAND_ALL)
      geoTree.expandAll();
    else geoTree.collapseAll();

    geoTree.setSelected(geos, false);
    if (!isShowing()) {
      // pack and center on first showing
      if (firstTime) {
        pack();
        setLocationRelativeTo(app.getMainComponent());
        firstTime = false;
      }

      // ensure min size
      Dimension dim = getSize();
      if (dim.width < MIN_WIDTH) {
        dim.width = MIN_WIDTH;
        setSize(dim);
      }
      if (dim.height < MIN_HEIGHT) {
        dim.height = MIN_HEIGHT;
        setSize(dim);
      }

      super.setVisible(true);
    }
  }
Exemplo n.º 3
0
  /**
   * Creates a dialog to create a new GeoNumeric for a slider.
   *
   * @param x, y: location of slider in screen coords
   */
  public ButtonDialog(Application app, int x, int y, boolean textField) {
    super(app.getFrame(), false);
    this.app = app;
    this.textField = textField;
    addWindowListener(this);
    this.x = x;
    this.y = y;
    // create temp geos that may be returned as result
    // Construction cons = app.getKernel().getConstruction();
    // button = textField ? new GeoTextField(cons) : new GeoButton(cons);
    // button.setEuclidianVisible(true);
    // button.setAbsoluteScreenLoc(x, y);

    createGUI();
    pack();
    setLocationRelativeTo(app.getMainComponent());
  }
  public void keyPressed(KeyEvent e) {
    int keyCode = e.getKeyCode();

    // we don't want to trap AltGr
    // as it is used eg for entering {[}] is some locales
    // NB e.isAltGraphDown() doesn't work
    if (e.isAltDown() && e.isControlDown()) return;

    // swallow eg ctrl-a ctrl-b ctrl-p on Mac
    if (Application.MAC_OS && e.isControlDown()) e.consume();

    ctrlC = false;

    switch (keyCode) {
      case KeyEvent.VK_Z:
      case KeyEvent.VK_Y:
        if (Application.isControlDown(e)) {
          app.getGlobalKeyDispatcher().handleGeneralKeys(e);
          e.consume();
        }
        break;

      case KeyEvent.VK_0:
      case KeyEvent.VK_1:
      case KeyEvent.VK_2:
      case KeyEvent.VK_3:
      case KeyEvent.VK_4:
      case KeyEvent.VK_5:
      case KeyEvent.VK_6:
      case KeyEvent.VK_7:
      case KeyEvent.VK_8:
      case KeyEvent.VK_9:
        if (Application.isControlDown(e) && e.isShiftDown())
          app.getGlobalKeyDispatcher().handleGeneralKeys(e);
        break;

        // process input
      case KeyEvent.VK_C:
        if (Application.isControlDown(e)) // workaround for MAC_OS
        {
          ctrlC = true;
        }

        break;

      case KeyEvent.VK_ESCAPE:
        if (!handleEscapeKey) {
          break;
        }

        Component comp = SwingUtilities.getRoot(this);
        if (comp instanceof JDialog) {
          ((JDialog) comp).setVisible(false);
          return;
        }

        setText(null);
        break;

      case KeyEvent.VK_LEFT_PARENTHESIS:
        break;

      case KeyEvent.VK_UP:
        if (!handleEscapeKey) {
          break;
        }
        if (historyPopup == null) {
          String text = getPreviousInput();
          if (text != null) setText(text);
        } else if (!historyPopup.isDownPopup()) {
          historyPopup.showPopup();
        }
        break;

      case KeyEvent.VK_DOWN:
        if (!handleEscapeKey) {
          break;
        }
        if (historyPopup != null && historyPopup.isDownPopup()) historyPopup.showPopup();
        else setText(getNextInput());
        break;

      case KeyEvent.VK_F9:
        // needed for applets
        if (app.isApplet()) app.getGlobalKeyDispatcher().handleGeneralKeys(e);
        break;

      case KeyEvent.VK_RIGHT:
        if (moveToNextArgument(false)) {
          e.consume();
        }
        break;

      case KeyEvent.VK_TAB:
        if (moveToNextArgument(true)) {
          e.consume();
        }
        break;

      case KeyEvent.VK_F1:
        if (autoComplete) {
          if (getText().equals("")) {

            Object[] options = {app.getPlain("OK"), app.getPlain("ShowOnlineHelp")};
            int n =
                JOptionPane.showOptionDialog(
                    app.getMainComponent(),
                    app.getPlain("InputFieldHelp"),
                    app.getPlain("ApplicationName") + " - " + app.getMenu("Help"),
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE,
                    null, // do not use a custom Icon
                    options, // the titles of buttons
                    options[0]); // default button title

            if (n == 1) app.getGuiManager().openHelp(Application.WIKI_MANUAL);

          } else {
            int pos = getCaretPosition();
            while (pos > 0 && getText().charAt(pos - 1) == '[') {
              pos--;
            }
            String word = getWordAtPos(getText(), pos);
            String lowerCurWord = word.toLowerCase();
            String closest = dict.lookup(lowerCurWord);

            if (closest != null) // && lowerCurWord.equals(closest.toLowerCase()))		
            showCommandHelp(app.getInternalCommand(closest));
            else app.getGuiManager().openHelp(Application.WIKI_MANUAL);
          }
        } else app.getGuiManager().openHelp(Application.WIKI_MANUAL);

        e.consume();
        break;
      default:
    }
  }