Last active
August 29, 2015 13:55
-
-
Save yu-tang/8714231 to your computer and use it in GitHub Desktop.
OmegaT scripting: Open segmentation customizer with large font
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Open segmentation customizer with large font | |
* | |
* @author Yu Tang | |
* @date 2013-01-31 | |
* @version 0.2 | |
*/ | |
import java.awt.Component; | |
import java.awt.event.WindowAdapter; | |
import java.awt.event.WindowEvent; | |
import java.awt.Font; | |
import java.awt.Window; | |
import javax.swing.DefaultCellEditor; | |
import javax.swing.JComponent; | |
import javax.swing.JDialog; | |
import javax.swing.JOptionPane; | |
import javax.swing.JTable; | |
import javax.swing.JTextField; | |
import javax.swing.plaf.FontUIResource; | |
import javax.swing.table.TableColumn; | |
import javax.swing.UIDefaults; | |
import javax.swing.UIManager; | |
import org.omegat.core.Core; | |
import org.omegat.core.segmentation.SRX; | |
import org.omegat.gui.segmentation.SegmentationCustomizer; | |
import org.omegat.gui.main.ProjectUICommands; | |
import org.omegat.util.OStrings; | |
import org.omegat.util.Preferences; | |
// User config | |
boolean projectSpecific = true // set false if you want to edit global segmentation rules. | |
SRX projectSRX = null; | |
if (projectSpecific) { | |
if (!project.isProjectLoaded()) { | |
mainWindow.showMessageDialog "Please try again after open your project." | |
return | |
} | |
projectSRX = project.projectProperties.projectSRX | |
} | |
def oldUITable = changeUI(); | |
SegmentationCustomizer segment_window = new SegmentationCustomizer(mainWindow, projectSpecific, SRX.default, | |
Preferences.SRX, projectSRX) | |
segment_window.addWindowListener(new WindowAdapter() { | |
@Override | |
public void windowOpened(WindowEvent e) { | |
final int LINE_SPACING = 6 | |
Window window = e.window | |
JTable ruleTable = window.ruleTable | |
JTable mapTable = window.mapTable | |
Font font = ruleTable.font | |
// change table's row height | |
int rowHeight = font.size + LINE_SPACING | |
mapTable.rowHeight = ruleTable.rowHeight = rowHeight | |
} | |
}); | |
segment_window.setVisible(true); | |
restoreUI(oldUITable) | |
if (segment_window.returnStatus == SegmentationCustomizer.RET_OK) { | |
// save changes | |
if (projectSpecific) { | |
project.projectProperties.projectSRX = segment_window.SRX | |
} else { | |
Preferences.SRX = segment_window.SRX | |
} | |
boolean needReload = projectSpecific || (project.isProjectLoaded() && project.projectProperties.projectSRX == null) | |
if (needReload) { | |
// asking to reload a project | |
int res = JOptionPane.showConfirmDialog(mainWindow, OStrings.getString("MW_REOPEN_QUESTION"), | |
OStrings.getString("MW_REOPEN_TITLE"), JOptionPane.YES_NO_OPTION); | |
if (res == JOptionPane.YES_OPTION) { | |
ProjectUICommands.projectReload() | |
} | |
} | |
} | |
// sub routines | |
def changeUI() { | |
def oldUITable = [:]; | |
FontUIResource font = new FontUIResource(getLargeFont()) | |
oldUITable["Table.font"] = UIManager.put("Table.font", font) | |
oldUITable["TextField.font"] = UIManager.put("TextField.font", font) | |
oldUITable["ScrollBar.width"] = UIManager.put("ScrollBar.width", 24) | |
oldUITable; | |
} | |
def restoreUI(oldUITable) { | |
oldUITable.each { UIManager.put it.key, it.value } | |
} | |
def getLargeFont() { | |
final Font appFont = Core.getMainWindow().getApplicationFont() | |
final int newFontSize = appFont.getSize() * 2 | |
new Font(appFont.getFontName(), appFont.getStyle(), newFontSize); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment