OmegaT の背景に画像を表示します。
refactoring: Effect クラスを Abstract に変更して具象クラスの継承元をそちらに変更し、インターフェイス IEffect を削除
| @@ -20,7 +20,6 @@ | ||
| 20 | 20 | import java.util.List; |
| 21 | 21 | import java.util.Map; |
| 22 | 22 | import jp.sourceforge.users.yutang.omegat.plugin.moenizer.effect.Effect; |
| 23 | -import jp.sourceforge.users.yutang.omegat.plugin.moenizer.effect.IEffect; | |
| 24 | 23 | import org.omegat.util.Log; |
| 25 | 24 | |
| 26 | 25 | /** |
| @@ -61,7 +60,7 @@ | ||
| 61 | 60 | |
| 62 | 61 | try { |
| 63 | 62 | Effect.Type type = (Effect.Type) conf.get("type"); |
| 64 | - IEffect effect = Effect.create(type, conf); | |
| 63 | + Effect effect = Effect.create(type, conf); | |
| 65 | 64 | effect.invoke(model); |
| 66 | 65 | } catch (Exception ex) { |
| 67 | 66 | ex.printStackTrace(); |
| @@ -1,29 +0,0 @@ | ||
| 1 | -/************************************************************************** | |
| 2 | - Moenizer - Allow to set background image for OmegaT. | |
| 3 | - | |
| 4 | - Copyright (C) 2014 Yu Tang | |
| 5 | - Home page: http://sourceforge.jp/users/yu-tang/ | |
| 6 | - Support center: http://sourceforge.jp/users/yu-tang/pf/Moenizer/ | |
| 7 | - | |
| 8 | - This file is part of plugin for OmegaT. | |
| 9 | - http://www.omegat.org/ | |
| 10 | - | |
| 11 | - License: GNU GPL version 3 or (at your option) any later version. | |
| 12 | - | |
| 13 | - You should have received a copy of the GNU General Public License | |
| 14 | - along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 15 | - **************************************************************************/ | |
| 16 | - | |
| 17 | -package jp.sourceforge.users.yutang.omegat.plugin.moenizer.effect; | |
| 18 | - | |
| 19 | -import jp.sourceforge.users.yutang.omegat.plugin.moenizer.MoeUI; | |
| 20 | - | |
| 21 | -/** | |
| 22 | - * | |
| 23 | - * @author Yu-Tang | |
| 24 | - */ | |
| 25 | -public interface IEffect { | |
| 26 | - | |
| 27 | - public void invoke(MoeUI ui); | |
| 28 | - | |
| 29 | -} |
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | |
| 18 | 18 | import java.lang.reflect.Constructor; |
| 19 | 19 | import java.util.Map; |
| 20 | +import jp.sourceforge.users.yutang.omegat.plugin.moenizer.MoeUI; | |
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * static method only |
| @@ -23,24 +24,25 @@ | ||
| 23 | 24 | * |
| 24 | 25 | * @author Yu-Tang |
| 25 | 26 | */ |
| 26 | -public class Effect { | |
| 27 | +public abstract class Effect { | |
| 27 | 28 | |
| 28 | - private Effect() { | |
| 29 | - // prevent instantiation | |
| 30 | - } | |
| 31 | - | |
| 32 | 29 | public enum Type { |
| 33 | 30 | BasicEffect |
| 34 | 31 | } |
| 35 | 32 | |
| 36 | - public static IEffect create(Type type, Map conf) throws Exception { | |
| 33 | + public static Effect create(Type type, Map conf) throws Exception { | |
| 37 | 34 | final String CLASS_NAME = Effect.class.getPackage().getName() + "." + type.name(); |
| 38 | - Class<? extends IEffect> clazz = (Class<? extends IEffect>) Class.forName(CLASS_NAME); | |
| 35 | + Class<? extends Effect> clazz = (Class<? extends Effect>) Class.forName(CLASS_NAME); | |
| 39 | 36 | Class<?>[] types = {Map.class}; |
| 40 | - Constructor<? extends IEffect> constructor = clazz.getConstructor(types); | |
| 37 | + Constructor<? extends Effect> constructor = clazz.getConstructor(types); | |
| 41 | 38 | Object[] args = {conf}; |
| 42 | - IEffect newInstance = constructor.newInstance(args); | |
| 39 | + Effect newInstance = constructor.newInstance(args); | |
| 43 | 40 | return newInstance; |
| 44 | 41 | } |
| 45 | 42 | |
| 43 | + protected <T> T get(String key, Map<String, Object> config, T valueDefault) { | |
| 44 | + return config.containsKey(key) ? (T) config.get(key) : valueDefault; | |
| 45 | + } | |
| 46 | + | |
| 47 | + public abstract void invoke(MoeUI ui); | |
| 46 | 48 | } |
| @@ -33,7 +33,7 @@ | ||
| 33 | 33 | * |
| 34 | 34 | * @author Yu-Tang |
| 35 | 35 | */ |
| 36 | -public class BasicEffect implements IEffect { | |
| 36 | +public class BasicEffect extends Effect { | |
| 37 | 37 | |
| 38 | 38 | private final String KEY_TARGET = "target"; |
| 39 | 39 | private final String KEY_OPACITY = "opacity"; |
| @@ -56,10 +56,6 @@ | ||
| 56 | 56 | exclude = get(KEY_EXCLUDE, config, exclude); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - private <T> T get(String key, Map<String, Object> config, T valueDefault) { | |
| 60 | - return config.containsKey(key) ? (T) config.get(key) : valueDefault; | |
| 61 | - } | |
| 62 | - | |
| 63 | 59 | @Override |
| 64 | 60 | public void invoke(MoeUI ui) { |
| 65 | 61 | if (image.isEmpty()) { |