Пример #1
0
  //    public static final String showElementTreeAction = "showElementTree";
  // -------------------------------------------------------------
  public void openFile(String currDirStr, String currFileStr) {

    if (fileDialog == null) {
      fileDialog = new FileDialog(this);
    }
    fileDialog.setMode(FileDialog.LOAD);
    if (!(currDirStr.equals(""))) {
      fileDialog.setDirectory(currDirStr);
    }
    if (!(currFileStr.equals(""))) {
      fileDialog.setFile(currFileStr);
    }
    fileDialog.show();

    String file = fileDialog.getFile(); // cancel pushed
    if (file == null) {
      return;
    }
    String directory = fileDialog.getDirectory();
    File f = new File(directory, file);
    if (f.exists()) {
      Document oldDoc = getEditor().getDocument();
      if (oldDoc != null)
        // oldDoc.removeUndoableEditListener(undoHandler);
        /*
          if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
          }
        */
        getEditor().setDocument(new PlainDocument());
      fileDialog.setTitle(file);
      Thread loader = new FileLoader(f, editor1.getDocument());
      loader.start();
    }
  }
Пример #2
0
 /** This is the action listener method that the menu items invoke */
 public void actionPerformed(ActionEvent e) {
   String command = e.getActionCommand();
   if (command.equals("quit")) {
     YesNoDialog d =
         new YesNoDialog(
             this, "Really Quit?", "Are you sure you want to quit?", "Yes", "No", null);
     d.addActionListener(
         new ActionListener() {
           public void actionPerformed(ActionEvent e) {
             if (e.getActionCommand().equals("yes")) System.exit(0);
             else textarea.append("Quit not confirmed\n");
           }
         });
     d.show();
   } else if (command.equals("open")) {
     FileDialog d = new FileDialog(this, "Open File", FileDialog.LOAD);
     d.show(); // display the dialog and block until answered
     textarea.append("You selected file: " + d.getFile() + "\n");
     d.dispose();
   } else if (command.equals("about")) {
     InfoDialog d =
         new InfoDialog(
             this,
             "About",
             "This demo was written by David Flanagan\n"
                 + "Copyright (c) 1997 O'Reilly & Associates");
     d.show();
   }
 }
Пример #3
0
 /**
  * Display a histogram of jMusic Note data in the score
  *
  * @param score the score to be displayed
  */
 public static void histogram() {
   FileDialog fd = new FileDialog(new Frame(), "Select a MIDI file to display.", FileDialog.LOAD);
   fd.show();
   String fileName = fd.getFile();
   if (fileName != null) {
     Score score = new Score();
     org.jm.util.Read.midi(score, fd.getDirectory() + fileName);
     HistogramFrame hf = new HistogramFrame(score);
   }
 }
Пример #4
0
  /** Handle ItemEvents. */
  public void itemStateChanged(ItemEvent e) {

    final String dialog_title = ResourceHandler.getMessage("template_dialog.title");

    Component target = (Component) e.getSource();

    if (target == recursiveCheckBox) {
      converter.setRecurse(recursiveCheckBox.isSelected());
    } else if (target == staticVersioningRadioButton || target == dynamicVersioningRadioButton) {
      converter.setStaticVersioning(staticVersioningRadioButton.isSelected());
    } else if (target == templateCh
        && (e.getStateChange() == e.SELECTED)) { // Process only when item is Selected

      // Get the current template selection
      String choiceStr = (String) templateCh.getSelectedItem();

      // If the user chooses 'other', display a file dialog to allow
      // them to select a template file.
      if (choiceStr.equals(TemplateFileChoice.OTHER_STR)) {
        String templatePath = null;
        FileDialog fd = new FileDialog(this, dialog_title, FileDialog.LOAD);
        fd.show();

        // Capture the path entered, if any.
        if (fd.getDirectory() != null && fd.getFile() != null) {
          templatePath = fd.getDirectory() + fd.getFile();
        }

        // If the template file is valid add it and select it.
        if (templatePath != null && setTemplateFile(templatePath)) {
          if (!templateCh.testIfInList(templatePath)) {
            templateCh.addItem(templatePath);
          }
          templateCh.select(templatePath);
        } else {
          templateCh.select(templateCh.getPreviousSelection());
        }
        fd.dispose();
      } else {
        templateCh.select(choiceStr);
      }
    }
  }
  /** Handles item selections */
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case MENU_TOGGLE_CONNECT:
        if (myBTCommunicator == null || connected == false) {
          selectNXT();

        } else {
          destroyBTCommunicator();
          updateButtonsAndMenu();
        }

        return true;

      case MENU_START_SW:
        if (programList.size() == 0) {
          showToast(R.string.no_programs_found, Toast.LENGTH_SHORT);
          break;
        }

        FileDialog myFileDialog = new FileDialog(this, programList);
        myFileDialog.show(mRobotType == R.id.robot_type_lejos);
        return true;

      case MENU_QUIT:
        destroyBTCommunicator();
        finish();

        if (btOnByUs) showToast(R.string.bt_off_message, Toast.LENGTH_SHORT);

        SplashMenu.quitApplication();
        return true;
    }

    return false;
  }
  /**
   * Method declaration
   *
   * @param ev
   */
  public void actionPerformed(ActionEvent ev) {

    String s = ev.getActionCommand();

    if (s == null) {
      if (ev.getSource() instanceof MenuItem) {
        MenuItem i;

        s = ((MenuItem) ev.getSource()).getLabel();
      }
    }

    if (s.equals("Execute")) {
      execute();
    } else if (s.equals("Exit")) {
      windowClosing(null);
    } else if (s.equals("Transfer")) {
      Transfer.work(null);
    } else if (s.equals("Dump")) {
      Transfer.work(new String[] {"-d"});

      /* NB - 26052002 Restore is not implemented yet in the transfer tool */
      /*
              } else if (s.equals("Restore")) {
                  Transfer.work(new String[]{"-r"});
      */
    } else if (s.equals("Logging on")) {
      jdbcSystem.setLogToSystem(true);
    } else if (s.equals("Logging off")) {
      jdbcSystem.setLogToSystem(false);
    } else if (s.equals("Refresh Tree")) {
      refreshTree();
    } else if (s.startsWith("#")) {
      int i = Integer.parseInt(s.substring(1));

      txtCommand.setText(sRecent[i]);
    } else if (s.equals("Connect...")) {
      connect(ConnectionDialog.createConnection(fMain, "Connect"));
      refreshTree();
    } else if (s.equals("Results in Grid")) {
      iResult = 0;

      pResult.removeAll();
      pResult.add("Center", gResult);
      pResult.doLayout();
    } else if (s.equals("Open Script...")) {
      FileDialog f = new FileDialog(fMain, "Open Script", FileDialog.LOAD);

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setDirectory(defDirectory);
      }

      f.show();

      String file = f.getFile();

      if (file != null) {
        txtCommand.setText(DatabaseManagerCommon.readFile(f.getDirectory() + file));
      }
    } else if (s.equals("Save Script...")) {
      FileDialog f = new FileDialog(fMain, "Save Script", FileDialog.SAVE);

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setDirectory(defDirectory);
      }

      f.show();

      String file = f.getFile();

      if (file != null) {
        DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtCommand.getText());
      }
    } else if (s.equals("Save Result...")) {
      FileDialog f = new FileDialog(fMain, "Save Result", FileDialog.SAVE);

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setDirectory(defDirectory);
      }

      f.show();

      String file = f.getFile();

      if (file != null) {
        showResultInText();
        DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtResult.getText());
      }
    } else if (s.equals("Results in Text")) {
      iResult = 1;

      pResult.removeAll();
      pResult.add("Center", txtResult);
      pResult.doLayout();
      showResultInText();
    } else if (s.equals("AutoCommit on")) {
      try {
        cConn.setAutoCommit(true);
      } catch (SQLException e) {
      }
    } else if (s.equals("AutoCommit off")) {
      try {
        cConn.setAutoCommit(false);
      } catch (SQLException e) {
      }
    } else if (s.equals("Enlarge Tree")) {
      Dimension d = tTree.getMinimumSize();

      d.width += 20;

      tTree.setMinimumSize(d);
      fMain.pack();
    } else if (s.equals("Shrink Tree")) {
      Dimension d = tTree.getMinimumSize();

      d.width -= 20;

      if (d.width >= 0) {
        tTree.setMinimumSize(d);
      }

      fMain.pack();
    } else if (s.equals("Enlarge Command")) {
      txtCommand.setRows(txtCommand.getRows() + 1);
      fMain.pack();
    } else if (s.equals("Shrink Command")) {
      int i = txtCommand.getRows() - 1;

      txtCommand.setRows(i < 1 ? 1 : i);
      fMain.pack();
    } else if (s.equals("Commit")) {
      try {
        cConn.commit();
      } catch (SQLException e) {
      }
    } else if (s.equals("Insert test data")) {
      insertTestData();
    } else if (s.equals("Rollback")) {
      try {
        cConn.rollback();
      } catch (SQLException e) {
      }
    } else if (s.equals("Disable MaxRows")) {
      try {
        sStatement.setMaxRows(0);
      } catch (SQLException e) {
      }
    } else if (s.equals("Set MaxRows to 100")) {
      try {
        sStatement.setMaxRows(100);
      } catch (SQLException e) {
      }
    } else if (s.equals("SELECT")) {
      showHelp(DatabaseManagerCommon.selectHelp);
    } else if (s.equals("INSERT")) {
      showHelp(DatabaseManagerCommon.insertHelp);
    } else if (s.equals("UPDATE")) {
      showHelp(DatabaseManagerCommon.updateHelp);
    } else if (s.equals("DELETE")) {
      showHelp(DatabaseManagerCommon.deleteHelp);
    } else if (s.equals("CREATE TABLE")) {
      showHelp(DatabaseManagerCommon.createTableHelp);
    } else if (s.equals("DROP TABLE")) {
      showHelp(DatabaseManagerCommon.dropTableHelp);
    } else if (s.equals("CREATE INDEX")) {
      showHelp(DatabaseManagerCommon.createIndexHelp);
    } else if (s.equals("DROP INDEX")) {
      showHelp(DatabaseManagerCommon.dropIndexHelp);
    } else if (s.equals("CHECKPOINT")) {
      showHelp(DatabaseManagerCommon.checkpointHelp);
    } else if (s.equals("SCRIPT")) {
      showHelp(DatabaseManagerCommon.scriptHelp);
    } else if (s.equals("SHUTDOWN")) {
      showHelp(DatabaseManagerCommon.shutdownHelp);
    } else if (s.equals("SET")) {
      showHelp(DatabaseManagerCommon.setHelp);
    } else if (s.equals("Test Script")) {
      showHelp(DatabaseManagerCommon.testHelp);
    }
  }
Пример #7
0
  public ParseMidiSmart() {
    FileDialog fd;
    Frame f = new Frame();

    // open a MIDI file
    fd = new FileDialog(f, "Open MIDI file or choose cancel to" + " finish.", FileDialog.LOAD);
    fd.show();

    // break out when user presses cancel
    if (fd.getFile() == null) return;
    //        SMF smf = new SMF();
    //        try {
    //            smf.read(new FileInputStream(new File(fd.getDirectory()+fd.getFile())));
    //        } catch (IOException e) {
    //            e.printStackTrace();
    //        }
    //        Vector vector = smf.getTrackList();
    //        for (int i = 0; i < vector.size(); i++) {
    //            Score score = new Score();
    //            MidiParser.SMFToScore(score, smf);
    //            System.out.println();
    //        }
    Read.midi(s, fd.getDirectory() + fd.getFile());
    s.setTitle(fd.getFile());
    //        try {
    //            System.out.println(MidiSystem.getMidiFileFormat(fd.getFiles()[0]));
    //        } catch (InvalidMidiDataException e) {
    //            e.printStackTrace();
    //        } catch (IOException e) {
    //            e.printStackTrace();
    //        }

    Score scoreToWrite = null;
    for (int i = 0; i < s.getSize(); i++) {
      scoreToWrite = new Score();
      scoreToWrite.add(s.getPart(i));
      scoreToWrite.setTempo(200);
      Write.midi(scoreToWrite, String.format(fd.getFile() + "%d.mid", i));

      Part part = s.getPart(i);
      for (int j = 0; j < part.getSize(); j++) {
        Phrase phrase = part.getPhrase(j);
        for (int ii = 0; ii < phrase.getSize(); ii++) {
          System.out.println(phrase.getNote(ii).getNote());
        }
      }
    }

    //            //keep track of the number of scores analysed
    //            scoreCount++;
    //            //reset melody length
    //            int tempLength = 0;
    //            // iterate through each note
    //            //find the highest and lowest notes
    //            Enumeration enum1 = s.getPartList().elements();
    //            while(enum1.hasMoreElements()){
    //                Part nextPt = (Part)enum1.nextElement();
    //                Enumeration enum2 =
    //                        nextPt.getPhraseList().elements();
    //                while(enum2.hasMoreElements()){
    //                    Phrase nextPhr =
    //                            (Phrase)enum2.nextElement();
    //                    Enumeration enum3 =
    //                            nextPhr.getNoteList().elements();
    //                    while(enum3.hasMoreElements()){
    //                        Note nextNote =
    //                                (Note)enum3.nextElement();
    //                        int pitch = nextNote.getPitch();
    //                        //check range
    //                        pitchRange(pitch);
    //                        double rv =
    //                                nextNote.getRhythmValue();
    //                        //check rhythmic values
    //                        rhythmRange(rv);
    //                        //check meldoy length
    //                        tempLength++;
    //                        //check direction
    //                        upOrDown(pitch);
    //                    }
    //                }
    //            }
    // update length extremes
    // musicLength(tempLength);

    //            //output the current stats
    //            System.out.print(PRE_TEXT);
    //            System.out.println("STATS after "+scoreCount+
    //                    " files. Last score called "+
    //                    s.getTitle());
    //            System.out.print(PRE_TEXT);
    //            System.out.println("Lowest note is "+lowNote);
    //            System.out.println("Highest note is "+highNote);
    //            System.out.println("---------------------------------");
    //            System.out.println("Shortest note is "+shortestRhythm);
    //            System.out.println("Longest note is "+longestRhythm);
    //            System.out.println("---------------------------------");
    //            System.out.println("Smallest score contains "+
    //                    shortLength+" notes");
    //            System.out.println("Largest score contains "+longLength+
    //                    " notes");
    //            System.out.println("---------------------------------");
    //            System.out.println("Upward movements were "+ascending);
    //            System.out.println("Downward movements were "+
    //                    descending);
    //            System.out.println("---------------------------------");
  }