• 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

Revision36 (tree)
Time2014-05-20 02:00:35
Authoryu-tang

Log Message

背景処理用のパッケージ effect/ を追加し、処理を imageLoader から ThemeChanger に移動

Change Summary

Incremental Difference

--- trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/MoeConfig.java (revision 35)
+++ trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/MoeConfig.java (revision 36)
@@ -32,6 +32,7 @@
3232 import java.util.Map;
3333 import java.util.Set;
3434 import java.util.TreeSet;
35+import jp.sourceforge.users.yutang.omegat.plugin.moenizer.effect.Effect;
3536 import org.omegat.util.Log;
3637
3738 /**
@@ -43,9 +44,6 @@
4344
4445 static final String FILE_NAME = "config.groovy";
4546
46- public enum ProviderType {
47- Color, SimpleImage
48- }
4947 private final String KEY_INDEX = "index";
5048 private final String KEY_ISACTIVE = "isActive";
5149
@@ -151,9 +149,7 @@
151149 }
152150
153151 ConfigObject effect = new ConfigObject();
154- effect.put("type", ProviderType.SimpleImage.name());
155- effect.put("target", "mainWindow");
156- effect.put("opacity", 0.5f); // 0.0f (Transparent) <--> 1.0f (Opaque)
152+ effect.put("type", Effect.Type.SimpleImage.name());
157153 effect.put("image", image);
158154
159155 List<ConfigObject> effects = new ArrayList<ConfigObject>(1);
--- trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/Moenizer.java (revision 35)
+++ trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/Moenizer.java (revision 36)
@@ -16,7 +16,6 @@
1616
1717 package jp.sourceforge.users.yutang.omegat.plugin.moenizer;
1818
19-import groovy.util.ConfigObject;
2019 import java.awt.image.BufferedImage;
2120 import java.util.concurrent.TimeUnit;
2221 import javax.swing.SwingUtilities;
@@ -68,16 +67,13 @@
6867 try {
6968 CoreEvents.registerProjectChangeListener(this);
7069
71- ui = null;
7270 config = new MoeConfig(MoeUtil.getMoeConfigFile());
73- imageLoader = ImageLoader.getInstance(config.getCurrentConfig());
7471 // この時点ではまだウィンドウがインスタンス化されていないので、
7572 // ウィンドウに対する処理は少し待つ。
7673
77- (new SlideShow()).execute();
78-
7974 ui = MoeUI.getInstance();
80- themeChanger = new ThemeChanger(config.getCurrentConfig());
75+ themeChanger = new ThemeChanger(ui);
76+ themeChanger.setTheme(config.getCurrentConfig());
8177
8278 // この時点でコンポーネントの透過設定をしても反映されない(タイミング?)。
8379 // Workaround として、invokeLater でキューに突っ込んで、後で処理する。
@@ -85,7 +81,6 @@
8581 @Override
8682 public void run() {
8783 CoreEvents.unregisterApplicationEventListener(Moenizer.this);
88- ui.transparent();
8984 themeChanger.apply();
9085 }
9186 });
@@ -111,7 +106,7 @@
111106 @Override
112107 public void run() {
113108 CoreEvents.unregisterProjectChangeListener(Moenizer.this);
114- ui.transparentEditor();
109+ ui.transparentEditor(); //@@TODO これは effect の方から指定をもらわないと
115110 }
116111 });
117112
--- trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/ThemeChanger.java (revision 35)
+++ trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/ThemeChanger.java (revision 36)
@@ -17,6 +17,11 @@
1717 package jp.sourceforge.users.yutang.omegat.plugin.moenizer;
1818
1919 import groovy.util.ConfigObject;
20+import java.util.List;
21+import java.util.Map;
22+import jp.sourceforge.users.yutang.omegat.plugin.moenizer.effect.Effect;
23+import jp.sourceforge.users.yutang.omegat.plugin.moenizer.effect.IEffect;
24+import org.omegat.util.Log;
2025
2126 /**
2227 *
@@ -24,21 +29,41 @@
2429 */
2530 public class ThemeChanger {
2631
27- private ConfigObject config;
32+ private MoeUI model = null;
33+ private ConfigObject theme = null;
2834
29- public ThemeChanger(ConfigObject config) {
30- this.config = config;
35+ public ThemeChanger(MoeUI ui) {
36+ this.model = ui;
3137 }
3238
39+ public void setTheme(ConfigObject theme) {
40+ this.theme = theme;
41+
42+ // check constraints
43+ //@@TODO 整合性チェック。たとえば、mainWindow 対象の処理が複数ある、など
44+ }
45+
3346 public void apply() {
34- if (config == null) {
47+ // no theme, no effects
48+ if (theme == null || !theme.containsKey("effects")) { //@@TODO literal to const
3549 return;
3650 }
3751
38-
39-
40-
41-
42-
52+ // get effect list (ArrayList)
53+ List<ConfigObject> effects = (List<ConfigObject>) theme.get("effects"); //@@TODO literal to const
54+ if (effects.isEmpty()) {
55+ return;
56+ }
57+
58+ // apply effects
59+ for (Map conf: effects) {
60+ String type = (String) conf.get("type");
61+ try {
62+ IEffect effect = Effect.create(Effect.Type.valueOf(type), conf);
63+ effect.invoke(model);
64+ } catch (Exception ex) {
65+ Log.log("Error on ThemeChanger#apply(): " + ex.getMessage());
66+ }
67+ }
4368 }
4469 }
--- trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/effect/IEffect.java (nonexistent)
+++ trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/effect/IEffect.java (revision 36)
@@ -0,0 +1,29 @@
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+}
--- trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/effect/Effect.java (nonexistent)
+++ trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/effect/Effect.java (revision 36)
@@ -0,0 +1,47 @@
1+/**
2+ * ************************************************************************
3+ * Moenizer - Allow to set background image for OmegaT.
4+ *
5+ * Copyright (C) 2014 Yu Tang 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. http://www.omegat.org/
9+ *
10+ * License: GNU GPL version 3 or (at your option) any later version.
11+ *
12+ * You should have received a copy of the GNU General Public License along with
13+ * this program. If not, see <http://www.gnu.org/licenses/>.
14+ *************************************************************************
15+ */
16+package jp.sourceforge.users.yutang.omegat.plugin.moenizer.effect;
17+
18+import groovy.util.ConfigObject;
19+import java.lang.reflect.Constructor;
20+import java.util.Map;
21+
22+/**
23+ * static method only
24+ *
25+ * @author Yu-Tang
26+ */
27+public class Effect {
28+
29+ private Effect() {
30+ // prevent instantiation
31+ }
32+
33+ public enum Type {
34+ SimpleImage
35+ }
36+
37+ public static IEffect create(Type type, Map conf) throws Exception {
38+ final String CLASS_NAME = Effect.class.getPackage().getName() + "." + type.name();
39+ Class<? extends IEffect> clazz = (Class<? extends IEffect>) Class.forName(CLASS_NAME);
40+ Class<?>[] types = {Map.class};
41+ Constructor<? extends IEffect> constructor = clazz.getConstructor(types);
42+ Object[] args = {conf};
43+ IEffect newInstance = constructor.newInstance(args);
44+ return newInstance;
45+ }
46+
47+}
--- trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/effect/SimpleImage.java (nonexistent)
+++ trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/effect/SimpleImage.java (revision 36)
@@ -0,0 +1,112 @@
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 groovy.util.ConfigObject;
20+import java.io.File;
21+import java.io.IOException;
22+import java.net.MalformedURLException;
23+import java.net.URL;
24+import java.util.ArrayList;
25+import java.util.List;
26+import java.util.Map;
27+import java.util.logging.Level;
28+import java.util.logging.Logger;
29+import javax.imageio.ImageIO;
30+import jp.sourceforge.users.yutang.omegat.plugin.moenizer.MoeUI;
31+import org.omegat.util.Log;
32+
33+/**
34+ *
35+ * @author Yu-Tang
36+ */
37+public class SimpleImage implements IEffect {
38+
39+ private final String KEY_TARGET = "target";
40+ private final String KEY_OPACITY = "opacity";
41+ private final String KEY_IMAGE = "image";
42+ private final String KEY_EXCEPTIONS = "exceptions";
43+
44+ private String target = "mainWindow";
45+ private float opacity = 0.5f;
46+ private String image = "";
47+ private List<String> exceptions = new ArrayList<String>();
48+
49+ public SimpleImage(Map config) {
50+ if (config.containsKey(KEY_TARGET)) {
51+ target = (String) config.get(KEY_TARGET);
52+ if (!target.equals("mainWindow")) {
53+ //@@TODO 他のtargetにも対応
54+ throw new IllegalArgumentException(
55+ "target argument '" + target + "' is not supported.");
56+ }
57+ }
58+
59+ if (config.containsKey(KEY_OPACITY)) {
60+ opacity = (Float) config.get(KEY_OPACITY);
61+ }
62+
63+ if (config.containsKey(KEY_IMAGE)) {
64+ image = (String) config.get(KEY_IMAGE);
65+ }
66+
67+ if (config.containsKey(KEY_EXCEPTIONS)) {
68+ exceptions = (List<String>) config.get(KEY_EXCEPTIONS);
69+ }
70+ }
71+
72+ @Override
73+ public void invoke(MoeUI ui) {
74+ if (image.isEmpty()) {
75+ return;
76+ }
77+
78+ if (exceptions.contains("menubar")) {
79+ ui.setMakeTransparentMenubar(false);
80+ }
81+
82+ if (exceptions.contains("statusbar")) {
83+ ui.setMakeTransparentStatusbar(false);
84+ }
85+
86+ if (exceptions.contains("buttonpanel")) {
87+ ui.setMakeTransparentButtonPanel(false);
88+ }
89+
90+ if (exceptions.contains("panetitlebar")) {
91+ ui.setMakeTransparentPaneTitlebar(false);
92+ }
93+
94+ String lcased = image.toLowerCase();
95+ try {
96+ if (lcased.startsWith("http://") || lcased.startsWith("https://")) {
97+ ui.setBackground(ImageIO.read(new URL(image)));
98+ } else {
99+ ui.setBackground(ImageIO.read(new File(image)));
100+ }
101+ } catch (MalformedURLException ex) {
102+ Log.log(ex.getMessage());
103+ } catch (IOException ex) {
104+ Log.log(ex.getMessage());
105+ }
106+
107+ ui.transparent();
108+ //@@TODO transparentEditor
109+ //@@TODO opacity
110+ }
111+
112+}