diff options
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/visualization/style')
10 files changed, 97 insertions, 86 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/visualization/style/ClusterStylingPolicy.java b/src/de/lmu/ifi/dbs/elki/visualization/style/ClusterStylingPolicy.java index 1d329736..7adecc68 100644 --- a/src/de/lmu/ifi/dbs/elki/visualization/style/ClusterStylingPolicy.java +++ b/src/de/lmu/ifi/dbs/elki/visualization/style/ClusterStylingPolicy.java @@ -77,14 +77,15 @@ public class ClusterStylingPolicy implements ClassStylingPolicy { colors = new TIntArrayList(clusters.size()); Iterator<? extends Cluster<?>> ci = clusters.iterator(); - for(int i = 0;; i++) { + for(int i = 0; ci.hasNext(); i++) { Cluster<?> c = ci.next(); ids.add(DBIDUtil.ensureSet(c.getIDs())); Color col = SVGUtil.stringToColor(colorset.getColor(i)); - if (col != null) { + if(col != null) { colors.add(col.getRGB()); - } else { - LoggingUtil.warning("Unrecognized color name: "+colorset.getColor(i)); + } + else { + LoggingUtil.warning("Unrecognized color name: " + colorset.getColor(i)); } if(!ci.hasNext()) { break; diff --git a/src/de/lmu/ifi/dbs/elki/visualization/style/PropertiesBasedStyleLibrary.java b/src/de/lmu/ifi/dbs/elki/visualization/style/PropertiesBasedStyleLibrary.java index 2bdae5e6..6b0869fb 100644 --- a/src/de/lmu/ifi/dbs/elki/visualization/style/PropertiesBasedStyleLibrary.java +++ b/src/de/lmu/ifi/dbs/elki/visualization/style/PropertiesBasedStyleLibrary.java @@ -49,7 +49,7 @@ public class PropertiesBasedStyleLibrary implements StyleLibrary { /** * Logger */ - protected static final Logging logger = Logging.getLogger(PropertiesBasedStyleLibrary.class); + private static final Logging LOG = Logging.getLogger(PropertiesBasedStyleLibrary.class); /** * Name of the default color scheme. @@ -130,24 +130,20 @@ public class PropertiesBasedStyleLibrary implements StyleLibrary { InputStream stream = null; try { stream = FileUtil.openSystemFile(filename); - } - catch(FileNotFoundException e) { + } catch (FileNotFoundException e) { try { stream = FileUtil.openSystemFile(filename + DEFAULT_PROPERTIES_EXTENSION); - } - catch(FileNotFoundException e2) { + } catch (FileNotFoundException e2) { try { stream = FileUtil.openSystemFile(DEFAULT_PROPERTIES_PATH + filename + DEFAULT_PROPERTIES_EXTENSION); - } - catch(FileNotFoundException e3) { + } catch (FileNotFoundException e3) { throw new AbortException("Could not find style scheme file '" + filename + "' for scheme '" + name + "'!"); } } } try { properties.load(stream); - } - catch(Exception e) { + } catch (Exception e) { throw new AbortException("Error loading properties file " + filename + ".\n", e); } } @@ -171,7 +167,7 @@ public class PropertiesBasedStyleLibrary implements StyleLibrary { * @return Resulting value */ private <T> T getCached(String prefix, String postfix, Class<T> cls) { - return cache.get(prefix + "." + postfix, cls); + return cache.get(prefix + '.' + postfix, cls); } /** @@ -183,7 +179,7 @@ public class PropertiesBasedStyleLibrary implements StyleLibrary { * @param data Data */ private <T> void setCached(String prefix, String postfix, T data) { - cache.put(prefix + "." + postfix, data); + cache.put(prefix + '.' + postfix, data); } /** @@ -195,26 +191,26 @@ public class PropertiesBasedStyleLibrary implements StyleLibrary { */ protected String getPropertyValue(String prefix, String postfix) { String ret = properties.getProperty(prefix + "." + postfix); - if(ret != null) { + if (ret != null) { // logger.debugFine("Found property: "+prefix + "." + // postfix+" for "+prefix); return ret; } int pos = prefix.length(); - while(pos > 0) { - pos = prefix.lastIndexOf(".", pos - 1); - if(pos <= 0) { + while (pos > 0) { + pos = prefix.lastIndexOf('.', pos - 1); + if (pos <= 0) { break; } - ret = properties.getProperty(prefix.substring(0, pos) + "." + postfix); - if(ret != null) { + ret = properties.getProperty(prefix.substring(0, pos) + '.' + postfix); + if (ret != null) { // logger.debugFine("Found property: "+prefix.substring(0, pos) + "." + // postfix+" for "+prefix); return ret; } } ret = properties.getProperty(postfix); - if(ret != null) { + if (ret != null) { // logger.debugFine("Found property: "+postfix+" for "+prefix); return ret; } @@ -239,7 +235,7 @@ public class PropertiesBasedStyleLibrary implements StyleLibrary { @Override public ColorLibrary getColorSet(String key) { ColorLibrary cl = getCached(key, COLORSET, ColorLibrary.class); - if(cl == null) { + if (cl == null) { String[] colors = getPropertyValue(key, COLORSET).split(LIST_SEPARATOR); cl = new ListBasedColorLibrary(colors, "Default"); setCached(key, COLORSET, cl); @@ -250,29 +246,27 @@ public class PropertiesBasedStyleLibrary implements StyleLibrary { @Override public double getLineWidth(String key) { Double lw = getCached(key, LINE_WIDTH, Double.class); - if(lw == null) { + if (lw == null) { try { - lw = Double.parseDouble(getPropertyValue(key, LINE_WIDTH)) * SCALE; - } - catch(NullPointerException e) { - throw new AbortException("Missing/invalid value in style library: " + key + "." + LINE_WIDTH); + lw = Double.valueOf(Double.parseDouble(getPropertyValue(key, LINE_WIDTH)) * SCALE); + } catch (NullPointerException e) { + throw new AbortException("Missing/invalid value in style library: " + key + '.' + LINE_WIDTH); } } - return lw; + return lw.doubleValue(); } @Override public double getTextSize(String key) { Double lw = getCached(key, TEXT_SIZE, Double.class); - if(lw == null) { + if (lw == null) { try { - lw = Double.parseDouble(getPropertyValue(key, TEXT_SIZE)) * SCALE; - } - catch(NullPointerException e) { - throw new AbortException("Missing/invalid value in style library: " + key + "." + TEXT_SIZE); + lw = Double.valueOf(Double.parseDouble(getPropertyValue(key, TEXT_SIZE)) * SCALE); + } catch (NullPointerException e) { + throw new AbortException("Missing/invalid value in style library: " + key + '.' + TEXT_SIZE); } } - return lw; + return lw.doubleValue(); } @Override @@ -283,47 +277,43 @@ public class PropertiesBasedStyleLibrary implements StyleLibrary { @Override public double getSize(String key) { Double lw = getCached(key, GENERIC_SIZE, Double.class); - if(lw == null) { + if (lw == null) { try { - lw = Double.parseDouble(getPropertyValue(key, GENERIC_SIZE)) * SCALE; - } - catch(NullPointerException e) { - throw new AbortException("Missing/invalid value in style library: " + key + "." + GENERIC_SIZE); + lw = Double.valueOf(Double.parseDouble(getPropertyValue(key, GENERIC_SIZE)) * SCALE); + } catch (NullPointerException e) { + throw new AbortException("Missing/invalid value in style library: " + key + '.' + GENERIC_SIZE); } } - return lw; + return lw.doubleValue(); } @Override public double getOpacity(String key) { Double lw = getCached(key, OPACITY, Double.class); - if(lw == null) { + if (lw == null) { try { - lw = Double.parseDouble(getPropertyValue(key, OPACITY)); - } - catch(NullPointerException e) { - throw new AbortException("Missing/invalid value in style library: " + key + "." + OPACITY); + lw = Double.valueOf(Double.parseDouble(getPropertyValue(key, OPACITY))); + } catch (NullPointerException e) { + throw new AbortException("Missing/invalid value in style library: " + key + '.' + OPACITY); } } - return lw; + return lw.doubleValue(); } @Override public LineStyleLibrary lines() { - if(linelib == null) { + if (linelib == null) { String libname = properties.getProperty(PROP_LINES_LIBRARY, SolidLineStyleLibrary.class.getName()); try { Class<?> cls; try { cls = Class.forName(libname); - } - catch(ClassNotFoundException e) { - cls = Class.forName(LineStyleLibrary.class.getPackage().getName() + "." + libname); + } catch (ClassNotFoundException e) { + cls = Class.forName(LineStyleLibrary.class.getPackage().getName() + '.' + libname); } linelib = (LineStyleLibrary) cls.getConstructor(StyleLibrary.class).newInstance(this); - } - catch(Exception e) { - logger.exception(e); + } catch (Exception e) { + LOG.exception(e); linelib = new SolidLineStyleLibrary(this); } } @@ -332,23 +322,21 @@ public class PropertiesBasedStyleLibrary implements StyleLibrary { @Override public MarkerLibrary markers() { - if(markerlib == null) { + if (markerlib == null) { String libname = properties.getProperty(PROP_MARKER_LIBRARY, PrettyMarkers.class.getName()); try { Class<?> cls; try { cls = Class.forName(libname); - } - catch(ClassNotFoundException e) { - cls = Class.forName(MarkerLibrary.class.getPackage().getName() + "." + libname); + } catch (ClassNotFoundException e) { + cls = Class.forName(MarkerLibrary.class.getPackage().getName() + '.' + libname); } markerlib = (MarkerLibrary) cls.getConstructor(StyleLibrary.class).newInstance(this); - } - catch(Exception e) { - logger.exception(e); + } catch (Exception e) { + LOG.exception(e); markerlib = new PrettyMarkers(this); } } return markerlib; } -}
\ No newline at end of file +} diff --git a/src/de/lmu/ifi/dbs/elki/visualization/style/StyleResult.java b/src/de/lmu/ifi/dbs/elki/visualization/style/StyleResult.java index fe8a73ce..e8f0d3fb 100644 --- a/src/de/lmu/ifi/dbs/elki/visualization/style/StyleResult.java +++ b/src/de/lmu/ifi/dbs/elki/visualization/style/StyleResult.java @@ -32,7 +32,6 @@ import de.lmu.ifi.dbs.elki.result.Result; * @apiviz.landmark * @apiviz.composedOf StylingPolicy */ -// TODO: pull style library etc. from VisualizerContext here? public class StyleResult implements Result { /** * Styling policy @@ -40,6 +39,11 @@ public class StyleResult implements Result { StylingPolicy policy; /** + * Style library + */ + StyleLibrary library; + + /** * Get the active styling policy * * @return Styling policy @@ -57,6 +61,24 @@ public class StyleResult implements Result { this.policy = policy; } + /** + * Get the style library + * + * @return Style library + */ + public StyleLibrary getStyleLibrary() { + return library; + } + + /** + * Get the style library + * + * @param library Style library + */ + public void setStyleLibrary(StyleLibrary library) { + this.library = library; + } + @Override public String getLongName() { return "Style policy"; @@ -66,4 +88,4 @@ public class StyleResult implements Result { public String getShortName() { return "style-policy"; } -}
\ No newline at end of file +} diff --git a/src/de/lmu/ifi/dbs/elki/visualization/style/lines/DashedLineStyleLibrary.java b/src/de/lmu/ifi/dbs/elki/visualization/style/lines/DashedLineStyleLibrary.java index 5dbfe67a..e3abd7c1 100644 --- a/src/de/lmu/ifi/dbs/elki/visualization/style/lines/DashedLineStyleLibrary.java +++ b/src/de/lmu/ifi/dbs/elki/visualization/style/lines/DashedLineStyleLibrary.java @@ -107,14 +107,14 @@ public class DashedLineStyleLibrary implements LineStyleLibrary { boolean interpolated = false; // process flavoring flags for(Object flag : flags) { - if(flag == LineStyleLibrary.FLAG_STRONG) { + if(LineStyleLibrary.FLAG_STRONG.equals(flag)) { width = width * 1.5; } - else if(flag == LineStyleLibrary.FLAG_WEAK) { + else if(LineStyleLibrary.FLAG_WEAK.equals(flag)) { cls.setStatement(CSSConstants.CSS_STROKE_OPACITY_PROPERTY, ".50"); width = width * 0.75; } - else if(flag == LineStyleLibrary.FLAG_INTERPOLATED) { + else if(LineStyleLibrary.FLAG_INTERPOLATED.equals(flag)) { interpolated = true; } } @@ -125,10 +125,10 @@ public class DashedLineStyleLibrary implements LineStyleLibrary { double[] pat = dashpatterns[styleflav]; assert (pat.length % 2 == 0); if(pat.length > 0) { - StringBuffer pattern = new StringBuffer(); + StringBuilder pattern = new StringBuilder(); for(int i = 0; i < pat.length; i++) { if(i > 0) { - pattern.append(","); + pattern.append(','); } pattern.append(SVGUtil.fmt(pat[i] * width * 30)); // pattern.append("%"); @@ -144,10 +144,10 @@ public class DashedLineStyleLibrary implements LineStyleLibrary { assert (pat.length % 2 == 0); // TODO: add dotting. if(pat.length > 0) { - StringBuffer pattern = new StringBuffer(); + StringBuilder pattern = new StringBuilder(); for(int i = 0; i < pat.length; i++) { if(i > 0) { - pattern.append(","); + pattern.append(','); } pattern.append(SVGUtil.fmt(pat[i] * width)); // pattern.append("%"); diff --git a/src/de/lmu/ifi/dbs/elki/visualization/style/lines/LineStyleLibrary.java b/src/de/lmu/ifi/dbs/elki/visualization/style/lines/LineStyleLibrary.java index aff1e0fc..79f3eda0 100644 --- a/src/de/lmu/ifi/dbs/elki/visualization/style/lines/LineStyleLibrary.java +++ b/src/de/lmu/ifi/dbs/elki/visualization/style/lines/LineStyleLibrary.java @@ -50,17 +50,17 @@ public interface LineStyleLibrary { /** * Meta flag to request a 'stronger' version of the style */ - public final static String FLAG_STRONG = "strong"; + public static final String FLAG_STRONG = "strong"; /** * Meta flag to request a 'weaker' version of the style */ - public final static String FLAG_WEAK = "weak"; + public static final String FLAG_WEAK = "weak"; /** * Meta flag to request an 'interpolated' version of the style */ - public final static String FLAG_INTERPOLATED = "interpolated"; + public static final String FLAG_INTERPOLATED = "interpolated"; /** * Add the formatting statements to the given CSS class. diff --git a/src/de/lmu/ifi/dbs/elki/visualization/style/lines/SolidLineStyleLibrary.java b/src/de/lmu/ifi/dbs/elki/visualization/style/lines/SolidLineStyleLibrary.java index 051bff0a..51491db2 100644 --- a/src/de/lmu/ifi/dbs/elki/visualization/style/lines/SolidLineStyleLibrary.java +++ b/src/de/lmu/ifi/dbs/elki/visualization/style/lines/SolidLineStyleLibrary.java @@ -87,20 +87,20 @@ public class SolidLineStyleLibrary implements LineStyleLibrary { boolean interpolated = false; // process flavoring flags for(Object flag : flags) { - if(flag == LineStyleLibrary.FLAG_STRONG) { + if(LineStyleLibrary.FLAG_STRONG.equals(flag)) { width = width * 1.5; } - else if(flag == LineStyleLibrary.FLAG_WEAK) { + else if(LineStyleLibrary.FLAG_WEAK.equals(flag)) { cls.setStatement(CSSConstants.CSS_STROKE_OPACITY_PROPERTY, ".50"); width = width * 0.75; } - else if(flag == LineStyleLibrary.FLAG_INTERPOLATED) { + else if(LineStyleLibrary.FLAG_INTERPOLATED.equals(flag)) { interpolated = true; } } cls.setStatement(CSSConstants.CSS_STROKE_WIDTH_PROPERTY, SVGUtil.fmt(width)); if(interpolated) { - cls.setStatement(CSSConstants.CSS_STROKE_DASHARRAY_PROPERTY, "" + SVGUtil.fmt(width / StyleLibrary.SCALE * 2) + "," + SVGUtil.fmt(width / StyleLibrary.SCALE * 2)); + cls.setStatement(CSSConstants.CSS_STROKE_DASHARRAY_PROPERTY, "" + SVGUtil.fmt(width / StyleLibrary.SCALE * 2.) + "," + SVGUtil.fmt(width / StyleLibrary.SCALE * 2.)); } } } diff --git a/src/de/lmu/ifi/dbs/elki/visualization/style/marker/CircleMarkers.java b/src/de/lmu/ifi/dbs/elki/visualization/style/marker/CircleMarkers.java index b847d571..ae066c9e 100644 --- a/src/de/lmu/ifi/dbs/elki/visualization/style/marker/CircleMarkers.java +++ b/src/de/lmu/ifi/dbs/elki/visualization/style/marker/CircleMarkers.java @@ -72,7 +72,7 @@ public class CircleMarkers implements MarkerLibrary { */ @Override public Element useMarker(SVGPlot plot, Element parent, double x, double y, int stylenr, double size) { - Element marker = plot.svgCircle(x, y, size / 2); + Element marker = plot.svgCircle(x, y, size * .5); final String col; if(stylenr == -1) { col = dotcolor; diff --git a/src/de/lmu/ifi/dbs/elki/visualization/style/marker/MinimalMarkers.java b/src/de/lmu/ifi/dbs/elki/visualization/style/marker/MinimalMarkers.java index 2f5a8c2a..b7ad6274 100644 --- a/src/de/lmu/ifi/dbs/elki/visualization/style/marker/MinimalMarkers.java +++ b/src/de/lmu/ifi/dbs/elki/visualization/style/marker/MinimalMarkers.java @@ -72,7 +72,7 @@ public class MinimalMarkers implements MarkerLibrary { */ @Override public Element useMarker(SVGPlot plot, Element parent, double x, double y, int stylenr, double size) { - Element marker = plot.svgRect(x - size / 2, y - size / 2, size, size); + Element marker = plot.svgRect(x - size * .5, y - size * .5, size, size); final String col; if(stylenr == -1) { col = dotcolor; diff --git a/src/de/lmu/ifi/dbs/elki/visualization/style/marker/PrettyMarkers.java b/src/de/lmu/ifi/dbs/elki/visualization/style/marker/PrettyMarkers.java index d868bb06..7352fea3 100644 --- a/src/de/lmu/ifi/dbs/elki/visualization/style/marker/PrettyMarkers.java +++ b/src/de/lmu/ifi/dbs/elki/visualization/style/marker/PrettyMarkers.java @@ -48,7 +48,7 @@ public class PrettyMarkers implements MarkerLibrary { /** * Default prefix to use. */ - private final static String DEFAULT_PREFIX = "s"; + private static final String DEFAULT_PREFIX = "s"; /** * Prefix for the IDs generated. @@ -159,7 +159,7 @@ public class PrettyMarkers implements MarkerLibrary { } case 5: { // O filled circle - Element circ = plot.svgCircle(x, y, size / 2); + Element circ = plot.svgCircle(x, y, size * .5); SVGUtil.setStyle(circ, SVGConstants.CSS_FILL_PROPERTY + ":" + colorstr); parent.appendChild(circ); break; @@ -192,7 +192,7 @@ public class PrettyMarkers implements MarkerLibrary { * @param size Size */ protected void plotGray(SVGPlot plot, Element parent, double x, double y, double size) { - Element marker = plot.svgCircle(x, y, size / 2); + Element marker = plot.svgCircle(x, y, size * .5); SVGUtil.setStyle(marker, SVGConstants.CSS_FILL_PROPERTY + ":" + greycolor); parent.appendChild(marker); } @@ -207,7 +207,7 @@ public class PrettyMarkers implements MarkerLibrary { * @param size Size */ protected void plotUncolored(SVGPlot plot, Element parent, double x, double y, double size) { - Element marker = plot.svgCircle(x, y, size / 2); + Element marker = plot.svgCircle(x, y, size * .5); SVGUtil.setStyle(marker, SVGConstants.CSS_FILL_PROPERTY + ":" + dotcolor); parent.appendChild(marker); } diff --git a/src/de/lmu/ifi/dbs/elki/visualization/style/presentation.properties b/src/de/lmu/ifi/dbs/elki/visualization/style/presentation.properties index 8c597066..01264673 100644 --- a/src/de/lmu/ifi/dbs/elki/visualization/style/presentation.properties +++ b/src/de/lmu/ifi/dbs/elki/visualization/style/presentation.properties @@ -74,9 +74,9 @@ xycurve.text-size=0.04 overview.labels.text-size=0.08 ## Selection colors -plot.selection.color=darkblue +plot.selection.color=red plot.selection.opacity=0.4 -plot.selection.size=0.015 +plot.selection.size=0.03 ## Circle segment colors. Will be interpolated to produce extra classes. segments.border.color=#FF0073 |