View Javadoc
1   package fr.ifremer.quadrige3.ui.swing.component;
2   
3   /*-
4    * #%L
5    * Quadrige3 Core :: Quadrige3 UI Common
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2017 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  
27  import javax.swing.*;
28  import java.awt.*;
29  
30  /**
31   * A dashed line
32   *
33   * Created by Ludovic on 27/05/2015.
34   */
35  public class DashedLineIcon implements Icon {
36  
37      private final Color color;
38      private final int dashWidth;
39      private final int dashHeight;
40      private final int emptyWidth;
41      private final int emptyHeight;
42  
43      /**
44       * <p>Constructor for DashedLineIcon.</p>
45       *
46       * @param color a {@link java.awt.Color} object.
47       * @param dashWidth a int.
48       * @param dashHeight a int.
49       * @param emptyWidth a int.
50       * @param emptyHeight a int.
51       */
52      public DashedLineIcon(Color color, int dashWidth, int dashHeight, int emptyWidth, int emptyHeight )
53      {
54          this.color = color;
55          this.dashWidth = dashWidth;
56          this.dashHeight = dashHeight;
57          this.emptyWidth = emptyWidth;
58          this.emptyHeight = emptyHeight;
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public void paintIcon(Component c, Graphics g, int x, int y) {
64          g.setColor(color);
65          g.fillRect(x, y, dashWidth, dashHeight);
66      }
67  
68      /** {@inheritDoc} */
69      @Override
70      public int getIconWidth() {
71          return dashWidth + emptyWidth;
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public int getIconHeight() {
77          return dashHeight + emptyHeight;
78      }
79  }