use of org.geotools.styling.FeatureTypeStyle in project hale by halestudio.
the class StyleHelper method getSpectrumStyles.
/**
* Returns a default style for the given type.
*
* @param dataSetTypes type definitions associated to their data set
* @return the style
*/
public static Style getSpectrumStyles(SetMultimap<DataSet, TypeDefinition> dataSetTypes) {
int defWidth = StylePreferences.getDefaultWidth();
Style style = styleFactory.createStyle();
GeometrySchemaService gss = PlatformUI.getWorkbench().getService(GeometrySchemaService.class);
for (DataSet dataSet : dataSetTypes.keySet()) {
float saturation;
float brightness;
switch(dataSet) {
case TRANSFORMED:
saturation = 0.8f;
brightness = 0.6f;
break;
case SOURCE:
default:
saturation = 0.75f;
brightness = 0.8f;
break;
}
Set<TypeDefinition> types = new HashSet<>(dataSetTypes.get(dataSet));
Iterator<TypeDefinition> it = types.iterator();
while (it.hasNext()) {
TypeDefinition type = it.next();
// remove invalid types
if (type.getConstraint(AbstractFlag.class).isEnabled() || gss.getDefaultGeometry(type) == null) {
it.remove();
}
}
int numberOfTypes = types.size();
int index = 0;
for (TypeDefinition typeDef : types) {
FeatureTypeStyle fts;
// TODO based on default geometry?
// polygon is always OK as it contains stroke and fill
// Color color = generateRandomColor(Color.WHITE);
Color color;
if (numberOfTypes == 1) {
color = generateRandomColor(saturation, brightness);
} else {
color = Color.getHSBColor((float) index / (float) numberOfTypes, saturation, brightness);
}
fts = createPolygonStyle(color, defWidth);
fts.featureTypeNames().add(new NameImpl(getFeatureTypeName(typeDef)));
style.featureTypeStyles().add(fts);
index++;
}
}
return style;
}
use of org.geotools.styling.FeatureTypeStyle in project hale by halestudio.
the class StyleHelper method createPointStyle.
/**
* Manually create a default point style.
*
* @param color the point color
* @param width the line width
* @return a Style for Point objects.
*/
@SuppressWarnings("unused")
private static FeatureTypeStyle createPointStyle(Color color, double width) {
PointSymbolizer symbolizer = createPointSymbolizer(color, width);
// symbolizer.getGraphic().setSize(filterFactory.literal(1));
Rule rule = styleFactory.createRule();
rule.symbolizers().add(symbolizer);
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
fts.rules().add(rule);
return fts;
}
use of org.geotools.styling.FeatureTypeStyle in project hale by halestudio.
the class StyleHelper method createLineStyle.
/**
* Create a default line style.
*
* @param color the line color
* @param width the line width
* @return a Style for Line/LineString objects.
*/
@SuppressWarnings("unused")
private static FeatureTypeStyle createLineStyle(Color color, double width) {
LineSymbolizer symbolizer = createLineSymbolizer(color, width);
Rule rule = styleFactory.createRule();
rule.symbolizers().add(symbolizer);
FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
fts.rules().add(rule);
return fts;
}
use of org.geotools.styling.FeatureTypeStyle in project hale by halestudio.
the class FeatureStyleDialog method setStyle.
/**
* Set the feature type style
*
* @param style the style
*/
public void setStyle(Style style) {
// set the feature names
for (FeatureTypeStyle fts : style.featureTypeStyles()) {
fts.featureTypeNames().clear();
fts.featureTypeNames().add(new NameImpl(StyleHelper.getFeatureTypeName(type)));
}
this.style = style;
}
use of org.geotools.styling.FeatureTypeStyle in project hale by halestudio.
the class RuleStylePage method getStyle.
/**
* @see FeatureStylePage#getStyle(boolean)
*/
@Override
public Style getStyle(boolean force) throws Exception {
updateCurrentRule();
if (force || changed) {
Rule[] ruleArray = new Rule[rules.size()];
for (int i = 0; i < rules.size(); i++) {
Rule rule = rules.get(i).getRule();
// set else filter
rule.setIsElseFilter(rule.getFilter() == null);
// TODO other rule manipulation?
ruleArray[i] = rule;
}
// create style
// $NON-NLS-1$
FeatureTypeStyle fts = styleBuilder.createFeatureTypeStyle("Feature", ruleArray);
Style style = styleBuilder.createStyle();
style.featureTypeStyles().add(fts);
return style;
} else {
return null;
}
}
Aggregations