ICU-5933 icu4j demos
X-SVN-Rev: 22684
This commit is contained in:
parent
546faac4ab
commit
b9384ca1ea
@ -82,6 +82,7 @@
|
||||
<property name="icudatajar.file" value="${src.dir}/com/ibm/icu/impl/data/icudata.jar" />
|
||||
<property name="testjar.file" value="icu4jtests.jar" />
|
||||
<property name="jar.file" value="icu4j.jar" />
|
||||
<property name="demos-jar.file" value="icu4jdemos.jar" />
|
||||
<property name="charsets.jar.file" value="icu4j-charsets.jar" />
|
||||
<property name="jarSrc.file" value="icu4jsrc.jar" />
|
||||
<property name="zipTestSrc.file" value="icu4jtsrc.zip" />
|
||||
@ -346,6 +347,7 @@
|
||||
debug="on"
|
||||
deprecation="off">
|
||||
<include name="com/ibm/icu/dev/demo/**/*.java" />
|
||||
<include name="com/ibm/icu/dev/demo/*.java" />
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
@ -639,6 +641,26 @@
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="jarDemos" depends="demos" description="build demos to 'icu4jdemos.jar' jar file">
|
||||
<jar jarfile="${demos-jar.file}" compress="true">
|
||||
<fileset dir="${build.dir}" includes="com/ibm/icu/dev/demo/**" />
|
||||
<manifest>
|
||||
<attribute name="Built-By" value="${corp}" />
|
||||
<section name="common">
|
||||
<attribute name="Specification-Title" value="${manifest.specification.title}" />
|
||||
<attribute name="Specification-Version" value="${icu4j.spec.version.string}" />
|
||||
<attribute name="Specification-Vendor" value="ICU" />
|
||||
<attribute name="Implementation-Title" value=" ICU for Java Demos" />
|
||||
<attribute name="Implementation-Version" value="${icu4j.impl.version.string}" />
|
||||
<attribute name="Implementation-Vendor" value="${corp}" />
|
||||
<attribute name="Implementation-Vendor-Id" value="com.ibm" />
|
||||
<attribute name="Copyright-Info" value="${copyright}" />
|
||||
<attribute name="Sealed" value="false" />
|
||||
</section>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="translitIMEJar" depends="collator, transliterator" description="build transliterator IME 'icutransime.jar' jar file">
|
||||
<javac includes="com/ibm/icu/dev/tool/ime/translit/*.java" excludes="**/CVS/**/*" srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath" source="${icu4j.javac.source}" target="${icu4j.javac.target}" debug="on" deprecation="off" />
|
||||
<copy file="${src.dir}/com/ibm/icu/dev/tool/ime/translit/Transliterator.properties" todir="${build.dir}/com/ibm/icu/dev/tool/ime/translit" />
|
||||
|
186
icu4j/src/com/ibm/icu/dev/demo/Launcher.java
Normal file
186
icu4j/src/com/ibm/icu/dev/demo/Launcher.java
Normal file
@ -0,0 +1,186 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2007, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.icu.dev.demo;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.Color;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Label;
|
||||
import java.awt.Panel;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import com.ibm.icu.dev.demo.impl.DemoApplet;
|
||||
import com.ibm.icu.dev.demo.impl.DemoUtility;
|
||||
import com.ibm.icu.util.VersionInfo;
|
||||
|
||||
|
||||
/**
|
||||
* @author srl
|
||||
* Application to provide a panel of demos to launch
|
||||
*/
|
||||
public class Launcher extends DemoApplet {
|
||||
private static final long serialVersionUID = -8054963875776183877L;
|
||||
|
||||
/**
|
||||
* base package of all demos
|
||||
*/
|
||||
public static final String demoBase = "com.ibm.icu.dev.demo";
|
||||
/**
|
||||
* list of classes, relative to the demoBase. all must have a static void main(String[])
|
||||
*/
|
||||
public static final String demoList[] = {
|
||||
"calendar.CalendarApp",
|
||||
"charsetdet.DetectingViewer",
|
||||
"holiday.HolidayCalendarDemo",
|
||||
// "number.CurrencyDemo", -- console
|
||||
// "rbbi.DBBIDemo",
|
||||
// "rbbi.RBBIDemo",
|
||||
// "rbbi.TextBoundDemo",
|
||||
"rbnf.RbnfDemo",
|
||||
// "timescale.PivotDemo", -- console
|
||||
"translit.Demo",
|
||||
};
|
||||
|
||||
public class LauncherFrame extends Frame implements ActionListener {
|
||||
private static final long serialVersionUID = -8054963875776183878L;
|
||||
|
||||
public Button buttonList[] = new Button[demoList.length]; // one button for each demo
|
||||
public Label statusLabel;
|
||||
private DemoApplet applet;
|
||||
|
||||
LauncherFrame(DemoApplet applet) {
|
||||
init();
|
||||
this.applet = applet;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
// close down when close is clicked.
|
||||
// TODO: this should be factored..
|
||||
addWindowListener(
|
||||
new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
|
||||
if (applet != null) {
|
||||
applet.demoClosed();
|
||||
} else System.exit(0);
|
||||
}
|
||||
} );
|
||||
|
||||
setBackground(DemoUtility.bgColor);
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
Panel topPanel = new Panel();
|
||||
topPanel.setLayout(new GridLayout(5,3));
|
||||
|
||||
for(int i=0;i<buttonList.length;i++) {
|
||||
String demo = demoList[i];
|
||||
Button b = new Button(demo);
|
||||
b.addActionListener(this);
|
||||
buttonList[i]=b;
|
||||
topPanel.add(b);
|
||||
}
|
||||
add(BorderLayout.CENTER,topPanel);
|
||||
statusLabel = new Label("");
|
||||
statusLabel.setAlignment(Label.LEFT);
|
||||
add(BorderLayout.NORTH, new Label(
|
||||
"ICU Demos \u2022 ICU version "+VersionInfo.ICU_VERSION +
|
||||
" \u2022 http://icu-project.org"));
|
||||
add(BorderLayout.SOUTH,statusLabel);
|
||||
// set up an initial status.
|
||||
showStatus(buttonList.length+" demos ready. ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the 'status' field, and set it to black
|
||||
* @param status
|
||||
*/
|
||||
void showStatus(String status) {
|
||||
statusLabel.setText(status);
|
||||
statusLabel.setForeground(Color.BLACK);
|
||||
statusLabel.setBackground(Color.WHITE);
|
||||
// statusLabel.setFont(Font.PLAIN);
|
||||
doLayout();
|
||||
}
|
||||
void showStatus(String demo, String status) {
|
||||
showStatus(demo+": "+status);
|
||||
}
|
||||
void showFailure(String status) {
|
||||
statusLabel.setText(status);
|
||||
statusLabel.setBackground(Color.GRAY);
|
||||
statusLabel.setForeground(Color.RED);
|
||||
// statusLabel.setFont(Font.BOLD);
|
||||
doLayout();
|
||||
}
|
||||
void showFailure(String demo, String status) {
|
||||
showFailure(demo+": "+status);
|
||||
}
|
||||
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// find button
|
||||
for(int i=0;i<buttonList.length;i++) {
|
||||
if(e.getSource() == buttonList[i]) {
|
||||
String demoShort = demoList[i];
|
||||
String demo = demoBase+'.'+demoShort;
|
||||
showStatus(demoShort, "launching");
|
||||
try {
|
||||
Class c = Class.forName(demo);
|
||||
String args[] = new String[0];
|
||||
Class params[] = new Class[1];
|
||||
params[0] = args.getClass();
|
||||
Method m = c.getMethod("main", params );
|
||||
Object[] argList = { args };
|
||||
m.invoke(null, argList);
|
||||
showStatus(demoShort, "launched.");
|
||||
} catch (ClassNotFoundException e1) {
|
||||
showFailure(demoShort,e1.toString());
|
||||
e1.printStackTrace();
|
||||
} catch (SecurityException se) {
|
||||
showFailure(demoShort,se.toString());
|
||||
se.printStackTrace();
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
showFailure(demoShort,nsme.toString());
|
||||
nsme.printStackTrace();
|
||||
} catch (IllegalArgumentException iae) {
|
||||
showFailure(demoShort,iae.toString());
|
||||
iae.printStackTrace();
|
||||
} catch (IllegalAccessException iae) {
|
||||
showFailure(demoShort,iae.toString());
|
||||
iae.printStackTrace();
|
||||
} catch (InvocationTargetException ite) {
|
||||
showFailure(demoShort,ite.toString());
|
||||
ite.printStackTrace();
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* This creates a Frame for the demo applet. */
|
||||
protected Frame createDemoFrame(DemoApplet applet) {
|
||||
return new LauncherFrame(applet);
|
||||
}
|
||||
|
||||
/**
|
||||
* The main function which defines the behavior of the Demo
|
||||
* applet when an applet is started.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
new Launcher().showDemo();
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ import java.nio.charset.Charset;
|
||||
import javax.swing.*;
|
||||
|
||||
import com.ibm.icu.charset.CharsetICU;
|
||||
import com.ibm.icu.dev.demo.impl.DemoApplet;
|
||||
import com.ibm.icu.text.CharsetDetector;
|
||||
import com.ibm.icu.text.CharsetMatch;
|
||||
|
||||
@ -42,10 +43,11 @@ public class DetectingViewer extends JFrame implements ActionListener
|
||||
public DetectingViewer()
|
||||
{
|
||||
super();
|
||||
DemoApplet.demoFrameOpened();
|
||||
|
||||
fileChooser = new JFileChooser();
|
||||
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setSize(800, 800);
|
||||
|
||||
setJMenuBar(makeMenus());
|
||||
@ -61,6 +63,18 @@ public class DetectingViewer extends JFrame implements ActionListener
|
||||
|
||||
getContentPane().add(scrollPane);
|
||||
setVisible(true);
|
||||
|
||||
addWindowListener(
|
||||
new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
// setVisible(false);
|
||||
// dispose();
|
||||
|
||||
doQuit();
|
||||
}
|
||||
} );
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent event)
|
||||
@ -345,7 +359,9 @@ public class DetectingViewer extends JFrame implements ActionListener
|
||||
|
||||
private void doQuit()
|
||||
{
|
||||
System.exit(0);
|
||||
DemoApplet.demoFrameClosed();
|
||||
this.setVisible(false);
|
||||
this.dispose();
|
||||
}
|
||||
|
||||
private JMenuBar makeMenus()
|
||||
|
@ -60,13 +60,16 @@ public abstract class DemoApplet extends java.applet.Applet {
|
||||
demoFrameClosed();
|
||||
}
|
||||
|
||||
protected static void demoFrameOpened() {
|
||||
public static void demoFrameOpened() {
|
||||
demoFrameCount++;
|
||||
System.err.println("DemoFrameOpened, now at:"+demoFrameCount);
|
||||
}
|
||||
protected static void demoFrameClosed() {
|
||||
public static void demoFrameClosed() {
|
||||
if (--demoFrameCount == 0) {
|
||||
System.err.println("DemoFrameClosed, now at:"+demoFrameCount + " - quitting");
|
||||
System.exit(0);
|
||||
}
|
||||
System.err.println("DemoFrameClosed, now at:"+demoFrameCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,6 +335,18 @@ public class RbnfDemo extends DemoApplet {
|
||||
|
||||
window.doLayout();
|
||||
window.show();
|
||||
final DemoApplet theApplet = applet;
|
||||
window.addWindowListener(
|
||||
new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
setVisible(false);
|
||||
window.dispose();
|
||||
|
||||
if (theApplet != null) {
|
||||
theApplet.demoClosed();
|
||||
} else System.exit(0);
|
||||
}
|
||||
} );
|
||||
return window;
|
||||
}
|
||||
|
||||
|
@ -64,10 +64,12 @@ public class Demo extends Frame {
|
||||
Frame f = new Demo(600, 200);
|
||||
f.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
com.ibm.icu.dev.demo.impl.DemoApplet.demoFrameClosed();
|
||||
// System.exit(0);
|
||||
}
|
||||
});
|
||||
f.setVisible(true);
|
||||
com.ibm.icu.dev.demo.impl.DemoApplet.demoFrameOpened();
|
||||
}
|
||||
|
||||
public Demo(int width, int height) {
|
||||
|
Loading…
Reference in New Issue
Block a user