/** * Adds the MATSim Logo in the lower right corner of the chart. */ public void addMatsimLogo() { try { Image image = MatsimResource.getAsImage("matsim_logo_transparent_small.png"); Title subtitle = new ImageTitle(image, RectangleEdge.BOTTOM, HorizontalAlignment.RIGHT, VerticalAlignment.BOTTOM); this.chart.addSubtitle(subtitle); } catch ( Exception e ) { e.printStackTrace() ; // I just had a resource-not-found error inside the method; don't know what that means but does not feel like a reason // to not continue. kai, apr'30 } }
@Override protected void onInit(GL2 gl) { texture = GLUtils.createTexture(gl, MatsimResource.getAsInputStream("icon18.png")); }
/** * @param filename relative path from within the resource directory to a file to be loaded * @return a Stream to the requested resource file, or <code>null</code> if no such file exists. */ public final static Image getAsImage(final String filename) { final URL url = getAsURL(filename); if (url == null) { return null; } try { return ImageIO.read(url); } catch (IOException e) { log.error("Could not load requested image", e); return null; } } }
private void copyResourceToFile(final String resourceFilename, final String destinationFilename) throws IOException { InputStream inStream = null; OutputStream outStream = null; try { inStream = MatsimResource.getAsInputStream(resourceFilename); outStream = new FileOutputStream(destinationFilename); IOUtils.copyStream(inStream, outStream); } finally { if (inStream != null) { inStream.close(); } if (outStream != null) { outStream.close(); } } }
public final void testGetAsImage() { final Image logo = MatsimResource.getAsImage("matsim_logo_transparent.png"); // verify that the correct image was correctly loaded by testing its dimension assertEquals(256, logo.getWidth(null)); assertEquals(48, logo.getHeight(null)); }
this.writer.addNonKMLFile(MatsimResource.getAsInputStream("car.png"), "data/car.png"); iconLink.setHref("./car.png"); } catch (IOException e1) {
playIcon = new ImageIcon(MatsimResource.getAsImage("otfvis/buttonPlay.png"), "Play"); pauseIcon = new ImageIcon(MatsimResource.getAsImage("otfvis/buttonPause.png"), "Pause"); button2.setToolTipText("restart the server/simulation"); String imgLocation2 = "otfvis/" + "buttonRestart" + ".png"; ImageIcon icon2 = new ImageIcon(MatsimResource.getAsImage(imgLocation2), "Restart"); button2.setIcon(icon2); add(button2); button1.setToolTipText("go several timesteps backwards"); String imgLocation1 = "otfvis/" + "buttonStepBB" + ".png"; ImageIcon icon1 = new ImageIcon(MatsimResource.getAsImage(imgLocation1), "<<"); button1.setIcon(icon1); add(button1); button.setToolTipText("go one timestep backwards"); String imgLocation = "otfvis/" + "buttonStepB" + ".png"; ImageIcon icon = new ImageIcon(MatsimResource.getAsImage(imgLocation), "<"); button.setIcon(icon); add(button); button2.setToolTipText("press to play simulation continuously"); String imgLocation2 = "otfvis/" + "buttonPlay" + ".png"; ImageIcon icon2 = new ImageIcon(MatsimResource.getAsImage(imgLocation2), "PLAY"); button2.setIcon(icon2); playPauseButton = button2; button1.setToolTipText("go one timestep forward"); String imgLocation1 = "otfvis/" + "buttonStepF" + ".png";
@Override public StyleType createDefaultNetworkNodeStyle() throws IOException { if (this.defaultnetworknodestyle == null) { this.defaultnetworknodestyle = kmlObjectFactory.createStyleType(); this.defaultnetworknodestyle.setId("defaultnetworknodestyle"); LinkType iconLink = kmlObjectFactory.createLinkType(); iconLink.setHref(DEFAULTNODEICON); this.writer.addNonKMLFile(MatsimResource.getAsInputStream(DEFAULTNODEICONRESOURCE), DEFAULTNODEICON); IconStyleType iStyle = kmlObjectFactory.createIconStyleType(); iStyle.setIcon(iconLink); iStyle.setColor(MatsimKmlStyleFactory.MATSIMRED); iStyle.setScale(MatsimKmlStyleFactory.ICONSCALE); this.defaultnetworknodestyle.setIconStyle(iStyle); this.document.getAbstractStyleSelectorGroup().add(kmlObjectFactory.createStyle(this.defaultnetworknodestyle)); } return this.defaultnetworknodestyle; }
.getAsInputStream("icons/plus.png"), CROSSICON); this.writer.addNonKMLFile(MatsimResource .getAsInputStream("icons/minus.png"), MINUSICON); } catch (IOException e) { log.error("Could not copy copy plus-/minus-icons to the KMZ.", e);
long iconFileSize = ByteStreams.toByteArray(MatsimResource.getAsInputStream(MatsimKmlStyleFactory.DEFAULTNODEICONRESOURCE)).length; assertEquals("uncompressed size of icon is wrong.", iconFileSize, linkIconEntry.getSize()); assertEquals("uncompressed size of icon is wrong.", iconFileSize, nodeIconEntry.getSize());
@Override public StyleType createDefaultNetworkLinkStyle() throws IOException { if (this.defaultnetworklinkstyle == null) { this.defaultnetworklinkstyle = kmlObjectFactory.createStyleType(); this.defaultnetworklinkstyle.setId("defaultnetworklinkstyle"); LinkType iconLink = kmlObjectFactory.createLinkType(); iconLink.setHref(DEFAULTLINKICON); this.writer.addNonKMLFile(MatsimResource.getAsInputStream(DEFAULTNODEICONRESOURCE), DEFAULTLINKICON); IconStyleType iStyle = kmlObjectFactory.createIconStyleType(); iStyle.setIcon(iconLink); iStyle.setColor(MatsimKmlStyleFactory.MATSIMWHITE); iStyle.setScale(MatsimKmlStyleFactory.ICONSCALE); this.defaultnetworklinkstyle.setIconStyle(iStyle); LineStyleType lineStyle = kmlObjectFactory.createLineStyleType(); lineStyle.setColor(MatsimKmlStyleFactory.MATSIMGREY); lineStyle.setWidth(12.0); this.defaultnetworklinkstyle.setLineStyle(lineStyle); this.document.getAbstractStyleSelectorGroup().add(kmlObjectFactory.createStyle(this.defaultnetworklinkstyle)); } return this.defaultnetworklinkstyle; }
this.writer.addNonKMLFile(MatsimResource.getAsInputStream("icons/circle.png"), CIRCLEICON); this.writer.addNonKMLFile(MatsimResource.getAsInputStream("icons/plus.png"), CROSSICON); this.writer.addNonKMLFile(MatsimResource.getAsInputStream("icons/minus.png"), MINUSICON); } catch (IOException e) { log.error("Could not copy copy plus-/minus-icons to the KMZ.", e);
@Override public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); this.textRenderer = new TextRenderer(new Font("SansSerif", Font.PLAIN, 32), true, false); gl.setSwapInterval(0); float[] components = otfVisConfig.getBackgroundColor().getColorComponents(new float[4]); gl.glClearColor(components[0], components[1], components[2], components[3]); gl.glClear( GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); if (!glInited) { // This method can (and will) be called several times. // (Gl contexts can change without notice.) float minEasting = (float)clientQ.getMinEasting(); float minNorthing = (float)clientQ.getMinNorthing(); float maxNorthing = (float)clientQ.getMaxNorthing(); double aspectRatio = (double) drawable.getSurfaceWidth() / (double) drawable.getSurfaceHeight(); double pixelRatio = (double) drawable.getSurfaceHeight() / (double) (maxNorthing-minNorthing); this.scale = 1.0f / (float) pixelRatio; this.viewBounds = new QuadTree.Rect(minEasting, minNorthing, minEasting + (maxNorthing - minNorthing) * aspectRatio, maxNorthing); if (otfVisConfig.isMapOverlayMode()) { setScale(nearestPowerOfTwo(this.scale)); } int time = this.hostControlBar.getSimTime(); QuadTree.Rect rect = new QuadTree.Rect((float)clientQ.getMinEasting(), (float)clientQ.getMinNorthing(), (float)clientQ.getMaxEasting(), (float)clientQ.getMaxNorthing()); this.currentSceneGraph = this.clientQ.getSceneGraph(time, rect); } marker = GLUtils.createTexture(gl, MatsimResource.getAsInputStream("otfvis/marker.png")); currentSceneGraph.glInit(); glInited = true; }
/** * Creates a legend * @return a ScreenOverlay read from a file * @throws IOException */ private ScreenOverlayType createLegend() throws IOException { this.writer.addNonKMLFile(MatsimResource.getAsInputStream("countsKml/countsLegend240x300.png"), "countsLegend.png"); ScreenOverlayType overlay = this.kmlObjectFactory.createScreenOverlayType(); LinkType icon = this.kmlObjectFactory.createLinkType(); icon.setHref("./countsLegend.png"); overlay.setIcon(icon); overlay.setName("Legend"); // place the image bottom left Vec2Type overlayXY = this.kmlObjectFactory.createVec2Type(); overlayXY.setX(0.0); overlayXY.setY(0.0); overlayXY.setXunits(UnitsEnumType.FRACTION); overlayXY.setYunits(UnitsEnumType.FRACTION); overlay.setOverlayXY(overlayXY); Vec2Type screenXY = this.kmlObjectFactory.createVec2Type(); screenXY.setX(0.02); screenXY.setY(0.07); screenXY.setXunits(UnitsEnumType.FRACTION); screenXY.setYunits(UnitsEnumType.FRACTION); overlay.setScreenXY(screenXY); return overlay; }
/** * Creates a legend * * @return a ScreenOverlay read from a file * @throws IOException */ private ScreenOverlayType createLegend() throws IOException { this.writer.addNonKMLFile(MatsimResource .getAsInputStream("countsKml/countsLegend240x300.png"), "countsLegend.png"); ScreenOverlayType overlay = kmlObjectFactory.createScreenOverlayType(); LinkType icon = kmlObjectFactory.createLinkType(); icon.setHref("./countsLegend.png"); overlay.setIcon(icon); overlay.setName("Legend"); // place the image bottom left Vec2Type overlayXY = kmlObjectFactory.createVec2Type(); overlayXY.setX(0.0); overlayXY.setY(0.0); overlayXY.setXunits(UnitsEnumType.FRACTION); overlayXY.setYunits(UnitsEnumType.FRACTION); overlay.setOverlayXY(overlayXY); Vec2Type screenXY = kmlObjectFactory.createVec2Type(); screenXY.setX(0.02); screenXY.setY(0.07); screenXY.setXunits(UnitsEnumType.FRACTION); screenXY.setYunits(UnitsEnumType.FRACTION); overlay.setScreenXY(screenXY); return overlay; }
/** * Creates a legend * @return a ScreenOverlay read from a file * @throws IOException */ private ScreenOverlayType createLegendNormalized() throws IOException { this.writer.addNonKMLFile(MatsimResource.getAsInputStream("countsKml/countsLegendNormalized.png"), "countsLegendNormalized.png"); ScreenOverlayType overlay = this.kmlObjectFactory.createScreenOverlayType(); LinkType icon = this.kmlObjectFactory.createLinkType(); icon.setHref("./countsLegendNormalized.png"); overlay.setIcon(icon); overlay.setName("Legend Normalized"); // place the image bottom left Vec2Type overlayXY = this.kmlObjectFactory.createVec2Type(); overlayXY.setX(0.0); overlayXY.setY(0.0); overlayXY.setXunits(UnitsEnumType.FRACTION); overlayXY.setYunits(UnitsEnumType.FRACTION); overlay.setOverlayXY(overlayXY); Vec2Type screenXY = this.kmlObjectFactory.createVec2Type(); screenXY.setX(0.02); screenXY.setY(0.07); screenXY.setXunits(UnitsEnumType.FRACTION); screenXY.setYunits(UnitsEnumType.FRACTION); overlay.setScreenXY(screenXY); overlay.setVisibility(Boolean.FALSE); return overlay; }
/** * Creates a legend * @return a ScreenOverlay read from a file * @throws IOException */ private ScreenOverlayType createLegendGEH() throws IOException { this.writer.addNonKMLFile(MatsimResource.getAsInputStream("countsKml/countsLegendGEH.png"), "countsLegendGEH.png"); ScreenOverlayType overlay = this.kmlObjectFactory.createScreenOverlayType(); LinkType icon = this.kmlObjectFactory.createLinkType(); icon.setHref("./countsLegendGEH.png"); overlay.setIcon(icon); overlay.setName("Legend GEH"); // place the image bottom left Vec2Type overlayXY = this.kmlObjectFactory.createVec2Type(); overlayXY.setX(0.0); overlayXY.setY(0.0); overlayXY.setXunits(UnitsEnumType.FRACTION); overlayXY.setYunits(UnitsEnumType.FRACTION); overlay.setOverlayXY(overlayXY); Vec2Type screenXY = this.kmlObjectFactory.createVec2Type(); screenXY.setX(0.02); screenXY.setY(0.07); screenXY.setXunits(UnitsEnumType.FRACTION); screenXY.setYunits(UnitsEnumType.FRACTION); overlay.setScreenXY(screenXY); overlay.setVisibility(Boolean.FALSE); return overlay; }
writer.addNonKMLFile(MatsimResource.getAsInputStream("matsim_logo_transparent.png"), "matsimLogo.png");