OmegaT の背景に画像を表示します。
不要になった imageloader パッケージを削除
| @@ -1,197 +0,0 @@ | ||
| 1 | -/************************************************************************** | |
| 2 | - Moenizer - Allow to set background image for OmegaT. | |
| 3 | - | |
| 4 | - Copyright (C) 2013-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.imageloader; | |
| 18 | - | |
| 19 | -import groovy.util.ConfigObject; | |
| 20 | -import java.awt.image.BufferedImage; | |
| 21 | -import java.io.File; | |
| 22 | -import java.net.MalformedURLException; | |
| 23 | -import java.net.URL; | |
| 24 | -import java.util.regex.Pattern; | |
| 25 | -import javax.imageio.ImageIO; | |
| 26 | -import org.omegat.util.Log; | |
| 27 | - | |
| 28 | -/** | |
| 29 | - * Default image loader. | |
| 30 | - * | |
| 31 | - * calling order is: | |
| 32 | - * 1. availableNext() ... exit if returned false | |
| 33 | - * 2. readyForNextImage() | |
| 34 | - * 3. getNextInterval() ... skipped first time | |
| 35 | - * 4. getNextImage() | |
| 36 | - * ... loop back to step 1 | |
| 37 | - * | |
| 38 | - * @author Yu-Tang | |
| 39 | - */ | |
| 40 | -public class DefaultImageLoader implements IImageLoader { | |
| 41 | - | |
| 42 | - private static final Pattern RE_HAS_IMAGE_EXTENSION = Pattern.compile(".+\\.(?:bmp|png|jpg|jpeg|gif)"); | |
| 43 | - private final String CONF_KEY_INTERVAL = "interval"; | |
| 44 | - private final String CONF_KEY_ENABLED = "enabled"; | |
| 45 | - private final String CONF_KEY_IMAGE = "image"; | |
| 46 | - | |
| 47 | - private final int DEFAULT_INTERVAL = 0; | |
| 48 | - | |
| 49 | - private final long interval; | |
| 50 | - private Object[] sources; | |
| 51 | - private Object currentSource; | |
| 52 | - private int sourceIndex; | |
| 53 | - | |
| 54 | - protected BufferedImage image; | |
| 55 | - | |
| 56 | - public DefaultImageLoader(ConfigObject config) throws MalformedURLException { | |
| 57 | - interval = getInterval(config); | |
| 58 | - sources = getSources(config); | |
| 59 | - currentSource = null; | |
| 60 | - image = null; | |
| 61 | - sourceIndex = -1; | |
| 62 | - } | |
| 63 | - | |
| 64 | - /** | |
| 65 | - * get if source is acceptable. | |
| 66 | - * @return bool. | |
| 67 | - */ | |
| 68 | - public static boolean isAcceptable(Object source) { | |
| 69 | - if (source instanceof URL) { | |
| 70 | - return true; | |
| 71 | - } else if (source instanceof File) { | |
| 72 | - String name = ((File) source).getName().toLowerCase(); | |
| 73 | - if (RE_HAS_IMAGE_EXTENSION.matcher(name).matches()) { | |
| 74 | - return true; | |
| 75 | - } | |
| 76 | - } | |
| 77 | - return false; | |
| 78 | - } | |
| 79 | - | |
| 80 | - @Override | |
| 81 | - public boolean availableNext() { | |
| 82 | - boolean ret = false; | |
| 83 | - if (sources.length == 0) { | |
| 84 | - // it's over! | |
| 85 | - } else if (sources.length == 1) { | |
| 86 | - if (currentSource == null || interval > 0) { // first time or refresh | |
| 87 | - currentSource = sources[0]; | |
| 88 | - ret = true; | |
| 89 | - } | |
| 90 | - } else { | |
| 91 | - currentSource = getCircularNextSource(); | |
| 92 | - ret = true; | |
| 93 | - } | |
| 94 | - return ret; | |
| 95 | - } | |
| 96 | - | |
| 97 | - /** | |
| 98 | - * get next image. | |
| 99 | - * @return BufferedImage object. Can be null if image is not available. | |
| 100 | - */ | |
| 101 | - @Override | |
| 102 | - public BufferedImage getNextImage() { | |
| 103 | - return image; | |
| 104 | - } | |
| 105 | - | |
| 106 | - /** | |
| 107 | - * Do anything should be done for the next image. | |
| 108 | - * Calling before getNextImage(). | |
| 109 | - */ | |
| 110 | - @Override | |
| 111 | - public void readyForNextImage() { | |
| 112 | - //TODO use cache | |
| 113 | - image = null; | |
| 114 | - try { | |
| 115 | - if (currentSource != null) { | |
| 116 | - if (currentSource instanceof File) { | |
| 117 | - image = ImageIO.read((File) currentSource); | |
| 118 | - } else if (currentSource instanceof URL) { | |
| 119 | - image = ImageIO.read((URL) currentSource); | |
| 120 | - } else { | |
| 121 | - removeCurrentSource(); | |
| 122 | - } | |
| 123 | - } | |
| 124 | - } catch (Exception ex) { | |
| 125 | - Log.log(ex); | |
| 126 | - removeCurrentSource(); | |
| 127 | - } | |
| 128 | - } | |
| 129 | - | |
| 130 | - /** | |
| 131 | - * get next interval. | |
| 132 | - * This method is not called at first time loop. | |
| 133 | - * @return long by milliseconds | |
| 134 | - */ | |
| 135 | - @Override | |
| 136 | - public long getNextInterval() { | |
| 137 | - return interval; | |
| 138 | - } | |
| 139 | - | |
| 140 | - private Object getCircularNextSource() { | |
| 141 | - sourceIndex++; | |
| 142 | - if (sourceIndex >= sources.length) { | |
| 143 | - sourceIndex = 0; | |
| 144 | - } | |
| 145 | - return sources[sourceIndex]; | |
| 146 | - } | |
| 147 | - | |
| 148 | - private void removeCurrentSource() { | |
| 149 | - if (sourceIndex >= 0 && sourceIndex < sources.length) { | |
| 150 | - sourceIndex = 0; // something is wrong. rewind index. | |
| 151 | - } else { | |
| 152 | - Object[] newSources = new Object[sources.length - 1]; | |
| 153 | - for (int i = 0; i < sources.length; i++) { | |
| 154 | - if ( i == sourceIndex ) { | |
| 155 | - // skip | |
| 156 | - } else if ( i < sourceIndex ) { | |
| 157 | - newSources[i] = sources[i]; | |
| 158 | - } else { | |
| 159 | - newSources[i - 1] = sources[i]; | |
| 160 | - } | |
| 161 | - } | |
| 162 | - sources = newSources; | |
| 163 | - if (sourceIndex >= sources.length) { | |
| 164 | - sourceIndex = 0; | |
| 165 | - } | |
| 166 | - } | |
| 167 | - } | |
| 168 | - | |
| 169 | - private long getInterval(ConfigObject config) { | |
| 170 | - if (config.containsKey(CONF_KEY_INTERVAL)) { | |
| 171 | - return (Integer) config.get(CONF_KEY_INTERVAL); | |
| 172 | - } else { | |
| 173 | - return DEFAULT_INTERVAL; | |
| 174 | - } | |
| 175 | - } | |
| 176 | - | |
| 177 | - private Object[] getSources(ConfigObject config) throws MalformedURLException { | |
| 178 | - boolean enabled = false; | |
| 179 | - if (config.containsKey(CONF_KEY_ENABLED)) { | |
| 180 | - enabled = (Boolean) config.get(CONF_KEY_ENABLED); | |
| 181 | - } | |
| 182 | - | |
| 183 | - if (enabled) { | |
| 184 | - if (config.containsKey(CONF_KEY_IMAGE)) { | |
| 185 | - String s = (String) config.get(CONF_KEY_IMAGE); | |
| 186 | - if (s.startsWith("http://") || s.startsWith("https://")) { | |
| 187 | - return new Object[]{new URL(s)}; | |
| 188 | - } else { | |
| 189 | - return new Object[]{new File(s)}; | |
| 190 | - } | |
| 191 | - } | |
| 192 | - } | |
| 193 | - | |
| 194 | - return new Object[]{}; | |
| 195 | - } | |
| 196 | - | |
| 197 | -} |
| @@ -1,60 +0,0 @@ | ||
| 1 | -/************************************************************************** | |
| 2 | - Moenizer - Allow to set background image for OmegaT. | |
| 3 | - | |
| 4 | - Copyright (C) 2013-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.imageloader; | |
| 18 | - | |
| 19 | -import java.awt.image.BufferedImage; | |
| 20 | - | |
| 21 | -/** | |
| 22 | - * Interface for Image Loader | |
| 23 | - * | |
| 24 | - * calling order is: | |
| 25 | - * 1. availableNext() ... exit from loop if returned false | |
| 26 | - * 2. readyForNextImage() | |
| 27 | - * 3. getNextInterval() ... skiped first time | |
| 28 | - * 4. getNextImage() | |
| 29 | - * ... loop back to step 1 | |
| 30 | - * | |
| 31 | - * @author Yu-Tang | |
| 32 | - */ | |
| 33 | -public interface IImageLoader { | |
| 34 | - | |
| 35 | - /** | |
| 36 | - * get if next image available. | |
| 37 | - * @return bool. | |
| 38 | - */ | |
| 39 | - boolean availableNext(); | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * get next interval. | |
| 43 | - * This method is not called at first time loop. | |
| 44 | - * @return long by milliseconds | |
| 45 | - */ | |
| 46 | - long getNextInterval(); | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * Do anything should be done for the next image. | |
| 50 | - * Calling before getNextImage(). | |
| 51 | - */ | |
| 52 | - void readyForNextImage(); | |
| 53 | - | |
| 54 | - /** | |
| 55 | - * get next image. | |
| 56 | - * @return BufferedImage object. Can be null if image is not available. | |
| 57 | - */ | |
| 58 | - BufferedImage getNextImage(); | |
| 59 | - | |
| 60 | -} |
| @@ -1,56 +0,0 @@ | ||
| 1 | -/************************************************************************** | |
| 2 | - Moenizer - Allow to set background image for OmegaT. | |
| 3 | - | |
| 4 | - Copyright (C) 2013-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.imageloader; | |
| 18 | - | |
| 19 | -import groovy.util.ConfigObject; | |
| 20 | -import java.lang.reflect.Method; | |
| 21 | -import java.net.MalformedURLException; | |
| 22 | -import org.omegat.util.Log; | |
| 23 | - | |
| 24 | -/** | |
| 25 | - * | |
| 26 | - * @author Yu-Tang | |
| 27 | - */ | |
| 28 | -public class ImageLoader { | |
| 29 | - | |
| 30 | - public static IImageLoader getInstance(ConfigObject config) throws MalformedURLException { | |
| 31 | - /*Object[] sources = getSources(); | |
| 32 | - | |
| 33 | - if (sources.length == 0) { | |
| 34 | - return null; // no source, no need loader | |
| 35 | - }*/ | |
| 36 | - | |
| 37 | - // default | |
| 38 | - return new DefaultImageLoader(config); | |
| 39 | - } | |
| 40 | - | |
| 41 | - private static Object getAcceptableSource(Class<?> c, Object[] sources) { | |
| 42 | - for (Object source: sources) { | |
| 43 | - try { | |
| 44 | - Method method = c.getDeclaredMethod("isAcceptable", new Class[]{ Object.class }); | |
| 45 | - boolean isAcceptable = (Boolean) method.invoke(null, source); | |
| 46 | - if (isAcceptable) { | |
| 47 | - return source; | |
| 48 | - } | |
| 49 | - } catch (Exception ex) { | |
| 50 | - Log.log(ex); | |
| 51 | - } | |
| 52 | - } | |
| 53 | - return null; | |
| 54 | - } | |
| 55 | - | |
| 56 | -} |
| @@ -20,7 +20,6 @@ | ||
| 20 | 20 | import java.util.concurrent.TimeUnit; |
| 21 | 21 | import javax.swing.SwingUtilities; |
| 22 | 22 | import javax.swing.SwingWorker; |
| 23 | -import jp.sourceforge.users.yutang.omegat.plugin.moenizer.imageloader.IImageLoader; | |
| 24 | 23 | import org.omegat.core.Core; |
| 25 | 24 | import org.omegat.core.CoreEvents; |
| 26 | 25 | import org.omegat.core.events.IApplicationEventListener; |
| @@ -35,7 +34,6 @@ | ||
| 35 | 34 | |
| 36 | 35 | private static boolean instantiated = false; |
| 37 | 36 | |
| 38 | - private IImageLoader imageLoader; | |
| 39 | 37 | private MoeUI ui; |
| 40 | 38 | private MoeConfig config; |
| 41 | 39 | private ThemeChanger themeChanger; |
| @@ -89,34 +87,4 @@ | ||
| 89 | 87 | // not used. |
| 90 | 88 | } |
| 91 | 89 | |
| 92 | - //@@TODO effect の具象クラスに移動 | |
| 93 | - private class SlideShow extends SwingWorker<Object, Void> { | |
| 94 | - private long interval = -1; | |
| 95 | - | |
| 96 | - @Override | |
| 97 | - protected Object doInBackground() throws Exception { | |
| 98 | - while (imageLoader.availableNext()) { | |
| 99 | - imageLoader.readyForNextImage(); | |
| 100 | - interval = interval < 0 ? 0 : imageLoader.getNextInterval(); | |
| 101 | - if (interval > 0) { | |
| 102 | - try { | |
| 103 | - TimeUnit.MILLISECONDS.sleep(interval); | |
| 104 | - } catch (InterruptedException e) { /* ignore */ } | |
| 105 | - } | |
| 106 | - BufferedImage image = imageLoader.getNextImage(); | |
| 107 | - | |
| 108 | - if (image != null) { | |
| 109 | - // 初期化直後に、まだ MoeUI がインスタンス化されていない | |
| 110 | - // 空白時間に遭遇する可能性があるため、その場合は 0.1 秒 | |
| 111 | - // 単位で MoeUI のインスタンス化を待機する。 | |
| 112 | - while (ui == null) { | |
| 113 | - TimeUnit.MILLISECONDS.sleep(100); | |
| 114 | - } | |
| 115 | - //ui.setBackground(image); | |
| 116 | - } | |
| 117 | - } | |
| 118 | - return null; | |
| 119 | - } | |
| 120 | - } | |
| 121 | - | |
| 122 | 90 | } |