📄 rtextl10ngenplugin.java
字号:
* @return The options panel.
*/
public PluginOptionsDialogPanel getOptionsDialogPanel() {
return null;
}
/*****************************************************************************/
/**
* Returns the prefix to use in the resource bundle for many keys.
*
* @return The prefix.
*/
private final String getPrefix() {
return "Plugin.Wizard." + (mode==MODE_CREATE ? "Create.":"Package.");
}
/*****************************************************************************/
/**
* Returns the parent RText instance.
*
* @return The parent RText instance.
*/
public RText getRText() {
return rtext;
}
/*****************************************************************************/
/**
* Returns the version of the plugin.
*
* @return The version number of this plugin.
*/
public String getVersion() {
return VERSION;
}
/*****************************************************************************/
/**
* Returns the title of the Wizard dialog.
*
* @return The title of the wizard dialog.
*/
public String getWizardDialogTitle() {
return msg.getString(getPrefix() + "DialogTitle");
}
/*****************************************************************************/
/**
* Returns the dialog information to display when the wizard has
* completed successfully.
*
* @param dialog The dialog in which this information will be displayed.
* @return The panel.
* @see #getIntroductionPanel
* @see #getInfoPanel
*/
protected WizardDialogInfoPanel getWizardSuccessfulPanel(
WizardPluginDialog dialog) {
switch (mode) {
case MODE_CREATE:
return new CreatePlaypenSuccessfulPanel(msg);
default:
case MODE_PACKAGE:
return new PackagePlaypenSuccessfulPanel(msg);
}
}
/*****************************************************************************/
/**
* This method is called if the user runs the wizard and clicks the
* "Finish" button; e.g., the wizard has run to completion. Subclasses
* should override this method to perform whatever action the wizard was
* gathering information about.
*
* @param panels The "step" panels in which the user entered values.
*/
protected void handleWizardSuccessful(WizardDialogInfoPanel[] panels) {
}
/*****************************************************************************/
/**
* Called just after a plugin is added to a GUI application. If this is
* a <code>GUIPlugin</code>, it has already been added visually. Plugins
* should use this method to register any listeners to the GUI application
* and do any other necessary setup.
*
* @param app The application to which this plugin was just added.
* @see #uninstall
*/
public void install(AbstractPluggableGUIApplication app) {
}
/*****************************************************************************/
/**
* Returns whether or not the specified character is a hex character
* (<code>0-9</code>, <code>a-f</code>, or <code>A-F</code>).
*
* @param ch The character.
* @return Whether or not the character is a hex character.
*/
private static final boolean isHex(char ch) {
return (ch>='0' && ch<='9') || (ch>='a' && ch<='f') ||
(ch>='A' && ch<='F');
}
/*****************************************************************************/
/**
* Creates ASCII versions of the UTF-16LE files in the specified directory
* tree and adds them to a single zip file.
*
* @param rootDir The root directory.
* @param dir The directory to add to the zip file.
* @param zipOut An output stream writing to the zip file.
* @return Whether or not the packaging was successful.
* @throws IOException If an IO error occurs.
*/
protected void packageDirectory(String rootDir, File dir,
ZipOutputStream zipOut) throws IOException {
if (dir!=null) {
File[] files = dir.listFiles();
int count = files.length;
for (int i=0; i<count; i++) {
if (files[i].isDirectory()) {
packageDirectory(rootDir, files[i], zipOut);
}
else if (files[i].getName().endsWith(".properties")) {
String name = files[i].getAbsolutePath();
if (name.startsWith(rootDir)) { // Always true.
name = name.substring(rootDir.length());
}
ZipEntry entry = new ZipEntry(name);
zipOut.putNextEntry(entry);
writeAsAscii(files[i], zipOut);
zipOut.closeEntry();
}
}
}
}
/*****************************************************************************/
/**
* Creates ASCII versions of the UTF-16LE files in the specified directory
* tree and adds them to a single zip file.
*
* @param playpen The directory to add to the zip file.
* @param zipFile The zip file to create.
* @return Whether or not the packaging was successful.
* @throws IOException If an IO error occurs.
*/
public boolean packagePlaypen(File playpen, File zipFile) throws IOException {
ZipOutputStream zipOut = new ZipOutputStream(
new FileOutputStream(zipFile));
String rootDir = playpen.getAbsolutePath();
if (!rootDir.endsWith(File.separator))
rootDir = rootDir + File.separator;
packageDirectory(rootDir, playpen, zipOut);
zipOut.close();
return true;
}
/*****************************************************************************/
/**
* Called when the GUI application is shutting down. When this method is
* called, the <code>Plugin</code> should save any properties via the
* Java Preferences API.
*
* @see PluginPreferences
*/
public void savePreferences() {
}
/*****************************************************************************/
/**
* Called just before this <code>Plugin</code> is removed from an
* <code>GUIApplication</code>. This gives the plugin a chance to clean
* up any loose ends (kill any threads, close any files, remove listeners,
* etc.).
*
* @return Whether the uninstall went cleanly.
* @see #install
*/
public boolean uninstall() {
return true;
}
/*****************************************************************************/
/**
* Reads characters from the UTF-16LE file and writes them to the specified
* output stream as US-ASCII. Characters > <code>127</code> are
* converted to their Unicode escape (e.g. <code>\\uXXXX</code>, where
* <code>XXXX</code> is the hexadecimal representation of the character).
*
* @param inFile The UTF-16LE file to read.
* @param out The output stream to write to.
* @throws IOException If an IO error occurs.
*/
protected void writeAsAscii(File inFile, ZipOutputStream out) throws IOException {
UnicodeReader r = new UnicodeReader(inFile, "UTF-16LE");
int count = 0;
char[] buf = new char[BUF_SIZE];
while ((count=r.read(buf, 0,BUF_SIZE))!=-1) {
//w.write(buf, 0,count);
for (int i=0; i<count; i++) {
if (buf[i]<128) { // Already US-ASCII 7-bit char.
out.write(buf[i]);
}
else { // UTF-16LE char; convert to \\uXXXX.
out.write('\\');
out.write('u');
String hex = Integer.toHexString(buf[i]);
while (hex.length()<4)
hex = "0" + hex;
for (int j=0; j<4; j++)
out.write(hex.charAt(j));
}
}
}
r.close();
}
/*****************************************************************************/
/**
* Reads characters from the input stream and writes them to the
* specified file in UTF-16LE, converting any sequences of the form
* <code>\\uXXXX</code> to a single character, where <code>XXXX</code>
* is the hexadecimal representation of the character.
*
* @param in The input streamfrom which to read.
* @param newFile The file to write the UTF-16LE output to.
* @throws IOException If an IO error occurs.
*/
protected void writeUtf16LE(InputStream in, File newFile) throws IOException {
InputStreamReader r = new InputStreamReader(in, "US-ASCII");
UnicodeWriter w = new UnicodeWriter(newFile, "UTF-16LE");
int count = 0;
char[] buf = new char[BUF_SIZE];
while ((count=r.read(buf, 0,BUF_SIZE))!=-1) {
//w.write(buf, 0,count);
int i = 0;
do {
switch (buf[i]) {
case '\\':
if (i<count-5 && buf[i+1]=='u' &&
isHex(buf[i+2]) && isHex(buf[i+3]) &&
isHex(buf[i+4]) && isHex(buf[i+5])) {
try {
int j = Integer.parseInt(new String(buf, i+2,4), 16);
w.write((char)j);
i += 5;
} catch (Exception ex) {
throw new IOException("Invalid property file: " + name);
}
}
else {
w.write(buf[i]);
}
break;
default:
w.write(buf[i]);
break;
}
} while (++i<count);
}
w.flush();
w.close();
r.close();
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -