Package jpianotrain.util

Examples of jpianotrain.util.UserConfiguration


public class ApplicationContext {
  private static final Logger log=Logger.getLogger(ApplicationContext.class);
 
  private ApplicationContext() {
    contextListener=new ArrayList<ApplicationContextListener>();
    UserConfiguration uc=UserConfiguration.getInstance();
    keyHintColor=uc.getColorProperty(COLOR_HINTS, Constants.COLOR_HINTS);
    keyWrongColor=uc.getColorProperty(COLOR_WRONG_KEY, Constants.COLOR_WRONG_KEY);
    showWrongKey=uc.getBooleanProperty(SHOW_WRONG_KEY, true);
    showHints=uc.getBooleanProperty(SHOW_HINTS, true);
  }
View Full Code Here


   * user configuration.
   *
   * @see UserConfiguration
   */
  protected void load() {
    UserConfiguration uc=UserConfiguration.getInstance();
    int i=uc.getIntProperty(RANDOM_TUNE_FACTORY_NOTE_COUNT, -1);
    if (i==-1) {
      return;
    }
    try {
      setBothHands(uc.getBooleanProperty(RANDOM_TUNE_FACTORY_BOTH_HANDS, false));
      setNoteCount(uc.getIntProperty(RANDOM_TUNE_FACTORY_NOTE_COUNT, 0));
      setUpperBoundBass(uc.getIntProperty(RANDOM_TUNE_FACTORY_UPPER_BASS, 0));
      setLowerBoundBass(uc.getIntProperty(RANDOM_TUNE_FACTORY_LOWER_BASS, 0));
      setUpperBoundTreble(uc.getIntProperty(RANDOM_TUNE_FACTORY_UPPER_TREBLE, 0));
      setLowerBoundTreble(uc.getIntProperty(RANDOM_TUNE_FACTORY_LOWER_TREBLE, 0));
      setScale(Scale.parse(uc.getProperty(RANDOM_TUNE_FACTORY_SCALE, null)));
    catch (Exception ex) {
      log.error("failed to load user configuration for random tune factory", ex);
      setBothHands(false);
      setNoteCount(0);
      setUpperBoundBass(0);
View Full Code Here

   * Stores all parameters in user configuration.
   *
   * @see UserConfiguration
   */
  protected void store() {
    UserConfiguration uc=UserConfiguration.getInstance();
    Scale s=getScale();
    if (s!=null) {
      uc.putProperty(RANDOM_TUNE_FACTORY_BOTH_HANDS,isBothHands());
      uc.putProperty(RANDOM_TUNE_FACTORY_UPPER_BASS,getUpperBoundBass());
      uc.putProperty(RANDOM_TUNE_FACTORY_LOWER_BASS,getLowerBoundBass());
      uc.putProperty(RANDOM_TUNE_FACTORY_UPPER_TREBLE,getUpperBoundTreble());
      uc.putProperty(RANDOM_TUNE_FACTORY_LOWER_TREBLE,getLowerBoundTreble());
      uc.putProperty(RANDOM_TUNE_FACTORY_SCALE,s.toString());
      uc.putProperty(RANDOM_TUNE_FACTORY_NOTE_COUNT, getNoteCount());
    }
  }
View Full Code Here

  /**
   * Init GUI like setting layout, adding panels
   * and components.
   */
  public void initGui() {
    UserConfiguration uc=UserConfiguration.getInstance();
    String lf=uc.getProperty(LOOK_AND_FEEL, null);
    if (lf!=null) {
      try {
        UIManager.setLookAndFeel(lf);
        SwingUtilities.updateComponentTreeUI(this);
      } catch (Exception ex) {
        log.error(ResourceFactory.getString(ERROR_LOOK_AND_FEEL), ex);
        ErrorHandler.handleError(ERROR_LOOK_AND_FEEL, lf);
      }
    }

    Rectangle bounds=uc.getRectProperty(WINDOW_BOUNDS,
        Constants.DEFAULT_BOUNDS);
    setBounds(bounds);
    setJMenuBar(initMenu());

    notationPanel=new NotationPanel();

    JPanel mainPanel=new JPanel();
    mainPanel.setLayout(new GridLayout(3,1));
    mainPanel.add(notationPanel);

    messagePanel=new JTextArea();
    messagePanel.setText("Initiated\n"+
      "Lesson Mode, both hands, Beginner\n"+
      "MIDI active, Input/Output recognized\n"+
      "Start with key press on your keyboard");
    messagePanel.setEditable(false);
    mainPanel.add(new JScrollPane(messagePanel));

    keyboardPanel=new JKeyBoard(Constants.KEYBOARD_OCTAVE_RANGE);
    ApplicationContext.getInstance().addListener(keyboardPanel);
    Dimension d=new Dimension(getSize());
    d.height=d.height/3;
    keyboardPanel.setPreferredSize(d);
    mainPanel.add(keyboardPanel);

    InfoPanel helpPanel=new InfoPanel();

    splitPanel=new JSplitPane(JSplitPane.VERTICAL_SPLIT,
      mainPanel,
      new JScrollPane(helpPanel));
    splitPanel.setOneTouchExpandable(true);

    if (uc.getIntProperty(INFO_PANEL_LOCATION, -1)!=-1) {
      log.debug("re-minimizing info panel");
      splitPanel.setDividerLocation(uc.getIntProperty(INFO_PANEL_LOCATION,0));
      splitPanel.setLastDividerLocation(uc.getIntProperty(INFO_PANEL_LAST_LOCATION, 0));
    }
    Container contentPane=getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(splitPanel, BorderLayout.CENTER);

View Full Code Here

      r.x-=i.left;
      r.y-=i.top;
    }

    TuneFactory.storeConfiguration();
    UserConfiguration uc=UserConfiguration.getInstance();
    log.debug("saving bounds: "+r);
    log.debug("insets "+getInsets());
    uc.putProperty(WINDOW_BOUNDS, r);
    uc.putProperty(LOOK_AND_FEEL, UIManager.getLookAndFeel().getClass().getName());
    log.debug("info panel minimized: "+(splitPanel.getDividerLocation()>=splitPanel.getMaximumDividerLocation()));
    uc.putProperty(INFO_PANEL_LOCATION, splitPanel.getDividerLocation());
    uc.putProperty(INFO_PANEL_LAST_LOCATION, splitPanel.getLastDividerLocation());
    uc.done();
  }
View Full Code Here

   * factories to be saved to user configuration. Normally
   * this is done, if the application is shutting down,
   * e.g. when main window is closing.
   */
  public static void storeConfiguration() {
    UserConfiguration uc=UserConfiguration.getInstance();
    storeRandomConfig(uc);
    storeMidiFileConfig(uc);
    storeLessonConfig(uc);
  }
View Full Code Here

  }

  @Override
  public void saveData() {
    boolean flag=false;
    UserConfiguration uc=UserConfiguration.getInstance();
    ApplicationContext ctx=ApplicationContext.getInstance();
    try {
      this.midiOutIndex=midiOutBox.getSelectedIndex();
      uc.putProperty(MIDI_OUT_DEVICE, midiOutIndex);
      MidiDevice.Info outInfo=(MidiDevice.Info)midiOutBox.getSelectedItem();
     
      this.metronomeIndex=metronomeOutBox.getSelectedIndex();
      uc.putProperty(MIDI_METRONOME_DEVICE, metronomeIndex);
      MidiDevice.Info metronomeInfo=null;
      if (metronomeIndex>0) {
        metronomeInfo=(MidiDevice.Info)metronomeOutBox.getSelectedItem();
      }
      this.keyInIndex=keyboardInBox.getSelectedIndex();
      uc.putProperty(KEYBOARD_IN_DEVICE, keyInIndex);
      MidiDevice.Info keyInfo=(MidiDevice.Info)keyboardInBox.getSelectedItem();
      MidiDevice metroDev=null;
      if (metronomeInfo!=null) {
        metroDev=MidiSystem.getMidiDevice(metronomeInfo);
        if (metroDev.getMaxReceivers()==0) {
View Full Code Here

    int c=info.length;
    MidiDevice dev;
    keyboardInBox.removeAllItems();
    metronomeOutBox.removeAllItems();
    midiOutBox.removeAllItems();
    UserConfiguration uc=UserConfiguration.getInstance();
    if (keyInIndex==-1) {
      keyInIndex=uc.getIntProperty(KEYBOARD_IN_DEVICE, -1);
    }
    if (metronomeIndex==-1) {
      metronomeIndex=uc.getIntProperty(MIDI_METRONOME_DEVICE, -1);
    }
    if (midiOutIndex==-1) {
      midiOutIndex=uc.getIntProperty(MIDI_OUT_DEVICE, -1);
    }
    try {
      metronomeOutBox.addItem(ResourceFactory.getString(LIST_ITEM_UNDEFINED));
      for (int i=0;i<c;i++) {
        dev=MidiSystem.getMidiDevice(info[i]);
View Full Code Here

    }
    ((SpinnerNumberModel)bankSpinner.getModel()).setMinimum(minBank);
    ((SpinnerNumberModel)bankSpinner.getModel()).setMaximum(maxBank);
   
    keyboardInBox.removeAllItems();
    UserConfiguration uc=UserConfiguration.getInstance();
    if (uc.getBooleanProperty(SYNTHESIZER_ENABLED, false)) {
      activateCheck.setSelected(true);
      enableSynthesizer(true);
    } else {
      activateCheck.setSelected(false);
      enableSynthesizer(false);
    }
    int bank=uc.getIntProperty(SYNTHESIZER_BANK, -1);
    if (bank!=-1) {
      bankSpinner.setValue(bank);
    }
    int instrument=uc.getIntProperty(SYNTHESIZER_INSTRUMENT, -1);
    if (instrument!=-1) {
      instrumentList.setSelectedIndex(instrument);
    }
    if (keyInIndex==-1) {
      keyInIndex=uc.getIntProperty(KEYBOARD_IN_DEVICE, -1);
    }
    try {
      MidiDevice dev;
      MidiDevice.Info[] info=MidiSystem.getMidiDeviceInfo();
      int c=info.length;
View Full Code Here

      synth.close();
    }
  }
 
  public void saveData() {
    UserConfiguration uc=UserConfiguration.getInstance();
    uc.putProperty(SYNTHESIZER_ENABLED, activateCheck.isSelected());
    uc.putProperty(SYNTHESIZER_BANK,
        ((SpinnerNumberModel)bankSpinner.getModel()).getNumber().intValue());
    uc.putProperty(SYNTHESIZER_INSTRUMENT, instrumentList.getSelectedIndex());
    ApplicationContext ctx=ApplicationContext.getInstance();
    if (synth.isOpen()) {
      synth.close();
    }
    boolean flag=false;
    try {
      this.keyInIndex=keyboardInBox.getSelectedIndex();
      uc.putProperty(KEYBOARD_IN_DEVICE, keyInIndex);
      MidiDevice.Info keyInfo=(MidiDevice.Info)keyboardInBox.getSelectedItem();
      MidiDevice keyDev=MidiSystem.getMidiDevice(keyInfo);
      if (keyDev.getMaxTransmitters()==0) {
        JOptionPane.showMessageDialog(ctx.getDefaultDialogOwner(),
            ResourceFactory.getString(MESSAGE_NO_TRANSMITTER),
View Full Code Here

TOP

Related Classes of jpianotrain.util.UserConfiguration

Copyright © 2018 www.massapicom. 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.