Ejemplo n.º 1
0
 public void saveUnsaved() throws SaveAbortedException {
   if (!saved) {
     int option = 0;
     if (loadedFile == null)
       option =
           JOptionPane.showConfirmDialog(
               this,
               new JLabel("Save changes to UNTITLED?"),
               "Warning",
               JOptionPane.YES_NO_CANCEL_OPTION,
               JOptionPane.WARNING_MESSAGE);
     else
       option =
           JOptionPane.showConfirmDialog(
               this,
               new JLabel("Save changes to " + loadedFile.getName() + "?"),
               "Warning",
               JOptionPane.YES_NO_CANCEL_OPTION,
               JOptionPane.WARNING_MESSAGE);
     if (option == JOptionPane.YES_OPTION) {
       if (loadedFile == null) // SAVE NEW FILE
       {
         if (nameTF.getText().equals("")) {
           JOptionPane.showMessageDialog(
               this,
               new JLabel("Please type in the Scale Name"),
               "Warning",
               JOptionPane.WARNING_MESSAGE);
           throw new SaveAbortedException();
         }
         fileChooser.setFileFilter(filter);
         int option2 = fileChooser.showSaveDialog(this);
         if (option2 == JFileChooser.APPROVE_OPTION) {
           File target = fileChooser.getSelectedFile();
           try {
             PrintStream stream = new PrintStream(new FileOutputStream(target), true);
             save(stream);
             stream.close();
           } catch (Exception ex) {
             JOptionPane.showMessageDialog(
                 this,
                 new JLabel("Error: " + ex.getMessage()),
                 "Error",
                 JOptionPane.ERROR_MESSAGE);
           }
         } else throw new SaveAbortedException();
         ;
       } else // save LOADED FILE
       {
         try {
           PrintStream stream = new PrintStream(new FileOutputStream(loadedFile), true);
           save(stream);
           stream.close();
         } catch (Exception ex) {
           JOptionPane.showMessageDialog(
               this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
         }
       }
     } else if (option == JOptionPane.CANCEL_OPTION) throw new SaveAbortedException();
     ;
   }
 }
  public boolean initialize(String[] args) {
    if (m_initialized) {
      return false;
    }

    if (args != null && args.length > 0 && args[0] != null) {
      String temp = args[0].trim();
      if (temp.length() > 0) {
        settings.settingsFileName = temp;
      }
    }

    if (settings.load()) {
      console.writeLine("Settings successfully loaded from file: " + settings.settingsFileName);
    } else {
      console.writeLine("Failed to load settings from file: " + settings.settingsFileName);

      if (settings.settingsFileName != null
          && !SettingsManager.defaultSettingsFileName.equalsIgnoreCase(settings.settingsFileName)) {
        boolean loaded = false;

        while (!loaded) {
          int choice =
              JOptionPane.showConfirmDialog(
                  null,
                  "Unable to load settings from custom settings file. Use alternate settings file?\nNote that when the program is closed, this settings file will be generated if it does not exist.",
                  "Settings Loading Failed",
                  JOptionPane.YES_NO_CANCEL_OPTION);
          if (choice == JOptionPane.YES_OPTION) {
            String newSettingsFileName =
                JOptionPane.showInputDialog(
                    null, "Enter a settings file name:", SettingsManager.defaultSettingsFileName);
            if (newSettingsFileName != null) {
              settings.settingsFileName = newSettingsFileName;
              loaded = settings.load();

              if (loaded) {
                console.writeLine(
                    "Settings successfully loaded from file: " + settings.settingsFileName);
              }
            } else {
              break;
            }
          } else {
            break;
          }
        }
      }
    }

    if (!pluginManager.initialize(paletteEditorWindow.getFrame())) {
      JOptionPane.showMessageDialog(
          paletteEditorWindow.getFrame(),
          "Failed to initialize plugin manager!",
          "Initialization Failed",
          JOptionPane.ERROR_MESSAGE);

      return false;
    }

    if (settings.autoLoadPlugins) {
      pluginManager.loadPlugins();
    }

    m_initialized = true;

    boolean error = false;

    console.addTarget(paletteEditorWindow);

    if (!paletteEditorWindow.initialize()) {
      JOptionPane.showMessageDialog(
          paletteEditorWindow.getFrame(),
          "Failed to initialize palette editor window!",
          "Palette Editor Init Failed",
          JOptionPane.ERROR_MESSAGE);

      return false;
    }

    if (!error) {
      console.writeLine("Palette Editor initialized successfully!");
    }

    VersionChecker.checkVersion(false);

    return true;
  }
Ejemplo n.º 3
0
  public void actionPerformed(ActionEvent e) {
    JButton b = (JButton) e.getSource();
    if (b.getText() == "PLAY") {
      if (scoreP != null) scoreP.playScale(sp.getScale(), tempoP.getValue());
    } else if (b.getText() == "New") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      sp.notes.removeAllElements();
      sp.repaint();
      nameTF.setText("");
      loadedFile = null;
    } else if (b.getText() == "Save") {
      if (nameTF.getText().equals("")) {
        JOptionPane.showMessageDialog(
            this,
            new JLabel("Please type in the Scale Name"),
            "Warning",
            JOptionPane.WARNING_MESSAGE);
        return;
      }
      fileChooser.setFileFilter(filter);
      int option = fileChooser.showSaveDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        File target = fileChooser.getSelectedFile();
        if (target.getName().indexOf(".scl") == -1) target = new File(target.getPath() + ".scl");
        try {
          PrintStream stream = new PrintStream(new FileOutputStream(target), true);
          save(stream);
          stream.close();
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
        }
      }
    } else if (b.getText() == "Load") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      fileChooser.setFileFilter(filter);
      int option = fileChooser.showOpenDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        loadedFile = fileChooser.getSelectedFile();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        ScaleParser handler = new ScaleParser(false);
        try {
          SAXParser parser = factory.newSAXParser();
          parser.parse(loadedFile, handler);
          // System.out.println("success");
        } catch (Exception ex) {
          // System.out.println("no!!!!!! exception: "+e);
          // System.out.println(ex.getMessage());
          ex.printStackTrace();
        }
        // -----now :P:P---------------
        System.out.println("name: " + handler.getName());
        nameTF.setText(handler.getName());
        sp.notes.removeAllElements();
        int[] scale = handler.getScale();
        for (int i = 0; i < scale.length; i++) {
          sp.addNote(scale[i]);
        }
        sp.repaint();
      } else loadedFile = null;
    }
  }