/** * Adds the rule and symbol panels for the rules and symbols attached to the given style and * returns a list of the corresponding {@link RuleWrapper}s. * * @param style Style * @return A list of {@link RuleWrapper}s corresponding to the newly added rule panels. * @see #addSymbolPanels(org.orbisgis.coremap.renderer.se.Rule) */ private List<RuleWrapper> addRuleAndSymbolPanels(Style style) { List<Rule> rules = style.getRules(); List<RuleWrapper> ruleWrapperList = new LinkedList<RuleWrapper>(); for (int i = 0; i < rules.size(); i++) { // Get the rule. Rule rule = rules.get(i); // Get a new RuleWrapper based on this rule and the list of // symbol panels constructed in addSymbolPanels. RuleWrapper ruleWrapper = new RuleWrapper(this, rule, addSymbolPanels(rule)); addRulePanel(ruleWrapper); // Add the rule wrapper panel to the list of rule wrapper panels. ruleWrapperList.add(ruleWrapper); } return ruleWrapperList; }
// @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); } }