| 1 | |
package org.jtheque.core.managers.view.impl.actions; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 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 | |
|
| 30 | |
|
| 31 | |
|
| 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 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
protected JThequeAction(String key) { |
| 45 | 0 | this(key, EMPTY_REPLACES); |
| 46 | 0 | } |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 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 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
final void setTextKey(String key) { |
| 76 | 0 | setText(Managers.getManager(ILanguageManager.class).getMessage(key)); |
| 77 | 0 | } |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
final void setTextKey(String key, Object... replaces) { |
| 86 | 0 | setText(Managers.getManager(ILanguageManager.class).getMessage(key, replaces)); |
| 87 | 0 | } |
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
public final void setText(String text) { |
| 95 | 0 | putValue(Action.NAME, text); |
| 96 | 0 | } |
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 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 | |
} |