mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-16 18:25:57 +00:00
RichEdit control classes - miscellaneous applications built with the RichEdit control.
X-SVN-Rev: 1189
This commit is contained in:
parent
836a55c735
commit
d6ed5975e9
7 changed files with 519 additions and 0 deletions
46
icu4j/src/com/ibm/richtext/textapps/AppCloser.java
Executable file
46
icu4j/src/com/ibm/richtext/textapps/AppCloser.java
Executable file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* @(#)$RCSfile: AppCloser.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:48:51 $
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textapps;
|
||||
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Window;
|
||||
|
||||
class AppCloser {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private int fCount = 0;
|
||||
|
||||
private WindowAdapter fAdapter = new WindowAdapter() {
|
||||
|
||||
public void windowClosing(WindowEvent e) {
|
||||
--fCount;
|
||||
if (fCount == 0) {
|
||||
System.exit(0);
|
||||
}
|
||||
Window w = e.getWindow();
|
||||
w.setVisible(false);
|
||||
w.dispose();
|
||||
}
|
||||
};
|
||||
|
||||
public void listenToFrame(Frame frame) {
|
||||
|
||||
++fCount;
|
||||
frame.addWindowListener(fAdapter);
|
||||
}
|
||||
}
|
88
icu4j/src/com/ibm/richtext/textapps/BidiDemo.java
Executable file
88
icu4j/src/com/ibm/richtext/textapps/BidiDemo.java
Executable file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* @(#)$RCSfile: BidiDemo.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:48:51 $
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textapps;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import com.ibm.richtext.styledtext.StyledText;
|
||||
import com.ibm.textlayout.attributes.AttributeMap;
|
||||
import com.ibm.richtext.awtui.TextFrame;
|
||||
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.Toolkit;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Date;
|
||||
|
||||
public class BidiDemo {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final AppCloser fgListener = new AppCloser();
|
||||
|
||||
private static final String BUNDLE_NAME = "textapps.resources.Sample";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String docName;
|
||||
|
||||
if (args.length == 0) {
|
||||
docName = "default";
|
||||
}
|
||||
else {
|
||||
docName = args[0];
|
||||
}
|
||||
|
||||
openText(docName);
|
||||
}
|
||||
|
||||
private static void openText(String docName) {
|
||||
|
||||
try {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME);
|
||||
|
||||
Object document = bundle.getObject(docName+".sample");
|
||||
MConstText text;
|
||||
|
||||
if (document instanceof String) {
|
||||
text = new StyledText((String)document,
|
||||
AttributeMap.EMPTY_ATTRIBUTE_MAP);
|
||||
}
|
||||
else {
|
||||
URL url = (URL) document;
|
||||
ObjectInputStream in = new ObjectInputStream(url.openStream());
|
||||
text = (MConstText) in.readObject();
|
||||
}
|
||||
|
||||
String name = bundle.getString(docName+".name");
|
||||
|
||||
makeFrame(text, name);
|
||||
}
|
||||
catch(Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void makeFrame(MConstText text, String title) {
|
||||
|
||||
TextFrame frame = new TextFrame(text, title,
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard());
|
||||
frame.setSize(550, 700);
|
||||
frame.show();
|
||||
fgListener.listenToFrame(frame);
|
||||
}
|
||||
}
|
130
icu4j/src/com/ibm/richtext/textapps/FileUtils.java
Executable file
130
icu4j/src/com/ibm/richtext/textapps/FileUtils.java
Executable file
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* @(#)$RCSfile: FileUtils.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:48:51 $
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textapps;
|
||||
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
import java.io.*;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import com.ibm.richtext.styledtext.MText;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
/**
|
||||
* Present the user with a file dialog, and replace
|
||||
* dest with the MText in the selected file, and return
|
||||
* the file objct. If any errors occur, return null and
|
||||
* do not modify dest.
|
||||
*/
|
||||
public static File userLoadMText(String title, MText dest, Frame owner) {
|
||||
|
||||
FileDialog dialog = new FileDialog(owner, title, FileDialog.LOAD);
|
||||
dialog.show();
|
||||
String fileStr = dialog.getFile();
|
||||
String dirStr = dialog.getDirectory();
|
||||
|
||||
if (fileStr != null) {
|
||||
File rval = new File(dirStr, fileStr);
|
||||
MConstText src = loadMText(rval);
|
||||
if (src != null) {
|
||||
dest.replaceAll(src);
|
||||
return rval;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MText serialized in the given file.
|
||||
* In case of an error return null.
|
||||
*/
|
||||
public static MConstText loadMText(File file) {
|
||||
|
||||
Throwable error;
|
||||
|
||||
try {
|
||||
FileInputStream inStream = new FileInputStream(file);
|
||||
ObjectInputStream objStream = new ObjectInputStream(inStream);
|
||||
|
||||
MConstText text = (MConstText) objStream.readObject();
|
||||
inStream.close();
|
||||
return text;
|
||||
}
|
||||
catch(IOException e) {
|
||||
error = e;
|
||||
}
|
||||
catch(ClassNotFoundException e) {
|
||||
error = e;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
error.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt the user for the file if file is null. Then save the
|
||||
* text in the file, if any.
|
||||
*/
|
||||
public static File userSaveMText(File file, String title, MConstText text, Frame owner) {
|
||||
|
||||
if (file == null) {
|
||||
|
||||
FileDialog dialog = new FileDialog(owner, title, FileDialog.SAVE);
|
||||
dialog.show();
|
||||
String fileStr = dialog.getFile();
|
||||
String dirStr = dialog.getDirectory();
|
||||
|
||||
if (fileStr != null) {
|
||||
file = new File(dirStr, fileStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (file != null) {
|
||||
|
||||
saveMText(file, text);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
public static void saveMText(File file, MConstText text) {
|
||||
|
||||
Throwable error;
|
||||
|
||||
try {
|
||||
OutputStream outStream = new FileOutputStream(file);
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(outStream);
|
||||
|
||||
objStream.writeObject(text);
|
||||
outStream.close();
|
||||
return;
|
||||
}
|
||||
catch(IOException e) {
|
||||
error = e;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
84
icu4j/src/com/ibm/richtext/textapps/MTextToString.java
Executable file
84
icu4j/src/com/ibm/richtext/textapps/MTextToString.java
Executable file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* @(#)$RCSfile: MTextToString.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:48:51 $
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textapps;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public final class MTextToString {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
if (args.length != 2) {
|
||||
usage();
|
||||
}
|
||||
else {
|
||||
writeMTextAsString(args[0], args[1]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void usage() {
|
||||
|
||||
System.out.println("Usage: MTextToString inFile outFile");
|
||||
System.out.println("inFile must be a serialized MConstText");
|
||||
System.out.println("On exit, outFile will be a serialized String ");
|
||||
System.out.println("containing the characters in the text.");
|
||||
System.out.println("inFile and outFile must not be the same.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
public static void writeMTextAsString(String inFile, String outFile) {
|
||||
|
||||
File file = new File(inFile);
|
||||
MConstText text = FileUtils.loadMText(file);
|
||||
|
||||
if (text != null) {
|
||||
char[] ch = new char[text.length()];
|
||||
text.extractChars(0, ch.length, ch, 0);
|
||||
String str = new String(ch);
|
||||
writeString(str, outFile);
|
||||
}
|
||||
else {
|
||||
System.out.println("Can't read inFile.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeString(String stringToWrite, String outFile) {
|
||||
|
||||
File file = new File(outFile);
|
||||
Throwable error = null;
|
||||
|
||||
try {
|
||||
OutputStream outStream = new FileOutputStream(file);
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(outStream);
|
||||
|
||||
objStream.writeObject(stringToWrite);
|
||||
outStream.close();
|
||||
return;
|
||||
}
|
||||
catch(IOException e) {
|
||||
error = e;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
78
icu4j/src/com/ibm/richtext/textapps/StringToMText.java
Executable file
78
icu4j/src/com/ibm/richtext/textapps/StringToMText.java
Executable file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* @(#)$RCSfile: StringToMText.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:48:51 $
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textapps;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import com.ibm.richtext.styledtext.StyledText;
|
||||
import com.ibm.textlayout.attributes.AttributeMap;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public final class StringToMText {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
if (args.length != 2 || args[0].equals(args[1])) {
|
||||
usage();
|
||||
}
|
||||
else {
|
||||
String str = loadString(new File(args[0]));
|
||||
if (str == null) {
|
||||
throw new Error("Couldn't load String from file " + args[0]);
|
||||
}
|
||||
MConstText text = new StyledText(str, AttributeMap.EMPTY_ATTRIBUTE_MAP);
|
||||
FileUtils.saveMText(new File(args[1]), text);
|
||||
}
|
||||
}
|
||||
|
||||
private static void usage() {
|
||||
|
||||
System.out.println("Usage: StringToMText inFile outFile");
|
||||
System.out.println("inFile must be a serialized String");
|
||||
System.out.println("On exit, outFile will be a serialized MText ");
|
||||
System.out.println("containing the characters in the string.");
|
||||
System.out.println("inFile and outFile must not be the same.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
public static String loadString(File file) {
|
||||
|
||||
Throwable error;
|
||||
|
||||
try {
|
||||
FileInputStream inStream = new FileInputStream(file);
|
||||
ObjectInputStream objStream = new ObjectInputStream(inStream);
|
||||
|
||||
String str = (String) objStream.readObject();
|
||||
inStream.close();
|
||||
return str;
|
||||
}
|
||||
catch(IOException e) {
|
||||
error = e;
|
||||
}
|
||||
catch(ClassNotFoundException e) {
|
||||
error = e;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
error.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
77
icu4j/src/com/ibm/richtext/textapps/TestMTextToString.java
Executable file
77
icu4j/src/com/ibm/richtext/textapps/TestMTextToString.java
Executable file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* @(#)$RCSfile: TestMTextToString.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:48:51 $
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998-1999. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textapps;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import java.io.File;
|
||||
|
||||
public final class TestMTextToString {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
public static void main(String[] args) {
|
||||
|
||||
if (args.length != 2 || args[0].equals(args[1])) {
|
||||
usage();
|
||||
}
|
||||
else {
|
||||
boolean success = testMTextToString(args[0], args[1]);
|
||||
System.out.println(success? "PASSED" : "FAILED");
|
||||
}
|
||||
}
|
||||
|
||||
private static void usage() {
|
||||
|
||||
System.out.println("Usage: TestMTextToString mtextFile stringFile");
|
||||
System.out.println("Compares the characters in mtextFile to the");
|
||||
System.out.println("String in stringFile.");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public static boolean testMTextToString(String mtextFile, String stringFile) {
|
||||
|
||||
boolean success = false;
|
||||
|
||||
File mtext = new File(mtextFile);
|
||||
MConstText text = FileUtils.loadMText(mtext);
|
||||
if (text != null) {
|
||||
String str = StringToMText.loadString(new File(stringFile));
|
||||
if (str != null) {
|
||||
success = compareMTextToString(text, str);
|
||||
}
|
||||
else {
|
||||
System.out.println("Couldn't load String.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
System.out.println("Couldn't load MText.");
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public static boolean compareMTextToString(MConstText text, String str) {
|
||||
|
||||
if (text.length() != str.length()) {
|
||||
return false;
|
||||
}
|
||||
for (int i=str.length()-1; i >= 0; i--) {
|
||||
if (text.at(i) != str.charAt(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
16
icu4j/src/com/ibm/richtext/textapps/resources/Sample.java
Executable file
16
icu4j/src/com/ibm/richtext/textapps/resources/Sample.java
Executable file
|
@ -0,0 +1,16 @@
|
|||
package com.ibm.richtext.textapps.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public final class Sample extends ListResourceBundle {
|
||||
|
||||
public Object[][] getContents() {
|
||||
|
||||
return new Object[][] {
|
||||
{ "default.sample", this.getClass().getResource("hagan") },
|
||||
{ "default.name", "The Garden" },
|
||||
{ "japanese.sample", "\u6ce8: {1} \u306e\u30e1\u30bd\u30c3\u30c9 {0} \u306f\u63a8\u5968\u3055\u308c\u307e\u305b\u3093\u3002" },
|
||||
{ "japanese.name", "Japanese Message" },
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue