<< Chapter < Page | Chapter >> Page > |
Listing 25 . The program named Svg21a.java. |
---|
/*File Svg21a.java,
Copyright 2011, R.G.BaldwinRevised 08/07/11 to support the addition of a title
parameter to each element for IVEO compatibility. If theoutput SVG file is opened in IVEO, the title for the svg
element is spoken when the user opens the file, and thetitles for the individual elements are spoken when the
user touches a corresponding shape on the touchpad orclicks on that shape on the screen. If the SVG file won't
be used with IVEO, just leave the title strings unchanged.This program requires access to the file
named SvgLib21.javaThis is a demonstration program.
This program uses JDOM 1.1.1 and an SVG graphics libraryclass of my own design named SvgLib21 to draw an
abbreviated version of the mass-pulley system shown in Figure 4of the module that you will find at
http://cnx.org/contents/16d1b592-5126-458f-883e-3ae872cc18c0.Only one line of text is drawn by this program. Otherwise,
the drawing produced by this program is the same asthe drawing in the file named Phy1150a1.svg used in
that module titled Force and Motion -- Units of Force. Theoriginal drawing was produced by a sighted person using
Inkscape. This drawing was produced by a sighted personusing Baldwin's svg drawing library.
Tested using J2SE 6, JDOM 1.1.1, and Firefox 5running under Windows Vist Home Premium Edition.
*********************************************************/import java.io.*;
import org.jdom.*;public class Svg21a{
public static void main(String[]args){
//DO NOT MODIFY ANY OF THE CODE ABOVE THIS LINE.//##################################################//
//ONLY THE CODE BELOW THIS LINE CAN BE MODIFIED//CREATE A DRAWING CANVAS//This must be the first statement that you write in
// the program and it must appear only once.//The following statement creates a canvas that is
// 8.5x11 inches in size in a landscape layout.Element svg = SvgLib21.makeSvg(ns,
"Document Title",11,//width
8.5 //height);//DO NOT MODIFY THE FOLLOWING STATEMENT
//This statement must immediately follow the call to// the makeSvg method above and this statement MUST
// NOT BE MODIFIED.Document doc = new Document(svg,docType);
//Draw a rectangular border on the canvas.Element border = SvgLib21.makeRect(svg,
ns,"rectangle",
0.015,0.015,
10.97,8.47
);//Draw the floor.Element floor = SvgLib21.makeLine(svg,
ns,"line",
0.5,0.5,
10.5,0.5
);//Draw the wall.
Element wall = SvgLib21.makeLine(svg,ns,
"line",1.0,
0.5,1.0,
7.5);
//Draw the table top.Element tableTop = SvgLib21.makeRect(svg,
ns,"rectangle",
1.0,3.0,
7.0,1.0
);//Draw the table leg.
Element tableLeg = SvgLib21.makeRect(svg,ns,
"rectangle",6.5,
0.5,0.5,
2.5);//Draw Mass CElement massC = SvgLib21.makeRect(svg,
ns,"rectangle",
2.0,4.0,
2.0,2.0
);//Draw Mass B
Element massB = SvgLib21.makeRect(svg,ns,
"rectangle",5.0,
4.0,2.0,
2.0);
//Draw Mass AElement massA = SvgLib21.makePolygon(svg,
ns,"polygon",
new double[]{
7.5,1.0,9.5,1.0,
8.5,2.5});
//Draw pully supportElement pullySupport = SvgLib21.makeRect(svg,
ns,"rectangle",7.883,
3.595,0.392,
1.06);
//Draw the pulley wheel.Element pulleyWheel = SvgLib21.makeCircle(svg,
ns,"circle",
8.05,4.56,
0.45);
//Draw cord from wall to Mass CElement cordR = SvgLib21.makeLine(svg,
ns,"line",
1.0,5.0,
2,5.0
);//Draw cord from Mass C to Mass B
Element cordQ = SvgLib21.makeLine(svg,ns,
"line",4.0,
5.0,5.0,
5.0);
//Draw cord from Mass B to the top of the pulley.Element cordP1 = SvgLib21.makeLine(svg,
ns,"line",
7.0,5.0,
8.05,5.0
);//Draw the cord from the right side of the pulley to
// Mass AElement cordP2 = SvgLib21.makeLine(svg,
ns,"line",
8.5,4.5,
8.5,2.5
);//Set the line thicknesses for various objects.SvgLib21.setStrokeWidth(border,0.03);
SvgLib21.setStrokeWidth(floor,0.1);SvgLib21.setStrokeWidth(wall,0.1);
SvgLib21.setStrokeWidth(tableTop,0.03);SvgLib21.setStrokeWidth(tableLeg,0.03);
SvgLib21.setStrokeWidth(massC,0.05);SvgLib21.setStrokeWidth(massB,0.05);
SvgLib21.setStrokeWidth(massA,0.05);SvgLib21.setStrokeWidth(pullySupport,0.05);
SvgLib21.setStrokeWidth(pulleyWheel,0.05);SvgLib21.setStrokeWidth(cordR,0.03);
SvgLib21.setStrokeWidth(cordQ,0.03);SvgLib21.setStrokeWidth(cordP1,0.03);
SvgLib21.setStrokeWidth(cordP2,0.03);//Draw text
Element textA = SvgLib21.makeText(svg,
ns,2.5,
3.3,"arial",
32,"Friction free table."
);//WRITE OUTPUT FILE
//Don't include extension in output file name.SvgLib21.writePrettyFile("Svg21a",doc);//ONLY THE CODE ABOVE THIS LINE CAN BE MODIFIED
//##################################################////DO NOT MODIFY ANY OF THE FOLLOWING CODE.
}//end main//----------------------------------------------------//
//Create a String variable containing the namespace// URI to reduce the amount of typing that is required
// later. Note that the variable name is short and// easy to type.
static String ns = "http://www.w3.org/2000/svg";//For clarity, create strings containing the name of// the element that is constrained by the DTD (the
// root element), the Public ID of the DTD, and the// System ID of the DTD.
static String dtdConstrainedElement = "svg";static String dtdPublicID = "-//W3C//DTD SVG 1.1//EN";
static String dtdSystemID ="http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd";static DocType docType = new DocType(dtdConstrainedElement,dtdPublicID,dtdSystemID);
}//end class Svg21a |
Notification Switch
Would you like to follow the 'Accessible physics concepts for blind students' conversation and receive update notifications?