Last active
December 19, 2015 09:58
-
-
Save yu-tang/5936513 to your computer and use it in GitHub Desktop.
OmegaT scripting: Demonstrate to display first glossary entry to custom pane.
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
/* | |
* OmegaT scripting: | |
* Demonstrate to display first glossary entry to custom pane | |
* | |
* @author Yu Tang | |
* @date 2013-07-07 | |
* @version 0.2 | |
*/ | |
import java.awt.Component | |
import java.awt.Container | |
import java.awt.Dimension | |
import javax.swing.JScrollPane | |
import javax.swing.JTextPane | |
import org.omegat.core.Core | |
import org.omegat.gui.glossary.GlossaryEntry | |
import org.omegat.gui.glossary.GlossaryManager | |
import org.omegat.gui.main.DockableScrollPane | |
import org.omegat.util.gui.AlwaysVisibleCaret | |
import com.vlsolutions.swing.docking.Dockable | |
import com.vlsolutions.swing.docking.DockableState | |
import com.vlsolutions.swing.docking.DockingDesktop | |
import com.vlsolutions.swing.docking.DockKey | |
main() | |
def main() { | |
final String PANE_KEY = "MY_GLOSSARY" | |
final String PANE_NAME = "My Glossary" // Title | |
final String PANE_DESCRIPTION = "This is your glossary" | |
final String GLOSSARY_PATH = /Your\glossary\file\path/ | |
DockableScrollPane pane = | |
getPane(PANE_KEY) ?: | |
createPane([key: PANE_KEY, name: PANE_NAME, description: PANE_DESCRIPTION]) | |
File file = new File(GLOSSARY_PATH) | |
List<GlossaryEntry> list = Core.glossaryManager.loadGlossaryFile(file) | |
// demonstrate to display first glossary entry | |
pane.viewport.view.text = list[0] | |
} | |
DockableScrollPane getPane(String paneKey) { | |
for (DockableState ds: [email protected]) { | |
Dockable d = ds.dockable | |
if (paneKey == d.dockKey.key) { | |
return DockableScrollPane.class.cast(d) | |
} | |
} | |
// Not found | |
null | |
} | |
private DockableScrollPane createPane(Map args) { | |
JTextPane tp = new JTextPane() | |
tp.setEditable false | |
AlwaysVisibleCaret.apply tp | |
tp.setText args.description | |
tp.setMinimumSize new Dimension(100, 50) | |
DockableScrollPane pane = new DockableScrollPane(args.key, args.name, tp, true) | |
mainWindow.addDockable pane | |
pane | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment