OmegaT の背景に画像を表示します。
透過除外 UI パーツの管理を文字列から enum に移行
| @@ -22,6 +22,7 @@ | ||
| 22 | 22 | import java.net.MalformedURLException; |
| 23 | 23 | import java.net.URL; |
| 24 | 24 | import java.util.ArrayList; |
| 25 | +import java.util.EnumSet; | |
| 25 | 26 | import java.util.List; |
| 26 | 27 | import java.util.Map; |
| 27 | 28 | import java.util.logging.Level; |
| @@ -28,6 +29,7 @@ | ||
| 28 | 29 | import java.util.logging.Logger; |
| 29 | 30 | import javax.imageio.ImageIO; |
| 30 | 31 | import jp.sourceforge.users.yutang.omegat.plugin.moenizer.MoeUI; |
| 32 | +import jp.sourceforge.users.yutang.omegat.plugin.moenizer.MoeUI.Parts; | |
| 31 | 33 | import org.omegat.util.Log; |
| 32 | 34 | |
| 33 | 35 | /** |
| @@ -75,24 +77,15 @@ | ||
| 75 | 77 | return; |
| 76 | 78 | } |
| 77 | 79 | |
| 78 | - if (exclude.contains("menubar")) { | |
| 79 | - ui.setMakeTransparentMenubar(false); | |
| 80 | + EnumSet<Parts> excludeParts = EnumSet.noneOf(Parts.class); | |
| 81 | + for (Parts part: EnumSet.allOf(Parts.class)) { | |
| 82 | + if (exclude.contains(part.name())) { | |
| 83 | + excludeParts.add(part); | |
| 84 | + } | |
| 80 | 85 | } |
| 81 | 86 | |
| 82 | - if (exclude.contains("statusbar")) { | |
| 83 | - ui.setMakeTransparentStatusbar(false); | |
| 84 | - } | |
| 85 | - | |
| 86 | - if (exclude.contains("buttonpanel")) { | |
| 87 | - ui.setMakeTransparentButtonPanel(false); | |
| 88 | - } | |
| 89 | - | |
| 90 | - if (exclude.contains("panetitlebar")) { | |
| 91 | - ui.setMakeTransparentPaneTitlebar(false); | |
| 92 | - } | |
| 93 | - | |
| 94 | - String lcased = image.toLowerCase(); | |
| 95 | 87 | try { |
| 88 | + String lcased = image.toLowerCase(); | |
| 96 | 89 | if (lcased.startsWith("http://") || lcased.startsWith("https://")) { |
| 97 | 90 | ui.setBackground(ImageIO.read(new URL(image))); |
| 98 | 91 | } else { |
| @@ -104,7 +97,7 @@ | ||
| 104 | 97 | Log.log(ex.getMessage()); |
| 105 | 98 | } |
| 106 | 99 | |
| 107 | - ui.transparent(); | |
| 100 | + ui.transparent(excludeParts); | |
| 108 | 101 | //@@TODO transparentEditor |
| 109 | 102 | //@@TODO opacity |
| 110 | 103 | } |
| @@ -30,6 +30,7 @@ | ||
| 30 | 30 | import java.awt.Graphics; |
| 31 | 31 | import java.awt.SystemColor; |
| 32 | 32 | import java.awt.image.BufferedImage; |
| 33 | +import java.util.EnumSet; | |
| 33 | 34 | import javax.swing.JComponent; |
| 34 | 35 | import javax.swing.JEditorPane; |
| 35 | 36 | import javax.swing.JFrame; |
| @@ -60,6 +61,10 @@ | ||
| 60 | 61 | private boolean makeTransparentStatusbar = true; |
| 61 | 62 | private boolean makeTransparentPaneTitlebar = true; |
| 62 | 63 | |
| 64 | + public enum Parts { | |
| 65 | + MenuBar, StatusBar, ButtonPanel, PaneTitleBar | |
| 66 | + } | |
| 67 | + | |
| 63 | 68 | static { |
| 64 | 69 | moeUI = null; |
| 65 | 70 | } |
| @@ -78,7 +83,18 @@ | ||
| 78 | 83 | return moeUI; |
| 79 | 84 | } |
| 80 | 85 | |
| 81 | - public void transparent() { | |
| 86 | + public void transparent(EnumSet<Parts> exclude) { | |
| 87 | + if (exclude != null) { | |
| 88 | + makeTransparentMenubar = exclude.contains(Parts.MenuBar); | |
| 89 | + makeTransparentButtonPanel = exclude.contains(Parts.ButtonPanel); | |
| 90 | + makeTransparentStatusbar = exclude.contains(Parts.StatusBar); | |
| 91 | + makeTransparentPaneTitlebar = exclude.contains(Parts.PaneTitleBar); | |
| 92 | + } | |
| 93 | + | |
| 94 | + transparent(); | |
| 95 | + } | |
| 96 | + | |
| 97 | + private void transparent() { | |
| 82 | 98 | UIThreadsUtil.mustBeSwingThread(); |
| 83 | 99 | |
| 84 | 100 | if (makeTransparentMenubar) { |
| @@ -155,22 +171,6 @@ | ||
| 155 | 171 | }); |
| 156 | 172 | } |
| 157 | 173 | |
| 158 | - public void setMakeTransparentMenubar(boolean makeTransparentMenubar) { | |
| 159 | - this.makeTransparentMenubar = makeTransparentMenubar; | |
| 160 | - } | |
| 161 | - | |
| 162 | - public void setMakeTransparentButtonPanel(boolean makeTransparentButtonPanel) { | |
| 163 | - this.makeTransparentButtonPanel = makeTransparentButtonPanel; | |
| 164 | - } | |
| 165 | - | |
| 166 | - public void setMakeTransparentStatusbar(boolean makeTransparentStatusbar) { | |
| 167 | - this.makeTransparentStatusbar = makeTransparentStatusbar; | |
| 168 | - } | |
| 169 | - | |
| 170 | - public void setMakeTransparentPaneTitlebar(boolean makeTransparentPaneTitlebar) { | |
| 171 | - this.makeTransparentPaneTitlebar = makeTransparentPaneTitlebar; | |
| 172 | - } | |
| 173 | - | |
| 174 | 174 | private void initUI() { |
| 175 | 175 | frame = Core.getMainWindow().getApplicationFrame(); |
| 176 | 176 | layeredPane = new MoeLayeredPane(); |