Package jpianotrain.gui.action

Source Code of jpianotrain.gui.action.CreateStaffAction

/* License see bottom */
package jpianotrain.gui.action;

import java.awt.event.ActionEvent;

import javax.swing.JOptionPane;

import jpianotrain.ApplicationContext;
import jpianotrain.staff.Tune;
import jpianotrain.staff.TuneFactory;

import jpianotrain.util.ResourceFactory;
import static jpianotrain.util.ResourceKeys.*;

/**
* Action to initiate the staff according to
* the active mode.
*
* @since 0
* @author Alexander Methke
*/
public class CreateStaffAction extends AbstractAction {
  public static interface TuneReceiver {
    void setTune(Tune t);
  }

  public CreateStaffAction(TuneReceiver rec) {
    super(ACTION_CREATE_STAFF);
    tuneReceiver=rec;
  }

  public void actionPerformed(ActionEvent e) {
    switch(ApplicationContext.getInstance().getMode()) {
      case MIDI_FILES: {
        createForMidiFiles();
      } break;
      case RANDOM_NOTES: {
        createForRandomNotes();
      } break;
      case LESSONS: {
        createForLessons();
      } break;
    }
  }

  private void createForMidiFiles() {
    JOptionPane.showMessageDialog(ApplicationContext.getInstance().getDefaultDialogOwner(),
      ResourceFactory.getString(MESSAGE_OPERATION_NOT_SUPPORTED));
  }

  private void createForRandomNotes() {
    TuneFactory tf=TuneFactory.getRandomFactory();
    if (tf.getScale()==null) {
      JOptionPane.showMessageDialog(ApplicationContext.getInstance().getDefaultDialogOwner(),
        ResourceFactory.getString(MESSAGE_TUNE_FACTORY_BLANK),
        ResourceFactory.getString(TITLE_ERROR),
        JOptionPane.ERROR_MESSAGE);
    } else {
      tuneReceiver.setTune(tf.create());
    }
  }

  private void createForLessons() {
    JOptionPane.showMessageDialog(ApplicationContext.getInstance().getDefaultDialogOwner(),
      ResourceFactory.getString(MESSAGE_OPERATION_NOT_SUPPORTED));
  }

  private TuneReceiver tuneReceiver;
}
/*
    Copyright (C) 2008  Alexander Methke

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program (gplv3.txt).
*/
TOP

Related Classes of jpianotrain.gui.action.CreateStaffAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.