View Javadoc

1   package org.sat4j.sat.visu;
2   
3   import info.monitorenter.gui.chart.ITracePoint2D;
4   import info.monitorenter.gui.chart.traces.painters.ATracePainter;
5   
6   import java.awt.Graphics;
7   
8   public class TracePainterCross extends ATracePainter {
9   
10      /**
11  	 * 
12  	 */
13      private static final long serialVersionUID = 1L;
14  
15      private static final int DEFAULT_SIZE = 6;
16  
17      /** The implementation for rendering the point as a cross. */
18      private final PointPainterCross mPointPainter;
19  
20      /**
21       * Creates an instance with a default cross size of 4.
22       * <p>
23       */
24      public TracePainterCross() {
25          this.mPointPainter = new PointPainterCross(DEFAULT_SIZE);
26      }
27  
28      /**
29       * Creates an instance with the given cross size.
30       * 
31       * @param crossSize
32       *            the cross size in pixel to use.
33       */
34      public TracePainterCross(final int crossSize) {
35          this.mPointPainter = new PointPainterCross(crossSize);
36      }
37  
38      /**
39       * @see info.monitorenter.gui.chart.ITracePainter#endPaintIteration(java.awt.Graphics)
40       */
41      @Override
42      public void endPaintIteration(final Graphics g2d) {
43          if (g2d != null) {
44              int previousX = this.getPreviousX();
45              int previousY = this.getPreviousY();
46              if (previousX != Integer.MIN_VALUE
47                      || previousY != Integer.MIN_VALUE) {
48                  this.mPointPainter.paintPoint(previousX, previousY, 0, 0, g2d,
49                          this.getPreviousPoint());
50              }
51          }
52          this.mPointPainter.endPaintIteration(g2d);
53      }
54  
55      /**
56       * @see java.lang.Object#equals(java.lang.Object)
57       */
58      @Override
59      public boolean equals(final Object obj) {
60          if (this == obj) {
61              return true;
62          }
63          if (!super.equals(obj)) {
64              return false;
65          }
66          if (this.getClass() != obj.getClass()) {
67              return false;
68          }
69          final TracePainterCross other = (TracePainterCross) obj;
70          if (this.mPointPainter == null) {
71              if (other.mPointPainter != null) {
72                  return false;
73              }
74          } else if (!this.mPointPainter.equals(other.mPointPainter)) {
75              return false;
76          }
77          return true;
78      }
79  
80      /**
81       * Returns the size of the cross to paint in pixel.
82       * <p>
83       * 
84       * @return the size of the cross to paint in pixel.
85       */
86      public int getCrossSize() {
87          return this.mPointPainter.getCrossSize();
88      }
89  
90      /**
91       * @see java.lang.Object#hashCode()
92       */
93      @Override
94      public int hashCode() {
95          final int prime = 31;
96          int result = super.hashCode();
97          result = prime
98                  * result
99                  + (this.mPointPainter == null ? 0 : this.mPointPainter
100                         .hashCode());
101         return result;
102     }
103 
104     /**
105      * @see info.monitorenter.gui.chart.traces.painters.ATracePainter#paintPoint(int,
106      *      int, int, int, java.awt.Graphics,
107      *      info.monitorenter.gui.chart.ITracePoint2D)
108      */
109     @Override
110     public void paintPoint(final int absoluteX, final int absoluteY,
111             final int nextX, final int nextY, final Graphics g,
112             final ITracePoint2D original) {
113         super.paintPoint(absoluteX, absoluteY, nextX, nextY, g, original);
114         this.mPointPainter.paintPoint(absoluteX, absoluteY, nextX, nextY, g,
115                 original);
116     }
117 
118     /**
119      * Sets the size of the crosses to paint in pixel.
120      * <p>
121      * 
122      * @param crossSize
123      *            the size of the crosses to paint in pixel.
124      */
125     public void setPlusSize(final int plusSize) {
126         this.mPointPainter.setCrossSize(plusSize);
127     }
128 
129     /**
130      * @see info.monitorenter.gui.chart.traces.painters.ATracePainter#startPaintIteration(java.awt.Graphics)
131      */
132     @Override
133     public void startPaintIteration(final Graphics g2d) {
134         super.startPaintIteration(g2d);
135         this.mPointPainter.startPaintIteration(g2d);
136     }
137 }