~ubuntu-branches/ubuntu/trusty/drmips/trusty-backports

« back to all changes in this revision

Viewing changes to src/pc/DrMIPS/src/com/jtattoo/plaf/smart/SmartTitlePane.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.smart;
 
25
 
 
26
import com.jtattoo.plaf.*;
 
27
import java.awt.*;
 
28
import javax.swing.JDialog;
 
29
import javax.swing.JRootPane;
 
30
 
 
31
/**
 
32
 * @author  Michael Hagen
 
33
 */
 
34
public class SmartTitlePane extends BaseTitlePane {
 
35
 
 
36
    public SmartTitlePane(JRootPane root, BaseRootPaneUI ui) {
 
37
        super(root, ui);
 
38
    }
 
39
 
 
40
    public void createButtons() {
 
41
        iconifyButton = new BaseTitleButton(iconifyAction, ICONIFY, iconifyIcon, 1.0f);
 
42
        maxButton = new BaseTitleButton(restoreAction, MAXIMIZE, maximizeIcon, 1.0f);
 
43
        closeButton = new BaseTitleButton(closeAction, CLOSE, closeIcon, 1.0f);
 
44
    }
 
45
 
 
46
    public void paintBorder(Graphics g) {
 
47
        if (isActive()) {
 
48
            g.setColor(AbstractLookAndFeel.getTheme().getFrameColor());
 
49
        } else {
 
50
            g.setColor(ColorHelper.brighter(AbstractLookAndFeel.getTheme().getFrameColor(), 40));
 
51
        }
 
52
        g.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1);
 
53
    }
 
54
 
 
55
    public void paintBackground(Graphics g) {
 
56
        Graphics2D g2D = (Graphics2D) g;
 
57
        int width = getWidth();
 
58
        int height = getHeight();
 
59
        Color backColor = null;
 
60
        Color frameColor = null;
 
61
        if (JTattooUtilities.isActive(this)) {
 
62
            backColor = AbstractLookAndFeel.getTheme().getWindowTitleColors()[10];
 
63
            frameColor = AbstractLookAndFeel.getTheme().getFrameColor();
 
64
            JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getWindowTitleColors(), 0, 0, width, height);
 
65
        } else {
 
66
            backColor = AbstractLookAndFeel.getTheme().getWindowInactiveTitleColors()[10];
 
67
            frameColor = ColorHelper.brighter(AbstractLookAndFeel.getTheme().getFrameColor(), 40);
 
68
            JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getWindowInactiveTitleColors(), 0, 0, width, height);
 
69
        }
 
70
 
 
71
        int iconWidth = 0;
 
72
        if (menuBar != null) {
 
73
            iconWidth = menuBar.getWidth() + 5;
 
74
        }
 
75
 
 
76
        int titleWidth = 0;
 
77
        String frameTitle = getTitle();
 
78
        if (frameTitle != null) {
 
79
            Font f = getFont();
 
80
            g.setFont(f);
 
81
            FontMetrics fm = g.getFontMetrics();
 
82
            titleWidth = fm.stringWidth(JTattooUtilities.getClippedText(getTitle(), fm, getWidth() - iconWidth - buttonsWidth - 15)) + 10;
 
83
            if (getWindow() instanceof JDialog) {
 
84
                Image image = getFrameIconImage();
 
85
                if (image != null) {
 
86
                    titleWidth += getHeight();
 
87
                }
 
88
            }
 
89
        }
 
90
 
 
91
        int dx;
 
92
        int dw;
 
93
        boolean leftToRight = isLeftToRight();
 
94
        int xOffset = leftToRight ? iconWidth + 10 + titleWidth : width - 10 - iconWidth - titleWidth;
 
95
 
 
96
        if (leftToRight) {
 
97
            dw = width - buttonsWidth - xOffset - 10;
 
98
            dx = xOffset;
 
99
        } else {
 
100
            dw = xOffset - buttonsWidth - 10;
 
101
            dx = buttonsWidth + 10;
 
102
        }
 
103
        int dy = 3;
 
104
 
 
105
        if (!AbstractLookAndFeel.getTheme().isMacStyleWindowDecorationOn() && !AbstractLookAndFeel.getTheme().isCenterWindowTitleOn() && (dw > 0)) {
 
106
            Composite composite = g2D.getComposite();
 
107
            AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
 
108
            g2D.setComposite(alpha);
 
109
 
 
110
            float dc1 = 50.0f;
 
111
            float dc2 = 5.0f;
 
112
 
 
113
            Color c1 = ColorHelper.brighter(backColor, dc1);
 
114
            Color c2 = null;
 
115
            while ((dy + 5) < height) {
 
116
                c2 = ColorHelper.darker(backColor, dc2);
 
117
                dc2 += 5.0f;
 
118
                g.setColor(c1);
 
119
                g.drawLine(dx, dy, dx + dw, dy);
 
120
                dy++;
 
121
                g.setColor(c2);
 
122
                g.drawLine(dx, dy, dx + dw, dy);
 
123
                dy += 3;
 
124
            }
 
125
            g2D.setComposite(composite);
 
126
        }
 
127
        g.setColor(frameColor);
 
128
        g.drawLine(0, height - 1, width, height - 1);
 
129
    }
 
130
 
 
131
    public void paintText(Graphics g, int x, int y, String title) {
 
132
        x += paintIcon(g, x, y);
 
133
        if (isActive()) {
 
134
            Color titleColor = AbstractLookAndFeel.getWindowTitleForegroundColor();
 
135
            if (ColorHelper.getGrayValue(titleColor) > 164) {
 
136
                g.setColor(Color.black);
 
137
                JTattooUtilities.drawString(rootPane, g, title, x + 1, y + 1);
 
138
            }
 
139
            g.setColor(titleColor);
 
140
            JTattooUtilities.drawString(rootPane, g, title, x, y);
 
141
        } else {
 
142
            g.setColor(AbstractLookAndFeel.getWindowInactiveTitleForegroundColor());
 
143
            JTattooUtilities.drawString(rootPane, g, title, x, y);
 
144
        }
 
145
    }
 
146
 
 
147
}