Hi Luca,
here is another example:

public boolean execute(PlugInContext context) throws Exception{
   
        this.reportNothingToUndoYet(context);
        Layer lyr=context.getLayerManager().getLayer("yourLayerName");
       
        //getting the ColorThemingStyle from the layer
        ColorThemingStyle colorThemingStyle = ColorThemingStyle.get(lyr);
        //defining the field on which the ColorThemingStyle is based
      colorThemingStyle.setAttributeName("yourFieldName");
      //creating an invisible BasicStyle and making it the DefaultStyle of the ColorThemingStyle
      BasicStyle defStyle = new BasicStyle();
      defStyle.setAlpha(255);
      colorThemingStyle.setDefaultStyle(defStyle);
      //as an example creating some BasicStyles
      BasicStyle basStyle1 = new BasicStyle();
      basStyle1.setFillColor(new Color(255,255,153));
      basStyle1.setLineColor(new Color(178,178,107));
      basStyle1.setLineWidth(1);
      BasicStyle basStyle2 = new BasicStyle();
      basStyle2.setFillColor(new Color(255,99,75));
      basStyle2.setLineColor(new Color(178,69,52));
      basStyle2.setLineWidth(1);
      BasicStyle basStyle3 = new BasicStyle();
      basStyle3.setFillColor(new Color(127,201,127));
      basStyle3.setLineColor(new Color(88,140,88));
      basStyle3.setLineWidth(1);
      BasicStyle basStyle4 = new BasicStyle();
      basStyle4.setFillColor(new Color(0,153,0));
      basStyle4.setLineColor(new Color(0,107,0));
      basStyle4.setLineWidth(1);;
      basStyle4.setFillPattern(WKTFillPattern.createVerticalHorizontalStripePattern(2, 2, false, true));
      basStyle4.setRenderingFillPattern(true);
      BasicStyle basStyle6 = new BasicStyle();
      basStyle6.setFillColor(new Color(0,0,0));
      basStyle6.setLineColor(new Color(0,0,0));
      basStyle6.setLineWidth(1);
      basStyle6.setFillPattern(WKTFillPattern.createDiagonalStripePattern(2, 2, true, false));
      basStyle6.setRenderingFillPattern(true);
      //creating a HashMap and making it the AttributeValueToBasicStyleMap of the ColorThemingStyle
      //(referencing the values in the field set above to a BasicStyle)
      HashMap<Integer,BasicStyle> attributeToStyleMap = new HashMap<Integer,BasicStyle>();
        attributeToStyleMap.put(1, basStyle1);
        attributeToStyleMap.put(2, basStyle2);
        attributeToStyleMap.put(3, basStyle3);
        attributeToStyleMap.put(4, basStyle4);
        attributeToStyleMap.put(6, basStyle6);
      colorThemingStyle.setAttributeValueToBasicStyleMap(attributeToStyleMap);
      //creating a HashMap and making it the AttributeValueToLabelMap of the ColorThemingStyle
      //(referencing the values in the field set above to a Label)
      HashMap<Integer,String> attributeToLabelMap = new HashMap<Integer,String>();
      attributeToLabelMap.put(1, "firstLabel");
      attributeToLabelMap.put(2, "secondLabel");
      attributeToLabelMap.put(3, "thirdLabel");
      attributeToLabelMap.put(4, "fourthLabel");
      attributeToLabelMap.put(6, "fifthLabel");
      colorThemingStyle.setAttributeValueToLabelMap(attributeToLabelMap);
      //disable the BasicStyle and enable the ColorThemingStyle of the layer
      colorThemingStyle.setEnabled(true);
      lyr.getBasicStyle().setEnabled(false);
      lyr.fireAppearanceChanged();
      bolRueck=true;
}


Larry Becker schrieb:
Here is an example:

   public boolean execute(final PlugInContext context) throws Exception
    {
        reportNothingToUndoYet(context);
        new CopySelectedItemsPlugIn().execute(context);
       
        Layer[] selectedLayers = context.getLayerNamePanel().getSelectedLayers();
       
        FeatureSchema featureSchema = new FeatureSchema();
            featureSchema.addAttribute("GEOMETRY", AttributeType.GEOMETRY);
        featureSchema.addAttribute(LAYER, AttributeType.STRING);
        //add all attributes from selected layers
        for (int i=0; i<selectedLayers.length; i++) {
            FeatureSchema schema = selectedLayers[i].getFeatureCollectionWrapper()
                .getFeatureSchema();
            for (int j=0; j<schema.getAttributeCount(); j++) {
                String name = schema.getAttributeName(j);
                if (!featureSchema.hasAttribute(name)) {
                    featureSchema.addAttribute(name, schema.getAttributeType(name));
                } else if (schema.getAttributeType(name)
                        != featureSchema.getAttributeType(name)) {
                    featureSchema.addAttribute(name
                            +getAttributeTypeChar(schema.getAttributeType(name)),
                            schema.getAttributeType(name));                   
                }
            }
        }

        FeatureDataset featureDataset = new FeatureDataset(featureSchema);
       
        Collection selectedCategories = context.getLayerNamePanel().getSelectedCategories();
        Layer newLayer = context.addLayer(selectedCategories.isEmpty()
            ? StandardCategoryNames.RESULT
            : selectedCategories.iterator().next().toString(), "Combined",
            featureDataset);
       
        newLayer.setFeatureCollectionModified(true).setEditable(true);
        Map attributeToStyleMap = new HashMap();
        ColorScheme colorScheme = ColorScheme.create("Set 3 (ColorBrewer)");         
        for (int i=0; i<selectedLayers.length; i++) {
            Layer layer = selectedLayers[i];
            Collection features = layer.getFeatureCollectionWrapper().getFeatures();
            newLayer.getFeatureCollectionWrapper().addAll(
                    conform(features,featureSchema, layer.getName()));
            attributeToStyleMap.put(layer.getName(), new BasicStyle(colorScheme.next()));
        }

        newLayer.getBasicStyle().setEnabled(false);
        ColorThemingStyle themeStyle = new ColorThemingStyle(LAYER, attributeToStyleMap, new BasicStyle(Color.gray));
        themeStyle.setEnabled(true);
        newLayer.addStyle(themeStyle);
        ColorThemingStyle.get(newLayer).setEnabled(true);
        newLayer.removeStyle(ColorThemingStyle.get(newLayer));
        ColorThemingStyle.get(newLayer).setEnabled(true);
        newLayer.getBasicStyle().setEnabled(false);
       
        return true;
    }
 
regards,
Larry

On Tue, Dec 8, 2009 at 10:54 AM, luca marletta <lucama...@gmail.com> wrote:
Hi All,
first tanks for the new openjump 1.3.1!!

This my question:

Can some one give me an suggestion which way I can apply a color
scheme for each feature based on a field. I mean the same effect that
from theme panel but programmaticaly.

I'm working on a plugin for check polygon and I'd like to see the
result immediately by colors.

I need an indication for some class or some piece of code.

Thanks a lot

luca

luca marletta
www.beopen.it

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel



--
Larry Becker
Integrated Systems Analysts, Inc.

------------------------------------------------------------------------------ Return on Information: Google Enterprise Search pays you back Get the facts. http://p.sf.net/sfu/google-dev2dev

_______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel


-- 
Dipl.-Biol. Nils Kuhn
Email: nils.k...@bws-gmbh.de
Fon: +49 (0)40 - 23 16 65-26
Fax: +49 (0)40 - 23 16 65-01

BWS GmbH 
Gotenstraße 14
D-20097 Hamburg
Sitz der Gesellschaft: Hamburg
Amtsgericht Hamburg: HRB 87830
Geschäftsführer:
Dipl.-Geol. Robert Dési
Dipl.-Geogr. Hydr. Lutz Krob


*************************************************************************************************************

HINWEIS: 
Diese E-Mail und beigefügte Dateien dienen nur der Vorabstimmung und stellen 
keine rechtswirksame Willenserklärungen oder Beratungsleistungen dar. Es können 
keine Haftungsansprüche gegenüber der BWS GmbH geltend gemacht werden. 
Alle rechtswirksamen Äußerungen (Verträge, Stellungnahmen, Berechnungen, Vermerke etc.)
erhalten Sie von uns in schriftlicher Form und gegebenenfalls auf separatem Datenträger.
Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, 
informieren Sie bitte den Absender und vernichten Sie diese E-Mail. 
Unerlaubtes Kopieren und Weiterleiten dieser E-Mail sind nicht gestattet.

*************************************************************************************************************
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to