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