Ejemplo n.º 1
0
  // @Test
  public void experimentGraphic() throws IOException, ParameterException, InvalidStyle {
    JFrame frame = new JFrame();
    frame.setTitle("StrokeTest");

    // Get the JFrame’s ContentPane.
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new BorderLayout());

    // Create an instance of DisplayJAI.
    DisplayJAI dj = new DisplayJAI();

    System.out.println(dj.getColorModel());

    fts = new Style(null, "src/test/resources/org/orbisgis/core/renderer/se/strokes.se");

    // 1)
    /*try {
    	JAXBContext jaxbContext = JAXBContext.newInstance(Style.class);
    	Marshaller marshaller = jaxbContext.createMarshaller();
    	marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
              ByteArrayOutputStream oStream = new ByteArrayOutputStream();

    	//marshaller.marshal(fts.getJAXBElement(), oStream);
    } catch (Exception ex) {
              Services.getErrorManager().error("Unable to marshall", ex);
              ex.printStackTrace(System.err);
              assertTrue(false);
    }*/

    PointSymbolizer ps =
        (PointSymbolizer) fts.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0);
    GraphicCollection collec = ps.getGraphicCollection();

    MapTransform mt = new MapTransform();
    double width = Uom.toPixel(270, Uom.MM, mt.getDpi(), null, null);
    double height = Uom.toPixel(160, Uom.MM, mt.getDpi(), null, null);

    // Rectangle2D.Double dim = new Rectangle2D.Double(-width/2, -height/2, width, height);
    BufferedImage img = new BufferedImage((int) width, (int) height, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D rg = img.createGraphics();
    rg.setRenderingHints(mt.getRenderingHints());

    collec.draw(rg, null, false, mt, AffineTransform.getTranslateInstance(width / 2, height / 2));

    rg.setStroke(new BasicStroke(1));
    rg.setPaint(Color.BLACK);
    rg.drawLine(0, (int) height / 2, (int) width, (int) height / 2);
    rg.drawLine((int) width / 2, 0, (int) width / 2, (int) height);

    dj.setBounds(0, 0, (int) width, (int) height);
    // dj.setBounds((int)rg.getMinX(), (int)rg.getMinY(), (int)rg.getWidth(), (int)rg.getHeight());

    // RenderedImage r = rg.createRendering(mt.getCurrentRenderContext());

    dj.set(img, 0, 0);

    File file = new File("/tmp/stroke.png");
    ImageIO.write(img, "png", file);

    // Add to the JFrame’s ContentPane an instance of JScrollPane
    // containing the DisplayJAI instance.
    // contentPane.add(new JScrollPane(dj), BorderLayout.CENTER);
    contentPane.add(dj, BorderLayout.CENTER);

    // Set the closing operation so the application is finished.
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize((int) width, (int) height + 24); // adjust the frame size.
    frame.setVisible(true); // show the frame.

    try {
      Thread.sleep(5000);
    } catch (InterruptedException ex) {
      Logger.getLogger(StrokeTest.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Ejemplo n.º 2
0
  public void drawGraphic() throws IOException, ParameterException, InvalidStyle {
    JFrame frame = new JFrame();
    frame.setTitle("Test GraphicCollection");

    // Get the JFrame’s ContentPane.
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new BorderLayout());

    // Create an instance of DisplayJAI.
    DisplayJAI dj = new DisplayJAI();

    System.out.println(dj.getColorModel());

    fts = new Style(null, "src/test/resources/org/orbisgis/core/renderer/se/strokes_rapport.se");

    // 1)
    try {
      Marshaller marshaller = Services.JAXBCONTEXT.createMarshaller();
      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
      ByteArrayOutputStream oStream = new ByteArrayOutputStream();

      marshaller.marshal(fts.getJAXBElement(), oStream);
    } catch (Exception ex) {
      LOGGER.error("Unable to marshall", ex);
      ex.printStackTrace(System.err);
      assertTrue(false);
    }

    PointSymbolizer ps =
        (PointSymbolizer) fts.getRules().get(0).getCompositeSymbolizer().getSymbolizerList().get(0);
    GraphicCollection collec = ps.getGraphicCollection();

    MapTransform mt = new MapTransform();
    double width = Uom.toPixel(270, Uom.MM, mt.getDpi(), null, null);
    double height = Uom.toPixel(160, Uom.MM, mt.getDpi(), null, null);

    Rectangle2D.Double dim = new Rectangle2D.Double(-width / 2, -height / 2, width, height);
    RenderableGraphics rg = new RenderableGraphics(dim);

    collec.draw(rg, null, false, mt, new AffineTransform());

    rg.setPaint(Color.BLACK);
    rg.drawLine((int) rg.getMinX(), 0, (int) (rg.getMinX() + rg.getWidth()), 0);
    rg.drawLine(0, (int) rg.getMinY(), 0, (int) (rg.getMinY() + rg.getHeight()));

    dj.setBounds((int) rg.getMinX(), (int) rg.getMinY(), (int) rg.getWidth(), (int) rg.getHeight());
    RenderedImage r = rg.createRendering(mt.getCurrentRenderContext());
    dj.set(r, (int) rg.getWidth() / 2, (int) rg.getHeight() / 2);

    File file = new File("/tmp/stroke_rapport.png");
    ImageIO.write(r, "png", file);

    // Add to the JFrame’s ContentPane an instance of JScrollPane
    // containing the DisplayJAI instance.
    // contentPane.add(new JScrollPane(dj), BorderLayout.CENTER);
    contentPane.add(dj, BorderLayout.CENTER);

    // Set the closing operation so the application is finished.
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize((int) rg.getWidth(), (int) rg.getHeight() + 24); // adjust the frame size.
    frame.setVisible(true); // show the frame.

    try {
      Thread.sleep(5000);
    } catch (InterruptedException ex) {
      LOGGER.error(ex);
    }
  }