• R/O
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

OmegaT の背景に画像を表示します。


Commit MetaInfo

Revision23 (tree)
Time2014-05-11 23:58:56
Authoryu-tang

Log Message

リファクタリング:ConfigSet クラス

Change Summary

Incremental Difference

--- trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/config/ConfigSet.java (revision 22)
+++ trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/config/ConfigSet.java (revision 23)
@@ -24,11 +24,13 @@
2424 import java.io.IOException;
2525 import java.io.Writer;
2626 import java.net.URL;
27+import java.util.AbstractMap;
2728 import java.util.ArrayList;
2829 import java.util.Collections;
2930 import java.util.Comparator;
3031 import java.util.List;
3132 import java.util.Map;
33+import java.util.Set;
3234 import java.util.TreeSet;
3335 import jp.sourceforge.users.yutang.omegat.plugin.moenizer.MoeUtil;
3436 import org.omegat.util.Log;
@@ -40,18 +42,47 @@
4042 */
4143 public class ConfigSet {
4244
45+ private final String CONF_GENERAL = "__general__";
46+
4347 private final File file;
4448 private ConfigObject config = null;
45- private TreeSet<Config> configSet = null;
49+ private final TreeSet<Map.Entry<String, ConfigObject>> configs
50+ = new TreeSet<Map.Entry<String, ConfigObject>>
51+ (new Comparator<Map.Entry<String, ConfigObject>>() {
52+ @Override
53+ public int compare(Map.Entry<String, ConfigObject> conf1, Map.Entry<String, ConfigObject> conf2) {
54+ int index1 = (Integer) conf1.getValue().get(Config.KEY_INDEX);
55+ int index2 = (Integer) conf2.getValue().get(Config.KEY_INDEX);
56+ return index1 - index2;
57+ }
58+ });
59+;
4660
4761 public ConfigSet(File file) throws IOException {
4862 this.file = file;
4963 if (file.isFile()) {
5064 config = new ConfigSlurper().parse(file.toURI().toURL());
51- configSet = getConfigSet(config);
65+ buildProviderConfigs(config);
5266 }
5367 }
5468
69+ public Set<Map.Entry<String, ConfigObject>> getConfigs() {
70+ return configs;
71+ }
72+
73+ public Map.Entry<String, ConfigObject> getCurrentConfig() {
74+ for (Map.Entry<String, ConfigObject> entry : configs) {
75+ boolean enabled = (Boolean) entry.getValue().get("enabled");
76+ if (enabled) {
77+ return entry;
78+ }
79+ }
80+
81+ Map.Entry<String, ConfigObject> defaultConfig = getDefaultConfig();
82+ boolean enabled = (Boolean) defaultConfig.getValue().get("enabled");
83+ return enabled ? defaultConfig : null;
84+ }
85+
5586 public void save() throws IOException {
5687 Writer writer = null;
5788 try {
@@ -66,45 +97,21 @@
6697 }
6798 }
6899
69- private TreeSet<Config> getConfigSet(ConfigObject config) {
70- TreeSet<Config> ts = new TreeSet<Config>(new Comparator<Config>() {
71-
72- @Override
73- public int compare(Config o1, Config o2) {
74- return o1.getIndex() - o2.getIndex();
75- }
76- });
77-
100+ private void buildProviderConfigs(ConfigObject config) {
78101 for (Object entry : config.entrySet()) {
79102 Map.Entry<String, ConfigObject> e = (Map.Entry<String, ConfigObject>) entry;
80103 String name = e.getKey();
81104 ConfigObject conf = e.getValue();
82- String providerName = (String) conf.get(Config.KEY_PROVIDER_TYPE);
83- ts.add(createConfig(name, conf, Config.ProviderType.valueOf(providerName)));
105+ if (!name.equals(CONF_GENERAL)) {
106+ configs.add(e);
107+ }
84108 }
85-
86- return ts;
87109 }
88110
89- private Config createConfig(String name, ConfigObject conf,
90- Config.ProviderType provider) {
91- switch(provider) {
92- case Color:
93- return new ColorConfig(name, conf);
94- case SimpleImage:
95- return new SimpleImageConfig(name, conf);
96- default:
97- throw new AssertionError(provider.name());
98- }
99- }
111+ public static Map.Entry<String, ConfigObject> getDefaultConfig() {
112+ boolean enabled = false;
113+ String image = "";
100114
101- public static Config getDefaultConfig() {
102- String name = "__default__";
103- int index = -1;
104- int opacity = 50;
105- boolean enabled = false;
106- String image = null;
107-
108115 // search image files
109116 File parentDir = MoeUtil.getMoeConfigDir();
110117 try {
@@ -117,7 +124,13 @@
117124 Log.log(ex.getMessage());
118125 }
119126
120- return new SimpleImageConfig(name, index, enabled, opacity, image);
127+ ConfigObject conf = new ConfigObject();
128+ conf.put("index", -1);
129+ conf.put("enabled", enabled);
130+ conf.put("opacity", 50);
131+ conf.put("image", image);
132+
133+ return new AbstractMap.SimpleEntry<String, ConfigObject>("__default__",conf);
121134 }
122135
123136 private static List<String> getImagePaths(File parentDir) throws IOException {