annotate java/src/uk/ac/qmul/eecs/ccmi/gui/ResourceFactory.java @ 1:e3935c01cde2 tip

moved license of PdPersistenceManager to the beginning of the file
author Fiore Martin <f.martin@qmul.ac.uk>
date Tue, 08 Jul 2014 19:52:03 +0100
parents 78b7fc5391a2
children
rev   line source
f@0 1 /*
f@0 2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
f@0 3
f@0 4 Copyright (C) 2002 Cay S. Horstmann (http://horstmann.com)
f@0 5 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
f@0 6
f@0 7 This program is free software: you can redistribute it and/or modify
f@0 8 it under the terms of the GNU General Public License as published by
f@0 9 the Free Software Foundation, either version 3 of the License, or
f@0 10 (at your option) any later version.
f@0 11
f@0 12 This program is distributed in the hope that it will be useful,
f@0 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
f@0 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f@0 15 GNU General Public License for more details.
f@0 16
f@0 17 You should have received a copy of the GNU General Public License
f@0 18 along with this program. If not, see <http://www.gnu.org/licenses/>.
f@0 19 */
f@0 20
f@0 21 package uk.ac.qmul.eecs.ccmi.gui;
f@0 22
f@0 23 import java.awt.event.ActionListener;
f@0 24 import java.beans.EventHandler;
f@0 25 import java.util.MissingResourceException;
f@0 26 import java.util.ResourceBundle;
f@0 27
f@0 28 import javax.swing.JMenu;
f@0 29 import javax.swing.JMenuItem;
f@0 30 import javax.swing.KeyStroke;
f@0 31
f@0 32 /**
f@0 33 * A factory class for swing components creation support.
f@0 34 *
f@0 35 * Components that are created via this class are, in turn created by {@code SpeechMenuFactory} methods.
f@0 36 * This class handles the labelling and other menu properties (such as accelerators)
f@0 37 * using the {@code ResourceBundle} passed as argument to the constructor.
f@0 38 */
f@0 39 class ResourceFactory{
f@0 40 public ResourceFactory(ResourceBundle bundle){
f@0 41 this.bundle = bundle;
f@0 42 }
f@0 43
f@0 44 public JMenu createMenu(String prefix){
f@0 45 String text = bundle.getString(prefix + ".text");
f@0 46 JMenu menu = SpeechMenuFactory.getMenu(text);
f@0 47 try{
f@0 48 String mnemonic = bundle.getString(prefix + ".mnemonic");
f@0 49 menu.setMnemonic(mnemonic.charAt(0));
f@0 50 }catch (MissingResourceException exception){
f@0 51 // ok not to set mnemonic
f@0 52 }
f@0 53
f@0 54 try{
f@0 55 String tooltip = bundle.getString(prefix + ".tooltip");
f@0 56 menu.setToolTipText(tooltip);
f@0 57 }
f@0 58 catch (MissingResourceException exception){
f@0 59 // ok not to set tooltip
f@0 60 }
f@0 61 return menu;
f@0 62 }
f@0 63
f@0 64 public JMenuItem createMenuItem(String prefix,
f@0 65 Object target, String methodName){
f@0 66 return createMenuItem(prefix,
f@0 67 (ActionListener) EventHandler.create(
f@0 68 ActionListener.class, target, methodName));
f@0 69 }
f@0 70
f@0 71 public JMenuItem createMenuItem(String prefix,
f@0 72 ActionListener listener){
f@0 73 String text = bundle.getString(prefix + ".text");
f@0 74 JMenuItem menuItem = SpeechMenuFactory.getMenuItem(text);
f@0 75 return configure(menuItem, prefix, listener);
f@0 76 }
f@0 77
f@0 78 public JMenuItem createCheckBoxMenuItem(String prefix,
f@0 79 ActionListener listener){
f@0 80 String text = bundle.getString(prefix + ".text");
f@0 81 JMenuItem menuItem = SpeechMenuFactory.getJCheckBoxMenuItem(text);
f@0 82 return configure(menuItem, prefix, listener);
f@0 83 }
f@0 84
f@0 85 private JMenuItem configure(JMenuItem menuItem,
f@0 86 String prefix, ActionListener listener){
f@0 87 menuItem.addActionListener(listener);
f@0 88 try{
f@0 89 String mnemonic = bundle.getString(prefix + ".mnemonic");
f@0 90 menuItem.setMnemonic(mnemonic.charAt(0));
f@0 91 }catch (MissingResourceException exception){
f@0 92 // ok not to set mnemonic
f@0 93 }
f@0 94
f@0 95 try{
f@0 96 String accelerator = bundle.getString(prefix + ".accelerator");
f@0 97 menuItem.setAccelerator(KeyStroke.getKeyStroke(accelerator));
f@0 98 }catch (MissingResourceException exception){
f@0 99 // ok not to set accelerator
f@0 100 }
f@0 101
f@0 102 try{
f@0 103 String tooltip = bundle.getString(prefix + ".tooltip");
f@0 104 menuItem.setToolTipText(tooltip);
f@0 105 }catch (MissingResourceException exception){
f@0 106 // ok not to set tooltip
f@0 107 }
f@0 108 return menuItem;
f@0 109 }
f@0 110
f@0 111 private ResourceBundle bundle;
f@0 112 }