Changeset 30396 in osm for applications/editors/josm/plugins/smed2
- Timestamp:
- 2014-04-13T10:12:06+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/smed2
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/smed2/jicons/build.xml
r30395 r30396 2 2 <property name="src" location="src"/> 3 3 <property name="build" location="build"/> 4 <property name="dist" location="dist"/> 5 4 <property name="jarfile" location="./jicons.jar"/> 5 <property name="ant.build.javac.target" value="1.7"/> 6 <property name="ant.build.javac.source" value="1.7"/> 7 <property name="batik.dir" value="/usr/local/bin/batik-1.7/"/> 8 <path id="classpath"> 9 <fileset dir="${batik.dir}" includes="**/*.jar"/> 10 </path> 11 6 12 <target name="init"> 7 13 <mkdir dir="${build}"/> … … 9 15 10 16 <target name="compile" depends="init" description="compile the source " > 11 <javac includeantruntime="false" srcdir="${src}" destdir="${build}"/> 17 <javac includeantruntime="false" srcdir="${src}" destdir="${build}" classpathref="classpath" encoding="UTF-8" /> 12 18 </target> 13 19 14 20 <target name="dist" depends="compile" description="generate the distribution" > 15 <jar jarfile=" ./jicons.jar" basedir="${build}" >21 <jar jarfile="${jarfile}" basedir="${build}" > 16 22 <manifest> 17 <attribute name="Main-Class" value="Jicons"/> 23 <attribute name="Main-Class" value="jicons.Jicons"/> 24 <attribute name="Class-Path" value="$jarfile"/> 18 25 </manifest> 26 <zipgroupfileset dir="${batik.dir}" includes="**/*.jar" /> 27 19 28 </jar> 20 29 </target> … … 22 31 <target name="clean" description="clean up" > 23 32 <delete dir="${build}"/> 24 <delete dir="${dist}"/> 25 <delete file="./jicons.jar"/> 33 <delete file="${jarfile}"/> 26 34 </target> 27 35 </project> -
applications/editors/josm/plugins/smed2/jicons/src/jicons/Jicons.java
r30395 r30396 10 10 package jicons; 11 11 12 import java.io.BufferedReader; 12 13 import java.io.File; 13 14 import java.io.FileOutputStream; 15 import java.io.FileReader; 14 16 import java.io.IOException; 15 17 import java.io.OutputStreamWriter; 16 18 import java.io.Writer; 17 import java.util.ArrayList;18 import java.awt.Color;19 19 import java.awt.Dimension; 20 import java.awt.Graphics;21 20 import java.awt.Graphics2D; 22 import java.awt.Panel;23 21 import java.awt.RenderingHints; 22 import java.awt.geom.Point2D; 24 23 import java.awt.image.BufferedImage; 25 24 26 25 import javax.imageio.ImageIO; 27 import javax.swing.JFrame;28 26 29 27 import org.apache.batik.svggen.SVGGraphics2D; … … 33 31 import org.w3c.dom.DOMImplementation; 34 32 35 import symbols.*; 36 import symbols.Symbols.*; 33 import s57.S57map; 34 import s57.S57map.Feature; 35 import s57.S57map.Snode; 37 36 import render.*; 38 37 39 public class Jicons extends Panel { 40 41 public static void main(String[] args) { 38 public class Jicons { 39 40 static S57map map = null; 41 static int x = 0; 42 static int y = 0; 43 static int w = 0; 44 static int h = 0; 45 static double s = 0; 46 47 public static void main(String[] args) throws IOException { 48 Render render; 49 BufferedReader in; 50 int line = 0; 51 String format = ""; 52 String file = ""; 53 String k = ""; 54 String v = ""; 55 42 56 BufferedImage img; 43 57 Graphics2D g2; 58 boolean inIcons = false; 59 boolean inIcon = false; 44 60 45 JFrame frame = new JFrame("Jicons"); 46 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 47 Panel panel = new Jicons(); 48 frame.getContentPane().add("Center", panel); 49 frame.setSize(256, 256); 50 frame.setVisible(true); 61 if (args.length < 2) { 62 System.err.println("Usage: java -jar jicons.jar icon_definition_file icons_directory"); 63 System.exit(-1); 64 } 65 in = new BufferedReader(new FileReader(args[0])); 51 66 52 img = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); 53 g2 = img.createGraphics(); 54 drawRendering(g2); 55 try { 56 ImageIO.write(img, "png", new File("/Users/mherring/Desktop/export.png")); 57 } catch (Exception e) { 58 System.out.println("Exception"); 59 } 60 61 DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); 62 String svgNS = "http://www.w3.org/2000/svg"; 63 Document document = domImpl.createDocument(svgNS, "svg", null); 64 SVGGraphics2D svgGenerator = new SVGGraphics2D(document); 65 svgGenerator.setSVGCanvasSize(new Dimension(256, 256)); 66 drawRendering(svgGenerator); 67 boolean useCSS = true; 68 Writer out = null; 69 try { 70 out = new OutputStreamWriter(new FileOutputStream("/Users/mherring/Desktop/export.svg"), "UTF-8"); 71 } catch (IOException e1) { 72 System.out.println("Exception"); 67 render = new Render(); 68 String ln; 69 while ((ln = in.readLine()) != null) { 70 line++; 71 if (inIcons) { 72 if (inIcon) { 73 if (ln.contains("</icon")) { 74 inIcon = false; 75 map.tagsDone(0); 76 // generate icon file 77 switch (format) { 78 case "PNG": 79 img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); 80 g2 = img.createGraphics(); 81 render.drawRendering(g2, s); 82 try { 83 ImageIO.write(img, "png", new File(args[1] + file + ".png")); 84 } catch (Exception e) { 85 System.err.println("Line " + line + ": PNG write Exception"); 86 } 87 System.err.println(file + ".png"); 88 break; 89 case "SVG": 90 DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation(); 91 String svgNS = "http://www.w3.org/2000/svg"; 92 Document document = domImpl.createDocument(svgNS, "svg", null); 93 SVGGraphics2D svgGenerator = new SVGGraphics2D(document); 94 svgGenerator.setSVGCanvasSize(new Dimension(w, h)); 95 render.drawRendering(svgGenerator, s); 96 boolean useCSS = true; 97 Writer out = null; 98 try { 99 out = new OutputStreamWriter(new FileOutputStream(args[1] + file + ".svg"), "UTF-8"); 100 } catch (IOException e1) { 101 System.err.println("Line " + line + ": SVG file Exception"); 102 } 103 try { 104 svgGenerator.stream(out, useCSS); 105 } catch (SVGGraphics2DIOException e) { 106 System.err.println("Line " + line + ": SVG write Exception"); 107 } 108 System.err.println(file + ".svg"); 109 break; 110 } 111 } else if (ln.contains("<tag")) { 112 k = v = ""; 113 String[] token = ln.split("k="); 114 k = token[1].split("[\"\']")[1]; 115 token = token[1].split("v="); 116 v = token[1].split("[\"\']")[1]; 117 if (k.isEmpty()) { 118 System.err.println("Line " + line + ": No key in tag"); 119 System.exit(-1); 120 } 121 if (v.isEmpty()) { 122 System.err.println("Line " + line + ": No value in tag"); 123 System.exit(-1); 124 } 125 map.addTag(k, v); 126 } 127 } else if (ln.contains("<icon")) { 128 inIcon = true; 129 h = w = x = y = -1; 130 s = 0; 131 file = format = ""; 132 map = new S57map(); 133 map.addNode(0, 0, 0); 134 for (String token : ln.split("[ ]+")) { 135 if (token.matches("^width=.+")) { 136 w = Integer.parseInt(token.split("[\"\']")[1]); 137 } else if (token.matches("^height=.+")) { 138 h = Integer.parseInt(token.split("[\"\']")[1]); 139 } else if (token.matches("^x=.+")) { 140 x = Integer.parseInt(token.split("[\"\']")[1]); 141 } else if (token.matches("^y=.+")) { 142 y = Integer.parseInt(token.split("[\"\']")[1]); 143 } else if (token.matches("^scale=.+")) { 144 s = Double.parseDouble(token.split("[\"\']")[1]); 145 } else if (token.matches("^file=.+")) { 146 file = (token.split("[\"\']")[1]); 147 } else if (token.matches("^format=.+")) { 148 format = (token.split("[\"\']")[1]); 149 } 150 } 151 if (file.isEmpty()) { 152 System.err.println("Line " + line + ": No filename"); 153 System.exit(-1); 154 } 155 if (format.isEmpty()) { 156 System.err.println("Line " + line + ": No format"); 157 System.exit(-1); 158 } 159 if ((h < 0) && (w < 0)) { 160 System.err.println("Line " + line + ": No icon size"); 161 System.exit(-1); 162 } 163 if (w < 0) { 164 w = h; 165 } 166 if (h < 0) { 167 h = w; 168 } 169 if (x < 0) { 170 x = w / 2; 171 } 172 if (y < 0) { 173 y = h / 2; 174 } 175 if (s == 0) { 176 s = 1; 177 } 178 } else if (ln.contains("</icons")) { 179 inIcons = false; 180 break; 181 } 182 } else if (ln.contains("<icons")) { 183 inIcons = true; 73 184 } 74 try { 75 svgGenerator.stream(out, useCSS); 76 } catch (SVGGraphics2DIOException e) { 77 System.out.println("Exception"); 78 } 185 } 186 in.close(); 187 System.err.println("Finished"); 188 System.exit(0); 79 189 } 80 190 81 public static void drawRendering(Graphics2D g2) { 82 double scale = Renderer.symbolScale[8]; 83 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 84 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); 85 Scheme scheme = new Scheme(); scheme.pat.add(Patt.H); scheme.col.add(Color.red); scheme.col.add(Color.yellow); scheme.col.add(Color.green); 86 Symbols.drawSymbol(g2, Buoys.Pillar, scale, 128.0, 128.0, scheme, null); 87 } 88 89 public void paint(Graphics g) { 90 Graphics2D g2 = (Graphics2D)g; 91 drawRendering(g2); 191 static class Render implements MapContext { 192 193 public void drawRendering(Graphics2D g2, double scale) { 194 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 195 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP); 196 Renderer.reRender(g2, 16, scale / Renderer.symbolScale[16], map, this); 197 } 198 199 @Override 200 public Point2D getPoint(Snode coord) { 201 return new Point2D.Double(x, y); 202 } 203 204 @Override 205 public double mile(Feature feature) { 206 return 1000; 207 } 92 208 } 93 209 } -
applications/editors/josm/plugins/smed2/jrender/build.xml
r30269 r30396 2 2 <property name="src" location="src"/> 3 3 <property name="build" location="build"/> 4 <property name="dist" location="dist"/> 5 4 <property name="jarfile" location="./jrender.jar"/> 5 <property name="ant.build.javac.target" value="1.7"/> 6 <property name="ant.build.javac.source" value="1.7"/> 7 <property name="batik.dir" value="/usr/local/bin/batik-1.7/"/> 8 <path id="classpath"> 9 <fileset dir="${batik.dir}" includes="**/*.jar"/> 10 </path> 11 6 12 <target name="init"> 7 13 <mkdir dir="${build}"/> … … 9 15 10 16 <target name="compile" depends="init" description="compile the source " > 11 <javac includeantruntime="false" srcdir="${src}" destdir="${build}"/> 17 <javac includeantruntime="false" srcdir="${src}" destdir="${build}" classpathref="classpath" encoding="UTF-8" /> 12 18 </target> 13 19 14 20 <target name="dist" depends="compile" description="generate the distribution" > 15 <jar jarfile=" ./jrender.jar" basedir="${build}" >21 <jar jarfile="${jarfile}" basedir="${build}" > 16 22 <manifest> 17 <attribute name="Main-Class" value="Jrender"/> 23 <attribute name="Main-Class" value="jrender.Jrender"/> 24 <attribute name="Class-Path" value="$jarfile"/> 18 25 </manifest> 26 <zipgroupfileset dir="${batik.dir}" includes="**/*.jar" /> 27 19 28 </jar> 20 29 </target> … … 22 31 <target name="clean" description="clean up" > 23 32 <delete dir="${build}"/> 24 <delete dir="${dist}"/> 25 <delete file="./jrender.jar"/> 33 <delete file="${jarfile}"/> 26 34 </target> 27 35 </project> -
applications/editors/josm/plugins/smed2/jrender/src/jrender/Jrender.java
r30226 r30396 15 15 import java.io.OutputStreamWriter; 16 16 import java.io.Writer; 17 import java.util.ArrayList;18 17 import java.awt.Color; 19 18 import java.awt.Dimension; -
applications/editors/josm/plugins/smed2/src/render/Renderer.java
r30339 r30396 18 18 import s57.S57val.*; 19 19 import s57.S57map; 20 import s57.S57att.Att;21 20 import s57.S57map.*; 22 21 import symbols.Areas;
Note:
See TracChangeset
for help on using the changeset viewer.