org.apache.batik.gvt.GraphicsNode Java Examples
The following examples show how to use
org.apache.batik.gvt.GraphicsNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VehicleMapLayer.java From mars-sim with GNU General Public License v3.0 | 6 votes |
/** * Draws the parts attached to a light utility vehicle. * @param g2d the graphics context * @param vehicle the light utility vehicle. */ private void drawSVGPartAttachments(Graphics2D g2d, LightUtilityVehicle vehicle) { Iterator<Part> i = vehicle.getPossibleAttachmentParts().iterator(); while (i.hasNext()) { Part part = i.next(); if (vehicle.getInventory().getItemResourceNum(part) > 0) { // Use SVG image for part if available. GraphicsNode partSvg = SVGMapUtil.getAttachmentPartSVG(part.getName().toLowerCase()); GraphicsNode vehicleSvg = SVGMapUtil.getVehicleSVG(vehicle.getDescription().toLowerCase()); if ((partSvg != null) && (vehicleSvg != null)) { drawVehicleOverlay(g2d, vehicle.getXLocation(), vehicle.getYLocation(), vehicle.getWidth(), vehicle.getLength(), vehicle.getFacing(), vehicleSvg, partSvg); } } } }
Example #2
Source File: SwingUniversalImageSvg.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public static void render( Graphics2D gc, GraphicsNode svgGraphicsNode, Dimension2D svgGraphicsSize, int centerX, int centerY, int width, int height, double angleRadians ) { double scaleX = width / svgGraphicsSize.getWidth(); double scaleY = height / svgGraphicsSize.getHeight(); AffineTransform affineTransform = new AffineTransform(); if ( centerX != 0 || centerY != 0 ) { affineTransform.translate( centerX, centerY ); } affineTransform.scale( scaleX, scaleY ); if ( angleRadians != 0 ) { affineTransform.rotate( angleRadians ); } affineTransform.translate( -svgGraphicsSize.getWidth() / 2, -svgGraphicsSize.getHeight() / 2 ); svgGraphicsNode.setTransform( affineTransform ); svgGraphicsNode.paint( gc ); }
Example #3
Source File: SvgLayerFactory.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
private GraphicsNode createNode(String svgContent) throws GeomajasException { // batik magic String parser = XMLResourceDescriptor.getXMLParserClassName(); SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); SVGDocument document; try { document = f.createSVGDocument("", new StringReader(svgContent)); } catch (IOException e) { throw new RasterException(e, RasterException.BAD_SVG, "Cannot parse SVG"); } UserAgent userAgent = new UserAgentAdapter(); DocumentLoader loader = new DocumentLoader(userAgent); BridgeContext bridgeContext = new BridgeContext(userAgent, loader); bridgeContext.setDynamic(true); GVTBuilder builder = new GVTBuilder(); return builder.build(bridgeContext, document); }
Example #4
Source File: SvgLayerFactory.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
public Layer createLayer(MapContext mapContent, ClientLayerInfo clientLayerInfo) throws GeomajasException { if (!(clientLayerInfo instanceof ClientSvgLayerInfo)) { throw new IllegalArgumentException( "SvgLayerFactory.createLayer() should only be called using ClientSvgLayerInfo"); } ClientSvgLayerInfo layerInfo = (ClientSvgLayerInfo) clientLayerInfo; SvgDirectLayer layer = new SvgDirectLayer(mapContent); String finalSvg; finalSvg = addAttributesToSvg(layerInfo.getSvgContent(), layerInfo.getViewBoxScreenBounds()); GraphicsNode graphicsNode = createNode(finalSvg); layer.setGraphicsNode(graphicsNode); layer.setSvgWorldBounds(new ReferencedEnvelope(converterService.toInternal(layerInfo.getViewBoxWorldBounds()), mapContent.getCoordinateReferenceSystem())); Bbox viewBox = layerInfo.getViewBoxScreenBounds(); int w = (int) viewBox.getWidth(); int h = (int) viewBox.getHeight(); int x = (int) viewBox.getX(); int y = (int) viewBox.getY(); layer.setSvgScreenBounds(new Rectangle(x, y, w, h)); layer.getUserData().put(USERDATA_KEY_SHOWING, layerInfo.isShowing()); return layer; }
Example #5
Source File: TestSVGMapUtil.java From mars-sim with GNU General Public License v3.0 | 6 votes |
/** * Test the getConstructionSiteSVG method. */ public void testGetConstructionSiteSVG() { // Check that all construction stage names are mapped to a SVG image. ConstructionConfig config = SimulationConfig.instance().getConstructionConfiguration(); List<ConstructionStageInfo> constructionStages = new ArrayList<ConstructionStageInfo>(); constructionStages.addAll(config.getConstructionStageInfoList(ConstructionStageInfo.FOUNDATION)); constructionStages.addAll(config.getConstructionStageInfoList(ConstructionStageInfo.FRAME)); constructionStages.addAll(config.getConstructionStageInfoList(ConstructionStageInfo.BUILDING)); Iterator<ConstructionStageInfo> i = constructionStages.iterator(); while (i.hasNext()) { ConstructionStageInfo constStageInfo = i.next(); String constName = constStageInfo.getName(); GraphicsNode svg = SVGMapUtil.getConstructionSiteSVG(constName); assertNotNull(constName + " is not mapped to a SVG image.", svg); } }
Example #6
Source File: VehicleMapLayer.java From mars-sim with GNU General Public License v3.0 | 6 votes |
/** * Gets a buffered image for a given graphics node. * @param svg the graphics node. * @param width the vehicle width. * @param length the vehicle length. * @return buffered image. */ private BufferedImage getBufferedImage(GraphicsNode svg, double width, double length) { // Get image cache for current scale or create it if it doesn't exist. Map<GraphicsNode, BufferedImage> imageCache = null; if (svgImageCache.containsKey(scale)) { imageCache = svgImageCache.get(scale); } else { imageCache = new HashMap<GraphicsNode, BufferedImage>(100); svgImageCache.put(scale, imageCache); } // Get image from image cache or create it if it doesn't exist. BufferedImage image = null; if (imageCache.containsKey(svg)) image = imageCache.get(svg); else { image = createBufferedImage(svg, width, length); imageCache.put(svg, image); } return image; }
Example #7
Source File: SwingUniversalImageSvg.java From hop with Apache License 2.0 | 6 votes |
public static void render( Graphics2D gc, GraphicsNode svgGraphicsNode, Dimension2D svgGraphicsSize, int centerX, int centerY, int width, int height, double angleRadians ) { double scaleX = width / svgGraphicsSize.getWidth(); double scaleY = height / svgGraphicsSize.getHeight(); AffineTransform affineTransform = new AffineTransform(); if ( centerX != 0 || centerY != 0 ) { affineTransform.translate( centerX, centerY ); } affineTransform.scale( scaleX, scaleY ); if ( angleRadians != 0 ) { affineTransform.rotate( angleRadians ); } affineTransform.translate( -svgGraphicsSize.getWidth() / 2, -svgGraphicsSize.getHeight() / 2 ); svgGraphicsNode.setTransform( affineTransform ); svgGraphicsNode.paint( gc ); }
Example #8
Source File: SVGIcon.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected Image createAndPaintImage( Component c, ColorModel colorModel, int deviceWidth, int deviceHeight, double scale) { BufferedImage img = createBufferedImage(colorModel, deviceWidth, deviceHeight); /* Use Batik's createGraphics method to improve performance and avoid the "Graphics2D from BufferedImage lacks BUFFERED_IMAGE hint" warning. */ final Graphics2D g = GraphicsUtil.createGraphics(img); try { g.scale(scale, scale); try { GraphicsNode graphicsNode = getGraphicsNode(); g.addRenderingHints(createHints()); graphicsNode.paint(g); } catch (IOException e) { LOG.log(Level.WARNING, "Unexpected exception while re-loading an SVG file that previously loaded successfully", e); } } finally { g.dispose(); } return img; }
Example #9
Source File: VehicleMapLayer.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Constructor * @param mapPanel the settlement map panel. */ public VehicleMapLayer(SettlementMapPanel mapPanel) { // Initialize data members. this.mapPanel = mapPanel; svgImageCache = new HashMap<Double, Map<GraphicsNode, BufferedImage>>(21); // Set Apache Batik library system property so that it doesn't output: // "Graphics2D from BufferedImage lacks BUFFERED_IMAGE hint" in system err. System.setProperty("org.apache.batik.warn_destination", "false"); //$NON-NLS-1$ //$NON-NLS-2$ }
Example #10
Source File: TestSVGMapUtil.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Test the getBuildingSVG method. */ public void testGetBuildingSVG() { // Check that all configured building names are mapped to a SVG image. Iterator<String> i = SimulationConfig.instance().getBuildingConfiguration(). getBuildingTypes().iterator(); while (i.hasNext()) { String buildingName = i.next(); GraphicsNode svg = SVGMapUtil.getBuildingSVG(buildingName); assertNotNull(buildingName + " is not mapped to a SVG image.", svg); } }
Example #11
Source File: SVGIcon.java From netbeans with Apache License 2.0 | 5 votes |
private SVGIcon(URL url, GraphicsNode initialGraphicsNode, int width, int height) { super(width, height); Parameters.notNull("url", url); Parameters.notNull("initialGraphicsNode", initialGraphicsNode); this.url = url; this.graphicsNodeStrongRef = initialGraphicsNode; this.graphicsNodeWeakRef = new WeakReference<GraphicsNode>(initialGraphicsNode); }
Example #12
Source File: SVGMapUtil.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Gets an SVG graphics node for a given map item name. * @param prefix the property key prefix (ex: building) * @param name the name of the map item. * @return the SVG graphics node. */ private static GraphicsNode getSVGGraphicsNode(String prefix, String name) { GraphicsNode result = null; // Load svgMapProperties from file if necessary. if (svgMapProperties == null) { loadSVGImageMappingPropertiesFile(); } // Append property prefix. StringBuffer propertyNameBuff = new StringBuffer(""); if (prefix != null) { propertyNameBuff.append(prefix); propertyNameBuff.append("."); } // Append name. if (name != null) { String prepName = name.trim().toLowerCase().replace(" ", "_"); propertyNameBuff.append(prepName); } String propertyName = propertyNameBuff.toString(); String svgFileName = svgMapProperties.getProperty(propertyName); if (svgFileName != null) { result = SVGLoader.getSVGImage(svgFileName); } return result; }
Example #13
Source File: VehicleMapLayer.java From mars-sim with GNU General Public License v3.0 | 5 votes |
@Override public void destroy() { // Clear all buffered image caches. Iterator<Map<GraphicsNode, BufferedImage>> i = svgImageCache.values().iterator(); while (i.hasNext()) { i.next().clear(); } svgImageCache.clear(); }
Example #14
Source File: VehicleMapLayer.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Creates a buffered image from a SVG graphics node. * @param svg the SVG graphics node. * @param width the width of the produced image. * @param length the length of the produced image. * @return the created buffered image. */ private BufferedImage createBufferedImage(GraphicsNode svg, double width, double length) { int imageWidth = (int) (width * scale); if (imageWidth <= 0) { imageWidth = 1; } int imageLength = (int) (length * scale); if (imageLength <= 0) { imageLength = 1; } BufferedImage bufferedImage = new BufferedImage( imageWidth, imageLength, BufferedImage.TYPE_INT_ARGB ); // Determine bounds. Rectangle2D bounds = svg.getBounds(); // Determine transform information. double scalingWidth = width / bounds.getWidth() * scale; double scalingLength = length / bounds.getHeight() * scale; // Draw the SVG image on the buffered image. Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); svg.setTransform(AffineTransform.getScaleInstance(scalingWidth, scalingLength)); svg.paint(g2d); // Cleanup and return image g2d.dispose(); return bufferedImage; }
Example #15
Source File: TestSVGMapUtil.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Test the getVehicleSVG method. */ public void testGetVehicleSVG() { // Check that all vehicle types are mapped to a SVG image. Iterator<String> i = SimulationConfig.instance().getVehicleConfiguration(). getVehicleTypes().iterator(); while (i.hasNext()) { String vehicleType = i.next(); GraphicsNode svg = SVGMapUtil.getVehicleSVG(vehicleType); assertNotNull(vehicleType + " is not mapped to a SVG image.", svg); } }
Example #16
Source File: TestSVGMapUtil.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Test the getMaintenanceOverlaySVG method. */ public void testGetMaintenanceOverlaySVG() { // Check that all vehicle types have a maintenance overlay mapped to a SVG image. Iterator<String> i = SimulationConfig.instance().getVehicleConfiguration(). getVehicleTypes().iterator(); while (i.hasNext()) { String vehicleType = i.next(); GraphicsNode svg = SVGMapUtil.getMaintenanceOverlaySVG(vehicleType); assertNotNull(vehicleType + " does not have a maintenance overlay mapped to a SVG image.", svg); } }
Example #17
Source File: SVGIcon.java From netbeans with Apache License 2.0 | 5 votes |
/** * Get the {@code GraphicsNode}, re-loading it from the original resource if a cached instance * is no longer available. Once this method has been called at least once, garbage collection * may cause the cache to be cleared. */ private synchronized GraphicsNode getGraphicsNode() throws IOException { GraphicsNode ret = graphicsNodeWeakRef.get(); if (ret != null) { // Allow the GraphicsNode to be garbage collected after the initial paint. graphicsNodeStrongRef = null; return ret; } ret = loadGraphicsNode(url, null); graphicsNodeWeakRef = new WeakReference<GraphicsNode>(ret); return ret; }
Example #18
Source File: TestSVGMapUtil.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Test the getLoadingOverlaySVG method. */ public void testGetLoadingOverlaySVG() { // Check that all vehicle types have a loading overlay mapped to a SVG image. Iterator<String> i = SimulationConfig.instance().getVehicleConfiguration(). getVehicleTypes().iterator(); while (i.hasNext()) { String vehicleType = i.next(); if (!vehicleType.equalsIgnoreCase("Light Utility Vehicle")) { GraphicsNode svg = SVGMapUtil.getLoadingOverlaySVG(vehicleType); assertNotNull(vehicleType + " does not have a loading overlay mapped to a SVG image.", svg); } } }
Example #19
Source File: TestSVGMapUtil.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Test the getAttachmentPartSVG method. */ public void testGetAttachmentPartSVG() { // Check that all vehicle attachment parts are mapped to a SVG image. Iterator<Part> i = SimulationConfig.instance().getVehicleConfiguration(). getAttachableParts("Light Utility Vehicle").iterator(); while (i.hasNext()) { Part attachmentPart = i.next(); GraphicsNode svg = SVGMapUtil.getAttachmentPartSVG(attachmentPart.getName()); assertNotNull(attachmentPart.getName() + " is not mapped to a SVG image.", svg); } }
Example #20
Source File: VehicleMapLayer.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Draw the SVG loading/unloading overlay on the vehicle. * @param g2d the graphics context. * @param vehicle the vehicle. */ private void drawSVGLoading(Graphics2D g2d, Vehicle vehicle) { // Use SVG image for vehicle loading overlay if available. GraphicsNode loadOverlaySvg = SVGMapUtil.getLoadingOverlaySVG(vehicle.getDescription().toLowerCase()); GraphicsNode vehicleSvg = SVGMapUtil.getVehicleSVG(vehicle.getDescription().toLowerCase()); if ((loadOverlaySvg != null) && (vehicleSvg != null)) { drawVehicleOverlay(g2d, vehicle.getXLocation(), vehicle.getYLocation(), vehicle.getWidth(), vehicle.getLength(), vehicle.getFacing(), vehicleSvg, loadOverlaySvg); } }
Example #21
Source File: VehicleMapLayer.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Draw the SVG repair/maint overlay on the vehicle. * @param g2d the graphics context. * @param vehicle the vehicle. */ private void drawSVGRepairMaint(Graphics2D g2d, Vehicle vehicle) { // Use SVG image for vehicle maintenance overlay if available. GraphicsNode maintOverlaySvg = SVGMapUtil.getMaintenanceOverlaySVG(vehicle.getDescription().toLowerCase()); GraphicsNode vehicleSvg = SVGMapUtil.getVehicleSVG(vehicle.getDescription().toLowerCase()); if ((maintOverlaySvg != null) && (vehicleSvg != null)) { drawVehicleOverlay(g2d, vehicle.getXLocation(), vehicle.getYLocation(), vehicle.getWidth(), vehicle.getLength(), vehicle.getFacing(), vehicleSvg, maintOverlaySvg); } }
Example #22
Source File: VehicleMapLayer.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Draws a vehicle on the map. * @param vehicle the vehicle. * @param g2d the graphics context. */ private void drawVehicle(Vehicle vehicle, Graphics2D g2d) { // Use SVG image for vehicle if available. GraphicsNode svg = SVGMapUtil.getVehicleSVG(vehicle.getDescription().toLowerCase()); if (svg != null) { // Draw base SVG image for vehicle. drawSVGVehicle(g2d, vehicle.getXLocation(), vehicle.getYLocation(), vehicle.getWidth(), vehicle.getLength(), vehicle.getFacing(), svg); // Draw overlay if the vehicle is being maintained or repaired. if (isVehicleRepairOrMaintenance(vehicle)) { drawSVGRepairMaint(g2d, vehicle); } // Draw overlay if the vehicle is being loaded or unloaded. if (isVehicleLoading(vehicle)) { drawSVGLoading(g2d, vehicle); } // Draw attachment parts for light utility vehicle. if (vehicle instanceof LightUtilityVehicle) { drawSVGPartAttachments(g2d, (LightUtilityVehicle) vehicle); } } else { // Otherwise draw colored rectangle for vehicle. drawRectangleVehicle( g2d, vehicle.getXLocation(), vehicle.getYLocation(), vehicle.getWidth(), vehicle.getLength(), vehicle.getFacing(), VEHICLE_COLOR ); } }
Example #23
Source File: WappalyzerJsonParser.java From zap-extensions with Apache License 2.0 | 5 votes |
private static ImageIcon createSvgIcon(URL url) throws Exception { if (url == null) { return null; } String xmlParser = XMLResourceDescriptor.getXMLParserClassName(); SAXSVGDocumentFactory df = new SAXSVGDocumentFactory(xmlParser); SVGDocument doc = null; GraphicsNode svgIcon = null; try { doc = df.createSVGDocument(url.toString()); } catch (RuntimeException re) { // v1 SVGs are unsupported return null; } doc.getRootElement().setAttribute("width", String.valueOf(SIZE)); doc.getRootElement().setAttribute("height", String.valueOf(SIZE)); UserAgent userAgent = new UserAgentAdapter(); DocumentLoader loader = new DocumentLoader(userAgent); GVTBuilder builder = new GVTBuilder(); try { svgIcon = builder.build(new BridgeContext(userAgent, loader), doc); } catch (BridgeException | StringIndexOutOfBoundsException ex) { logger.debug("Failed to parse SVG. " + ex.getMessage()); return null; } AffineTransform transform = new AffineTransform(1, 0.0, 0.0, 1, 0, 0); BufferedImage image = new BufferedImage(SIZE, SIZE, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = addRenderingHints(image); svgIcon.setTransform(transform); svgIcon.paint(g2d); g2d.dispose(); return new ImageIcon(image); }
Example #24
Source File: SVGDrawable.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public SVGDrawable( final GraphicsNode rootNode ) { if ( rootNode == null ) { throw new NullPointerException(); } this.rootNode = rootNode; final Rectangle2D bounds = rootNode.getBounds(); if ( bounds != null ) { this.width = bounds.getWidth(); this.height = bounds.getHeight(); } }
Example #25
Source File: StructureMapLayer.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Gets a buffered image for a given graphics node. * @param svg the SVG graphics node. * @param width the structure width (meters). * @param length the structure length (meters). * @param patternSVG the pattern SVG graphics node (null if no pattern). * @return buffered image. */ private BufferedImage getBufferedImage( GraphicsNode svg, double width, double length, GraphicsNode patternSVG) { // Get image cache for current scale or create it if it doesn't exist. Map<BuildingKey, BufferedImage> imageCache = null; if (svgImageCache.containsKey(scale)) { imageCache = svgImageCache.get(scale); } else { imageCache = new HashMap<BuildingKey, BufferedImage>(100); svgImageCache.put(scale, imageCache); } // Get image from image cache or create it if it doesn't exist. BufferedImage image = null; BuildingKey buildingKey = new BuildingKey(svg, width, length); if (imageCache.containsKey(buildingKey)) { image = imageCache.get(buildingKey); } else { image = createBufferedImage(svg, width, length, patternSVG); imageCache.put(buildingKey, image); } return image; }
Example #26
Source File: SvgTranscoder.java From radiance with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Transcodes the SVG image into Java2D code. Does nothing if the * {@link #listener} is <code>null</code>. * * @param templateStream Stream with the template content */ public Document transcode(InputStream templateStream) { if (this.listener == null) return null; UserAgentAdapter ua = new UserAgentAdapter(); DocumentLoader loader = new DocumentLoader(ua); BridgeContext batikBridgeContext = new BridgeContext(ua, loader); batikBridgeContext.setDynamicState(BridgeContext.DYNAMIC); ua.setBridgeContext(batikBridgeContext); GVTBuilder builder = new GVTBuilder(); Document svgDoc; try { svgDoc = loader.loadDocument(this.uri); GraphicsNode gvtRoot = builder.build(batikBridgeContext, svgDoc); this.transcode(gvtRoot, templateStream); return svgDoc; } catch (IOException ex) { Logger.getLogger(SvgTranscoder.class.getName()).log(Level.SEVERE, null, ex); return null; } finally { try { loader.dispose(); batikBridgeContext.dispose(); } catch (Throwable t) { Logger.getLogger(SvgTranscoder.class.getName()).log(Level.SEVERE, null, t); } } }
Example #27
Source File: StructureMapLayer.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Draws a construction site on the map. * @param site the construction site. * @param g2d the graphics context. */ private void drawConstructionSite(ConstructionSite site, Graphics2D g2d) { // Use SVG image for construction site if available. GraphicsNode svg = null; ConstructionStage stage = site.getCurrentConstructionStage(); //System.out.println("stage is " + stage.toString()); if (stage != null) { svg = SVGMapUtil.getConstructionSiteSVG(stage.getInfo().getName().toLowerCase()); } if (svg != null) { // Determine construction site pattern SVG image if available. GraphicsNode patternSVG = SVGMapUtil .getConstructionSitePatternSVG( stage.getInfo().getName().toLowerCase() ); drawSVGStructure( g2d, site.getXLocation(), site.getYLocation(), site.getWidth(), site.getLength(), site.getFacing(), svg, patternSVG ); } else { Color color = SELECTED_CONSTRUCTION_SITE_COLOR; // Else draw colored rectangle for construction site. if (site.isMousePicked()) color = SELECTED_CONSTRUCTION_SITE_COLOR; else color = CONSTRUCTION_SITE_COLOR; drawRectangleStructure( g2d, site.getXLocation(), site.getYLocation(), site.getWidth(), site.getLength(), site.getFacing(), color ); } }
Example #28
Source File: StructureMapLayer.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Draws a building on the map. * @param building the building. * @param g2d the graphics context. */ public void drawBuilding(Building building, Graphics2D g2d) { // Check if it's drawing the mouse-picked building if (building.equals(mapPanel.getSelectedBuilding())) selected = true; else selected = false; // Use SVG image for building if available. // Need to STAY getName() or getBuildingType(), NOT changing to getNickName() // or else svg for the building won't load up GraphicsNode svg = SVGMapUtil.getBuildingSVG(building.getBuildingType().toLowerCase()); if (svg != null) { // Determine building pattern SVG image if available. GraphicsNode patternSVG = SVGMapUtil.getBuildingPatternSVG(building.getBuildingType().toLowerCase()); drawSVGStructure( g2d, building.getXLocation(), building.getYLocation(), building.getWidth(), building.getLength(), building.getFacing(), svg, patternSVG ); } else { // Otherwise draw colored rectangle for building. drawRectangleStructure( g2d, building.getXLocation(), building.getYLocation(), building.getWidth(), building.getLength(), building.getFacing(), BUILDING_COLOR ); } }
Example #29
Source File: StructureMapLayer.java From mars-sim with GNU General Public License v3.0 | 5 votes |
public void drawOneBuilding(Building building, Graphics2D g2d) { GraphicsNode svg = SVGMapUtil.getBuildingSVG(building.getBuildingType().toLowerCase()); if (svg != null) { // Determine building pattern SVG image if available. GraphicsNode patternSVG = SVGMapUtil.getBuildingPatternSVG(building.getBuildingType().toLowerCase()); drawSVGStructure( g2d, 0.0, 0.0, //g2d, building.getXLocation(), building.getYLocation(), building.getWidth(), building.getLength(), building.getFacing(), svg, patternSVG ); } }
Example #30
Source File: SVGLoader.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Load the SVG image with the specified name. This operation may either * create a new graphics node of returned a previously created one. * @param name Name of the SVG file to load. * @return GraphicsNode containing SVG image or null if none found. */ public static GraphicsNode getSVGImage(String name) { if (svgCache == null) svgCache = new HashMap<String, GraphicsNode>(); GraphicsNode found = svgCache.get(name); if (found == null) { String fileName = SVG_DIR + name; URL resource = SVGLoader.class.getResource(fileName); try { String xmlParser = XMLResourceDescriptor.getXMLParserClassName(); SAXSVGDocumentFactory df = new SAXSVGDocumentFactory(xmlParser); SVGDocument doc = df.createSVGDocument(resource.toString()); UserAgent userAgent = new UserAgentAdapter(); DocumentLoader loader = new DocumentLoader(userAgent); BridgeContext ctx = new BridgeContext(userAgent, loader); ctx.setDynamicState(BridgeContext.DYNAMIC); GVTBuilder builder = new GVTBuilder(); found = builder.build(ctx, doc); svgCache.put(name, found); } catch (Exception e) { System.err.println("getSVGImage error: " + fileName); e.printStackTrace(System.err); } } return found; }