Universal VisioViewer组件接口程序示例
阮俊杰
如本blog前两篇文章所述,我们所开发的“Universal VisioViewer”是一个Java组件,可以方便而容易地嵌入到任何基于Java的应用中,无论是本地应用还是Web应用。本文将公布一段Java源代码,以便例示在最为简单的情况下,即在程序中只显示Visio文档、而不具备任何应用逻辑的情况下,应用该组件的便利性。从程序中可见,所涉及的语句中有4、5行代码(以//!!!进行注释)。
网友如有疑问,可通过rjj@dawninfo.com.cn进行联系。
package Nativeexam;
/**
* <p>Title: VisioViewer test--Native application</p>
* <p>Description: Show how to use the VisioCom.jar in a native application</p>
* <p>Copyright: Copyright (c) 2007~2008</p>
* <p>Company: Beijing Dawninfo Tech. Co., Ltd.</p>
* @author Junjie Ruan
* @version 1.0
*/
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import com.xckx.Visio.Interface.*;
public class PaintPanel extends JPanel {
private AppFrame main = null;
private Color bkColor;
public PaintPanel(AppFrame mainf) {
this.main = mainf;
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
//adding the VisioViewer object to the mouseEvent listener
this.addMouseListener(main.getViewer()); //!!!very important way to integrate the controlling with VisioLib functions
this.addMouseMotionListener(main.getViewer());//!!!very important way to integrate the controlling with VisioLib functions
this.addMouseListener(main);
}
private void jbInit() throws Exception {
bkColor = main.getPanelBkColor(); //!important to get&set the background of the Panel
setBackground(bkColor);
setForeground(bkColor);
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D)g;
g.setColor(bkColor);
g.fillRect(0,0,this.getWidth(),this.getHeight());
if (main.getViewer() != null)
main.getViewer().draw(g2d); //!!!invoke the LabelsDoc "draw" method to reveal the content of Visio Documents
}
public void update(Graphics g) {
paint(g);
}
public void setBkColor(Color color) {
bkColor = color;
setBackground(bkColor);
setForeground(bkColor);
repaint();
}
}