OmegaT の背景に画像を表示します。
effect/SimpleImage のクラス名が実情にそぐわなくなってきたので、effect/BasicEffect に変更
| @@ -150,7 +150,7 @@ | ||
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | ConfigObject effect = new ConfigObject(); |
| 153 | - effect.put("type", Effect.Type.SimpleImage.name()); | |
| 153 | + effect.put("type", Effect.Type.BasicEffect.name()); | |
| 154 | 154 | effect.put("image", image); |
| 155 | 155 | |
| 156 | 156 | List<ConfigObject> effects = new ArrayList<ConfigObject>(1); |
| @@ -1,105 +0,0 @@ | ||
| 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 java.io.File; | |
| 20 | -import java.io.IOException; | |
| 21 | -import java.net.MalformedURLException; | |
| 22 | -import java.net.URL; | |
| 23 | -import java.util.ArrayList; | |
| 24 | -import java.util.EnumSet; | |
| 25 | -import java.util.List; | |
| 26 | -import java.util.Map; | |
| 27 | -import javax.imageio.ImageIO; | |
| 28 | -import jp.sourceforge.users.yutang.omegat.plugin.moenizer.MoeUI; | |
| 29 | -import jp.sourceforge.users.yutang.omegat.plugin.moenizer.MoeUI.Parts; | |
| 30 | -import org.omegat.util.Log; | |
| 31 | - | |
| 32 | -/** | |
| 33 | - * | |
| 34 | - * @author Yu-Tang | |
| 35 | - */ | |
| 36 | -public class SimpleImage implements IEffect { | |
| 37 | - | |
| 38 | - private final String KEY_TARGET = "target"; | |
| 39 | - private final String KEY_OPACITY = "opacity"; | |
| 40 | - private final String KEY_IMAGE = "image"; | |
| 41 | - private final String KEY_EXCLUDE = "exclude"; | |
| 42 | - | |
| 43 | - private Parts target = Parts.MainWindow; | |
| 44 | - private float opacity = 0.5f; | |
| 45 | - private String image = ""; | |
| 46 | - private List<String> exclude = new ArrayList<String>(); | |
| 47 | - | |
| 48 | - public SimpleImage(Map config) { | |
| 49 | - if (config.containsKey(KEY_TARGET)) { | |
| 50 | - //@@TODO 設定自体を Enum で受け取れるように | |
| 51 | - String targetName = (String) config.get(KEY_TARGET); | |
| 52 | - try { | |
| 53 | - target = Parts.valueOf(targetName); | |
| 54 | - } catch (IllegalArgumentException ex) { | |
| 55 | - Log.log("warning: target name '" + targetName + "' is not found in Parts enum."); | |
| 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_EXCLUDE)) { | |
| 68 | - exclude = (List<String>) config.get(KEY_EXCLUDE); | |
| 69 | - } | |
| 70 | - } | |
| 71 | - | |
| 72 | - @Override | |
| 73 | - public void invoke(MoeUI ui) { | |
| 74 | - if (image.isEmpty()) { | |
| 75 | - return; | |
| 76 | - } | |
| 77 | - | |
| 78 | - EnumSet<Parts> excludeParts = EnumSet.noneOf(Parts.class); | |
| 79 | - for (Parts part: EnumSet.allOf(Parts.class)) { | |
| 80 | - if (exclude.contains(part.name())) { | |
| 81 | - excludeParts.add(part); | |
| 82 | - } | |
| 83 | - } | |
| 84 | - | |
| 85 | - try { | |
| 86 | - String lcased = image.toLowerCase(); | |
| 87 | - if (lcased.startsWith("http://") || lcased.startsWith("https://")) { | |
| 88 | - ui.setBackground(target, ImageIO.read(new URL(image))); | |
| 89 | - } else { | |
| 90 | - ui.setBackground(target, ImageIO.read(new File(image))); | |
| 91 | - } | |
| 92 | - } catch (MalformedURLException ex) { | |
| 93 | - Log.log(ex.getMessage()); | |
| 94 | - } catch (IOException ex) { | |
| 95 | - Log.log(ex.getMessage()); | |
| 96 | - } | |
| 97 | - | |
| 98 | - ui.setOpacity(target, opacity); | |
| 99 | - | |
| 100 | - if (target == Parts.MainWindow) { | |
| 101 | - ui.transparent(excludeParts); | |
| 102 | - } | |
| 103 | - } | |
| 104 | - | |
| 105 | -} |
| @@ -30,7 +30,7 @@ | ||
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public enum Type { |
| 33 | - SimpleImage | |
| 33 | + BasicEffect | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | public static IEffect create(Type type, Map conf) throws Exception { |
| @@ -0,0 +1,105 @@ | ||
| 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 java.io.File; | |
| 20 | +import java.io.IOException; | |
| 21 | +import java.net.MalformedURLException; | |
| 22 | +import java.net.URL; | |
| 23 | +import java.util.ArrayList; | |
| 24 | +import java.util.EnumSet; | |
| 25 | +import java.util.List; | |
| 26 | +import java.util.Map; | |
| 27 | +import javax.imageio.ImageIO; | |
| 28 | +import jp.sourceforge.users.yutang.omegat.plugin.moenizer.MoeUI; | |
| 29 | +import jp.sourceforge.users.yutang.omegat.plugin.moenizer.MoeUI.Parts; | |
| 30 | +import org.omegat.util.Log; | |
| 31 | + | |
| 32 | +/** | |
| 33 | + * | |
| 34 | + * @author Yu-Tang | |
| 35 | + */ | |
| 36 | +public class BasicEffect implements IEffect { | |
| 37 | + | |
| 38 | + private final String KEY_TARGET = "target"; | |
| 39 | + private final String KEY_OPACITY = "opacity"; | |
| 40 | + private final String KEY_IMAGE = "image"; | |
| 41 | + private final String KEY_EXCLUDE = "exclude"; | |
| 42 | + | |
| 43 | + private Parts target = Parts.MainWindow; | |
| 44 | + private float opacity = 0.5f; | |
| 45 | + private String image = ""; | |
| 46 | + private List<String> exclude = new ArrayList<String>(); | |
| 47 | + | |
| 48 | + public BasicEffect(Map config) { | |
| 49 | + if (config.containsKey(KEY_TARGET)) { | |
| 50 | + //@@TODO 設定自体を Enum で受け取れるように | |
| 51 | + String targetName = (String) config.get(KEY_TARGET); | |
| 52 | + try { | |
| 53 | + target = Parts.valueOf(targetName); | |
| 54 | + } catch (IllegalArgumentException ex) { | |
| 55 | + Log.log("warning: target name '" + targetName + "' is not found in Parts enum."); | |
| 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_EXCLUDE)) { | |
| 68 | + exclude = (List<String>) config.get(KEY_EXCLUDE); | |
| 69 | + } | |
| 70 | + } | |
| 71 | + | |
| 72 | + @Override | |
| 73 | + public void invoke(MoeUI ui) { | |
| 74 | + if (image.isEmpty()) { | |
| 75 | + return; | |
| 76 | + } | |
| 77 | + | |
| 78 | + EnumSet<Parts> excludeParts = EnumSet.noneOf(Parts.class); | |
| 79 | + for (Parts part: EnumSet.allOf(Parts.class)) { | |
| 80 | + if (exclude.contains(part.name())) { | |
| 81 | + excludeParts.add(part); | |
| 82 | + } | |
| 83 | + } | |
| 84 | + | |
| 85 | + try { | |
| 86 | + String lcased = image.toLowerCase(); | |
| 87 | + if (lcased.startsWith("http://") || lcased.startsWith("https://")) { | |
| 88 | + ui.setBackground(target, ImageIO.read(new URL(image))); | |
| 89 | + } else { | |
| 90 | + ui.setBackground(target, ImageIO.read(new File(image))); | |
| 91 | + } | |
| 92 | + } catch (MalformedURLException ex) { | |
| 93 | + Log.log(ex.getMessage()); | |
| 94 | + } catch (IOException ex) { | |
| 95 | + Log.log(ex.getMessage()); | |
| 96 | + } | |
| 97 | + | |
| 98 | + ui.setOpacity(target, opacity); | |
| 99 | + | |
| 100 | + if (target == Parts.MainWindow) { | |
| 101 | + ui.transparent(excludeParts); | |
| 102 | + } | |
| 103 | + } | |
| 104 | + | |
| 105 | +} |