/*
 * Licensed Materials - Property of Perforce Software, Inc. 
 * © Copyright Perforce Software, Inc. 2014, 2021 
 * © Copyright IBM Corp. 2009, 2014
 * © Copyright ILOG 1996, 2009
 * All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:
 * The Software and Documentation were developed at private expense and
 * are "Commercial Items" as that term is defined at 48 CFR 2.101,
 * consisting of "Commercial Computer Software" and
 * "Commercial Computer Software Documentation", as such terms are
 * used in 48 CFR 12.212 or 48 CFR 227.7202-1 through 227.7202-4,
 * as applicable.
 */

import java.awt.BasicStroke;
import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.IOException;

import ilog.views.IlvManager;
import ilog.views.graphic.IlvMarker;
import ilog.views.maps.IlvMapCSSRenderer;
import ilog.views.maps.IlvMapFeatureIterator;
import ilog.views.maps.format.IlvMapLoader;
import ilog.views.maps.labelling.IlvLabeledPointRenderer;
import ilog.views.maps.rendering.IlvDefaultAreaRenderer;
import ilog.views.maps.rendering.IlvMapAreaRenderingStyle;
import ilog.views.maps.rendering.IlvMapLineRenderingStyle;
import ilog.views.maps.rendering.IlvMapPointRenderingStyle;
import ilog.views.maps.rendering.IlvMapTextRenderingStyle;
import ilog.views.util.java2d.IlvPattern;
import ilog.views.util.styling.IlvStylingException;

/*
#roadsLinesStyle {      
    class : 'ilog.views.maps.rendering.IlvMapLineRenderingStyle';
    foreground : red;
}

roads {
    class : 'ilog.views.maps.rendering.IlvDefaultCurveRenderer';
    lineRenderingStyle : @=roadsLinesStyle;
}
*/

public class CSSRenderer {
  IlvManager manager = new IlvManager();

  public void sample1() throws FileNotFoundException, IOException, IlvStylingException {
    IlvMapCSSRenderer cssRenderer = new IlvMapCSSRenderer(null, // use as
                                                                // default
                                                                // renderer
        "roads", new String[] { "simple.css" });
    IlvMapLoader loader = new IlvMapLoader(manager);
    IlvMapFeatureIterator iterator = loader.makeFeatureIterator("roads.shp");
    loader.load(iterator, cssRenderer);
  }

  public void sample2() {
    IlvLabeledPointRenderer labelRenderer = new IlvLabeledPointRenderer();
    IlvMapPointRenderingStyle pStyle = new IlvMapPointRenderingStyle();
    pStyle.setMarkerSize(8);
    pStyle.setMarkerType(IlvMarker.IlvMarkerFilledDiamond | IlvMarker.IlvMarkerSquare);
    pStyle.setMarkerColor(new java.awt.Color(255, 238, 4, 153));
    // The #99ffee04 color notation has the same syntaxe as HTML,
    // the first 2 digits after the # represent the alpha channel.
    IlvMapTextRenderingStyle tStyle = new IlvMapTextRenderingStyle();
    tStyle.setBackgroundPaint(Color.yellow);
    tStyle.setFramePaint(Color.green);
    tStyle.setInnerMargin(2);
    tStyle.setMaximumHeight(20);
    tStyle.setMinimumHeight(15);
    tStyle.setScale(0.0000025f);
    tStyle.setAntialiasing(true);
//    IlvLabeledPointRenderer labelRender = new IlvLabeledPointRenderer();
    labelRenderer.setAttributeNames(new String[] { "nam" });
    labelRenderer.setPointRenderingStyle(pStyle);
    labelRenderer.setTextRenderingStyle(tStyle);
  }

  public void sample3() {
    IlvPattern pattern1 = new IlvPattern(IlvPattern.THICK_DIAGONAL_GRID, Color.gray, new Color(245, 222, 179));
    IlvMapLineRenderingStyle builtareasLineStyle = new IlvMapLineRenderingStyle();
    builtareasLineStyle.setForeground(new Color(128, 0, 0));
    builtareasLineStyle.setLineWidthZoomed(true);
    builtareasLineStyle.setLineWidth(2);
    builtareasLineStyle.setLineJoin(BasicStroke.JOIN_MITER);
    builtareasLineStyle.setEndCap(BasicStroke.CAP_ROUND);
    IlvMapAreaRenderingStyle builtareasAreaStyle = new IlvMapAreaRenderingStyle();
    builtareasAreaStyle.setFillingObject(true);
    builtareasAreaStyle.setFillPattern(pattern1);
    builtareasAreaStyle.setDrawingStroke(true);
    builtareasAreaStyle.setLineRenderingStyle(builtareasLineStyle);
    IlvDefaultAreaRenderer builtareas = new IlvDefaultAreaRenderer();
    builtareas.setUsingGeneralPath(true);
    builtareas.setAreaRenderingStyle(builtareasAreaStyle);
  }
}