View Javadoc
1   package com.jsql.view.swing.ui;
2   
3   import javax.swing.*;
4   import javax.swing.plaf.UIResource;
5   import javax.swing.plaf.metal.MetalLookAndFeel;
6   import java.awt.*;
7   import java.io.Serializable;
8   
9   public class CheckBoxIcon implements Icon, UIResource, Serializable {
10  
11      private static final int CONTROL_SIZE = 12;
12  
13      private void paintOceanIcon(Component c, Graphics g, int x, int y) {
14          
15          ButtonModel model = ((JCheckBoxMenuItem) c).getModel();
16  
17          g.translate(x, y);
18          
19          int w = this.getIconWidth();
20          int h = this.getIconHeight();
21          
22          if (model.isEnabled()) {
23              
24              if (model.isPressed() && model.isArmed()) {
25                  
26                  g.setColor(MetalLookAndFeel.getControlShadow());
27                  g.fillRect(0, 0, w, h);
28                  g.setColor(MetalLookAndFeel.getControlDarkShadow());
29                  g.fillRect(0, 0, w, 2);
30                  g.fillRect(0, 2, 2, h - 2);
31                  g.fillRect(w - 1, 1, 1, h - 1);
32                  g.fillRect(1, h - 1, w - 2, 1);
33                  
34              } else if (model.isRollover()) {
35                  
36                  g.setColor(MetalLookAndFeel.getControlDarkShadow());
37                  g.drawRect(0, 0, w - 1, h - 1);
38                  g.setColor(MetalLookAndFeel.getPrimaryControl());
39                  g.drawRect(1, 1, w - 3, h - 3);
40                  g.drawRect(2, 2, w - 5, h - 5);
41                  
42              } else {
43                  
44                  g.setColor(MetalLookAndFeel.getControlDarkShadow());
45                  g.drawRect(0, 0, w - 1, h - 1);
46              }
47              
48              g.setColor(MetalLookAndFeel.getControlInfo());
49              
50          } else {
51              
52              g.setColor(MetalLookAndFeel.getControlDarkShadow());
53              g.drawRect(0, 0, w - 1, h - 1);
54          }
55          
56          g.translate(-x, -y);
57          
58          if (model.isSelected()) {
59              this.drawCheck(g, x, y);
60          }
61      }
62      
63      protected void drawCheck(Graphics g, int x, int y) {
64          
65          g.fillRect(x + 3, y + 5, 2, CheckBoxIcon.CONTROL_SIZE - 8);
66          g.drawLine(x + CheckBoxIcon.CONTROL_SIZE - 4, y + 3, x + 5, y + CheckBoxIcon.CONTROL_SIZE - 6);
67          g.drawLine(x + CheckBoxIcon.CONTROL_SIZE - 4, y + 4, x + 5, y + CheckBoxIcon.CONTROL_SIZE - 5);
68      }
69  
70      @Override
71      public void paintIcon(Component c, Graphics g, int x, int y) {
72          this.paintOceanIcon(c, g, x, y);
73      }
74  
75      @Override
76      public int getIconWidth() {
77          return CheckBoxIcon.CONTROL_SIZE;
78      }
79  
80      @Override
81      public int getIconHeight() {
82          return CheckBoxIcon.CONTROL_SIZE;
83      }
84  }