OmegaT の背景に画像を表示します。
背景色の設定機能を実装
| @@ -58,6 +58,9 @@ | ||
| 58 | 58 | |
| 59 | 59 | public void setBackgroundColor(Color color) { |
| 60 | 60 | this.bgColor = color; |
| 61 | + if (component != null) { | |
| 62 | + component.setBackground(color); | |
| 63 | + } | |
| 61 | 64 | } |
| 62 | 65 | |
| 63 | 66 | public BufferedImage getBackgroundImage() { |
| @@ -73,6 +76,9 @@ | ||
| 73 | 76 | if (!c.isOpaque()) { |
| 74 | 77 | c.setOpaque(true); |
| 75 | 78 | } |
| 79 | + if (bgColor != null) { | |
| 80 | + c.setBackground(bgColor); | |
| 81 | + } | |
| 76 | 82 | this.component = c; |
| 77 | 83 | } |
| 78 | 84 |
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | |
| 17 | 17 | package jp.sourceforge.users.yutang.omegat.plugin.moenizer.effect; |
| 18 | 18 | |
| 19 | +import java.awt.Color; | |
| 19 | 20 | import java.io.File; |
| 20 | 21 | import java.io.IOException; |
| 21 | 22 | import java.net.MalformedURLException; |
| @@ -39,11 +40,13 @@ | ||
| 39 | 40 | private final String KEY_OPACITY = "opacity"; |
| 40 | 41 | private final String KEY_IMAGE = "image"; |
| 41 | 42 | private final String KEY_PATH = "path"; |
| 43 | + private final String KEY_BGCOLOR = "bgColor"; | |
| 42 | 44 | private final String KEY_EXCLUDE = "exclude"; |
| 43 | 45 | |
| 44 | 46 | private Parts target = Parts.MainWindow; |
| 45 | 47 | private float opacity = 0.5f; |
| 46 | 48 | private String image = ""; |
| 49 | + private Color bgColor = null; | |
| 47 | 50 | private List<Parts> exclude = new ArrayList<Parts>(); |
| 48 | 51 | |
| 49 | 52 | public BasicEffect(Map<String, Object> config) { |
| @@ -53,15 +56,15 @@ | ||
| 53 | 56 | image = get(KEY_PATH, conf, image); |
| 54 | 57 | opacity = get(KEY_OPACITY, conf, opacity); |
| 55 | 58 | } |
| 59 | + Integer rgb = get(KEY_BGCOLOR, config, null); | |
| 60 | + if (rgb != null) { | |
| 61 | + bgColor = new Color(rgb); | |
| 62 | + } | |
| 56 | 63 | exclude = get(KEY_EXCLUDE, config, exclude); |
| 57 | 64 | } |
| 58 | 65 | |
| 59 | 66 | @Override |
| 60 | 67 | public void invoke(MoeUI ui) { |
| 61 | - if (image.isEmpty()) { | |
| 62 | - return; | |
| 63 | - } | |
| 64 | - | |
| 65 | 68 | EnumSet<Parts> excludeParts = EnumSet.noneOf(Parts.class); |
| 66 | 69 | for (Parts part: EnumSet.allOf(Parts.class)) { |
| 67 | 70 | if (exclude.contains(part)) { |
| @@ -69,21 +72,25 @@ | ||
| 69 | 72 | } |
| 70 | 73 | } |
| 71 | 74 | |
| 72 | - try { | |
| 73 | - String lcased = image.toLowerCase(); | |
| 74 | - if (lcased.startsWith("http://") || lcased.startsWith("https://")) { | |
| 75 | - ui.setBackground(target, ImageIO.read(new URL(image))); | |
| 76 | - } else { | |
| 77 | - ui.setBackground(target, ImageIO.read(new File(image))); | |
| 75 | + if (!image.isEmpty()) { | |
| 76 | + try { | |
| 77 | + String lcased = image.toLowerCase(); | |
| 78 | + if (lcased.startsWith("http://") || lcased.startsWith("https://")) { | |
| 79 | + ui.setBackground(target, ImageIO.read(new URL(image))); | |
| 80 | + } else { | |
| 81 | + ui.setBackground(target, ImageIO.read(new File(image))); | |
| 82 | + } | |
| 83 | + } catch (MalformedURLException ex) { | |
| 84 | + Log.log(ex.getMessage()); | |
| 85 | + } catch (IOException ex) { | |
| 86 | + Log.log(ex.getMessage()); | |
| 78 | 87 | } |
| 79 | - } catch (MalformedURLException ex) { | |
| 80 | - Log.log(ex.getMessage()); | |
| 81 | - } catch (IOException ex) { | |
| 82 | - Log.log(ex.getMessage()); | |
| 83 | 88 | } |
| 84 | 89 | |
| 85 | 90 | ui.setOpacity(target, opacity); |
| 86 | 91 | |
| 92 | + ui.setBackground(target, bgColor); | |
| 93 | + | |
| 87 | 94 | ui.transparent(target, excludeParts); |
| 88 | 95 | } |
| 89 | 96 |