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

Reply via email to