~jd-team/jdownloader/appwork-utils

« back to all changes in this revision

Viewing changes to src/org/appwork/swing/components/RadioBoxIcon.java

  • Committer: daniel
  • Date: 2020-08-12 13:31:35 UTC
  • Revision ID: svn-v4:21714237-3853-44ef-a1f0-ef8f03a7d1fe::3403
CheckBoxIcon/RadioBoxIcon:
-fixed npe with Substance laf

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 *         Copyright (c) 2009-2015, AppWork GmbH <e-mail@appwork.org>
8
8
 *         Schwabacher Straße 117
9
9
 *         90763 Fürth
10
 
 *         Germany   
 
10
 *         Germany
11
11
 * === Preamble ===
12
12
 *     This license establishes the terms under which the [The Product] Source Code & Binary files may be used, copied, modified, distributed, and/or redistributed.
13
13
 *     The intent is that the AppWork GmbH is able to provide their utilities library for free to non-commercial projects whereas commercial usage is only permitted after obtaining a commercial license.
14
14
 *     These terms apply to all files that have the [The Product] License header (IN the file), a <filename>.license or <filename>.info (like mylib.jar.info) file that contains a reference to this license.
15
 
 *      
 
15
 *
16
16
 * === 3rd Party Licences ===
17
17
 *     Some parts of the [The Product] use or reference 3rd party libraries and classes. These parts may have different licensing conditions. Please check the *.license and *.info files of included libraries
18
 
 *     to ensure that they are compatible to your use-case. Further more, some *.java have their own license. In this case, they have their license terms in the java file header.      
19
 
 *      
 
18
 *     to ensure that they are compatible to your use-case. Further more, some *.java have their own license. In this case, they have their license terms in the java file header.
 
19
 *
20
20
 * === Definition: Commercial Usage ===
21
21
 *     If anybody or any organization is generating income (directly or indirectly) by using [The Product] or if there's any commercial interest or aspect in what you are doing, we consider this as a commercial usage.
22
22
 *     If your use-case is neither strictly private nor strictly educational, it is commercial. If you are unsure whether your use-case is commercial or not, consider it as commercial or contact us.
37
37
import java.awt.Graphics;
38
38
 
39
39
import javax.swing.Icon;
 
40
import javax.swing.JPanel;
40
41
import javax.swing.JRadioButton;
41
42
 
42
43
import org.appwork.utils.ImageProvider.ImageProvider;
45
46
    public static final RadioBoxIcon FALSE     = new RadioBoxIcon(false);
46
47
    public static final RadioBoxIcon TRUE      = new RadioBoxIcon(true);
47
48
    public static final RadioBoxIcon UNDEFINED = new RadioBoxIcon(true, false);
48
 
    private JRadioButton             cb;
49
 
    private Icon                     internalIcon;
50
 
    private int                      size;
 
49
    private final JRadioButton       cb;
 
50
    private final JPanel             panel;
 
51
    private final Icon               internalIcon;
 
52
    private final int                size;
51
53
 
52
54
    public RadioBoxIcon(final boolean selected, final boolean enabled) {
53
 
 
54
55
        cb = new JRadioButton() {
55
56
            {
56
 
                setSelected(true);
 
57
                setSelected(selected);
57
58
            }
58
59
 
59
60
            @Override
71
72
                return true;
72
73
            }
73
74
        };
74
 
 
75
 
        ;
76
 
        cb.setSelected(selected);
 
75
        panel = new JPanel();
 
76
        panel.add(cb);// Substance laf, special handling SubstanceColorUtilities.getBackgroundFillColor, component.getParent
77
77
        // we need this workaround.
78
78
        // if we would use cb.paint(g); for every paintIcon call, this might habe sideeffects on the LAF painter.
79
 
 
80
79
        size = 16;
81
 
 
82
 
        internalIcon = ImageProvider.toImageIcon(this);
83
 
 
84
80
        if (!enabled) {
85
 
            internalIcon = org.appwork.resources.AWUTheme.I().getDisabledIcon(internalIcon);
 
81
            internalIcon = org.appwork.resources.AWUTheme.I().getDisabledIcon(ImageProvider.toImageIcon(this));
 
82
        } else {
 
83
            internalIcon = ImageProvider.toImageIcon(this);
86
84
        }
87
 
 
88
85
    }
89
86
 
90
87
    public RadioBoxIcon(final boolean selected) {
95
92
    public void paintIcon(final Component c, Graphics g, final int x, final int y) {
96
93
        if (internalIcon != null) {
97
94
            internalIcon.paintIcon(c, g, x, y);
 
95
        } else {
 
96
            // g.setColor(Color.RED);
 
97
            // g.drawRect(0, 0, 14, 14);
 
98
            g = g.create(x, y, size, size);
 
99
            // g.translate(x, y);
 
100
            g.translate(-4, -4);
 
101
            cb.paint(g);
 
102
            g.dispose();
 
103
            // g.translate(4, 4);
 
104
            // g.translate(-x, -y);
98
105
 
99
 
            return;
 
106
            // g.dispose();
 
107
            // g.translate(0, -10);
100
108
        }
101
 
        // g.setColor(Color.RED);
102
 
        // g.drawRect(0, 0, 14, 14);
103
 
        g = g.create(x, y, size, size);
104
 
        // g.translate(x, y);
105
 
        g.translate(-4, -4);
106
 
        cb.paint(g);
107
 
        g.dispose();
108
 
        // g.translate(4, 4);
109
 
        // g.translate(-x, -y);
110
 
 
111
 
        // g.dispose();
112
 
        // g.translate(0, -10);
113
 
 
114
109
    }
115
110
 
116
111
    @Override