• R/O
  • SSH
  • HTTPS

コミット

よく使われているワード(クリックで追加)

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

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


コミットメタ情報

リビジョン53 (tree)
日時2014-05-25 19:08:26
作者yu-tang

ログメッセージ

エディターに2つあるモード(インスタントスタートと翻訳文書)を透過的に管理する仕組みを導入

変更サマリ

差分

--- trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/MoeConfig.java (revision 52)
+++ trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/MoeConfig.java (revision 53)
@@ -76,7 +76,7 @@
7676 Map map = new HashMap<String, Parts>();
7777
7878 // MoeUI.Parts enum
79- for (Parts part: Parts.values()) {
79+ for (Parts part: Parts.configullables()) {
8080 map.put(part.name(), part);
8181 }
8282
--- trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/MoeUI.java (revision 52)
+++ trunk/src/jp/sourceforge/users/yutang/omegat/plugin/moenizer/MoeUI.java (revision 53)
@@ -30,6 +30,7 @@
3030 import java.awt.Graphics;
3131 import java.awt.SystemColor;
3232 import java.awt.image.BufferedImage;
33+import java.util.ArrayList;
3334 import java.util.EnumMap;
3435 import java.util.EnumSet;
3536 import java.util.Map;
@@ -82,7 +83,17 @@
8283 MenuBar, StatusBar, ButtonPanel, PaneTitleBar,
8384 // Built-in panes
8485 EDITOR, MATCHES, GLOSSARY, NOTES, COMMENTS, MACHINE_TRANSLATE,
85- DICTIONARY, MULTIPLE_TRANS
86+ DICTIONARY, MULTIPLE_TRANS,
87+ // INSTANT_START (Another view of EDITOR)
88+ INSTANT_START;
89+
90+ public static Parts[] configullables() {
91+ Parts[] values = Parts.values();
92+ int length = values.length - 1; // leave INSTANT_START out
93+ Parts[] ret = new Parts[length];
94+ System.arraycopy(values, 0, ret, 0, length);
95+ return ret;
96+ }
8697 }
8798
8899 static {
@@ -114,18 +125,13 @@
114125 UIThreadsUtil.mustBeSwingThread();
115126
116127 if (target == Parts.MainWindow) {
117- MoeRootPaneUI ui;
118- if (uis.containsKey(target)) {
119- ui = (MoeRootPaneUI) uis.get(target);
120- } else {
121- ui = new MoeRootPaneUI();
122- rootPane.setUI(ui);
123- }
124- ui.setBackgroundImage(image);
125- uis.put(target, ui);
128+ getRootPaneUI().setBackgroundImage(image);
126129
127130 } else if (target.compareTo(Parts.EDITOR) >= 0) {
128131 getTextPaneUI(target).setBackgroundImage(image);
132+ if (target == Parts.EDITOR) {
133+ getTextPaneUI(Parts.INSTANT_START).setBackgroundImage(image);
134+ }
129135 }
130136 }
131137
@@ -133,18 +139,13 @@
133139 UIThreadsUtil.mustBeSwingThread();
134140
135141 if (target == Parts.MainWindow) {
136- MoeRootPaneUI ui;
137- if (uis.containsKey(target)) {
138- ui = (MoeRootPaneUI) uis.get(target);
139- } else {
140- ui = new MoeRootPaneUI();
141- rootPane.setUI(ui);
142- }
143- ui.setBackgroundColor(color);
144- uis.put(target, ui);
142+ getRootPaneUI().setBackgroundColor(color);
145143
146144 } else if (target.compareTo(Parts.EDITOR) >= 0) {
147145 getTextPaneUI(target).setBackgroundColor(color);
146+ if (target == Parts.EDITOR) {
147+ getTextPaneUI(Parts.INSTANT_START).setBackgroundColor(color);
148+ }
148149 }
149150 }
150151
@@ -152,15 +153,7 @@
152153 UIThreadsUtil.mustBeSwingThread();
153154
154155 if (target == Parts.MainWindow) {
155- MoeRootPaneUI ui;
156- if (uis.containsKey(target)) {
157- ui = (MoeRootPaneUI) uis.get(target);
158- } else {
159- ui = new MoeRootPaneUI();
160- rootPane.setUI(ui);
161- }
162- ui.setOpacity(opacity);
163- uis.put(target, ui);
156+ getRootPaneUI().setOpacity(opacity);
164157
165158 } else {
166159 // noop
@@ -186,7 +179,7 @@
186179
187180 case EDITOR:
188181 UIThreadsUtil.mustBeSwingThread();
189- transparentInstantStart(desktop);
182+ removeInstantStartBgColor();
190183
191184 // エディター(インスタントスタートではない方) ペインに個別に
192185 // 背景を設定するためには、結局プロジェクトのロード時に現在の
@@ -194,16 +187,19 @@
194187 // この行が実行される時点では、インスタントスタートと編集画面の
195188 // どちらのモードか不明なので、いったん編集画面の設定を試みて、
196189 // 失敗したらプロジェクトのロード時に再試行するクロージャを投げる。
197- final JEditorPane editor = getJEditorPaneFromEditor(desktop);
198- final MoeTextPaneUI ui = getTextPaneUI(Parts.EDITOR);
199- if (editor == null || editor instanceof javax.swing.JTextPane) {
190+ final JEditorPane editor = getJEditorPaneFromEditorView();
191+ final MoeTextPaneUI sourceUI = getTextPaneUI(Parts.INSTANT_START);
192+ if (editor == null) {
200193 // Editor is not available yet. Wait for project open event.
201- EditorUIRunner editorUIRunner = new EditorUIRunner();
202- editorUIRunner.setBackgroundImage(ui.getBackgroundImage());
203- editorUIRunner.setBackgroundColor(ui.getBackgroundColor());
194+ DocumentEditorUIRunner editorUIRunner = new DocumentEditorUIRunner();
195+ editorUIRunner.setBackgroundImage(sourceUI.getBackgroundImage());
196+ editorUIRunner.setBackgroundColor(sourceUI.getBackgroundColor());
204197 CoreEvents.registerProjectChangeListener(editorUIRunner);
205198 } else {
206199 // Editor is found. Set UI and migrate highlighter.
200+ MoeTextPaneUI ui = getTextPaneUI(Parts.EDITOR);
201+ ui.setBackgroundImage(sourceUI.getBackgroundImage());
202+ ui.setBackgroundColor(sourceUI.getBackgroundColor());
207203 Highlighter h = editor.getHighlighter(); // save old highlighter
208204 editor.setUI(ui);
209205 editor.setHighlighter(h); // restore highlighter
@@ -225,7 +221,7 @@
225221 ui.setMarginTop(marginTop);
226222 }
227223 transparentRecursive(contentPane);
228- transparentInstantStart(desktop);
224+ removeInstantStartBgColor();
229225
230226 // try to make transparent editor pane
231227 //@@TODO エディターが除外パーツになっている場合を考慮
@@ -241,6 +237,7 @@
241237
242238 @Override
243239 public void onProjectChanged(PROJECT_CHANGE_TYPE eventType) {
240+ //@@TODO Runnerに移行
244241 switch (eventType) {
245242 case CREATE:
246243 case LOAD:
@@ -264,21 +261,21 @@
264261 }
265262
266263 private int getDockViewTitleBarHeight(DockingDesktop desktop) {
267- Dockable dockable = null;
268- for (DockableState d: desktop.getDockables()) {
269- if (!isDockableIconized(d)) {
270- dockable = d.getDockable();
271- break;
272- }
273- }
264+ ArrayList<Dockable> dockables = desktop.getContext()
265+ .getDockablesByState(desktop, DockableState.STATE_DOCKED);
266+ if (!dockables.isEmpty()) {
267+ Dockable dockable = dockables.get(0);
274268
275- // DockView
276- Container container = dockable.getComponent().getParent();
277- DockView view = (DockView) container;
269+ // DockView
270+ Container container = dockable.getComponent().getParent();
271+ DockView view = (DockView) container;
278272
279- // TitleBar
280- DockViewTitleBar titleBar = view.getTitleBar();
281- return titleBar.getHeight();
273+ // TitleBar
274+ DockViewTitleBar titleBar = view.getTitleBar();
275+ return titleBar.getHeight();
276+ } else {
277+ return 0;
278+ }
282279 }
283280
284281 private boolean transparentEditor() {
@@ -294,8 +291,8 @@
294291
295292 UIThreadsUtil.mustBeSwingThread();
296293
297- JEditorPane editor = getJEditorPaneFromEditor(desktop);
298- if (editor == null || editor instanceof javax.swing.JTextPane) {
294+ JEditorPane editor = getJEditorPaneFromEditorView();
295+ if (editor == null) {
299296 return false;
300297 }
301298
@@ -309,58 +306,60 @@
309306 editor.setBackgroundImage(new Color( color.getRGB() & 0xffffff | 100 << 24, true));
310307 * */
311308 editor.setOpaque(false);
309+ isEditorTransparent = true;
312310 frame.repaint();
313311 return true;
314312 }
315313
316- private JEditorPane getJEditorPane(Parts pane) {
317-/*
318-dockable.getDockKey().getKey()
319- dockable.getComponent().class.name
320- dockable.getComponent().getViewport().getView().class.name
321--------------
322-EDITOR
323- org.omegat.gui.main.DockablePanel
324-MATCHES
325- org.omegat.gui.main.DockableScrollPane
326- org.omegat.gui.matches.MatchesTextArea
327-GLOSSARY
328- org.omegat.gui.main.DockableScrollPane
329- org.omegat.gui.glossary.GlossaryTextArea
330-NOTES
331- org.omegat.gui.main.DockableScrollPane
332- org.omegat.gui.notes.NotesTextArea
333-COMMENTS
334- org.omegat.gui.main.DockableScrollPane
335- org.omegat.gui.comments.CommentsTextArea
336-MACHINE_TRANSLATE
337- org.omegat.gui.main.DockableScrollPane
338- org.omegat.gui.exttrans.MachineTranslateTextArea
339-DICTIONARY
340- org.omegat.gui.main.DockableScrollPane
341- org.omegat.gui.dictionaries.DictionariesTextArea
342-MULTIPLE_TRANS
343- org.omegat.gui.main.DockableScrollPane
344- org.omegat.gui.multtrans.MultipleTransPane
314+ private JEditorPane getJEditorPane(Parts target) {
315+ /*
316+ dockable.getDockKey().getKey()
317+ dockable.getComponent().class.name
318+ dockable.getComponent().getViewport().getView().class.name
319+ -------------
320+ EDITOR
321+ org.omegat.gui.main.DockablePanel
322+ MATCHES
323+ org.omegat.gui.main.DockableScrollPane
324+ org.omegat.gui.matches.MatchesTextArea
325+ GLOSSARY
326+ org.omegat.gui.main.DockableScrollPane
327+ org.omegat.gui.glossary.GlossaryTextArea
328+ NOTES
329+ org.omegat.gui.main.DockableScrollPane
330+ org.omegat.gui.notes.NotesTextArea
331+ COMMENTS
332+ org.omegat.gui.main.DockableScrollPane
333+ org.omegat.gui.comments.CommentsTextArea
334+ MACHINE_TRANSLATE
335+ org.omegat.gui.main.DockableScrollPane
336+ org.omegat.gui.exttrans.MachineTranslateTextArea
337+ DICTIONARY
338+ org.omegat.gui.main.DockableScrollPane
339+ org.omegat.gui.dictionaries.DictionariesTextArea
340+ MULTIPLE_TRANS
341+ org.omegat.gui.main.DockableScrollPane
342+ org.omegat.gui.multtrans.MultipleTransPane
345343
346- xxxTextArea は、基本的に全部 JEditorPane の拡張。
347- MULTIPLE_TRANS も、同じ。
348- EntryInfoThreadPane -> EntryInfoPane -> JTextPane -> JEditorPane という感じ。
349- EDITOR だけちょっと特殊なので、分岐処理しておく。
350-*/
351- // エディターの場合
352- if (pane == Parts.EDITOR) {
353- return getJEditorPaneFromEditor(desktop);
354- } else {
355- // エディター以外の場合
356- final String PANE_NAME = pane.name();
357- for (DockableState d: desktop.getDockables()) {
358- Dockable dockable = d.getDockable();
359- if (dockable.getDockKey().getKey().equalsIgnoreCase(PANE_NAME)) {
344+ xxxTextArea は、基本的に全部 JEditorPane の拡張。
345+ MULTIPLE_TRANS も、同じ。
346+ EntryInfoThreadPane -> EntryInfoPane -> JTextPane -> JEditorPane という感じ。
347+ EDITOR と INSTANT_START だけちょっと特殊なので、分岐処理しておく。
348+ */
349+ switch (target) {
350+ case EDITOR:
351+ return getJEditorPaneFromEditorView();
352+ case INSTANT_START:
353+ return getJTextPaneFromInstantStartView();
354+ default:
355+ // エディター以外の場合
356+ final String PANE_NAME = target.name();
357+
358+ Dockable dockable = desktop.getContext().getDockableByKey(PANE_NAME);
359+ if (dockable != null) {
360360 JScrollPane sp = (JScrollPane) dockable.getComponent();
361- return (JTextPane) sp.getViewport().getView();
362- }
363- }
361+ return (JTextPane) sp.getViewport().getView();
362+ }
364363 }
365364 return null;
366365 }
@@ -427,23 +426,14 @@
427426 // + splitContainer(VERTICAL) <-- DockView.getParent()
428427 // + DockView <-- Dockable.getParent()
429428 // + Dockable <-- DockableState.getDockable()
430- for (DockableState d : desktop.getDockables()) {
431- if (!isDockableIconized(d)) {
432- transparentRecursive(d);
433- }
429+ ArrayList<Dockable> dockables = desktop.getContext()
430+ .getDockablesByState(desktop, DockableState.STATE_DOCKED);
431+ for (Dockable d : dockables) {
432+ transparentRecursive(d);
434433 }
435434 }
436- private boolean isDockableIconized(DockableState dockableState) {
437- double width = dockableState.getPosition().getWidth();
438435
439- // width (height や x, y でも可) が 0.0 以外の場合はアイコン化されている。
440- // 他に適切な判定方法がありそうだけれども、分からなかったので、とりあえずこれで。
441- return (width != 0.0);
442- }
443-
444- private void transparentRecursive(DockableState dockableState) {
445- Dockable dockable = dockableState.getDockable();
446-
436+ private void transparentRecursive(Dockable dockable) {
447437 // DockView
448438 Container container = dockable.getComponent().getParent();
449439 DockView view = (DockView) container;
@@ -477,12 +467,12 @@
477467 }
478468 }
479469
480- private void transparentInstantStart(DockingDesktop desktop) {
470+ private void removeInstantStartBgColor() {
481471 // お手軽スタートは、以下のような HTML で背景色が指定されている。
482472 // <body ... bgcolor="white" ...>
483473 // そのため、コンポーネント自体を透過にしても、HTML Body 背景色の
484474 // 白指定が効いて透過にならない。そこで、背景色指定を削除する。
485- JEditorPane ep = getJEditorPaneFromEditor(desktop);
475+ JTextPane ep = getJTextPaneFromInstantStartView();
486476 if (ep != null) {
487477 ep.setText(ep.getText().replace(" bgcolor=\"white\"", ""));
488478 ep.setCaretPosition(0);
@@ -539,30 +529,53 @@
539529 return panel == null ? null : (AutoHideButtonPanel) panel.getComponent(2);
540530 }
541531
542- private JEditorPane getJEditorPaneFromEditor(DockingDesktop desktop) {
543- for (DockableState d: desktop.getDockables()) {
544- Dockable dockable = d.getDockable();
545- if (dockable.getDockKey().getKey().equals(Parts.EDITOR.name())) {
546- JScrollPane sp;
532+ private JEditorPane getJEditorPaneFromEditorView() {
533+ JEditorPane pane = getJEditorPaneFromEditor();
534+ return pane instanceof JTextPane ? null : pane;
535+
536+ }
547537
548- // OmegaT 3.1.0 or later
549- if (dockable.getComponent() instanceof JPanel) {
550- // dockable.getComponent() => org.omegat.gui.main.DockablePanel
551- // extends JPanel implements Dockable
552- JPanel jp = (JPanel) dockable.getComponent();
553- sp = (JScrollPane) jp.getComponent(0);
538+ private JTextPane getJTextPaneFromInstantStartView() {
539+ JEditorPane pane = getJEditorPaneFromEditor();
540+ return pane instanceof JTextPane ? (JTextPane) pane : null;
541+
542+ }
554543
555- // less than OmegaT 3.1.0
556- } else {
557- sp = (JScrollPane) dockable.getComponent();
558- }
544+ private JEditorPane getJEditorPaneFromEditor() {
545+ Dockable dockable = desktop.getContext().getDockableByKey(Parts.EDITOR.name());
546+ if (dockable != null) {
547+ JScrollPane sp;
559548
560- return (JEditorPane) sp.getViewport().getView();
549+ // OmegaT 3.1.0 or later
550+ if (dockable.getComponent() instanceof JPanel) {
551+ // dockable.getComponent() => org.omegat.gui.main.DockablePanel
552+ // extends JPanel implements Dockable
553+ JPanel jp = (JPanel) dockable.getComponent();
554+ sp = (JScrollPane) jp.getComponent(0);
555+
556+ // less than OmegaT 3.1.0
557+ } else {
558+ sp = (JScrollPane) dockable.getComponent();
561559 }
560+
561+ return (JEditorPane) sp.getViewport().getView();
562562 }
563563 return null;
564564 }
565565
566+ private MoeRootPaneUI getRootPaneUI() {
567+ MoeRootPaneUI ui;
568+ Parts target = Parts.MainWindow;
569+ if (uis.containsKey(target)) {
570+ ui = (MoeRootPaneUI) uis.get(target);
571+ } else {
572+ ui = new MoeRootPaneUI();
573+ rootPane.setUI(ui);
574+ uis.put(target, ui);
575+ }
576+ return ui;
577+ }
578+
566579 private MoeTextPaneUI getTextPaneUI(Parts target) {
567580 MoeTextPaneUI ui;
568581 if (uis.containsKey(target)) {
@@ -570,14 +583,16 @@
570583 } else {
571584 ui = new MoeTextPaneUI();
572585 JEditorPane pane = getJEditorPane(target);
573- Highlighter h = pane.getHighlighter(); // save old highlighter
574- pane.setUI(ui);
575- pane.setHighlighter(h); // restore highlighter
576- if (!pane.isOpaque()) {
577- pane.setOpaque(true);
578- if (target == Parts.EDITOR) {
579- isEditorTransparent = false;
580- }
586+ if (pane != null) { // EDITOR の場合は null になることがあるため
587+ Highlighter h = pane.getHighlighter(); // save old highlighter
588+ pane.setUI(ui);
589+ pane.setHighlighter(h); // restore highlighter
590+ if (!pane.isOpaque()) {
591+ pane.setOpaque(true);
592+ if (target == Parts.EDITOR) {
593+ isEditorTransparent = false;
594+ }
595+ }
581596 }
582597 uis.put(target, ui);
583598 }
@@ -585,12 +600,12 @@
585600 }
586601
587602 /**
588- * エディター専用の UI です。プロジェクトの開始時にエディターに自身を UI と
603+ * エディター専用の UI です。プロジェクトの開始時にエディターに自身をUI と
589604 * して自動設定します。
590- * 呼び出し側で、このクラスのインスタンスをプロジェクトイベントのリスナーに
591- * 登録しておく必要があります。
605+ * 呼び出し側では、このクラスのインスタンスをプロジェクトイベントのリスナー
606+ * に登録しておく必要があります。
592607 */
593- private class EditorUIRunner extends MoeTextPaneUI
608+ private class DocumentEditorUIRunner extends MoeTextPaneUI
594609 implements IProjectEventListener, Runnable {
595610
596611 @Override
@@ -598,10 +613,10 @@
598613 // 実行は一回きりで良いので、リスナー登録を解除する
599614 CoreEvents.unregisterProjectChangeListener(this);
600615
601- // エディターに UI を設定し、ハイライターを復元する
602- JEditorPane editor = getJEditorPaneFromEditor(desktop);
616+ // エディターに UI(自身)を設定し、ハイライターを復元する
617+ JEditorPane editor = getJEditorPaneFromEditor();
603618 Highlighter h = editor.getHighlighter(); // save old highlighter
604- editor.setUI(this); //@@TODO このインスタンスを管理する必要がある
619+ editor.setUI(this);
605620 editor.setHighlighter(h); // restore highlighter
606621
607622 // エディターが透明の場合は不透過に設定する