|
| 1 | +/* |
| 2 | + * #%L |
| 3 | + * ImageJ software for multidimensional image processing and analysis. |
| 4 | + * %% |
| 5 | + * Copyright (C) 2009 - 2016 Board of Regents of the University of |
| 6 | + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck |
| 7 | + * Institute of Molecular Cell Biology and Genetics. |
| 8 | + * %% |
| 9 | + * Redistribution and use in source and binary forms, with or without |
| 10 | + * modification, are permitted provided that the following conditions are met: |
| 11 | + * |
| 12 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 13 | + * this list of conditions and the following disclaimer. |
| 14 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 15 | + * this list of conditions and the following disclaimer in the documentation |
| 16 | + * and/or other materials provided with the distribution. |
| 17 | + * |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE |
| 22 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | + * POSSIBILITY OF SUCH DAMAGE. |
| 29 | + * #L% |
| 30 | + */ |
| 31 | + |
| 32 | +package org.scijava.ui.swing.viewer.plot.jfreechart; |
| 33 | + |
| 34 | +import org.scijava.plot.MarkerStyle; |
| 35 | + |
| 36 | +import java.awt.*; |
| 37 | +import java.awt.geom.Ellipse2D; |
| 38 | +import java.awt.geom.Path2D; |
| 39 | +import java.awt.geom.Rectangle2D; |
| 40 | + |
| 41 | +/** |
| 42 | + * @author Matthias Arzt |
| 43 | + */ |
| 44 | + |
| 45 | +class AwtMarkerStyles { |
| 46 | + |
| 47 | + private final boolean visible; |
| 48 | + |
| 49 | + private final boolean filled; |
| 50 | + |
| 51 | + private final Shape shape; |
| 52 | + |
| 53 | + private AwtMarkerStyles(boolean visible, boolean filled, Shape shape) { |
| 54 | + this.visible = visible; |
| 55 | + this.filled = filled; |
| 56 | + this.shape = shape; |
| 57 | + } |
| 58 | + |
| 59 | + public boolean isVisible() { |
| 60 | + return visible; |
| 61 | + } |
| 62 | + |
| 63 | + public boolean isFilled() { |
| 64 | + return filled; |
| 65 | + } |
| 66 | + |
| 67 | + public Shape getShape() { |
| 68 | + return shape; |
| 69 | + } |
| 70 | + |
| 71 | + public static AwtMarkerStyles getInstance(MarkerStyle style) { |
| 72 | + if(style != null) |
| 73 | + switch (style) { |
| 74 | + case NONE: |
| 75 | + return none; |
| 76 | + case PLUS: |
| 77 | + return plus; |
| 78 | + case X: |
| 79 | + return x; |
| 80 | + case STAR: |
| 81 | + return star; |
| 82 | + case SQUARE: |
| 83 | + return square; |
| 84 | + case FILLEDSQUARE: |
| 85 | + return filledSquare; |
| 86 | + case CIRCLE: |
| 87 | + return circle; |
| 88 | + case FILLEDCIRCLE: |
| 89 | + return filledCircle; |
| 90 | + } |
| 91 | + return square; |
| 92 | + } |
| 93 | + |
| 94 | + // --- Helper Constants --- |
| 95 | + |
| 96 | + private static AwtMarkerStyles none = new AwtMarkerStyles(false, false, null); |
| 97 | + |
| 98 | + private static AwtMarkerStyles plus = new AwtMarkerStyles(true, false, Shapes.plus); |
| 99 | + |
| 100 | + private static AwtMarkerStyles x = new AwtMarkerStyles(true, false, Shapes.x); |
| 101 | + |
| 102 | + private static AwtMarkerStyles star = new AwtMarkerStyles(true, false, Shapes.star); |
| 103 | + |
| 104 | + private static AwtMarkerStyles square = new AwtMarkerStyles(true, false, Shapes.square); |
| 105 | + |
| 106 | + private static AwtMarkerStyles filledSquare = new AwtMarkerStyles(true, true, Shapes.square); |
| 107 | + |
| 108 | + private static AwtMarkerStyles circle = new AwtMarkerStyles(true, false, Shapes.circle); |
| 109 | + |
| 110 | + private static AwtMarkerStyles filledCircle = new AwtMarkerStyles(true, true, Shapes.circle); |
| 111 | + |
| 112 | + |
| 113 | + static private class Shapes { |
| 114 | + |
| 115 | + private static Shape x = getAwtXShape(); |
| 116 | + |
| 117 | + private static Shape plus = getAwtPlusShape(); |
| 118 | + |
| 119 | + private static Shape star = getAwtStarShape(); |
| 120 | + |
| 121 | + private static Shape square = new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0); |
| 122 | + |
| 123 | + private static Shape circle = new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0); |
| 124 | + |
| 125 | + private static Shape getAwtXShape() { |
| 126 | + final Path2D p = new Path2D.Double(); |
| 127 | + final double s = 3.0; |
| 128 | + p.moveTo(-s, -s); |
| 129 | + p.lineTo(s, s); |
| 130 | + p.moveTo(s, -s); |
| 131 | + p.lineTo(-s, s); |
| 132 | + return p; |
| 133 | + } |
| 134 | + |
| 135 | + private static Shape getAwtPlusShape() { |
| 136 | + final Path2D p = new Path2D.Double(); |
| 137 | + final double t = 4.0; |
| 138 | + p.moveTo(0, -t); |
| 139 | + p.lineTo(0, t); |
| 140 | + p.moveTo(t, 0); |
| 141 | + p.lineTo(-t, 0); |
| 142 | + return p; |
| 143 | + } |
| 144 | + |
| 145 | + private static Shape getAwtStarShape() { |
| 146 | + final Path2D p = new Path2D.Double(); |
| 147 | + final double s = 3.0; |
| 148 | + p.moveTo(-s, -s); |
| 149 | + p.lineTo(s, s); |
| 150 | + p.moveTo(s, -s); |
| 151 | + p.lineTo(-s, s); |
| 152 | + final double t = 4.0; |
| 153 | + p.moveTo(0, -t); |
| 154 | + p.lineTo(0, t); |
| 155 | + p.moveTo(t, 0); |
| 156 | + p.lineTo(-t, 0); |
| 157 | + return p; |
| 158 | + } |
| 159 | + |
| 160 | + } |
| 161 | + |
| 162 | +} |
0 commit comments