Пример #1
0
  public ScaleSelectionPanel() {
    this.setLayout(new BorderLayout());

    initScaleFileSelector();

    JButton fileButton = new JButton("...");
    fileButton.addActionListener(
        (ActionEvent e) -> {
          List<File> rValue = FileChooserManager.getDefault().showOpenDialog(FILE_CHOOSER_ID, null);

          if (!rValue.isEmpty()) {
            File f = rValue.get(0);

            if (!f.exists()) {
              return;
            }

            scale = Scale.loadScale(f);

            updateDisplay();
            fireChangeEvent();
          }
        });

    fileNameField.setEditable(false);

    this.add(fileNameField, BorderLayout.CENTER);
    this.add(fileButton, BorderLayout.EAST);

    popup.add(
        new AbstractAction("Reset (12TET)") {

          @Override
          public void actionPerformed(ActionEvent e) {
            setScale(Scale.get12TET());
            fireChangeEvent();
          }
        });

    fileNameField.addMouseListener(
        new MouseAdapter() {

          @Override
          public void mousePressed(MouseEvent evt) {
            if (UiUtilities.isRightMouseButton(evt)) {

              Component c = evt.getComponent();

              popup.show(c, evt.getX(), evt.getY());
            }
          }
        });
  }
Пример #2
0
  private void initScaleFileSelector() {
    final FileChooserManager fcm = FileChooserManager.getDefault();
    if (fcm.isDialogDefined(FILE_CHOOSER_ID)) {
      return;
    }

    fcm.setDialogTitle(FILE_CHOOSER_ID, BlueSystem.getString("pianoRoll.selectScalaFile"));
    fcm.addFilter(FILE_CHOOSER_ID, new ExtensionFilter("Scala File (*.scl)", "*.scl"));

    // SET DEFAULT DIR
    String fileName = BlueSystem.getUserConfigurationDirectory();
    fileName += File.separator + "scl";

    File defaultDir = new File(fileName);

    if (defaultDir.exists() && defaultDir.isDirectory()) {
      fcm.setSelectedFile(FILE_CHOOSER_ID, defaultDir);
    }
  }