~ubuntu-branches/ubuntu/vivid/drmips/vivid-backports

« back to all changes in this revision

Viewing changes to src/pc/DrMIPS/src/com/jtattoo/plaf/XPScrollButton.java

  • Committer: Package Import Robot
  • Author(s): Bruno Nova
  • Date: 2014-09-27 12:24:17 UTC
  • Revision ID: package-import@ubuntu.com-20140927122417-2gadkwt9k0u7j4zu
Tags: upstream-1.2.3
Import upstream version 1.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* Copyright (c) 2002 and later by MH Software-Entwicklung. All Rights Reserved.
 
3
*  
 
4
* JTattoo is multiple licensed. If your are an open source developer you can use
 
5
* it under the terms and conditions of the GNU General Public License version 2.0
 
6
* or later as published by the Free Software Foundation.
 
7
*  
 
8
* see: gpl-2.0.txt
 
9
 
10
* If you pay for a license you will become a registered user who could use the
 
11
* software under the terms and conditions of the GNU Lesser General Public License
 
12
* version 2.0 or later with classpath exception as published by the Free Software
 
13
* Foundation.
 
14
 
15
* see: lgpl-2.0.txt
 
16
* see: classpath-exception.txt
 
17
 
18
* Registered users could also use JTattoo under the terms and conditions of the 
 
19
* Apache License, Version 2.0 as published by the Apache Software Foundation.
 
20
*  
 
21
* see: APACHE-LICENSE-2.0.txt
 
22
*/
 
23
 
 
24
package com.jtattoo.plaf;
 
25
 
 
26
import java.awt.*;
 
27
import javax.swing.Icon;
 
28
 
 
29
/**
 
30
 * @author  Michael Hagen
 
31
 */
 
32
public abstract class XPScrollButton extends BaseScrollButton {
 
33
 
 
34
    public XPScrollButton(int direction, int width) {
 
35
        super(direction, width);
 
36
    }
 
37
 
 
38
    public abstract Icon getUpArrowIcon();
 
39
    public abstract Icon getDownArrowIcon();
 
40
    public abstract Icon getLeftArrowIcon();
 
41
    public abstract Icon getRightArrowIcon();
 
42
 
 
43
    public Color getFrameColor() {
 
44
        return Color.white;
 
45
    }
 
46
 
 
47
    public void paint(Graphics g) {
 
48
        Graphics2D g2D = (Graphics2D) g;
 
49
        Composite savedComposite = g2D.getComposite();
 
50
        Paint savedPaint = g2D.getPaint();
 
51
 
 
52
        boolean isPressed = getModel().isPressed();
 
53
        boolean isRollover = getModel().isRollover();
 
54
 
 
55
        int width = getWidth();
 
56
        int height = getHeight();
 
57
 
 
58
        Color[] tc = AbstractLookAndFeel.getTheme().getThumbColors();
 
59
        Color c1 = tc[0];
 
60
        Color c2 = tc[tc.length - 1];
 
61
        if (isPressed) {
 
62
            c1 = ColorHelper.darker(c1, 5);
 
63
            c2 = ColorHelper.darker(c2, 5);
 
64
        } else if (isRollover) {
 
65
            c1 = ColorHelper.brighter(c1, 20);
 
66
            c2 = ColorHelper.brighter(c2, 20);
 
67
        }
 
68
 
 
69
        g2D.setPaint(new GradientPaint(0, 0, c1, width, height, c2));
 
70
        g.fillRect(0, 0, width, height);
 
71
        g2D.setPaint(savedPaint);
 
72
 
 
73
        g.setColor(getFrameColor());
 
74
        g.drawLine(1, 1, width - 2, 1);
 
75
        g.drawLine(1, 1, 1, height - 3);
 
76
        g.drawLine(width - 2, 1, width - 2, height - 3);
 
77
        g.drawLine(2, height - 2, width - 3, height - 2);
 
78
 
 
79
        AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
 
80
        g2D.setComposite(alpha);
 
81
        g2D.setColor(c2);
 
82
        g.drawLine(2, 2, width - 3, 2);
 
83
        g.drawLine(2, 3, 2, height - 3);
 
84
 
 
85
        g.setColor(ColorHelper.darker(c2, 40));
 
86
        g.drawLine(width - 1, 2, width - 1, height - 3);
 
87
        g.drawLine(3, height - 1, width - 3, height - 1);
 
88
        alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f);
 
89
        g2D.setComposite(alpha);
 
90
        g.drawLine(1, height - 2, 2, height - 1);
 
91
        g.drawLine(width - 1, height - 2, width - 2, height - 1);
 
92
 
 
93
        g2D.setComposite(savedComposite);
 
94
 
 
95
        // paint the icon
 
96
        if (getDirection() == NORTH) {
 
97
            int x = (width / 2) - (getUpArrowIcon().getIconWidth() / 2);
 
98
            int y = (height / 2) - (getUpArrowIcon().getIconHeight() / 2);
 
99
            getUpArrowIcon().paintIcon(this, g, x, y);
 
100
        } else if (getDirection() == SOUTH) {
 
101
            int x = (width / 2) - (getDownArrowIcon().getIconWidth() / 2);
 
102
            int y = (height / 2) - (getDownArrowIcon().getIconHeight() / 2) + 1;
 
103
            getDownArrowIcon().paintIcon(this, g, x, y);
 
104
        } else if (getDirection() == WEST) {
 
105
            int x = (width / 2) - (getLeftArrowIcon().getIconWidth() / 2);
 
106
            int y = (height / 2) - (getLeftArrowIcon().getIconHeight() / 2);
 
107
            getLeftArrowIcon().paintIcon(this, g, x, y);
 
108
        } else {
 
109
            int x = (width / 2) - (getRightArrowIcon().getIconWidth() / 2) + 1;
 
110
            int y = (height / 2) - (getRightArrowIcon().getIconHeight() / 2);
 
111
            getRightArrowIcon().paintIcon(this, g, x, y);
 
112
        }
 
113
    }
 
114
 
 
115
    public Dimension getPreferredSize() {
 
116
        if (getDirection() == NORTH) {
 
117
            return new Dimension(buttonWidth, buttonWidth);
 
118
        } else if (getDirection() == SOUTH) {
 
119
            return new Dimension(buttonWidth, buttonWidth);
 
120
        } else if (getDirection() == EAST) {
 
121
            return new Dimension(buttonWidth, buttonWidth);
 
122
        } else if (getDirection() == WEST) {
 
123
            return new Dimension(buttonWidth, buttonWidth);
 
124
        } else {
 
125
            return new Dimension(0, 0);
 
126
        }
 
127
    }
 
128
}