Skip to content

Commit

Permalink
ttools: use static instances for plot modes
Browse files Browse the repository at this point in the history
Plot Modes as used in various plot types are now taken from static
members of the ShapeMode class rather than a new (stateless) instance
each time, which is a bit tidier and makes it easier to distinguish
whether two modes (hence Plotters) are the same.
  • Loading branch information
mbtaylor authored and mmpcn committed Nov 27, 2014
1 parent 00d7433 commit 372936c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
Expand Up @@ -24,7 +24,7 @@ public class SphereDataGeom implements DataGeom {
/**
* Private singleton constructor.
*/
public SphereDataGeom() {
private SphereDataGeom() {
}

/**
Expand Down
Expand Up @@ -48,8 +48,8 @@ public Plotter[] getPlotters() {
false, StyleKeys.ERROR_SHAPE_1D );
return new Plotter[] {
new LinePlotter(),
ShapePlotter.createFlatPlotter( MarkForm.SINGLE ),
ShapePlotter.createFlatPlotter( errorForm ),
ShapePlotter.createFlat2dPlotter( MarkForm.SINGLE ),
ShapePlotter.createFlat2dPlotter( errorForm ),
new SpectrogramPlotter( TimeDataGeom.T_COORD ),
new LabelPlotter(),
FunctionPlotter.PLANE,
Expand Down
61 changes: 39 additions & 22 deletions ttools/src/main/uk/ac/starlink/ttools/plot2/layer/ShapeMode.java
Expand Up @@ -54,6 +54,7 @@
* @since 19 Feb 2013
*/
public abstract class ShapeMode implements ModePlotter.Mode {

private final String name_;
private final Icon icon_;
private final Coord[] extraCoords_;
Expand All @@ -70,34 +71,50 @@ public abstract class ShapeMode implements ModePlotter.Mode {
*/
private static final int NO_BINS = Integer.MAX_VALUE;

/**
* List of modes suitable for use with 2D plotting.
*/
/** Auto density mode, no user settings. */
public static final ShapeMode AUTO = new AutoDensityMode();

/** Simple flat mode for use with 2D plots. */
public static final ShapeMode FLAT2D = new FlatMode( false, BIN_THRESH_2D );

/** Simple flat mode for use with 3D plots. */
public static final ShapeMode FLAT3D = new FlatMode( false, NO_BINS );

/** Transparency with automatic adjustment of opacity level. */
public static final ShapeMode TRANSLUCENT = new AutoTransparentMode();

/** Transparency with explicit opacity setting, suitable for 2D plots. */
public static final ShapeMode TRANSPARENT2D = new FlatMode( true,
BIN_THRESH_2D );

/** Transparency with explicit opacity setting, suitable for 3D plots. */
public static final ShapeMode TRANSPARENT3D = new FlatMode( true, NO_BINS );

/** Configurable density mode. */
public static final ShapeMode DENSITY = new CustomDensityMode();

/** Aux variable colouring mode. */
public static final ShapeMode AUX = new AuxShadingMode( true );

/** List of modes suitable for use with 2D plotting. */
public static final ShapeMode[] MODES_2D = new ShapeMode[] {
new AutoDensityMode(),
new FlatMode( false, BIN_THRESH_2D ),
new AutoTransparentMode(),
new FlatMode( true, BIN_THRESH_2D ),
new CustomDensityMode(),
new AuxShadingMode( true ),
AUTO,
FLAT2D,
TRANSLUCENT,
TRANSPARENT2D,
DENSITY,
AUX,
};

/**
* List of modes suitable for use with 3D plotting.
*/
/** List of modes suitable for use with 3D plotting. */
public static final ShapeMode[] MODES_3D = new ShapeMode[] {
new FlatMode( false, NO_BINS ),
new AutoTransparentMode(),
new FlatMode( true, NO_BINS ),
new CustomDensityMode(),
new AuxShadingMode( true ),
FLAT3D,
TRANSLUCENT,
TRANSPARENT3D,
DENSITY,
AUX,
};

/**
* Simple flat mode.
*/
public static final ShapeMode FLAT = new FlatMode( false, NO_BINS );

/**
* Constructor.
*
Expand Down
Expand Up @@ -111,14 +111,16 @@ public static ShapeModePlotter[] createShapePlotters( ShapeForm[] forms,
}

/**
* Creates a single ShapePlotter using mode flat.
* It is not intended for use with other plotters of the same form.
* Creates a single ShapePlotter using mode flat. Suitable for
* 2d plot types only.
* The returned object is not a {@link ModePlotter}, so will not be
* ganged together with other ShapePlotters.
*
* @param form shape form
* @return new plotter
* @return new 2d plotter
*/
public static ShapePlotter createFlatPlotter( ShapeForm form ) {
return new ShapePlotter( form.getFormName(), form, ShapeMode.FLAT );
public static ShapePlotter createFlat2dPlotter( ShapeForm form ) {
return new ShapePlotter( form.getFormName(), form, ShapeMode.FLAT2D );
}

/**
Expand Down

0 comments on commit 372936c

Please sign in to comment.