• 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

Revision19 (tree)
Time2014-05-10 21:06:13
Authoryu-tang

Log Message

Config の具象クラスを追加

Change Summary

Incremental Difference

--- trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/config/ConfigSet.java (revision 18)
+++ trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/config/ConfigSet.java (revision 19)
@@ -23,7 +23,15 @@
2323 import java.io.FileWriter;
2424 import java.io.IOException;
2525 import java.io.Writer;
26-import java.util.Properties;
26+import java.net.URL;
27+import java.util.ArrayList;
28+import java.util.Collections;
29+import java.util.Comparator;
30+import java.util.List;
31+import java.util.Map;
32+import java.util.TreeSet;
33+import jp.sourceforge.users.yutang.omegat.plugin.moenizer.MoeUtil;
34+import org.omegat.util.Log;
2735
2836 /**
2937 * Manage config collection
@@ -34,20 +42,13 @@
3442
3543 private final File file;
3644 private ConfigObject config = null;
45+ private TreeSet<Config> configSet = null;
3746
38- public static Properties getDefaultProperties() {
39- Properties p = new Properties();
40-
41- // set default property here
42- // p.setProperty("key", "value");
43-
44- return p;
45- }
46-
4747 public ConfigSet(File file) throws IOException {
4848 this.file = file;
4949 if (file.isFile()) {
5050 config = new ConfigSlurper().parse(file.toURI().toURL());
51+ configSet = getConfigSet(config);
5152 }
5253 }
5354
@@ -65,4 +66,80 @@
6566 }
6667 }
6768
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+
78+ for (Object entry : config.entrySet()) {
79+ Map.Entry<String, ConfigObject> e = (Map.Entry<String, ConfigObject>) entry;
80+ String name = e.getKey();
81+ ConfigObject conf = e.getValue();
82+ String providerName = (String) conf.get(Config.KEY_PROVIDER_TYPE);
83+ ts.add(createConfig(name, conf, Config.ProviderType.valueOf(providerName)));
84+ }
85+
86+ return ts;
87+ }
88+
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+ }
100+
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+
108+ // search image files
109+ File parentDir = MoeUtil.getMoeConfigDir();
110+ try {
111+ List<String> imagePaths = getImagePaths(parentDir);
112+ if (!imagePaths.isEmpty()) {
113+ enabled = true;
114+ image = imagePaths.get(0);
115+ }
116+ } catch (IOException ex) {
117+ Log.log(ex.getMessage());
118+ }
119+
120+ return new SimpleImageConfig(name, index, enabled, opacity, image);
121+ }
122+
123+ private static List<String> getImagePaths(File parentDir) throws IOException {
124+ ArrayList<String> array = new ArrayList<String>();
125+ if (parentDir.isDirectory()) {
126+ for (File f: parentDir.listFiles()) {
127+ if (f.isFile()) {
128+ if (MoeUtil.isImage(f)) {
129+ array.add(f.getCanonicalPath());
130+ }else if (MoeUtil.isURLShortcut(f)) {
131+ URL url = MoeUtil.getURL(f);
132+ array.add(url.toExternalForm());
133+ }
134+ }
135+ }
136+ }
137+
138+ if (!array.isEmpty()) {
139+ Collections.sort(array);
140+ }
141+
142+ return array;
143+ }
144+
68145 }
--- trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/config/SimpleImageConfig.java (nonexistent)
+++ trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/config/SimpleImageConfig.java (revision 19)
@@ -0,0 +1,57 @@
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.config;
18+
19+import groovy.util.ConfigObject;
20+
21+/**
22+ *
23+ * @author Yu-Tang
24+ */
25+public class SimpleImageConfig extends Config {
26+
27+ private final int opacity;
28+ private final String image;
29+
30+ public SimpleImageConfig(String name, ConfigObject conf) {
31+ this(name, (Integer) conf.get(Config.KEY_INDEX),
32+ (Boolean) conf.get(Config.KEY_ENABLED),
33+ (Integer) conf.get(Config.KEY_OPACITY),
34+ (String) conf.get(Config.KEY_IMAGE));
35+ }
36+
37+ public SimpleImageConfig(String name, int index, boolean enabled,
38+ int opacity, String image) {
39+ super(name, index, enabled);
40+ this.opacity = opacity;
41+ this.image = image;
42+ }
43+
44+ @Override
45+ ProviderType getProviderType() {
46+ return Config.ProviderType.SimpleImage;
47+ }
48+
49+ public int getOpacity() {
50+ return opacity;
51+ }
52+
53+ public String getImage() {
54+ return image;
55+ }
56+
57+}
--- trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/config/ColorConfig.java (nonexistent)
+++ trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/config/ColorConfig.java (revision 19)
@@ -0,0 +1,51 @@
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.config;
18+
19+import groovy.util.ConfigObject;
20+import java.awt.Color;
21+
22+/**
23+ *
24+ * @author Yu-Tang
25+ */
26+public class ColorConfig extends Config {
27+
28+ private final Color color;
29+
30+ public ColorConfig(String name, ConfigObject conf) {
31+ this(name, (Integer) conf.get(Config.KEY_INDEX),
32+ (Boolean) conf.get(Config.KEY_ENABLED),
33+ (Integer) conf.get(Config.KEY_RGB));
34+ }
35+
36+ public ColorConfig(String name, int index, boolean enabled,
37+ int rgb) {
38+ super(name, index, enabled);
39+ this.color = new Color(rgb);
40+ }
41+
42+ @Override
43+ ProviderType getProviderType() {
44+ return Config.ProviderType.Color;
45+ }
46+
47+ public Color getColor() {
48+ return color;
49+ }
50+
51+}
--- trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/config/Config.java (revision 18)
+++ trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/config/Config.java (revision 19)
@@ -23,6 +23,18 @@
2323 */
2424 public abstract class Config {
2525
26+ // common
27+ public static final String KEY_INDEX = "index";
28+ public static final String KEY_ENABLED = "enabled";
29+ public static final String KEY_PROVIDER_TYPE = "providerType";
30+
31+ // Color
32+ public static final String KEY_RGB = "rgb";
33+
34+ // SimpleImage
35+ public static final String KEY_OPACITY = "opacity";
36+ public static final String KEY_IMAGE = "image";
37+
2638 enum ProviderType {
2739 Color, SimpleImage
2840 }