view src/uk/ac/qmul/eecs/depic/daw/gui/actions/MenuAction.java @ 0:3074a84ef81e

first import
author Fiore Martin <f.martin@qmul.ac.uk>
date Wed, 26 Aug 2015 16:16:53 +0100
parents
children c0412c81d274
line wrap: on
line source
/*  
 Cross-Modal DAW Prototype - Prototype of a simple Cross-Modal Digital Audio Workstation.

 Copyright (C) 2015  Queen Mary University of London (http://depic.eecs.qmul.ac.uk/)
	
 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.  If not, see <http://www.gnu.org/licenses/>.
*/
package uk.ac.qmul.eecs.depic.daw.gui.actions;

import java.awt.event.KeyEvent;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import javax.swing.AbstractAction;
import javax.swing.KeyStroke;


abstract class MenuAction extends AbstractAction {
	private static final long serialVersionUID = 1L;

	public MenuAction(String resourceName){
		ResourceBundle bundle = ResourceBundle.getBundle(MenuAction.class.getName());
		/* set the menu label */
		String name = bundle.getString(resourceName+".text");
		putValue(AbstractAction.NAME,name);
		/* try and set the accelerator and mnemonic */ 
		try{
			String accelerator = bundle.getString(resourceName+".accelerator");
			putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(accelerator));
		}catch(MissingResourceException mre){
			// do nothing, accelerator just won't be set
		}
		
		try{
			String mnemonic = bundle.getString(resourceName+".mnemonic");
			putValue(AbstractAction.MNEMONIC_KEY,KeyEvent.getExtendedKeyCodeForChar(mnemonic.charAt(0)));
		}catch(MissingResourceException mre){
			// do nothing, mnmonic just won't be set
		}
	}
	
	public void setText(String resourceName){
		ResourceBundle bundle = ResourceBundle.getBundle(MenuAction.class.getName());
		String name = bundle.getString(resourceName+".text");
		putValue(AbstractAction.NAME,name);
	}
	
}