H
hunyuan
Unregistered / Unconfirmed
GUEST, unregistred user!
小弟刚转Java,准备开发一套曲线系统,用Java + SVG,Web服务器用Tomcat 4.1.29,现在只有初步的想法:用JSP读Oracle数据并处理,然后用JSP、Servlet或JavaBean调用DOM生成SVG文件(这里怎么也想不通怎么生成)。具体的实现细节想了两周都想不通,小弟对Java了解得太少了,项目又非常急,太需要您的帮助了!!
http://xml.apache.org/batik/ 这个batik是Tomcat中针对SVG的解决方案,不知道怎么用;
http://www.ilog.com/products/jviews/ 这个ilog也不知道sun网站提出来具体做什么用?
下面是摘到的代码,不知道怎么用在Server端?比如JSP中怎么做?
Using the SVGGraphics2D Class
Listing 2. Using the SVGGraphics2D SVG generator (HelloSVGWorld.java)
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.font.*;
import java.awt.event.*;
import java.io.*;
import org.w3c.dom.*;
import org.apache.xerces.dom.*;
import com.sun.awt.svg.*;
public class HelloSVGWorld extends Component {
String svgMessage = "Hello SVG World";
int width=320, height=250;
Shape diamond = new Polygon(new int[]{120, 210, 300, 210},
new int[]{120, 30, 120, 210},
4);
public Dimension getPreferredSize(){
return new Dimension(width, height);
}
public void paint(Graphics _g){
Graphics2D g = (Graphics2D)_g;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// Paint white background
g.setPaint(Color.white);
g.fillRect(0, 0, width, height);
// Paint a circle in blue
g.setPaint(new Color(102, 102, 153));
g.fillOval(30, 30, 180, 180);
// Paint a diamond in black
g.setPaint(Color.black);
g.fill(diamond);
// Draw a string
Font font = new Font("Verdana", Font.BOLD, 20);
g.setFont(font);
g.setPaint(Color.white);
g.drawString(svgMessage, 60, 120);
}
public static void main(String args[]) throws IOException{
// Create an instance of HelloSVGWorld whose paint method
// will be invoked both to render on the screen
// and to generate SVG.
HelloSVGWorld helloSVG = new HelloSVGWorld();
// Create a frame to display our component
Frame frame = new Frame();
// Add component to our frame and fit the
// frame size to its content.
frame.add(helloSVG);
frame.pack();
//
// Generate SVG content.
//
// First, create an instance of org.w3c.dom.Document
// required by the generator.
Documentdo
mFactory = newdo
cumentImpl();
// Second, create an instance of the generator. The
// generator will use thedo
mFactory to create the various
// SVG elements.
SVGGraphics2D svgGenerator = new SVGGraphics2D(domFactory);
// Now, ask the our helloSVG component to render into
// our custom Graphics2D implementation
helloSVG.paint(svgGenerator);
// Optional: set the canvas size
svgGenerator.setSVGCanvasSize(helloSVG.getPreferredSize());
String useCssStr = System.getProperty("useCss", "true");
boolean useCss = useCssStr.equalsIgnoreCase("true");
// Finally, stream out SVG to the standard output
Writer outWriter = new OutputStreamWriter(System.out, "UTF-8");
svgGenerator.stream(outWriter, useCss);
//
// Display component
//
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent evt){
System.exit(0);
}
});
frame.setVisible(true);
}
}
http://xml.apache.org/batik/ 这个batik是Tomcat中针对SVG的解决方案,不知道怎么用;
http://www.ilog.com/products/jviews/ 这个ilog也不知道sun网站提出来具体做什么用?
下面是摘到的代码,不知道怎么用在Server端?比如JSP中怎么做?
Using the SVGGraphics2D Class
Listing 2. Using the SVGGraphics2D SVG generator (HelloSVGWorld.java)
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.font.*;
import java.awt.event.*;
import java.io.*;
import org.w3c.dom.*;
import org.apache.xerces.dom.*;
import com.sun.awt.svg.*;
public class HelloSVGWorld extends Component {
String svgMessage = "Hello SVG World";
int width=320, height=250;
Shape diamond = new Polygon(new int[]{120, 210, 300, 210},
new int[]{120, 30, 120, 210},
4);
public Dimension getPreferredSize(){
return new Dimension(width, height);
}
public void paint(Graphics _g){
Graphics2D g = (Graphics2D)_g;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
// Paint white background
g.setPaint(Color.white);
g.fillRect(0, 0, width, height);
// Paint a circle in blue
g.setPaint(new Color(102, 102, 153));
g.fillOval(30, 30, 180, 180);
// Paint a diamond in black
g.setPaint(Color.black);
g.fill(diamond);
// Draw a string
Font font = new Font("Verdana", Font.BOLD, 20);
g.setFont(font);
g.setPaint(Color.white);
g.drawString(svgMessage, 60, 120);
}
public static void main(String args[]) throws IOException{
// Create an instance of HelloSVGWorld whose paint method
// will be invoked both to render on the screen
// and to generate SVG.
HelloSVGWorld helloSVG = new HelloSVGWorld();
// Create a frame to display our component
Frame frame = new Frame();
// Add component to our frame and fit the
// frame size to its content.
frame.add(helloSVG);
frame.pack();
//
// Generate SVG content.
//
// First, create an instance of org.w3c.dom.Document
// required by the generator.
Documentdo
mFactory = newdo
cumentImpl();
// Second, create an instance of the generator. The
// generator will use thedo
mFactory to create the various
// SVG elements.
SVGGraphics2D svgGenerator = new SVGGraphics2D(domFactory);
// Now, ask the our helloSVG component to render into
// our custom Graphics2D implementation
helloSVG.paint(svgGenerator);
// Optional: set the canvas size
svgGenerator.setSVGCanvasSize(helloSVG.getPreferredSize());
String useCssStr = System.getProperty("useCss", "true");
boolean useCss = useCssStr.equalsIgnoreCase("true");
// Finally, stream out SVG to the standard output
Writer outWriter = new OutputStreamWriter(System.out, "UTF-8");
svgGenerator.stream(outWriter, useCss);
//
// Display component
//
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent evt){
System.exit(0);
}
});
frame.setVisible(true);
}
}