逛奔的蜗牛

我不聪明,但我会很努力

   ::  :: 新随笔 ::  ::  :: 管理 ::

如果你想在Java应用中嵌入一个功能强大的文字编辑器,那么XDocBuilder可能是最好的选择
1、免费
2、格式丰富,可以处理段落、文字、图形、图片、图表、表格等
3、文件格式支持丰富:xdoc、docx、pdf、rtf、doc、htm、txt、swf、svg等
4、标准格式xdoc是一个简单的xml文本
5、包依赖少,只有一个包是必须的
6、嵌入简单,它只是一个JComponent
7、API功能强大:打开、编辑、打印、格式转换等

程序库:

 

名称

用途

下载地址

hg.jar

主程序库(必须)

http://www.hgsql.com/xdoc/lib/hg.jar

fgio.jar

输出swfsvgemfps

http://www.hgsql.com/xdoc/lib/fgio.jar

filters.jar

滤镜

http://www.hgsql.com/xdoc/lib/filters.jar

itext.jar

输出pdfrtf

http://www.hgsql.com/xdoc/lib/itext.jar

jfreechart.jar

图表

http://www.hgsql.com/xdoc/lib/jfreechart.jar

poi.jar

读取doc、输出xlsppt

http://www.hgsql.com/xdoc/lib/poi.jar

api文档:

http://www.hgsql.com/XDocApi/index.html

在线:

http://www.hgsql.com/XDocBuilder.asp

例子:

Java代码  收藏代码
  1. import java.awt.BorderLayout;  
  2. import java.awt.Container;  
  3. import java.awt.event.ActionEvent;  
  4. import java.awt.event.ActionListener;  
  5. import java.awt.event.WindowEvent;  
  6. import java.awt.event.WindowListener;  
  7. import java.io.File;  
  8.   
  9. import javax.swing.JButton;  
  10. import javax.swing.JFrame;  
  11. import javax.swing.JOptionPane;  
  12. import javax.swing.JToolBar;  
  13. import javax.swing.UIManager;  
  14.   
  15. import com.hg.xdoc.XDocBuilder;  
  16. import com.hg.xdoc.XDocIO;  
  17.   
  18. /** 
  19.  * XDocBuilder嵌入测试 
  20.  * @author xdoc 
  21.  */  
  22. public class XDocBuilderTest {  
  23.     private static XDocBuilder builder;  
  24.     /** 
  25.      * @param args 
  26.      */  
  27.     public static void main(String[] args) {  
  28.         try {  
  29.             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());  
  30.             //获取XDocBuilder实例  
  31.             builder = new XDocBuilder();  
  32.             JFrame frame = new JFrame("XDocBuilder嵌入测试");  
  33.             //将XDocBuilder放入面板中  
  34.             frame.getContentPane().add(builder, BorderLayout.CENTER);  
  35.             JToolBar bar = new JToolBar("工具条");  
  36.             JButton btn = new JButton("新建");  
  37.             btn.addActionListener(new ActionListener() {  
  38.                 public void actionPerformed(ActionEvent e) {  
  39.                     //新建  
  40.                     builder.create();  
  41.                 }  
  42.             });  
  43.             btn = new JButton("打开");  
  44.             btn.addActionListener(new ActionListener() {  
  45.                 public void actionPerformed(ActionEvent e) {  
  46.                     //打开  
  47.                     builder.open();  
  48.                     //builder.open("http://www.hgsql.com/down/XDocIntro.xdoc", XDocIO.READ_FORMAT_XDOC);  
  49.                 }  
  50.             });  
  51.             bar.add(btn);  
  52.             btn = new JButton("查看XML");  
  53.             btn.addActionListener(new ActionListener() {  
  54.                 public void actionPerformed(ActionEvent e) {  
  55.                     //显示XML内容  
  56.                     try {  
  57.                         JOptionPane.showMessageDialog(null, builder.getXml());  
  58.                     } catch (Exception e1) {  
  59.                         JOptionPane.showMessageDialog(null, e1.getMessage());  
  60.                     }  
  61.                 }  
  62.             });  
  63.             bar.add(btn);  
  64.             btn = new JButton("保存");  
  65.             btn.addActionListener(new ActionListener() {  
  66.                 public void actionPerformed(ActionEvent e) {  
  67.                     //保存当前文件  
  68.                     builder.save();  
  69.                 }  
  70.             });  
  71.             bar.add(btn);  
  72.             btn = new JButton("全部保存");  
  73.             btn.addActionListener(new ActionListener() {  
  74.                 public void actionPerformed(ActionEvent e) {  
  75.                     for (int i = 0; i < builder.getXDocCount(); i++) {  
  76.                         //选择第i个文件  
  77.                         builder.activeXDoc(i);  
  78.                         //保存  
  79.                         builder.save();  
  80.                         //builder.save("xdox" + i + ".rtf", XDocIO.WRITE_FORMAT_PDF);  
  81.                     }  
  82.                 }  
  83.             });  
  84.             bar.add(btn);  
  85.             btn = new JButton("关闭");  
  86.             btn.addActionListener(new ActionListener() {  
  87.                 public void actionPerformed(ActionEvent e) {  
  88.                     //关闭当前文件  
  89.                     builder.close();  
  90.                 }  
  91.             });  
  92.             bar.add(btn);  
  93.             btn = new JButton("打印");  
  94.             btn.addActionListener(new ActionListener() {  
  95.                 public void actionPerformed(ActionEvent e) {  
  96.                     builder.print();  
  97.                 }  
  98.             });  
  99.             bar.add(btn);  
  100.             btn = new JButton("直接打印");  
  101.             btn.addActionListener(new ActionListener() {  
  102.                 public void actionPerformed(ActionEvent e) {  
  103.                     //打印到指定打印机  
  104.                     builder.print("HG JPD 虚拟打印机");  
  105.                 }  
  106.             });  
  107.             bar.add(btn);  
  108.             btn = new JButton("关于");  
  109.             btn.addActionListener(new ActionListener() {  
  110.                 public void actionPerformed(ActionEvent e) {  
  111.                     builder.about();  
  112.                 }  
  113.             });  
  114.             bar.add(btn);  
  115.             Container content = frame.getContentPane();  
  116.             content.add(bar, BorderLayout.NORTH);  
  117.             frame.setSize(800600);  
  118.             frame.setVisible(true);  
  119.             frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);  
  120.             frame.addWindowListener(new WindowListener() {  
  121.                 public void windowOpened(WindowEvent e) {}  
  122.                 public void windowClosing(WindowEvent e) {  
  123.                     //frame关闭时做处理  
  124.                     for (int i = 0; i < builder.getXDocCount(); i++) {  
  125.                         try {  
  126.                             XDocIO.write(builder.getXDoc(i), new File("c:/xdoc" + i + ".xdoc"));  
  127.                         } catch (Exception e1) {  
  128.                             JOptionPane.showMessageDialog(null, e1.getMessage());  
  129.                         }  
  130.                     }  
  131.                     System.exit(0);  
  132.                 }  
  133.                 public void windowClosed(WindowEvent e) {}  
  134.                 public void windowIconified(WindowEvent e) {}  
  135.                 public void windowDeiconified(WindowEvent e) {}  
  136.                 public void windowActivated(WindowEvent e) {}  
  137.                 public void windowDeactivated(WindowEvent e) {}  
  138.             });  
  139.             frame.setExtendedState(JFrame.MAXIMIZED_BOTH);  
  140.         } catch (Exception e) {  
  141.             JOptionPane.showMessageDialog(null, e.getMessage());  
  142.         }  
  143.     }  
  144. }  

 运行效果:



From: http://xdoc.iteye.com/blog/1126216

@import url(http://www.cppblog.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
posted on 2011-09-17 18:44 逛奔的蜗牛 阅读(1833) 评论(1)  编辑 收藏 引用 所属分类: Java

评论

# re: Java:为你的Java应用嵌入一个功能强大的文字编辑器[未登录] 2016-08-01 15:04 1
1  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理