OmegaT の背景に画像を表示します。
設定ファイルで文字列による指定になっている箇所を Enum 値による指定に変更(Parts と Type)
| @@ -28,11 +28,14 @@ | ||
| 28 | 28 | import java.util.ArrayList; |
| 29 | 29 | import java.util.Collections; |
| 30 | 30 | import java.util.Comparator; |
| 31 | +import java.util.HashMap; | |
| 31 | 32 | import java.util.List; |
| 32 | 33 | import java.util.Map; |
| 33 | 34 | import java.util.Set; |
| 34 | 35 | import java.util.TreeSet; |
| 36 | +import jp.sourceforge.users.yutang.omegat.plugin.moenizer.MoeUI.Parts; | |
| 35 | 37 | import jp.sourceforge.users.yutang.omegat.plugin.moenizer.effect.Effect; |
| 38 | +import jp.sourceforge.users.yutang.omegat.plugin.moenizer.effect.Effect.Type; | |
| 36 | 39 | import org.omegat.util.Log; |
| 37 | 40 | |
| 38 | 41 | /** |
| @@ -63,12 +66,29 @@ | ||
| 63 | 66 | public MoeConfig(File file) throws IOException { |
| 64 | 67 | this.file = file; |
| 65 | 68 | if (file.isFile()) { |
| 66 | - //@@TODO setBinding で文字列の指定を追い出す | |
| 67 | - config = new ConfigSlurper().parse(file.toURI().toURL()); | |
| 69 | + config = createBindedConfigSlurper().parse(file.toURI().toURL()); | |
| 68 | 70 | addAll(sortedConfigs, config); |
| 69 | 71 | } |
| 70 | 72 | } |
| 71 | 73 | |
| 74 | + private ConfigSlurper createBindedConfigSlurper() { | |
| 75 | + ConfigSlurper configSlurper = new ConfigSlurper(); | |
| 76 | + Map map = new HashMap<String, Parts>(); | |
| 77 | + | |
| 78 | + // MoeUI.Parts enum | |
| 79 | + for (Parts part: Parts.values()) { | |
| 80 | + map.put(part.name(), part); | |
| 81 | + } | |
| 82 | + | |
| 83 | + // Effect.Type enum | |
| 84 | + for (Type type: Type.values()) { | |
| 85 | + map.put(type.name(), type); | |
| 86 | + } | |
| 87 | + | |
| 88 | + configSlurper.setBinding(map); | |
| 89 | + return configSlurper; | |
| 90 | + } | |
| 91 | + | |
| 72 | 92 | public Object get(String key) { |
| 73 | 93 | if (config != null) { |
| 74 | 94 | Map flatten = config.flatten(); |
| @@ -150,7 +170,7 @@ | ||
| 150 | 170 | } |
| 151 | 171 | |
| 152 | 172 | ConfigObject effect = new ConfigObject(); |
| 153 | - effect.put("type", Effect.Type.BasicEffect.name()); | |
| 173 | + effect.put("type", Effect.Type.BasicEffect); | |
| 154 | 174 | effect.put("image", image); |
| 155 | 175 | |
| 156 | 176 | List<ConfigObject> effects = new ArrayList<ConfigObject>(1); |
| @@ -41,6 +41,7 @@ | ||
| 41 | 41 | |
| 42 | 42 | // check constraints |
| 43 | 43 | //@@TODO 整合性チェック。たとえば、mainWindow 対象の処理が複数ある、など |
| 44 | + //@@TODO MainWindow の透過除外パーツに、後続指定のペインを含める | |
| 44 | 45 | } |
| 45 | 46 | |
| 46 | 47 | public void apply() { |
| @@ -48,7 +49,7 @@ | ||
| 48 | 49 | if (theme == null || !theme.containsKey("effects")) { //@@TODO literal to const |
| 49 | 50 | return; |
| 50 | 51 | } |
| 51 | - | |
| 52 | + | |
| 52 | 53 | // get effect list (ArrayList) |
| 53 | 54 | List<ConfigObject> effects = (List<ConfigObject>) theme.get("effects"); //@@TODO literal to const |
| 54 | 55 | if (effects.isEmpty()) { |
| @@ -57,9 +58,10 @@ | ||
| 57 | 58 | |
| 58 | 59 | // apply effects |
| 59 | 60 | for (Map conf: effects) { |
| 60 | - String type = (String) conf.get("type"); | |
| 61 | + | |
| 61 | 62 | try { |
| 62 | - IEffect effect = Effect.create(Effect.Type.valueOf(type), conf); | |
| 63 | + Effect.Type type = (Effect.Type) conf.get("type"); | |
| 64 | + IEffect effect = Effect.create(type, conf); | |
| 63 | 65 | effect.invoke(model); |
| 64 | 66 | } catch (Exception ex) { |
| 65 | 67 | ex.printStackTrace(); |
| @@ -43,17 +43,11 @@ | ||
| 43 | 43 | private Parts target = Parts.MainWindow; |
| 44 | 44 | private float opacity = 0.5f; |
| 45 | 45 | private String image = ""; |
| 46 | - private List<String> exclude = new ArrayList<String>(); | |
| 46 | + private List<Parts> exclude = new ArrayList<Parts>(); | |
| 47 | 47 | |
| 48 | 48 | public BasicEffect(Map config) { |
| 49 | 49 | if (config.containsKey(KEY_TARGET)) { |
| 50 | - //@@TODO 設定自体を Enum で受け取れるように | |
| 51 | - String targetName = (String) config.get(KEY_TARGET); | |
| 52 | - try { | |
| 53 | - target = Parts.valueOf(targetName); | |
| 54 | - } catch (IllegalArgumentException ex) { | |
| 55 | - Log.log("warning: target name '" + targetName + "' is not found in Parts enum."); | |
| 56 | - } | |
| 50 | + target = (Parts) config.get(KEY_TARGET); | |
| 57 | 51 | } |
| 58 | 52 | |
| 59 | 53 | if (config.containsKey(KEY_OPACITY)) { |
| @@ -65,7 +59,7 @@ | ||
| 65 | 59 | } |
| 66 | 60 | |
| 67 | 61 | if (config.containsKey(KEY_EXCLUDE)) { |
| 68 | - exclude = (List<String>) config.get(KEY_EXCLUDE); | |
| 62 | + exclude = (List<Parts>) config.get(KEY_EXCLUDE); | |
| 69 | 63 | } |
| 70 | 64 | } |
| 71 | 65 |
| @@ -77,7 +71,7 @@ | ||
| 77 | 71 | |
| 78 | 72 | EnumSet<Parts> excludeParts = EnumSet.noneOf(Parts.class); |
| 79 | 73 | for (Parts part: EnumSet.allOf(Parts.class)) { |
| 80 | - if (exclude.contains(part.name())) { | |
| 74 | + if (exclude.contains(part)) { | |
| 81 | 75 | excludeParts.add(part); |
| 82 | 76 | } |
| 83 | 77 | } |