• R/O
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythongamewindowsbathyscaphephpguic翻訳omegattwitterframeworktestbtronarduinovb.net計画中(planning stage)directxpreviewerゲームエンジンdom

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


Commit MetaInfo

Revisão82 (tree)
Hora2017-05-31 17:56:13
Autoryu-tang

Mensagem de Log

Separate a plugin loader

Mudança Sumário

Diff

--- trunk/manifest.mf (revision 81)
+++ trunk/manifest.mf (revision 82)
@@ -6,5 +6,5 @@
66 Permissions: all-permissions
77 Class-Path: lib/lib-mnemonics.jar
88 OmegaT-Plugins:
9- jp.sourceforge.users.yutang.omegat.plugin.moenizer.Moenizer
9+ jp.sourceforge.users.yutang.omegat.plugin.moenizer.PluginLoader
1010 OmegaT-Plugin: true
--- trunk/src/jp/osdn/users/yutang/omegat/plugin/moenizer/Moenizer.java (revision 81)
+++ trunk/src/jp/osdn/users/yutang/omegat/plugin/moenizer/Moenizer.java (revision 82)
@@ -16,122 +16,23 @@
1616
1717 package jp.osdn.users.yutang.omegat.plugin.moenizer;
1818
19-import groovy.util.ConfigObject;
20-import java.util.Set;
21-import javax.swing.SwingUtilities;
22-import jp.osdn.users.yutang.omegat.plugin.moenizer.gui.ConfigEditDialog;
23-import org.omegat.core.Core;
24-import org.omegat.core.CoreEvents;
25-import org.omegat.core.events.IApplicationEventListener;
26-import org.omegat.util.Log;
27-
2819 /**
2920 * allow to set background image
3021 *
3122 * @author Yu-Tang
3223 */
33-public class Moenizer implements IApplicationEventListener {
24+public class Moenizer {
3425
35- private static boolean instantiated = false;
36-
3726 private MoeUI ui;
3827 private MoeConfig config;
3928 private ThemeChanger themeChanger;
4029 private MenuHandler menu;
4130
42- public static void loadPlugins() {
43- try {
44- // Not initialize in console mode
45- if (instantiated) {
46- throw new RuntimeException("Moenizer plugin could be instantiated only once.");
47- } else if (!isSupportedVLDockingFramework()) {
48- throw new RuntimeException("Moenizer plugin is not compatibled "
49- + "with current VLDocking framework library.\n"
50- + "Please update to OmegaT 3.1.2u1 or later.");
51- } else if (isRunningJavaWebStart()) {
52- // Just log it, no error.
53- Log.log("Moenizer plugin is not working with Java Web Start.");
54- } else {
55- CoreEvents.registerApplicationEventListener(new Moenizer());
56- instantiated = true;
57- }
58- } catch (Throwable ex) {
59- String msg = ex.getMessage();
60- Log.logErrorRB("LD_ERROR", msg);
61- Core.pluginLoadingError(msg);
62- }
63- }
64-
65- private static boolean isSupportedVLDockingFramework() {
66- return !"2.1.4".equals(com.vlsolutions.swing.docking.DockingDesktop
67- .getDockingFrameworkVersion());
31+ public Moenizer(MoeUI ui, MoeConfig config, ThemeChanger themeChanger, MenuHandler menu) {
32+ this.ui = ui;
33+ this.config = config;
34+ this.themeChanger = themeChanger;
35+ this.menu = menu;
6836 }
6937
70- public static void unloadPlugins() {
71- // do nothing
72- }
73-
74- @Override
75- public void onApplicationStartup() {
76- try {
77- config = new MoeConfig(MoeUtil.getMoeConfigFile());
78- ui = MoeUI.getInstance();
79- /*
80- menu = new MenuHandler(new Runnable() {
81- @Override
82- public void run() {
83- showSettingDialog();
84- }
85- });
86- */
87- themeChanger = new ThemeChanger(ui);
88- themeChanger.setTheme(config.getCurrentConfig());
89-
90- // この時点でコンポーネントの透過設定をしても反映されない(タイミング?)。
91- // Workaround として、invokeLater でキューに突っ込んで、後で処理する。
92- SwingUtilities.invokeLater(new Runnable() {
93- @Override
94- public void run() {
95- CoreEvents.unregisterApplicationEventListener(Moenizer.this);
96- themeChanger.apply();
97- }
98- });
99- //CoreEvents.unregisterApplicationEventListener(this); // ここで発行すると、スレッドエラーになるので注意
100- } catch (Exception e) {
101- Log.log("Error raised at " + this.getClass().getCanonicalName() + ".onApplicationStartup()\n" + e);
102- e.printStackTrace();
103- }
104- }
105-
106- @Override
107- public void onApplicationShutdown() {
108- // not used.
109- }
110-
111- private void showSettingDialog() {
112- //@@TODO 前処理 -- 自動保存中断など
113- Set<ConfigObject> sortedConfigs = config.getSortedConfigs();
114- //MoeConfigEditDialog dialog = new MoeConfigEditDialog(sortedConfigs, themeChanger);
115- ConfigEditDialog dialog = new ConfigEditDialog(sortedConfigs, themeChanger);
116- //dialog.setSize(400, 200); //@@TODO remain size
117- //dialog.setLocationRelativeTo(null); // positioning at the center of the screen
118- dialog.setVisible(true);
119- onConfigUpdate();
120- //@@TODO 後処理 -- 自動保存再開など
121- }
122-
123- private void onConfigUpdate() {
124- //Log.log("-- onConfigUpdate()"); //@@TODO 要・実装
125- }
126-
127- private static boolean isRunningJavaWebStart() {
128- try {
129- Class.forName("javax.jnlp.ServiceManager");
130- return true;
131- } catch (ClassNotFoundException ex) {
132- // ignore
133- }
134- return false;
135- }
136-
13738 }
--- trunk/src/jp/osdn/users/yutang/omegat/plugin/moenizer/PluginLoader.java (nonexistent)
+++ trunk/src/jp/osdn/users/yutang/omegat/plugin/moenizer/PluginLoader.java (revision 82)
@@ -0,0 +1,118 @@
1+/**************************************************************************
2+ Moenizer - Allow to set background image for OmegaT.
3+
4+ Copyright (C) 2017 Yu Tang
5+ Home page: http://osdn.jp/users/yu-tang/
6+ Support center: http://osdn.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.osdn.users.yutang.omegat.plugin.moenizer;
18+
19+import javax.swing.SwingUtilities;
20+import org.omegat.core.Core;
21+import org.omegat.core.CoreEvents;
22+import org.omegat.core.events.IApplicationEventListener;
23+import org.omegat.util.Log;
24+
25+/**
26+ * loading and unloading a plugin
27+ *
28+ * @author Yu-Tang
29+ */
30+public class PluginLoader implements IApplicationEventListener {
31+
32+ private static boolean instantiated = false;
33+
34+ private static Moenizer moenizer;
35+
36+ public static void loadPlugins() {
37+ try {
38+ // Not initialize in console mode
39+ if (instantiated) {
40+ throw new RuntimeException("Moenizer plugin could be instantiated only once.");
41+ } else if (!isSupportedVLDockingFramework()) {
42+ throw new RuntimeException("Moenizer plugin is not compatibled "
43+ + "with current VLDocking framework library.\n"
44+ + "Please update to OmegaT 3.1.2u1 or later.");
45+ } else if (isRunningJavaWebStart()) {
46+ // Just log it, no error.
47+ Log.log("Moenizer plugin is not working with Java Web Start.");
48+ } else {
49+ CoreEvents.registerApplicationEventListener(new PluginLoader());
50+ instantiated = true;
51+ }
52+ } catch (Throwable ex) {
53+ String msg = ex.getMessage();
54+ Log.logErrorRB("LD_ERROR", msg);
55+ Core.pluginLoadingError(msg);
56+ }
57+ }
58+
59+ public static void unloadPlugins() {
60+ // do nothing
61+ }
62+
63+ private static boolean isSupportedVLDockingFramework() {
64+ return !"2.1.4".equals(com.vlsolutions.swing.docking.DockingDesktop
65+ .getDockingFrameworkVersion());
66+ }
67+
68+ @Override
69+ public void onApplicationStartup() {
70+ try {
71+ MoeConfig config = new MoeConfig(MoeUtil.getMoeConfigFile());
72+ MoeUI ui = MoeUI.getInstance();
73+ /*
74+ menu = new MenuHandler(new Runnable() {
75+ @Override
76+ public void run() {
77+ showSettingDialog();
78+ }
79+ });
80+ */
81+ ThemeChanger themeChanger = new ThemeChanger(ui);
82+ themeChanger.setTheme(config.getCurrentConfig());
83+
84+ MenuHandler menu = null;
85+
86+ // この時点でコンポーネントの透過設定をしても反映されない(タイミング?)。
87+ // Workaround として、invokeLater でキューに突っ込んで、後で処理する。
88+ SwingUtilities.invokeLater(new Runnable() {
89+ @Override
90+ public void run() {
91+ moenizer = new Moenizer(ui, config, themeChanger, menu);
92+ CoreEvents.unregisterApplicationEventListener(PluginLoader.this);
93+ themeChanger.apply();
94+ }
95+ });
96+ //CoreEvents.unregisterApplicationEventListener(this); // ここで発行すると、スレッドエラーになるので注意
97+ } catch (Exception e) {
98+ Log.log("Error raised at " + this.getClass().getCanonicalName() + ".onApplicationStartup()\n" + e);
99+ e.printStackTrace();
100+ }
101+ }
102+
103+ @Override
104+ public void onApplicationShutdown() {
105+ // not used.
106+ }
107+
108+ private static boolean isRunningJavaWebStart() {
109+ try {
110+ Class.forName("javax.jnlp.ServiceManager");
111+ return true;
112+ } catch (ClassNotFoundException ex) {
113+ // ignore
114+ }
115+ return false;
116+ }
117+
118+}