Coverage Report - org.jtheque.core.managers.view.impl.actions.JThequeAction
 
Classes in this File Line Coverage Branch Coverage Complexity
JThequeAction
0 %
0/23
0 %
0/4
1.286
 
 1  
 package org.jtheque.core.managers.view.impl.actions;
 2  
 
 3  
 /*
 4  
  * This file is part of JTheque.
 5  
  *
 6  
  * JTheque is free software: you can redistribute it and/or modify
 7  
  * it under the terms of the GNU General Public License as published by
 8  
  * the Free Software Foundation, either version 3 of the License.
 9  
  *
 10  
  * JTheque is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  *
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 
 19  
 import org.jtheque.core.managers.Managers;
 20  
 import org.jtheque.core.managers.language.ILanguageManager;
 21  
 import org.jtheque.core.managers.language.Internationalizable;
 22  
 import org.jtheque.utils.collections.ArrayUtils;
 23  
 
 24  
 import javax.swing.AbstractAction;
 25  
 import javax.swing.Action;
 26  
 import javax.swing.ImageIcon;
 27  
 
 28  
 /**
 29  
  * An action of JTheque.
 30  
  *
 31  
  * @author Baptiste Wicht
 32  
  */
 33  
 public abstract class JThequeAction extends AbstractAction implements Internationalizable {
 34  
     private final String key;
 35  
     private Object[] replaces;
 36  
 
 37  0
     private static final Object[] EMPTY_REPLACES = {};
 38  
 
 39  
     /**
 40  
      * Construct a new JThequeAction.
 41  
      *
 42  
      * @param key The internationalization key.
 43  
      */
 44  
     protected JThequeAction(String key) {
 45  0
         this(key, EMPTY_REPLACES);
 46  0
     }
 47  
 
 48  
     /**
 49  
      * Construct a new JThequeAction.
 50  
      *
 51  
      * @param key      The internationalization key.
 52  
      * @param replaces The replacements on the message resource.
 53  
      */
 54  
     protected JThequeAction(String key, Object... replaces) {
 55  0
         super();
 56  
 
 57  0
         Managers.getManager(ILanguageManager.class).addInternationalizable(this);
 58  
 
 59  0
         this.key = key;
 60  
 
 61  0
         if (ArrayUtils.isEmpty(replaces)) {
 62  0
             setTextKey(key);
 63  
         } else {
 64  0
             this.replaces = ArrayUtils.copyOf(replaces);
 65  
 
 66  0
             setTextKey(key, replaces);
 67  
         }
 68  0
     }
 69  
 
 70  
     /**
 71  
      * Set the text key.
 72  
      *
 73  
      * @param key The internationalization key.
 74  
      */
 75  
     final void setTextKey(String key) {
 76  0
         setText(Managers.getManager(ILanguageManager.class).getMessage(key));
 77  0
     }
 78  
 
 79  
     /**
 80  
      * Set the text key.
 81  
      *
 82  
      * @param key      The internationalization key.
 83  
      * @param replaces The replacements on the message resource.
 84  
      */
 85  
     final void setTextKey(String key, Object... replaces) {
 86  0
         setText(Managers.getManager(ILanguageManager.class).getMessage(key, replaces));
 87  0
     }
 88  
 
 89  
     /**
 90  
      * Set the text of the action.
 91  
      *
 92  
      * @param text The text.
 93  
      */
 94  
     public final void setText(String text) {
 95  0
         putValue(Action.NAME, text);
 96  0
     }
 97  
 
 98  
     /**
 99  
      * Set the icon of te action.
 100  
      *
 101  
      * @param icon The icon.
 102  
      */
 103  
     public final void setIcon(ImageIcon icon) {
 104  0
         putValue(Action.SMALL_ICON, icon);
 105  0
     }
 106  
 
 107  
     @Override
 108  
     public final void refreshText() {
 109  0
         if (replaces == null) {
 110  0
             setTextKey(key);
 111  
         } else {
 112  0
             setTextKey(key, replaces);
 113  
         }
 114  0
     }
 115  
 }