OmegaT の翻訳状況(Statistics)を Excel で表示します。
Change template files name
| @@ -36,8 +36,8 @@ | ||
| 36 | 36 | public class ExcelModel { |
| 37 | 37 | private static final String CONFIG_DIR_NAME = "stats2excel"; |
| 38 | 38 | private static final String WSF_NAME = "Stats2Excel.wsf"; |
| 39 | - private static final String LEGACY_TEMPLATE_NAME = "Template.xlt"; | |
| 40 | - private static final String TEMPLATE_NAME = "Template.xltx"; | |
| 39 | + private static final String LEGACY_STANDARD_TEMPLATE_NAME = "StandardTemplate.xlt"; | |
| 40 | + private static final String STANDARD_TEMPLATE_NAME = "StandardTemplate.xltx"; | |
| 41 | 41 | private static final String TXT_NAME = "Stats2Excel.txt"; |
| 42 | 42 | private static final File _wsf; |
| 43 | 43 | private static final File _txt; |
| @@ -141,8 +141,8 @@ | ||
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | String templateName = installedExcelVersion >= 12 ? |
| 144 | - TEMPLATE_NAME : // Excel 2007 or later | |
| 145 | - LEGACY_TEMPLATE_NAME; // Excel 2003 or earlier | |
| 144 | + STANDARD_TEMPLATE_NAME : // Excel 2007 or later | |
| 145 | + LEGACY_STANDARD_TEMPLATE_NAME; // Excel 2003 or earlier | |
| 146 | 146 | File template = new File(parent, templateName); |
| 147 | 147 | |
| 148 | 148 | if (! template.exists()) { |
| @@ -195,7 +195,7 @@ | ||
| 195 | 195 | return _txt; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - private static boolean activate() throws IOException, InterruptedException { | |
| 198 | + public static boolean activate() throws IOException, InterruptedException { | |
| 199 | 199 | final Command command = new Command(); |
| 200 | 200 | final String job = "activate"; |
| 201 | 201 | final int ret = command.execWSF(job, windowTitle); |
| @@ -16,6 +16,12 @@ | ||
| 16 | 16 | |
| 17 | 17 | package jp.sourceforge.users.yutang.omegat.plugin.stats2excel; |
| 18 | 18 | |
| 19 | +import java.awt.event.WindowAdapter; | |
| 20 | +import java.awt.event.WindowEvent; | |
| 21 | +import java.io.IOException; | |
| 22 | +import java.util.concurrent.Executors; | |
| 23 | +import java.util.concurrent.ScheduledExecutorService; | |
| 24 | +import java.util.concurrent.TimeUnit; | |
| 19 | 25 | import org.omegat.gui.stat.StatisticsWindow; |
| 20 | 26 | import org.omegat.util.Log; |
| 21 | 27 | import org.omegat.util.StaticUtils; |
| @@ -26,8 +32,23 @@ | ||
| 26 | 32 | */ |
| 27 | 33 | public class SplashStatisticsWindow extends StatisticsWindow { |
| 28 | 34 | |
| 35 | + private ScheduledExecutorService service = null; | |
| 36 | + private boolean isErrorOnDisplay = false; | |
| 37 | + | |
| 29 | 38 | public SplashStatisticsWindow(STAT_TYPE statType) { |
| 30 | 39 | super(statType); |
| 40 | + | |
| 41 | + this.addWindowListener(new WindowAdapter() { | |
| 42 | + | |
| 43 | + @Override | |
| 44 | + public void windowClosing(WindowEvent e) { | |
| 45 | + if (service != null && !service.isShutdown()) { | |
| 46 | + service.shutdown(); | |
| 47 | + service = null; | |
| 48 | + } | |
| 49 | + } | |
| 50 | + | |
| 51 | + }); | |
| 31 | 52 | setSize(400, 100); |
| 32 | 53 | } |
| 33 | 54 |
| @@ -38,7 +59,7 @@ | ||
| 38 | 59 | throw new Exception("Error: Statistcs result is empty."); |
| 39 | 60 | } |
| 40 | 61 | |
| 41 | - super.displayData(L10n.getProgressMsgLaunchingExcel()); | |
| 62 | + setText(L10n.getProgressMsgLaunchingExcel()); | |
| 42 | 63 | |
| 43 | 64 | String title = StaticUtils.format( |
| 44 | 65 | L10n.getExcelWindowTitle(), |
| @@ -46,14 +67,46 @@ | ||
| 46 | 67 | ExcelModel.setWindowTitle(title); |
| 47 | 68 | ExcelModel.display(result); |
| 48 | 69 | } catch (Exception ex) { |
| 70 | + isErrorOnDisplay = true; | |
| 49 | 71 | Log.log(ex); |
| 50 | - super.displayData(ex.getMessage()); | |
| 72 | + setText(ex.getMessage()); | |
| 51 | 73 | } |
| 52 | 74 | } |
| 53 | 75 | |
| 54 | 76 | @Override |
| 55 | 77 | public void finishData() { |
| 56 | - dispose(); | |
| 78 | + if (isErrorOnDisplay) { | |
| 79 | + return; | |
| 80 | + } | |
| 81 | + | |
| 82 | + service = Executors.newSingleThreadScheduledExecutor(); | |
| 83 | + | |
| 84 | + service.scheduleWithFixedDelay(new Runnable() { | |
| 85 | + | |
| 86 | + @Override | |
| 87 | + public void run() { | |
| 88 | + try { | |
| 89 | + if (ExcelModel.activate()) { | |
| 90 | + service.shutdown(); | |
| 91 | + service = null; | |
| 92 | + dispose(); | |
| 93 | + } | |
| 94 | + } catch (IOException ex) { | |
| 95 | + Log.log(ex); | |
| 96 | + setText(ex.getLocalizedMessage()); | |
| 97 | + service.shutdown(); | |
| 98 | + service =null; | |
| 99 | + } catch (InterruptedException ex) { | |
| 100 | + Log.log(ex); | |
| 101 | + setText(ex.getLocalizedMessage()); | |
| 102 | + service.shutdown(); | |
| 103 | + service =null; | |
| 104 | + } | |
| 105 | + } | |
| 106 | + }, 0, 500, TimeUnit.MILLISECONDS); | |
| 57 | 107 | } |
| 58 | 108 | |
| 109 | + private void setText(String text) { | |
| 110 | + super.displayData(text); | |
| 111 | + } | |
| 59 | 112 | } |