View Javadoc
1   
2   /**
3    * Copyright 2004 Juan Heyns. All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without modification, are
6    * permitted provided that the following conditions are met:
7    *
8    * 1. Redistributions of source code must retain the above copyright notice, this list of
9    * conditions and the following disclaimer.
10   *
11   * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12   * of conditions and the following disclaimer in the documentation and/or other materials
13   * provided with the distribution.
14   *
15   * THIS SOFTWARE IS PROVIDED BY JUAN HEYNS ``AS IS'' AND ANY EXPRESS OR IMPLIED
16   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JUAN HEYNS OR
18   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21   * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24   *
25   * The views and conclusions contained in the software and documentation are those of the
26   * authors and should not be interpreted as representing official policies, either expressed
27   * or implied, of Juan Heyns.
28   */
29  package fr.ifremer.quadrige3.ui.swing.component.date;
30  
31  /*
32   * #%L
33   * Reef DB :: UI
34   * $Id:$
35   * $HeadURL:$
36   * %%
37   * Copyright (C) 2014 - 2015 Ifremer
38   * %%
39   * This program is free software: you can redistribute it and/or modify
40   * it under the terms of the GNU Affero General Public License as published by
41   * the Free Software Foundation, either version 3 of the License, or
42   * (at your option) any later version.
43   * 
44   * This program is distributed in the hope that it will be useful,
45   * but WITHOUT ANY WARRANTY; without even the implied warranty of
46   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
47   * GNU General Public License for more details.
48   * 
49   * You should have received a copy of the GNU Affero General Public License
50   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
51   * #L%
52   */
53  
54  import fr.ifremer.quadrige3.ui.swing.component.date.graphics.JNextIcon;
55  import fr.ifremer.quadrige3.ui.swing.component.date.graphics.JPreviousIcon;
56  
57  import javax.imageio.ImageIO;
58  import javax.swing.*;
59  import java.awt.image.BufferedImage;
60  import java.io.IOException;
61  import java.io.InputStream;
62  public final class ComponentIconDefaults {
63  
64      private static ComponentIconDefaults instance;
65  
66      /**
67       * <p>Getter for the field <code>instance</code>.</p>
68       *
69       * @return a {@link ComponentIconDefaults} object.
70       */
71      public static ComponentIconDefaults getInstance() {
72          if (instance == null) {
73              instance = new ComponentIconDefaults();
74          }
75          return instance;
76      }
77  
78      public enum Key {
79          // TODO
80      }
81  
82      private Icon clearIcon;
83      private Icon nextMonthIconEnabled;
84      private Icon nextYearIconEnabled;
85      private Icon previousMonthIconEnabled;
86      private Icon previousYearIconEnabled;
87      private Icon nextMonthIconDisabled;
88      private Icon nextYearIconDisabled;
89      private Icon previousMonthIconDisabled;
90      private Icon previousYearIconDisabled;
91      private Icon popupButtonIcon;
92  
93      private ComponentIconDefaults() {
94          // TODO consider making all the icons vector images which will scale
95          try {
96              clearIcon = loadIcon("/org/jdatepicker/icons/clear.png");
97              popupButtonIcon = loadIcon("/org/jdatepicker/icons/arrow.png");
98              nextMonthIconEnabled = new JNextIcon(4, 7, false, true);
99              nextYearIconEnabled = new JNextIcon(8, 7, true, true);
100             previousMonthIconEnabled = new JPreviousIcon(4, 7, false, true);
101             previousYearIconEnabled = new JPreviousIcon(8, 7, true, true);
102             nextMonthIconDisabled = new JNextIcon(4, 7, false, false);
103             nextYearIconDisabled = new JNextIcon(8, 7, true, false);
104             previousMonthIconDisabled = new JPreviousIcon(4, 7, false, false);
105             previousYearIconDisabled = new JPreviousIcon(8, 7, true, false);
106         } catch (IOException e) {
107             e.printStackTrace();
108         }
109     }
110 
111     private static Icon loadIcon(String path) throws IOException {
112         try (InputStream stream = ComponentIconDefaults.class.getResourceAsStream(path)) {
113             BufferedImage image = ImageIO.read(stream);
114             return new ImageIcon(image);
115         }
116     }
117 
118     /**
119      * <p>Getter for the field <code>clearIcon</code>.</p>
120      *
121      * @return a {@link javax.swing.Icon} object.
122      */
123     public Icon getClearIcon() {
124         return clearIcon;
125     }
126 
127     /**
128      * <p>Setter for the field <code>clearIcon</code>.</p>
129      *
130      * @param clearIcon a {@link javax.swing.Icon} object.
131      */
132     public void setClearIcon(Icon clearIcon) {
133         this.clearIcon = clearIcon;
134     }
135 
136     /**
137      * <p>Getter for the field <code>nextMonthIconEnabled</code>.</p>
138      *
139      * @return a {@link javax.swing.Icon} object.
140      */
141     public Icon getNextMonthIconEnabled() {
142         return nextMonthIconEnabled;
143     }
144 
145     /**
146      * <p>Setter for the field <code>nextMonthIconEnabled</code>.</p>
147      *
148      * @param nextMonthIconEnabled a {@link javax.swing.Icon} object.
149      */
150     public void setNextMonthIconEnabled(Icon nextMonthIconEnabled) {
151         this.nextMonthIconEnabled = nextMonthIconEnabled;
152     }
153 
154     /**
155      * <p>Getter for the field <code>nextMonthIconDisabled</code>.</p>
156      *
157      * @return a {@link javax.swing.Icon} object.
158      */
159     public Icon getNextMonthIconDisabled() {
160         return nextMonthIconDisabled;
161     }
162 
163     /**
164      * <p>Setter for the field <code>nextMonthIconDisabled</code>.</p>
165      *
166      * @param nextMonthIconDisabled a {@link javax.swing.Icon} object.
167      */
168     public void setNextMonthIconDisabled(Icon nextMonthIconDisabled) {
169         this.nextMonthIconDisabled = nextMonthIconDisabled;
170     }
171 
172     /**
173      * <p>Getter for the field <code>nextYearIconEnabled</code>.</p>
174      *
175      * @return a {@link javax.swing.Icon} object.
176      */
177     public Icon getNextYearIconEnabled() {
178         return nextYearIconEnabled;
179     }
180 
181     /**
182      * <p>Setter for the field <code>nextYearIconEnabled</code>.</p>
183      *
184      * @param nextYearIconEnabled a {@link javax.swing.Icon} object.
185      */
186     public void setNextYearIconEnabled(Icon nextYearIconEnabled) {
187         this.nextYearIconEnabled = nextYearIconEnabled;
188     }
189 
190     /**
191      * <p>Getter for the field <code>nextYearIconDisabled</code>.</p>
192      *
193      * @return a {@link javax.swing.Icon} object.
194      */
195     public Icon getNextYearIconDisabled() {
196         return nextYearIconDisabled;
197     }
198 
199     /**
200      * <p>Setter for the field <code>nextYearIconDisabled</code>.</p>
201      *
202      * @param nextYearIconDisabled a {@link javax.swing.Icon} object.
203      */
204     public void setNextYearIconDisabled(Icon nextYearIconDisabled) {
205         this.nextYearIconDisabled = nextYearIconDisabled;
206     }
207 
208     /**
209      * <p>Getter for the field <code>previousMonthIconEnabled</code>.</p>
210      *
211      * @return a {@link javax.swing.Icon} object.
212      */
213     public Icon getPreviousMonthIconEnabled() {
214         return previousMonthIconEnabled;
215     }
216 
217     /**
218      * <p>Setter for the field <code>previousMonthIconEnabled</code>.</p>
219      *
220      * @param previousMonthIconEnabled a {@link javax.swing.Icon} object.
221      */
222     public void setPreviousMonthIconEnabled(Icon previousMonthIconEnabled) {
223         this.previousMonthIconEnabled = previousMonthIconEnabled;
224     }
225 
226     /**
227      * <p>Getter for the field <code>previousMonthIconDisabled</code>.</p>
228      *
229      * @return a {@link javax.swing.Icon} object.
230      */
231     public Icon getPreviousMonthIconDisabled() {
232         return previousMonthIconDisabled;
233     }
234 
235     /**
236      * <p>Setter for the field <code>previousMonthIconDisabled</code>.</p>
237      *
238      * @param previousMonthIconDisabled a {@link javax.swing.Icon} object.
239      */
240     public void setPreviousMonthIconDisabled(Icon previousMonthIconDisabled) {
241         this.previousMonthIconDisabled = previousMonthIconDisabled;
242     }
243 
244     /**
245      * <p>Getter for the field <code>previousYearIconEnabled</code>.</p>
246      *
247      * @return a {@link javax.swing.Icon} object.
248      */
249     public Icon getPreviousYearIconEnabled() {
250         return previousYearIconEnabled;
251     }
252 
253     /**
254      * <p>Setter for the field <code>previousYearIconEnabled</code>.</p>
255      *
256      * @param previousYearIconEnabled a {@link javax.swing.Icon} object.
257      */
258     public void setPreviousYearIconEnabled(Icon previousYearIconEnabled) {
259         this.previousYearIconEnabled = previousYearIconEnabled;
260     }
261 
262     /**
263      * <p>Getter for the field <code>previousYearIconDisabled</code>.</p>
264      *
265      * @return a {@link javax.swing.Icon} object.
266      */
267     public Icon getPreviousYearIconDisabled() {
268         return previousYearIconDisabled;
269     }
270 
271     /**
272      * <p>Setter for the field <code>previousYearIconDisabled</code>.</p>
273      *
274      * @param previousYearIconDisabled a {@link javax.swing.Icon} object.
275      */
276     public void setPreviousYearIconDisabled(Icon previousYearIconDisabled) {
277         this.previousYearIconDisabled = previousYearIconDisabled;
278     }
279 
280     /**
281      * <p>Getter for the field <code>popupButtonIcon</code>.</p>
282      *
283      * @return a {@link javax.swing.Icon} object.
284      */
285     public Icon getPopupButtonIcon() {
286         return popupButtonIcon;
287     }
288 
289     /**
290      * <p>Setter for the field <code>popupButtonIcon</code>.</p>
291      *
292      * @param popupButtonIcon a {@link javax.swing.Icon} object.
293      */
294     public void setPopupButtonIcon(Icon popupButtonIcon) {
295         this.popupButtonIcon = popupButtonIcon;
296     }
297 
298 }