View Javadoc
1   /**
2    * Copyright 2004 Juan Heyns. All rights reserved.
3    * <p/>
4    * Redistribution and use in source and binary forms, with or without modification, are
5    * permitted provided that the following conditions are met:
6    * <p/>
7    * 1. Redistributions of source code must retain the above copyright notice, this list of
8    * conditions and the following disclaimer.
9    * <p/>
10   * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11   * of conditions and the following disclaimer in the documentation and/or other materials
12   * provided with the distribution.
13   * <p/>
14   * THIS SOFTWARE IS PROVIDED BY JUAN HEYNS ``AS IS'' AND ANY EXPRESS OR IMPLIED
15   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JUAN HEYNS OR
17   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20   * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23   * <p/>
24   * The views and conclusions contained in the software and documentation are those of the
25   * authors and should not be interpreted as representing official policies, either expressed
26   * or implied, of Juan Heyns.
27   */
28  package fr.ifremer.quadrige3.ui.swing.component.date.graphics;
29  
30  /*
31   * #%L
32   * Reef DB :: UI
33   * $Id:$
34   * $HeadURL:$
35   * %%
36   * Copyright (C) 2014 - 2015 Ifremer
37   * %%
38   * This program is free software: you can redistribute it and/or modify
39   * it under the terms of the GNU Affero General Public License as published by
40   * the Free Software Foundation, either version 3 of the License, or
41   * (at your option) any later version.
42   * 
43   * This program is distributed in the hope that it will be useful,
44   * but WITHOUT ANY WARRANTY; without even the implied warranty of
45   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
46   * GNU General Public License for more details.
47   * 
48   * You should have received a copy of the GNU Affero General Public License
49   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
50   * #L%
51   */
52  
53  
54  import javax.swing.*;
55  import java.awt.*;
56  
57  /**
58   * Created on 26 Mar 2004
59   *
60   * @author Juan Heyns
61   */
62  public class JNextIcon implements Icon {
63  
64      private int width;
65      private int height;
66  
67      private final int[] xPoints = new int[3];
68      private final int[] yPoints = new int[3];
69  
70      private final boolean doubleArrow;
71      private final boolean enabled;
72  
73      /**
74       * <p>Constructor for JNextIcon.</p>
75       *
76       * @param width a int.
77       * @param height a int.
78       * @param doubleArrow a boolean.
79       * @param enabled a boolean.
80       */
81      public JNextIcon(int width, int height, boolean doubleArrow, boolean enabled) {
82          setDimension(width, height);
83          this.doubleArrow = doubleArrow;
84          this.enabled = enabled;
85      }
86  
87      /**
88       * <p>getIconWidth.</p>
89       *
90       * @return a int.
91       */
92      public int getIconWidth() {
93          return width;
94      }
95  
96      /**
97       * <p>getIconHeight.</p>
98       *
99       * @return a int.
100      */
101     public int getIconHeight() {
102         return height;
103     }
104 
105     /**
106      * <p>setDimension.</p>
107      *
108      * @param width a int.
109      * @param height a int.
110      */
111     public void setDimension(int width, int height) {
112         this.width = width;
113         this.height = height;
114     }
115 
116     /** {@inheritDoc} */
117     public void paintIcon(Component c, Graphics g, int x, int y) {
118         if (enabled) {
119             g.setColor(Color.BLACK);
120         } else {
121             g.setColor(Color.GRAY);
122         }
123 
124         if (doubleArrow) {
125             xPoints[0] = x + (width / 2);
126             yPoints[0] = y + (height / 2);
127 
128             xPoints[1] = x;
129             yPoints[1] = y - 1;
130 
131             xPoints[2] = x;
132             yPoints[2] = y + height;
133 
134             g.fillPolygon(xPoints, yPoints, 3);
135 
136             xPoints[0] = x + width;
137             yPoints[0] = y + (height / 2);
138 
139             xPoints[1] = x + (width / 2);
140             yPoints[1] = y - 1;
141 
142             xPoints[2] = x + (width / 2);
143             yPoints[2] = y + height;
144 
145             g.fillPolygon(xPoints, yPoints, 3);
146         } else {
147             xPoints[0] = x + width;
148             yPoints[0] = y + (height / 2);
149 
150             xPoints[1] = x;
151             yPoints[1] = y - 1;
152 
153             xPoints[2] = x;
154             yPoints[2] = y + height;
155 
156             g.fillPolygon(xPoints, yPoints, 3);
157         }
158     }
159 
160 }
161