| 1 | |
package org.jtheque.core.managers.view.impl.components; |
| 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.core.managers.view.ViewComponent; |
| 23 | |
import org.jtheque.utils.collections.ArrayUtils; |
| 24 | |
|
| 25 | |
import javax.swing.JLabel; |
| 26 | |
import java.awt.Color; |
| 27 | |
import java.awt.Font; |
| 28 | |
import java.awt.Graphics; |
| 29 | |
import java.awt.Graphics2D; |
| 30 | |
import java.awt.RenderingHints; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
public final class JThequeI18nLabel extends JLabel implements Internationalizable, ViewComponent { |
| 38 | |
private String textKey; |
| 39 | |
private Object[] replaces; |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
public JThequeI18nLabel(String textKey, Object... replaces) { |
| 48 | 0 | super(); |
| 49 | |
|
| 50 | 0 | setTextKey(textKey, replaces); |
| 51 | |
|
| 52 | 0 | Managers.getManager(ILanguageManager.class).addInternationalizable(this); |
| 53 | 0 | } |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
public JThequeI18nLabel(String key, Font font) { |
| 62 | 0 | this(key); |
| 63 | |
|
| 64 | 0 | setFont(font); |
| 65 | 0 | } |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
public JThequeI18nLabel(String key, Font font, Color foreground) { |
| 75 | 0 | this(key); |
| 76 | |
|
| 77 | 0 | setFont(font); |
| 78 | 0 | setForeground(foreground); |
| 79 | 0 | } |
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
public void setTextKey(String textKey, Object... replaces) { |
| 88 | 0 | this.textKey = textKey; |
| 89 | 0 | this.replaces = ArrayUtils.copyOf(replaces); |
| 90 | |
|
| 91 | 0 | refreshText(); |
| 92 | 0 | } |
| 93 | |
|
| 94 | |
@Override |
| 95 | |
public void refreshText() { |
| 96 | 0 | if (ArrayUtils.isEmpty(replaces)) { |
| 97 | 0 | setText(Managers.getManager(ILanguageManager.class).getMessage(textKey)); |
| 98 | |
} else { |
| 99 | 0 | setText(Managers.getManager(ILanguageManager.class).getMessage(textKey, replaces)); |
| 100 | |
} |
| 101 | 0 | } |
| 102 | |
|
| 103 | |
@Override |
| 104 | |
public void paint(Graphics g) { |
| 105 | 0 | ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
| 106 | |
|
| 107 | 0 | super.paint(g); |
| 108 | 0 | } |
| 109 | |
|
| 110 | |
@Override |
| 111 | |
public Object getImpl(){ |
| 112 | 0 | return this; |
| 113 | |
} |
| 114 | |
} |