1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| public class Aide extends VBean {
private static final ID Show = ID.registerProperty("SHOW");
private static final ID Clear = ID.registerProperty("CLEAR");
JFrame fm = new JFrame("SyGACUT Aide");
IHandler mHandler;
static String htmlString = "" ;
//public static void main(String[] args)
//{
// new Aide();
//}
public void init(IHandler handler)
{
super.init(handler);
mHandler = handler;
}
public boolean setProperty(ID property, Object value) {
if (property == Clear) {
htmlString = "" ;
return true;
}
else if(property == Show) {
htmlString = (String)value ;
Show();
return true;
}
// ------ other properties --------
else {
return super.setProperty(property, value);
}
}
private void Show()
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
// create jeditorpane
JEditorPane jEditorPane = new JEditorPane();
// make it read-only
jEditorPane.setEditable(false);
// create a scrollpane; modify its attributes as desired
JScrollPane scrollPane = new JScrollPane(jEditorPane);
// add an html editor kit
HTMLEditorKit kit = new HTMLEditorKit();
jEditorPane.setEditorKit(kit);
// add some styles to the html
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule("body {color:#000; font-family:times; margin: 4px; }");
styleSheet.addRule("h1 {color: blue;}");
styleSheet.addRule("h2 {color: #ff0000;}");
styleSheet.addRule("pre {font : 10px monaco; color : black; background-color : #fafafa; }");
// create some simple html as a string
/*String htmlString = "<html>\n"
+ "<body>\n"
+ "<hr/><center><h1>Welcome!</h1></center><hr/>\n"
+ "<h2>This is an H2 header</h2>\n"
+ "<p>This is some sample text</p>\n"
+ "<p><a href=\"http://devdaily.com/blog/\">devdaily blog</a></p>\n"
+ "</body>\n";*/
// create a document, set it on the jeditorpane, then add the html
Document doc = kit.createDefaultDocument();
jEditorPane.setDocument(doc);
jEditorPane.setText(htmlString);
// now add it all to a frame
//JFrame j = new JFrame("HtmlEditorKit Test");
fm.getContentPane().add(scrollPane, BorderLayout.CENTER);
// make it easy to close the application
//fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fm.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// display the frame
fm.setSize(new Dimension(500,400));
// pack it, if you prefer
//j.pack();
// center the jframe, then make it visible
fm.setLocationRelativeTo(null);
fm.setVisible(true);
}
});
}
} |
Partager