src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java
author tvaleev
Thu, 04 Oct 2018 12:40:55 -0700
changeset 52248 2e330da7cbf4
parent 47216 71c04702a3d5
child 55178 e448d58051ab
permissions -rw-r--r--
8211300: Convert C-style array declarations in JDK client code Reviewed-by: prr, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
     2
 * Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1837
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1837
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1837
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1837
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1837
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package com.sun.java.swing.plaf.gtk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import com.sun.java.swing.plaf.gtk.GTKConstants.ArrowType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.ColorUIResource;
42192
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
    32
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.synth.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.geom.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.image.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.xml.parsers.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import org.xml.sax.SAXException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import org.w3c.dom.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
class Metacity implements SynthConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    // Tutorial:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // http://developer.gnome.org/doc/tutorials/metacity/metacity-themes.html
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // Themes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    // http://art.gnome.org/theme_list.php?category=metacity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static Metacity INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static final String[] themeNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        getUserTheme(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        "blueprint",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        "Bluecurve",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        "Crux",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        "SwingFallbackTheme"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        for (String themeName : themeNames) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            if (themeName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                INSTANCE = new Metacity(themeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            } catch (FileNotFoundException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                logError(themeName, ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            } catch (ParserConfigurationException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                logError(themeName, ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            } catch (SAXException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                logError(themeName, ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            if (INSTANCE != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (INSTANCE == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            throw new Error("Could not find any installed metacity theme, and fallback failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private static boolean errorLogged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private static DocumentBuilder documentBuilder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private static Document xmlDoc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private static String userHome;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private Node frame_style_set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private Map<String, Object> frameGeometry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private Map<String, Map<String, Object>> frameGeometries;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private LayoutManager titlePaneLayout = new TitlePaneLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private ColorizeImageFilter imageFilter = new ColorizeImageFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private URL themeDir = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private SynthContext context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private String themeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private ArithmeticExpressionEvaluator aee = new ArithmeticExpressionEvaluator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private Map<String, Integer> variables;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // Reusable clip shape object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private RoundRectClipShape roundedClipShape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    protected Metacity(String themeName) throws IOException, ParserConfigurationException, SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        this.themeName = themeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        themeDir = getThemeDir(themeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (themeDir != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            URL themeURL = new URL(themeDir, "metacity-theme-1.xml");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            xmlDoc = getXMLDoc(themeURL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            if (xmlDoc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                throw new IOException(themeURL.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            throw new FileNotFoundException(themeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        // Initialize constants
1837
efd004b550b7 6771030: Code improvement and warnings removing from the com.sun.java.swing.plaf.gtk package
rupashka
parents: 1299
diff changeset
   127
        variables = new HashMap<String, Integer>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        NodeList nodes = xmlDoc.getElementsByTagName("constant");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        int n = nodes.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            Node node = nodes.item(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            String name = getStringAttr(node, "name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            if (name != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                String value = getStringAttr(node, "value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                        variables.put(name, Integer.parseInt(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    } catch (NumberFormatException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                        logError(themeName, ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                        // Ignore bad value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        // Cache frame geometries
1837
efd004b550b7 6771030: Code improvement and warnings removing from the com.sun.java.swing.plaf.gtk package
rupashka
parents: 1299
diff changeset
   147
        frameGeometries = new HashMap<String, Map<String, Object>>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        nodes = xmlDoc.getElementsByTagName("frame_geometry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        n = nodes.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            Node node = nodes.item(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            String name = getStringAttr(node, "name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            if (name != null) {
1837
efd004b550b7 6771030: Code improvement and warnings removing from the com.sun.java.swing.plaf.gtk package
rupashka
parents: 1299
diff changeset
   154
                HashMap<String, Object> gm = new HashMap<String, Object>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                frameGeometries.put(name, gm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                String parentGM = getStringAttr(node, "parent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                if (parentGM != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    gm.putAll(frameGeometries.get(parentGM));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                gm.put("has_title",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                       Boolean.valueOf(getBooleanAttr(node, "has_title",            true)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                gm.put("rounded_top_left",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                       Boolean.valueOf(getBooleanAttr(node, "rounded_top_left",     false)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                gm.put("rounded_top_right",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                       Boolean.valueOf(getBooleanAttr(node, "rounded_top_right",    false)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                gm.put("rounded_bottom_left",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                       Boolean.valueOf(getBooleanAttr(node, "rounded_bottom_left",  false)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                gm.put("rounded_bottom_right",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                       Boolean.valueOf(getBooleanAttr(node, "rounded_bottom_right", false)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                NodeList childNodes = node.getChildNodes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                int nc = childNodes.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                for (int j = 0; j < nc; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    Node child = childNodes.item(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    if (child.getNodeType() == Node.ELEMENT_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                        name = child.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                        Object value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                        if ("distance".equals(name)) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   181
                            value = Integer.valueOf(getIntAttr(child, "value", 0));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                        } else if ("border".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                            value = new Insets(getIntAttr(child, "top", 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                               getIntAttr(child, "left", 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                               getIntAttr(child, "bottom", 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                               getIntAttr(child, "right", 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                        } else if ("aspect_ratio".equals(name)) {
37714
7a0b1c7e7054 8154213: clean up uses of boxed primitive constructors in the java.desktop module
prr
parents: 25859
diff changeset
   188
                            value = Float.valueOf(getFloatAttr(child, "value", 1.0F));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                            logError(themeName, "Unknown Metacity frame geometry value type: "+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                        String childName = getStringAttr(child, "name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                        if (childName != null && value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                            gm.put(childName, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        frameGeometry = frameGeometries.get("normal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public static LayoutManager getTitlePaneLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return INSTANCE.titlePaneLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    private Shape getRoundedClipShape(int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                      int arcw, int arch, int corners) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (roundedClipShape == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            roundedClipShape = new RoundRectClipShape();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        roundedClipShape.setRoundedRect(x, y, w, h, arcw, arch, corners);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        return roundedClipShape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    void paintButtonBackground(SynthContext context, Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        updateFrameGeometry(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        this.context = context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        JButton button = (JButton)context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        String buttonName = button.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        int buttonState = context.getComponentState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        JComponent titlePane = (JComponent)button.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        Container titlePaneParent = titlePane.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
42192
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   229
        JInternalFrame jif = findInternalFrame(titlePaneParent);
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   230
        if (jif == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        boolean active = jif.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        button.setOpaque(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        String state = "normal";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if ((buttonState & PRESSED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            state = "pressed";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        } else if ((buttonState & MOUSE_OVER) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            state = "prelight";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        String function = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        String location = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        boolean left_corner  = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        boolean right_corner = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (buttonName == "InternalFrameTitlePane.menuButton") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            function = "menu";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            location = "left_left";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            left_corner = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        } else if (buttonName == "InternalFrameTitlePane.iconifyButton") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            function = "minimize";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            int nButtons = ((jif.isIconifiable() ? 1 : 0) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                            (jif.isMaximizable() ? 1 : 0) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                            (jif.isClosable() ? 1 : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            right_corner = (nButtons == 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            switch (nButtons) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
              case 1: location = "right_right"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
              case 2: location = "right_middle"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
              case 3: location = "right_left"; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        } else if (buttonName == "InternalFrameTitlePane.maximizeButton") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            function = "maximize";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            right_corner = !jif.isClosable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            location = jif.isClosable() ? "right_middle" : "right_right";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        } else if (buttonName == "InternalFrameTitlePane.closeButton") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            function = "close";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            right_corner = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            location = "right_right";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        Node frame = getNode(frame_style_set, "frame", new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            "focus", (active ? "yes" : "no"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            "state", (jif.isMaximum() ? "maximized" : "normal")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (function != null && frame != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            Node frame_style = getNode("frame_style", new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                "name", getStringAttr(frame, "style")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            if (frame_style != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                Shape oldClip = g.getClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                if ((right_corner && getBoolean("rounded_top_right", false)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    (left_corner  && getBoolean("rounded_top_left", false))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    Point buttonLoc = button.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    if (right_corner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                        g.setClip(getRoundedClipShape(0, 0, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                                                      12, 12, RoundRectClipShape.TOP_RIGHT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                        g.setClip(getRoundedClipShape(0, 0, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                                                      11, 11, RoundRectClipShape.TOP_LEFT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    Rectangle clipBounds = oldClip.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                    g.clipRect(clipBounds.x, clipBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                               clipBounds.width, clipBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                drawButton(frame_style, location+"_background", state, g, w, h, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                drawButton(frame_style, function, state, g, w, h, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                g.setClip(oldClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    protected void drawButton(Node frame_style, String function, String state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                            Graphics g, int w, int h, JInternalFrame jif) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        Node buttonNode = getNode(frame_style, "button",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                                  new String[] { "function", function, "state", state });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        if (buttonNode == null && !state.equals("normal")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            buttonNode = getNode(frame_style, "button",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                                 new String[] { "function", function, "state", "normal" });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (buttonNode != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            Node draw_ops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            String draw_ops_name = getStringAttr(buttonNode, "draw_ops");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            if (draw_ops_name != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                draw_ops = getNode("draw_ops", new String[] { "name", draw_ops_name });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                draw_ops = getNode(buttonNode, "draw_ops", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            variables.put("width",  w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            variables.put("height", h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            draw(draw_ops, g, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
42192
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   331
    JInternalFrame findInternalFrame(Component comp) {
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   332
        if (comp.getParent() instanceof BasicInternalFrameTitlePane) {
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   333
            comp = comp.getParent();
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   334
        }
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   335
        if (comp instanceof JInternalFrame) {
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   336
            return  (JInternalFrame)comp;
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   337
        } else if (comp instanceof JInternalFrame.JDesktopIcon) {
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   338
            return ((JInternalFrame.JDesktopIcon)comp).getInternalFrame();
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   339
        }
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   340
        assert false : "cannot find the internal frame";
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   341
        return null;
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   342
    }
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   343
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    void paintFrameBorder(SynthContext context, Graphics g, int x0, int y0, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        updateFrameGeometry(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        this.context = context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        JComponent comp = context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        JComponent titlePane = findChild(comp, "InternalFrame.northPane");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if (titlePane == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
42192
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   355
        JInternalFrame jif = findInternalFrame(comp);
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
   356
        if (jif == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        boolean active = jif.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        Font oldFont = g.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        g.setFont(titlePane.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        g.translate(x0, y0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        Rectangle titleRect = calculateTitleArea(jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        JComponent menuButton = findChild(titlePane, "InternalFrameTitlePane.menuButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        Icon frameIcon = jif.getFrameIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        variables.put("mini_icon_width",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                      (frameIcon != null) ? frameIcon.getIconWidth()  : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        variables.put("mini_icon_height",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                      (frameIcon != null) ? frameIcon.getIconHeight() : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        variables.put("title_width",  calculateTitleTextWidth(g, jif));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        FontMetrics fm = SwingUtilities2.getFontMetrics(jif, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        variables.put("title_height", fm.getAscent() + fm.getDescent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        // These don't seem to apply here, but the Galaxy theme uses them. Not sure why.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        variables.put("icon_width",  32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        variables.put("icon_height", 32);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (frame_style_set != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            Node frame = getNode(frame_style_set, "frame", new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                "focus", (active ? "yes" : "no"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                "state", (jif.isMaximum() ? "maximized" : "normal")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            if (frame != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                Node frame_style = getNode("frame_style", new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    "name", getStringAttr(frame, "style")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                if (frame_style != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    Shape oldClip = g.getClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    boolean roundTopLeft     = getBoolean("rounded_top_left",     false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                    boolean roundTopRight    = getBoolean("rounded_top_right",    false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    boolean roundBottomLeft  = getBoolean("rounded_bottom_left",  false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                    boolean roundBottomRight = getBoolean("rounded_bottom_right", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                    if (roundTopLeft || roundTopRight || roundBottomLeft || roundBottomRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                        jif.setOpaque(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                        g.setClip(getRoundedClipShape(0, 0, width, height, 12, 12,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                                        (roundTopLeft     ? RoundRectClipShape.TOP_LEFT     : 0) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                                        (roundTopRight    ? RoundRectClipShape.TOP_RIGHT    : 0) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                                        (roundBottomLeft  ? RoundRectClipShape.BOTTOM_LEFT  : 0) |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                                        (roundBottomRight ? RoundRectClipShape.BOTTOM_RIGHT : 0)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                    Rectangle clipBounds = oldClip.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    g.clipRect(clipBounds.x, clipBounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                               clipBounds.width, clipBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    int titleHeight = titlePane.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    boolean minimized = jif.isIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                    Insets insets = getBorderInsets(context, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    int leftTitlebarEdge   = getInt("left_titlebar_edge");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    int rightTitlebarEdge  = getInt("right_titlebar_edge");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    int topTitlebarEdge    = getInt("top_titlebar_edge");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                    int bottomTitlebarEdge = getInt("bottom_titlebar_edge");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                    if (!minimized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                        drawPiece(frame_style, g, "entire_background",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                                  0, 0, width, height, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    drawPiece(frame_style, g, "titlebar",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                              0, 0, width, titleHeight, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    drawPiece(frame_style, g, "titlebar_middle",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                              leftTitlebarEdge, topTitlebarEdge,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                              width - leftTitlebarEdge - rightTitlebarEdge,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                              titleHeight - topTitlebarEdge - bottomTitlebarEdge,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                              jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    drawPiece(frame_style, g, "left_titlebar_edge",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                              0, 0, leftTitlebarEdge, titleHeight, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    drawPiece(frame_style, g, "right_titlebar_edge",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                              width - rightTitlebarEdge, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                              rightTitlebarEdge, titleHeight, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    drawPiece(frame_style, g, "top_titlebar_edge",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                              0, 0, width, topTitlebarEdge, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    drawPiece(frame_style, g, "bottom_titlebar_edge",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                              0, titleHeight - bottomTitlebarEdge,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                              width, bottomTitlebarEdge, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    drawPiece(frame_style, g, "title",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                              titleRect.x, titleRect.y, titleRect.width, titleRect.height, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    if (!minimized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                        drawPiece(frame_style, g, "left_edge",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                                  0, titleHeight, insets.left, height-titleHeight, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                        drawPiece(frame_style, g, "right_edge",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                                  width-insets.right, titleHeight, insets.right, height-titleHeight, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                        drawPiece(frame_style, g, "bottom_edge",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                                  0, height - insets.bottom, width, insets.bottom, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                        drawPiece(frame_style, g, "overlay",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                                  0, 0, width, height, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    g.setClip(oldClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        g.translate(-x0, -y0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        g.setFont(oldFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
1837
efd004b550b7 6771030: Code improvement and warnings removing from the com.sun.java.swing.plaf.gtk package
rupashka
parents: 1299
diff changeset
   465
    private static class Privileged implements PrivilegedAction<Object> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        private static int GET_THEME_DIR  = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        private static int GET_USER_THEME = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        private static int GET_IMAGE      = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        private int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        private Object arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        public Object doPrivileged(int type, Object arg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            this.arg = arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            return AccessController.doPrivileged(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            if (type == GET_THEME_DIR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                String sep = File.separator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                String[] dirs = new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    userHome + sep + ".themes",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                    System.getProperty("swing.metacitythemedir"),
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   484
                    "/usr/X11R6/share/themes",
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   485
                    "/usr/X11R6/share/gnome/themes",
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   486
                    "/usr/local/share/themes",
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 5506
diff changeset
   487
                    "/usr/local/share/gnome/themes",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    "/usr/share/themes",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    "/usr/gnome/share/themes",  // Debian/Redhat/Solaris
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    "/opt/gnome2/share/themes"  // SuSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                URL themeDir = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                for (int i = 0; i < dirs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                    // System property may not be set so skip null directories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                    if (dirs[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                    File dir =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                        new File(dirs[i] + sep + arg + sep + "metacity-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                    if (new File(dir, "metacity-theme-1.xml").canRead()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                            themeDir = dir.toURI().toURL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                        } catch (MalformedURLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                            themeDir = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                if (themeDir == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                    String filename = "resources/metacity/" + arg +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                        "/metacity-1/metacity-theme-1.xml";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    URL url = getClass().getResource(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    if (url != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                        String str = url.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                            themeDir = new URL(str.substring(0, str.lastIndexOf('/'))+"/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                        } catch (MalformedURLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                            themeDir = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                return themeDir;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            } else if (type == GET_USER_THEME) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    // Set userHome here because we need the privilege
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    userHome = System.getProperty("user.home");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                    String theme = System.getProperty("swing.metacitythemename");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    if (theme != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                        return theme;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    // Note: this is a small file (< 1024 bytes) so it's not worth
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                    // starting an XML parser or even to use a buffered reader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    URL url = new URL(new File(userHome).toURI().toURL(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                                      ".gconf/apps/metacity/general/%25gconf.xml");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                    // Pending: verify character encoding spec for gconf
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    Reader reader = new InputStreamReader(url.openStream(), "ISO-8859-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                    char[] buf = new char[1024];
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   540
                    StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                    int n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    while ((n = reader.read(buf)) >= 0) {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   543
                        sb.append(buf, 0, n);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                    reader.close();
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 23010
diff changeset
   546
                    String str = sb.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    if (str != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                        String strLowerCase = str.toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                        int i = strLowerCase.indexOf("<entry name=\"theme\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                        if (i >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                            i = strLowerCase.indexOf("<stringvalue>", i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                            if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                                i += "<stringvalue>".length();
25122
1ecc464c69d2 8044460: Cleanup new Boolean and single character strings
rriggs
parents: 23010
diff changeset
   554
                                int i2 = str.indexOf('<', i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                                return str.substring(i, i2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                } catch (MalformedURLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                    // OK to just ignore. We'll use a fallback theme.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                    // OK to just ignore. We'll use a fallback theme.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            } else if (type == GET_IMAGE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                return new ImageIcon((URL)arg).getImage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    private static URL getThemeDir(String themeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        return (URL)new Privileged().doPrivileged(Privileged.GET_THEME_DIR, themeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    private static String getUserTheme() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        return (String)new Privileged().doPrivileged(Privileged.GET_USER_THEME, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    protected void tileImage(Graphics g, Image image, int x0, int y0, int w, int h, float[] alphas) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        Graphics2D g2 = (Graphics2D)g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        Composite oldComp = g2.getComposite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        int sw = image.getWidth(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        int sh = image.getHeight(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        int y = y0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        while (y < y0 + h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            sh = Math.min(sh, y0 + h - y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            int x = x0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            while (x < x0 + w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                float f = (alphas.length - 1.0F) * x / (x0 + w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                int i = (int)f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                f -= (int)f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                float alpha = (1-f) * alphas[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                if (i+1 < alphas.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                    alpha += f * alphas[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                int swm = Math.min(sw, x0 + w - x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                g.drawImage(image, x, y, x+swm, y+sh, 0, 0, swm, sh, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                x += swm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            y += sh;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        g2.setComposite(oldComp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
1837
efd004b550b7 6771030: Code improvement and warnings removing from the com.sun.java.swing.plaf.gtk package
rupashka
parents: 1299
diff changeset
   609
    private HashMap<String, Image> images = new HashMap<String, Image>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    protected Image getImage(String key, Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        Image image = images.get(key+"-"+c.getRGB());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        if (image == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            image = imageFilter.colorize(getImage(key), c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            if (image != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                images.put(key+"-"+c.getRGB(), image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    protected Image getImage(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        Image image = images.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (image == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            if (themeDir != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                    URL url = new URL(themeDir, key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                    image = (Image)new Privileged().doPrivileged(Privileged.GET_IMAGE, url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                } catch (MalformedURLException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                    //log("Bad image url: "+ themeDir + "/" + key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            if (image != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                images.put(key, image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        return image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    private class ColorizeImageFilter extends RGBImageFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        double cr, cg, cb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        public ColorizeImageFilter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            canFilterIndexColorModel = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        public void setColor(Color color) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            cr = color.getRed()   / 255.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            cg = color.getGreen() / 255.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            cb = color.getBlue()  / 255.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        public Image colorize(Image fromImage, Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            setColor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            ImageProducer producer = new FilteredImageSource(fromImage.getSource(), this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            return new ImageIcon(context.getComponent().createImage(producer)).getImage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        public int filterRGB(int x, int y, int rgb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            // Assume all rgb values are shades of gray
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            double grayLevel = 2 * (rgb & 0xff) / 255.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            double r, g, b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            if (grayLevel <= 1.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                r = cr * grayLevel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                g = cg * grayLevel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                b = cb * grayLevel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                grayLevel -= 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                r = cr + (1.0 - cr) * grayLevel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                g = cg + (1.0 - cg) * grayLevel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                b = cb + (1.0 - cb) * grayLevel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            return ((rgb & 0xff000000) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    (((int)(r * 255)) << 16) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                    (((int)(g * 255)) << 8) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                    (int)(b * 255));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    protected static JComponent findChild(JComponent parent, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        int n = parent.getComponentCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            JComponent c = (JComponent)parent.getComponent(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            if (name.equals(c.getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    protected class TitlePaneLayout implements LayoutManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        public void addLayoutComponent(String name, Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        public void removeLayoutComponent(Component c) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        public Dimension preferredLayoutSize(Container c)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            return minimumLayoutSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        public Dimension minimumLayoutSize(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            JComponent titlePane = (JComponent)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            Container titlePaneParent = titlePane.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            JInternalFrame frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            if (titlePaneParent instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                frame = (JInternalFrame)titlePaneParent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            } else if (titlePaneParent instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                frame = ((JInternalFrame.JDesktopIcon)titlePaneParent).getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            Dimension buttonDim = calculateButtonSize(titlePane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            Insets title_border  = (Insets)getFrameGeometry().get("title_border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            Insets button_border = (Insets)getFrameGeometry().get("button_border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            // Calculate width.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            int width = getInt("left_titlebar_edge") + buttonDim.width + getInt("right_titlebar_edge");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            if (title_border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                width += title_border.left + title_border.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            if (frame.isClosable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                width += buttonDim.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            if (frame.isMaximizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                width += buttonDim.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            if (frame.isIconifiable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                width += buttonDim.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            FontMetrics fm = frame.getFontMetrics(titlePane.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            String frameTitle = frame.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            int title_w = frameTitle != null ? SwingUtilities2.stringWidth(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                               frame, fm, frameTitle) : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            int title_length = frameTitle != null ? frameTitle.length() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            // Leave room for three characters in the title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            if (title_length > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                int subtitle_w = SwingUtilities2.stringWidth(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                    frame, fm, frameTitle.substring(0, 3) + "...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                width += (title_w < subtitle_w) ? title_w : subtitle_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                width += title_w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            // Calculate height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            int titleHeight = fm.getHeight() + getInt("title_vertical_pad");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            if (title_border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                titleHeight += title_border.top + title_border.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            int buttonHeight = buttonDim.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            if (button_border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                buttonHeight += button_border.top + button_border.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            int height = Math.max(buttonHeight, titleHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            return new Dimension(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        public void layoutContainer(Container c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            JComponent titlePane = (JComponent)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            Container titlePaneParent = titlePane.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            JInternalFrame frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            if (titlePaneParent instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                frame = (JInternalFrame)titlePaneParent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            } else if (titlePaneParent instanceof JInternalFrame.JDesktopIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                frame = ((JInternalFrame.JDesktopIcon)titlePaneParent).getInternalFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            }
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 25144
diff changeset
   771
            Map<String, Object> gm = getFrameGeometry();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            int w = titlePane.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            int h = titlePane.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            JComponent menuButton     = findChild(titlePane, "InternalFrameTitlePane.menuButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
            JComponent minimizeButton = findChild(titlePane, "InternalFrameTitlePane.iconifyButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            JComponent maximizeButton = findChild(titlePane, "InternalFrameTitlePane.maximizeButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            JComponent closeButton    = findChild(titlePane, "InternalFrameTitlePane.closeButton");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            Insets button_border = (Insets)gm.get("button_border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            Dimension buttonDim = calculateButtonSize(titlePane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            int y = (button_border != null) ? button_border.top : 0;
1297
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   785
            if (titlePaneParent.getComponentOrientation().isLeftToRight()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   786
                int x = getInt("left_titlebar_edge");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
1297
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   788
                menuButton.setBounds(x, y, buttonDim.width, buttonDim.height);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
1297
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   790
                x = w - buttonDim.width - getInt("right_titlebar_edge");
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   791
                if (button_border != null) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   792
                    x -= button_border.right;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   793
                }
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   794
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   795
                if (frame.isClosable()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   796
                    closeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   797
                    x -= buttonDim.width;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   798
                }
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   799
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   800
                if (frame.isMaximizable()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   801
                    maximizeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   802
                    x -= buttonDim.width;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   803
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
1297
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   805
                if (frame.isIconifiable()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   806
                    minimizeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   807
                }
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   808
            } else {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   809
                int x = w - buttonDim.width - getInt("right_titlebar_edge");
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   810
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   811
                menuButton.setBounds(x, y, buttonDim.width, buttonDim.height);
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   812
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   813
                x = getInt("left_titlebar_edge");
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   814
                if (button_border != null) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   815
                    x += button_border.left;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   816
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
1297
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   818
                if (frame.isClosable()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   819
                    closeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   820
                    x += buttonDim.width;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   821
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
1297
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   823
                if (frame.isMaximizable()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   824
                    maximizeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   825
                    x += buttonDim.width;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   826
                }
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   827
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   828
                if (frame.isIconifiable()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   829
                    minimizeButton.setBounds(x, y, buttonDim.width, buttonDim.height);
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
   830
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    } // end TitlePaneLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 25144
diff changeset
   835
    protected Map<String, Object> getFrameGeometry() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        return frameGeometry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 25144
diff changeset
   839
    protected void setFrameGeometry(JComponent titlePane, Map<String, Object> gm) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        this.frameGeometry = gm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        if (getInt("top_height") == 0 && titlePane != null) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   842
            gm.put("top_height", Integer.valueOf(titlePane.getHeight()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    protected int getInt(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        Integer i = (Integer)frameGeometry.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        if (i == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            i = variables.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        return (i != null) ? i.intValue() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    protected boolean getBoolean(String key, boolean fallback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        Boolean b = (Boolean)frameGeometry.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        return (b != null) ? b.booleanValue() : fallback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    protected void drawArc(Node node, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        Color color = parseColor(getStringAttr(attrs, "color"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        int x = aee.evaluate(getStringAttr(attrs, "x"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        int y = aee.evaluate(getStringAttr(attrs, "y"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        int w = aee.evaluate(getStringAttr(attrs, "width"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        int h = aee.evaluate(getStringAttr(attrs, "height"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        int start_angle = aee.evaluate(getStringAttr(attrs, "start_angle"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        int extent_angle = aee.evaluate(getStringAttr(attrs, "extent_angle"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        boolean filled = getBooleanAttr(node, "filled", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        if (getInt("width") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            x -= w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        if (getInt("height") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            y -= h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        if (filled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            g.fillArc(x, y, w, h, start_angle, extent_angle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            g.drawArc(x, y, w, h, start_angle, extent_angle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    protected void drawLine(Node node, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        Color color = parseColor(getStringAttr(attrs, "color"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        int x1 = aee.evaluate(getStringAttr(attrs, "x1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        int y1 = aee.evaluate(getStringAttr(attrs, "y1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        int x2 = aee.evaluate(getStringAttr(attrs, "x2"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        int y2 = aee.evaluate(getStringAttr(attrs, "y2"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        int lineWidth = aee.evaluate(getStringAttr(attrs, "width"), 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        if (lineWidth != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            Graphics2D g2d = (Graphics2D)g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            Stroke stroke = g2d.getStroke();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            g2d.setStroke(new BasicStroke((float)lineWidth));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            g2d.drawLine(x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            g2d.setStroke(stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            g.drawLine(x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    protected void drawRectangle(Node node, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        Color color = parseColor(getStringAttr(attrs, "color"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        boolean filled = getBooleanAttr(node, "filled", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        int x = aee.evaluate(getStringAttr(attrs, "x"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        int y = aee.evaluate(getStringAttr(attrs, "y"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        int w = aee.evaluate(getStringAttr(attrs, "width"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        int h = aee.evaluate(getStringAttr(attrs, "height"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        if (getInt("width") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            x -= w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        if (getInt("height") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            y -= h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        if (filled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            g.fillRect(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            g.drawRect(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    protected void drawTile(Node node, Graphics g, JInternalFrame jif) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        int x0 = aee.evaluate(getStringAttr(attrs, "x"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        int y0 = aee.evaluate(getStringAttr(attrs, "y"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        int w = aee.evaluate(getStringAttr(attrs, "width"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        int h = aee.evaluate(getStringAttr(attrs, "height"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        int tw = aee.evaluate(getStringAttr(attrs, "tile_width"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        int th = aee.evaluate(getStringAttr(attrs, "tile_height"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        int width  = getInt("width");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        int height = getInt("height");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        if (width == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            x0 -= w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        if (height == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            y0 -= h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        Shape oldClip = g.getClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        if (g instanceof Graphics2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            ((Graphics2D)g).clip(new Rectangle(x0, y0, w, h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        variables.put("width",  tw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        variables.put("height", th);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        Node draw_ops = getNode("draw_ops", new String[] { "name", getStringAttr(node, "name") });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        int y = y0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        while (y < y0 + h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            int x = x0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            while (x < x0 + w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                g.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                draw(draw_ops, g, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                g.translate(-x, -y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                x += tw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            y += th;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        variables.put("width",  width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        variables.put("height", height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        g.setClip(oldClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    protected void drawTint(Node node, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        Color color = parseColor(getStringAttr(attrs, "color"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        float alpha = Float.parseFloat(getStringAttr(attrs, "alpha"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        int x = aee.evaluate(getStringAttr(attrs, "x"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        int y = aee.evaluate(getStringAttr(attrs, "y"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        int w = aee.evaluate(getStringAttr(attrs, "width"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        int h = aee.evaluate(getStringAttr(attrs, "height"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        if (getInt("width") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            x -= w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        if (getInt("height") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            y -= h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        if (g instanceof Graphics2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            Graphics2D g2 = (Graphics2D)g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            Composite oldComp = g2.getComposite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            g2.setComposite(ac);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            g2.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            g2.fillRect(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            g2.setComposite(oldComp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    protected void drawTitle(Node node, Graphics g, JInternalFrame jif) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        String colorStr = getStringAttr(attrs, "color");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        int i = colorStr.indexOf("gtk:fg[");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            colorStr = colorStr.substring(0, i) + "gtk:text[" + colorStr.substring(i+7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        Color color = parseColor(colorStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        int x = aee.evaluate(getStringAttr(attrs, "x"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        int y = aee.evaluate(getStringAttr(attrs, "y"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        String title = jif.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        if (title != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            FontMetrics fm = SwingUtilities2.getFontMetrics(jif, g);
1297
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1007
            title = SwingUtilities2.clipStringIfNecessary(jif, fm, title,
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1008
                         calculateTitleArea(jif).width);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            g.setColor(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            SwingUtilities2.drawString(jif, g, title, x, y + fm.getAscent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    protected Dimension calculateButtonSize(JComponent titlePane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        int buttonHeight = getInt("button_height");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        if (buttonHeight == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            buttonHeight = titlePane.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            if (buttonHeight == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                buttonHeight = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                Insets button_border = (Insets)frameGeometry.get("button_border");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                if (button_border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                    buttonHeight -= (button_border.top + button_border.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        int buttonWidth = getInt("button_width");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        if (buttonWidth == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            buttonWidth = buttonHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            Float aspect_ratio = (Float)frameGeometry.get("aspect_ratio");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            if (aspect_ratio != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                buttonWidth = (int)(buttonHeight / aspect_ratio.floatValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        return new Dimension(buttonWidth, buttonHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    protected Rectangle calculateTitleArea(JInternalFrame jif) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        JComponent titlePane = findChild(jif, "InternalFrame.northPane");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        Dimension buttonDim = calculateButtonSize(titlePane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        Insets title_border = (Insets)frameGeometry.get("title_border");
1297
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1042
        Insets button_border = (Insets)getFrameGeometry().get("button_border");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
1297
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1044
        Rectangle r = new Rectangle();
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1045
        r.x = getInt("left_titlebar_edge");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        r.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        r.height = titlePane.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        if (title_border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            r.x += title_border.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            r.y += title_border.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            r.height -= (title_border.top + title_border.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
1297
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1054
        if (titlePane.getParent().getComponentOrientation().isLeftToRight()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1055
            r.x += buttonDim.width;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1056
            if (button_border != null) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1057
                r.x += button_border.left;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1058
            }
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1059
            r.width = titlePane.getWidth() - r.x - getInt("right_titlebar_edge");
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1060
            if (jif.isClosable()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1061
                r.width -= buttonDim.width;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1062
            }
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1063
            if (jif.isMaximizable()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1064
                r.width -= buttonDim.width;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1065
            }
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1066
            if (jif.isIconifiable()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1067
                r.width -= buttonDim.width;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1068
            }
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1069
        } else {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1070
            if (jif.isClosable()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1071
                r.x += buttonDim.width;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1072
            }
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1073
            if (jif.isMaximizable()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1074
                r.x += buttonDim.width;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1075
            }
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1076
            if (jif.isIconifiable()) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1077
                r.x += buttonDim.width;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1078
            }
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1079
            r.width = titlePane.getWidth() - r.x - getInt("right_titlebar_edge")
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1080
                    - buttonDim.width;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1081
            if (button_border != null) {
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1082
                r.x -= button_border.right;
59aad2292413 6579243: Windows, GTK: Internal frame title is drawn wrong if the frame has RTL orientation
mlapshin
parents: 438
diff changeset
  1083
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        if (title_border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            r.width -= title_border.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    protected int calculateTitleTextWidth(Graphics g, JInternalFrame jif) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        String title = jif.getTitle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        if (title != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            Rectangle r = calculateTitleArea(jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            return Math.min(SwingUtilities2.stringWidth(jif,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                     SwingUtilities2.getFontMetrics(jif, g), title), r.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
    protected void setClip(Node node, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        int x = aee.evaluate(getStringAttr(attrs, "x"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        int y = aee.evaluate(getStringAttr(attrs, "y"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        int w = aee.evaluate(getStringAttr(attrs, "width"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        int h = aee.evaluate(getStringAttr(attrs, "height"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        if (getInt("width") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            x -= w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        if (getInt("height") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            y -= h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        if (g instanceof Graphics2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            ((Graphics2D)g).clip(new Rectangle(x, y, w, h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
    protected void drawGTKArrow(Node node, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        String arrow    = getStringAttr(attrs, "arrow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        String shadow   = getStringAttr(attrs, "shadow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        String stateStr = getStringAttr(attrs, "state").toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        int x = aee.evaluate(getStringAttr(attrs, "x"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        int y = aee.evaluate(getStringAttr(attrs, "y"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        int w = aee.evaluate(getStringAttr(attrs, "width"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        int h = aee.evaluate(getStringAttr(attrs, "height"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        int state = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        if ("NORMAL".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            state = ENABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        } else if ("SELECTED".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            state = SELECTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        } else if ("INSENSITIVE".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            state = DISABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        } else if ("PRELIGHT".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            state = MOUSE_OVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        ShadowType shadowType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        if ("in".equals(shadow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            shadowType = ShadowType.IN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        } else if ("out".equals(shadow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            shadowType = ShadowType.OUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        } else if ("etched_in".equals(shadow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            shadowType = ShadowType.ETCHED_IN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        } else if ("etched_out".equals(shadow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            shadowType = ShadowType.ETCHED_OUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        } else if ("none".equals(shadow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            shadowType = ShadowType.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        ArrowType direction = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        if ("up".equals(arrow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            direction = ArrowType.UP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        } else if ("down".equals(arrow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            direction = ArrowType.DOWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        } else if ("left".equals(arrow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            direction = ArrowType.LEFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        } else if ("right".equals(arrow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            direction = ArrowType.RIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        GTKPainter.INSTANCE.paintMetacityElement(context, g, state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                "metacity-arrow", x, y, w, h, shadowType, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    protected void drawGTKBox(Node node, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        String shadow   = getStringAttr(attrs, "shadow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        String stateStr = getStringAttr(attrs, "state").toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        int x = aee.evaluate(getStringAttr(attrs, "x"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        int y = aee.evaluate(getStringAttr(attrs, "y"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        int w = aee.evaluate(getStringAttr(attrs, "width"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        int h = aee.evaluate(getStringAttr(attrs, "height"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        int state = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        if ("NORMAL".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            state = ENABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        } else if ("SELECTED".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            state = SELECTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        } else if ("INSENSITIVE".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            state = DISABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        } else if ("PRELIGHT".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            state = MOUSE_OVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        ShadowType shadowType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        if ("in".equals(shadow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            shadowType = ShadowType.IN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        } else if ("out".equals(shadow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            shadowType = ShadowType.OUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        } else if ("etched_in".equals(shadow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            shadowType = ShadowType.ETCHED_IN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        } else if ("etched_out".equals(shadow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            shadowType = ShadowType.ETCHED_OUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        } else if ("none".equals(shadow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            shadowType = ShadowType.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        GTKPainter.INSTANCE.paintMetacityElement(context, g, state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                "metacity-box", x, y, w, h, shadowType, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
    protected void drawGTKVLine(Node node, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        String stateStr = getStringAttr(attrs, "state").toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        int x  = aee.evaluate(getStringAttr(attrs, "x"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        int y1 = aee.evaluate(getStringAttr(attrs, "y1"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        int y2 = aee.evaluate(getStringAttr(attrs, "y2"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        int state = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        if ("NORMAL".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            state = ENABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        } else if ("SELECTED".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            state = SELECTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        } else if ("INSENSITIVE".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            state = DISABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        } else if ("PRELIGHT".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            state = MOUSE_OVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        GTKPainter.INSTANCE.paintMetacityElement(context, g, state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                "metacity-vline", x, y1, 1, y2 - y1, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    protected void drawGradient(Node node, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        String type = getStringAttr(attrs, "type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        float alpha = getFloatAttr(node, "alpha", -1F);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        int x = aee.evaluate(getStringAttr(attrs, "x"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        int y = aee.evaluate(getStringAttr(attrs, "y"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        int w = aee.evaluate(getStringAttr(attrs, "width"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        int h = aee.evaluate(getStringAttr(attrs, "height"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        if (getInt("width") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            x -= w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        if (getInt("height") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            y -= h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        // Get colors from child nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        Node[] colorNodes = getNodesByName(node, "color");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        Color[] colors = new Color[colorNodes.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        for (int i = 0; i < colorNodes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            colors[i] = parseColor(getStringAttr(colorNodes[i], "value"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        boolean horizontal = ("diagonal".equals(type) || "horizontal".equals(type));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        boolean vertical   = ("diagonal".equals(type) || "vertical".equals(type));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        if (g instanceof Graphics2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            Graphics2D g2 = (Graphics2D)g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            Composite oldComp = g2.getComposite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            if (alpha >= 0F) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            int n = colors.length - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                g2.setPaint(new GradientPaint(x + (horizontal ? (i*w/n) : 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                                              y + (vertical   ? (i*h/n) : 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                                              colors[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                                              x + (horizontal ? ((i+1)*w/n) : 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                                              y + (vertical   ? ((i+1)*h/n) : 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                                              colors[i+1]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                g2.fillRect(x + (horizontal ? (i*w/n) : 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                            y + (vertical   ? (i*h/n) : 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                            (horizontal ? (w/n) : w),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                            (vertical   ? (h/n) : h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            g2.setComposite(oldComp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    protected void drawImage(Node node, Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        String filename = getStringAttr(attrs, "filename");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        String colorizeStr = getStringAttr(attrs, "colorize");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        Color colorize = (colorizeStr != null) ? parseColor(colorizeStr) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        String alpha = getStringAttr(attrs, "alpha");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        Image object = (colorize != null) ? getImage(filename, colorize) : getImage(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        variables.put("object_width",  object.getWidth(null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        variables.put("object_height", object.getHeight(null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        String fill_type = getStringAttr(attrs, "fill_type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        int x = aee.evaluate(getStringAttr(attrs, "x"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        int y = aee.evaluate(getStringAttr(attrs, "y"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        int w = aee.evaluate(getStringAttr(attrs, "width"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        int h = aee.evaluate(getStringAttr(attrs, "height"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        if (getInt("width") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
            x -= w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        if (getInt("height") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            y -= h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        if (alpha != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            if ("tile".equals(fill_type)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                StringTokenizer tokenizer = new StringTokenizer(alpha, ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                float[] alphas = new float[tokenizer.countTokens()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                for (int i = 0; i < alphas.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                    alphas[i] = Float.parseFloat(tokenizer.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                tileImage(g, object, x, y, w, h, alphas);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                float a = Float.parseFloat(alpha);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                if (g instanceof Graphics2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                    Graphics2D g2 = (Graphics2D)g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                    Composite oldComp = g2.getComposite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, a));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                    g2.drawImage(object, x, y, w, h, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                    g2.setComposite(oldComp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            g.drawImage(object, x, y, w, h, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    protected void drawIcon(Node node, Graphics g, JInternalFrame jif) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        Icon icon = jif.getFrameIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        if (icon == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        String alpha = getStringAttr(attrs, "alpha");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        int x = aee.evaluate(getStringAttr(attrs, "x"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        int y = aee.evaluate(getStringAttr(attrs, "y"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        int w = aee.evaluate(getStringAttr(attrs, "width"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        int h = aee.evaluate(getStringAttr(attrs, "height"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        if (getInt("width") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            x -= w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        if (getInt("height") == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            y -= h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        if (alpha != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            float a = Float.parseFloat(alpha);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            if (g instanceof Graphics2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                Graphics2D g2 = (Graphics2D)g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                Composite oldComp = g2.getComposite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, a));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                icon.paintIcon(jif, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                g2.setComposite(oldComp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
            icon.paintIcon(jif, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    protected void drawInclude(Node node, Graphics g, JInternalFrame jif) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        int oldWidth  = getInt("width");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        int oldHeight = getInt("height");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        int x = aee.evaluate(getStringAttr(attrs, "x"),       0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        int y = aee.evaluate(getStringAttr(attrs, "y"),       0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        int w = aee.evaluate(getStringAttr(attrs, "width"),  -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        int h = aee.evaluate(getStringAttr(attrs, "height"), -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        if (w != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            variables.put("width",  w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        if (h != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
            variables.put("height", h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        Node draw_ops = getNode("draw_ops", new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            "name", getStringAttr(node, "name")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        g.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        draw(draw_ops, g, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        g.translate(-x, -y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        if (w != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
            variables.put("width",  oldWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        if (h != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            variables.put("height", oldHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
    protected void draw(Node draw_ops, Graphics g, JInternalFrame jif) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        if (draw_ops != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
            NodeList nodes = draw_ops.getChildNodes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            if (nodes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                Shape oldClip = g.getClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                for (int i = 0; i < nodes.getLength(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                    Node child = nodes.item(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                    if (child.getNodeType() == Node.ELEMENT_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                            String name = child.getNodeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                            if ("include".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                                drawInclude(child, g, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                            } else if ("arc".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                                drawArc(child, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                            } else if ("clip".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                                setClip(child, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                            } else if ("gradient".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                                drawGradient(child, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                            } else if ("gtk_arrow".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                                drawGTKArrow(child, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                            } else if ("gtk_box".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                                drawGTKBox(child, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                            } else if ("gtk_vline".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                                drawGTKVLine(child, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                            } else if ("image".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                                drawImage(child, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                            } else if ("icon".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                                drawIcon(child, g, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                            } else if ("line".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                                drawLine(child, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                            } else if ("rectangle".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                                drawRectangle(child, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                            } else if ("tint".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                                drawTint(child, g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                            } else if ("tile".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                                drawTile(child, g, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                            } else if ("title".equals(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                                drawTitle(child, g, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                                System.err.println("Unknown Metacity drawing op: "+child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                        } catch (NumberFormatException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                            logError(themeName, ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                g.setClip(oldClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
    protected void drawPiece(Node frame_style, Graphics g, String position, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
                             int width, int height, JInternalFrame jif) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        Node piece = getNode(frame_style, "piece", new String[] { "position", position });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        if (piece != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
            Node draw_ops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
            String draw_ops_name = getStringAttr(piece, "draw_ops");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
            if (draw_ops_name != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                draw_ops = getNode("draw_ops", new String[] { "name", draw_ops_name });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                draw_ops = getNode(piece, "draw_ops", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
            variables.put("width",  width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
            variables.put("height", height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
            g.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
            draw(draw_ops, g, jif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
            g.translate(-x, -y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    Insets getBorderInsets(SynthContext context, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        updateFrameGeometry(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        if (insets == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
            insets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        insets.top    = ((Insets)frameGeometry.get("title_border")).top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        insets.bottom = getInt("bottom_height");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        insets.left   = getInt("left_width");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        insets.right  = getInt("right_width");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
    private void updateFrameGeometry(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        this.context = context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        JComponent comp = context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        JComponent titlePane = findChild(comp, "InternalFrame.northPane");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
42192
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
  1474
        JInternalFrame jif = findInternalFrame(comp);
35a00ea5c65d 8062525: JInternalFrame can't show correctly with the specical option "-esa -ea -Xcheck:jni -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel".
ssadetsky
parents: 37714
diff changeset
  1475
        if (jif == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        if (frame_style_set == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
            Node window = getNode("window", new String[]{"type", "normal"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            if (window != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                frame_style_set = getNode("frame_style_set",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                        new String[] {"name", getStringAttr(window, "style_set")});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            if (frame_style_set == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                frame_style_set = getNode("frame_style_set", new String[] {"name", "normal"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        if (frame_style_set != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
            Node frame = getNode(frame_style_set, "frame", new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                "focus", (jif.isSelected() ? "yes" : "no"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                "state", (jif.isMaximum() ? "maximized" : "normal")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            if (frame != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                Node frame_style = getNode("frame_style", new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                    "name", getStringAttr(frame, "style")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                if (frame_style != null) {
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 25144
diff changeset
  1503
                    Map<String, Object> gm = frameGeometries.get(getStringAttr(frame_style, "geometry"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
                    setFrameGeometry(titlePane, gm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
    protected static void logError(String themeName, Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        logError(themeName, ex.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
    protected static void logError(String themeName, String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        if (!errorLogged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
            System.err.println("Exception in Metacity for theme \""+themeName+"\": "+msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
            errorLogged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
    // XML Parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
    protected static Document getXMLDoc(final URL xmlFile)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                                throws IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                                       ParserConfigurationException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                                       SAXException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
        if (documentBuilder == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
            documentBuilder =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                DocumentBuilderFactory.newInstance().newDocumentBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
        InputStream inputStream =
1837
efd004b550b7 6771030: Code improvement and warnings removing from the com.sun.java.swing.plaf.gtk package
rupashka
parents: 1299
diff changeset
  1536
            AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
efd004b550b7 6771030: Code improvement and warnings removing from the com.sun.java.swing.plaf.gtk package
rupashka
parents: 1299
diff changeset
  1537
                public InputStream run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                        return new BufferedInputStream(xmlFile.openStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                    } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        Document doc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        if (inputStream != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
            doc = documentBuilder.parse(inputStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        return doc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
    protected Node[] getNodesByName(Node parent, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
        NodeList nodes = parent.getChildNodes(); // ElementNode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        int n = nodes.getLength();
1837
efd004b550b7 6771030: Code improvement and warnings removing from the com.sun.java.swing.plaf.gtk package
rupashka
parents: 1299
diff changeset
  1557
        ArrayList<Node> list = new ArrayList<Node>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        for (int i=0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
            Node node = nodes.item(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
            if (name.equals(node.getNodeName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                list.add(node);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
        return list.toArray(new Node[list.size()]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
    protected Node getNode(String tagName, String[] attrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
        NodeList nodes = xmlDoc.getElementsByTagName(tagName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
        return (nodes != null) ? getNode(nodes, tagName, attrs) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
    protected Node getNode(Node parent, String name, String[] attrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
        Node node = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        NodeList nodes = parent.getChildNodes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
        if (nodes != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
            node = getNode(nodes, name, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
        if (node == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
            String inheritFrom = getStringAttr(parent, "parent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
            if (inheritFrom != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                Node inheritFromNode = getNode(parent.getParentNode(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                                               parent.getNodeName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                                               new String[] { "name", inheritFrom });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                if (inheritFromNode != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                    node = getNode(inheritFromNode, name, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
        return node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
    protected Node getNode(NodeList nodes, String name, String[] attrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        int n = nodes.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
        for (int i=0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
            Node node = nodes.item(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
            if (name.equals(node.getNodeName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                if (attrs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                    NamedNodeMap nodeAttrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                    if (nodeAttrs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                        boolean matches = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                        int nAttrs = attrs.length / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                        for (int a = 0; a < nAttrs; a++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                            String aName  = attrs[a * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                            String aValue = attrs[a * 2 + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
                            Node attr = nodeAttrs.getNamedItem(aName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                            if (attr == null ||
1837
efd004b550b7 6771030: Code improvement and warnings removing from the com.sun.java.swing.plaf.gtk package
rupashka
parents: 1299
diff changeset
  1609
                                aValue != null && !aValue.equals(attr.getNodeValue())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
                                matches = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                        if (matches) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                            return node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                    return node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
    protected String getStringAttr(Node node, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
        String value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        NamedNodeMap attrs = node.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        if (attrs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
            value = getStringAttr(attrs, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
            if (value == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                String inheritFrom = getStringAttr(attrs, "parent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                if (inheritFrom != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                    Node inheritFromNode = getNode(node.getParentNode(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                                                   node.getNodeName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                                                   new String[] { "name", inheritFrom });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                    if (inheritFromNode != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                        value = getStringAttr(inheritFromNode, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
    protected String getStringAttr(NamedNodeMap attrs, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
        Node item = attrs.getNamedItem(name);
1837
efd004b550b7 6771030: Code improvement and warnings removing from the com.sun.java.swing.plaf.gtk package
rupashka
parents: 1299
diff changeset
  1648
        return (item != null) ? item.getNodeValue() : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
    protected boolean getBooleanAttr(Node node, String name, boolean fallback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
        String str = getStringAttr(node, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
        if (str != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
            return Boolean.valueOf(str).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
        return fallback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
    protected int getIntAttr(Node node, String name, int fallback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
        String str = getStringAttr(node, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
        int value = fallback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
        if (str != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                value = Integer.parseInt(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
            } catch (NumberFormatException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                logError(themeName, ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
    protected float getFloatAttr(Node node, String name, float fallback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
        String str = getStringAttr(node, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
        float value = fallback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
        if (str != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                value = Float.parseFloat(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            } catch (NumberFormatException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                logError(themeName, ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
    protected Color parseColor(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
        StringTokenizer tokenizer = new StringTokenizer(str, "/");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
        int n = tokenizer.countTokens();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
        if (n > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            String function = tokenizer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
            if ("shade".equals(function)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                assert (n == 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                Color c = parseColor2(tokenizer.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                float alpha = Float.parseFloat(tokenizer.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                return GTKColorType.adjustColor(c, 1.0F, alpha, alpha);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
            } else if ("blend".equals(function)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
                assert (n == 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
                Color  bg = parseColor2(tokenizer.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
                Color  fg = parseColor2(tokenizer.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                float alpha = Float.parseFloat(tokenizer.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
                if (alpha > 1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                    alpha = 1.0f / alpha;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
                return new Color((int)(bg.getRed() + ((fg.getRed() - bg.getRed()) * alpha)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                                 (int)(bg.getRed() + ((fg.getRed() - bg.getRed()) * alpha)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
                                 (int)(bg.getRed() + ((fg.getRed() - bg.getRed()) * alpha)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
                System.err.println("Unknown Metacity color function="+str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
            return parseColor2(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
    protected Color parseColor2(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
        Color c = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
        if (str.startsWith("gtk:")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
            int i1 = str.indexOf('[');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
            if (i1 > 3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
                String typeStr = str.substring(4, i1).toLowerCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
                int i2 = str.indexOf(']');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
                if (i2 > i1+1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
                    String stateStr = str.substring(i1+1, i2).toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                    int state = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
                    if ("ACTIVE".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
                        state = PRESSED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                    } else if ("INSENSITIVE".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
                        state = DISABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                    } else if ("NORMAL".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
                        state = ENABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
                    } else if ("PRELIGHT".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
                        state = MOUSE_OVER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
                    } else if ("SELECTED".equals(stateStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
                        state = SELECTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
                    ColorType type = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
                    if ("fg".equals(typeStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
                        type = GTKColorType.FOREGROUND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                    } else if ("bg".equals(typeStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
                        type = GTKColorType.BACKGROUND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
                    } else if ("base".equals(typeStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
                        type = GTKColorType.TEXT_BACKGROUND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
                    } else if ("text".equals(typeStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
                        type = GTKColorType.TEXT_FOREGROUND;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
                    } else if ("dark".equals(typeStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
                        type = GTKColorType.DARK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
                    } else if ("light".equals(typeStr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
                        type = GTKColorType.LIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
                    if (state >= 0 && type != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
                        c = ((GTKStyle)context.getStyle()).getGTKColor(context, state, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
            c = parseColorString(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
        return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
    private static Color parseColorString(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
        if (str.charAt(0) == '#') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
            str = str.substring(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
            int i = str.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
            if (i < 3 || i > 12 || (i % 3) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
            i /= 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
            int r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
            int g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
            int b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
                r = Integer.parseInt(str.substring(0, i), 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                g = Integer.parseInt(str.substring(i, i * 2), 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                b = Integer.parseInt(str.substring(i * 2, i * 3), 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
            if (i == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
                return new ColorUIResource(r / 65535.0f, g / 65535.0f, b / 65535.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
            } else if (i == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
                return new ColorUIResource(r / 15.0f, g / 15.0f, b / 15.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
            } else if (i == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
                return new ColorUIResource(r, g, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
                return new ColorUIResource(r / 4095.0f, g / 4095.0f, b / 4095.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
            return XColors.lookupColor(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
    class ArithmeticExpressionEvaluator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
        private PeekableStringTokenizer tokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
        int evaluate(String expr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
            tokenizer = new PeekableStringTokenizer(expr, " \t+-*/%()", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
            return Math.round(expression());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
        int evaluate(String expr, int fallback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
            return (expr != null) ? evaluate(expr) : fallback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        public float expression() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
            float value = getTermValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
            boolean done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
            while (!done && tokenizer.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                String next = tokenizer.peek();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                if ("+".equals(next) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                    "-".equals(next) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
                    "`max`".equals(next) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
                    "`min`".equals(next)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                    tokenizer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                    float value2 = getTermValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                    if ("+".equals(next)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                        value += value2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                    } else if ("-".equals(next)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                        value -= value2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
                    } else if ("`max`".equals(next)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                        value = Math.max(value, value2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                    } else if ("`min`".equals(next)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                        value = Math.min(value, value2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                    done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
        public float getTermValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
            float value = getFactorValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
            boolean done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
            while (!done && tokenizer.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
                String next = tokenizer.peek();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
                if ("*".equals(next) || "/".equals(next) || "%".equals(next)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                    tokenizer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
                    float value2 = getFactorValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
                    if ("*".equals(next)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
                        value *= value2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
                    } else if ("/".equals(next)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
                        value /= value2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
                        value %= value2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
                    done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
        public float getFactorValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
            float value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
            if ("(".equals(tokenizer.peek())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
                tokenizer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
                value = expression();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
                tokenizer.nextToken(); // skip right paren
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
                String token = tokenizer.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
                if (Character.isDigit(token.charAt(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
                    value = Float.parseFloat(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
                    Integer i = variables.get(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                    if (i == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                        i = (Integer)getFrameGeometry().get(token);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                    if (i == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                        logError(themeName, "Variable \"" + token + "\" not defined");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                    value = (i != null) ? i.intValue() : 0F;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
    static class PeekableStringTokenizer extends StringTokenizer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
        String token = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
        public PeekableStringTokenizer(String str, String delim,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
                                       boolean returnDelims) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
            super(str, delim, returnDelims);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
            peek();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
        public String peek() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
            if (token == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                token = nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
            return token;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
        public boolean hasMoreTokens() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
            return (token != null || super.hasMoreTokens());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
        public String nextToken() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
            if (token != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
                String t = token;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
                token = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
                if (hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
                    peek();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
                return t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
                String token = super.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
                while ((token.equals(" ") || token.equals("\t"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
                       && hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
                    token = super.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
                return token;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
    static class RoundRectClipShape extends RectangularShape {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
        static final int TOP_LEFT = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
        static final int TOP_RIGHT = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
        static final int BOTTOM_LEFT = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
        static final int BOTTOM_RIGHT = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
        int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
        int y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
        int width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
        int height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
        int arcwidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
        int archeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
        int corners;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
        public RoundRectClipShape() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
        public RoundRectClipShape(int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                                  int arcw, int arch, int corners) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
            setRoundedRect(x, y, w, h, arcw, arch, corners);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
        public void setRoundedRect(int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
                                   int arcw, int arch, int corners) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
            this.corners = corners;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
            this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
            this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
            this.width = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
            this.height = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
            this.arcwidth = arcw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
            this.archeight = arch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
        public double getX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
            return (double)x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
        public double getY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
            return (double)y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
        public double getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
            return (double)width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
        public double getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
            return (double)height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
        public double getArcWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
            return (double)arcwidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
        public double getArcHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
            return (double)archeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
        public boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
            return false;  // Not called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
        public Rectangle2D getBounds2D() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
            return null;  // Not called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
        public int getCornerFlags() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
            return corners;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
        public void setFrame(double x, double y, double w, double h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
            // Not called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
        public boolean contains(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
            return false;  // Not called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
        private int classify(double coord, double left, double right, double arcsize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
            return 0;  // Not called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
        public boolean intersects(double x, double y, double w, double h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
            return false;  // Not called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
        public boolean contains(double x, double y, double w, double h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
            return false;  // Not called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
        public PathIterator getPathIterator(AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
            return new RoundishRectIterator(this, at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
        static class RoundishRectIterator implements PathIterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
            double x, y, w, h, aw, ah;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
            AffineTransform affine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
            int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
  2031
            double[][] ctrlpts;
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
  2032
            int[] types;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
            private static final double angle = Math.PI / 4.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
            private static final double a = 1.0 - Math.cos(angle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
            private static final double b = Math.tan(angle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
            private static final double c = Math.sqrt(1.0 + b * b) - 1 + a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
            private static final double cv = 4.0 / 3.0 * a * b / c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
            private static final double acv = (1.0 - cv) / 2.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
            // For each array:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
            //     4 values for each point {v0, v1, v2, v3}:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
            //         point = (x + v0 * w + v1 * arcWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
            //                  y + v2 * h + v3 * arcHeight);
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
  2045
            private static final double[][] CtrlPtTemplate = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
                {  0.0,  0.0,  1.0,  0.0 },     /* BOTTOM LEFT corner */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
                {  0.0,  0.0,  1.0, -0.5 },     /* BOTTOM LEFT arc start */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
                {  0.0,  0.0,  1.0, -acv,       /* BOTTOM LEFT arc curve */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
                   0.0,  acv,  1.0,  0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
                   0.0,  0.5,  1.0,  0.0 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
                {  1.0,  0.0,  1.0,  0.0 },     /* BOTTOM RIGHT corner */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
                {  1.0, -0.5,  1.0,  0.0 },     /* BOTTOM RIGHT arc start */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
                {  1.0, -acv,  1.0,  0.0,       /* BOTTOM RIGHT arc curve */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
                   1.0,  0.0,  1.0, -acv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
                   1.0,  0.0,  1.0, -0.5 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
                {  1.0,  0.0,  0.0,  0.0 },     /* TOP RIGHT corner */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
                {  1.0,  0.0,  0.0,  0.5 },     /* TOP RIGHT arc start */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
                {  1.0,  0.0,  0.0,  acv,       /* TOP RIGHT arc curve */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
                   1.0, -acv,  0.0,  0.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
                   1.0, -0.5,  0.0,  0.0 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
                {  0.0,  0.0,  0.0,  0.0 },     /* TOP LEFT corner */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
                {  0.0,  0.5,  0.0,  0.0 },     /* TOP LEFT arc start */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
                {  0.0,  acv,  0.0,  0.0,       /* TOP LEFT arc curve */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
                   0.0,  0.0,  0.0,  acv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
                   0.0,  0.0,  0.0,  0.5 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
                {},                             /* Closing path element */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
            };
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
  2068
            private static final int[] CornerFlags = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                RoundRectClipShape.BOTTOM_LEFT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
                RoundRectClipShape.BOTTOM_RIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
                RoundRectClipShape.TOP_RIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
                RoundRectClipShape.TOP_LEFT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
            RoundishRectIterator(RoundRectClipShape rr, AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
                this.x = rr.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
                this.y = rr.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
                this.w = rr.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
                this.h = rr.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
                this.aw = Math.min(w, Math.abs(rr.getArcWidth()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
                this.ah = Math.min(h, Math.abs(rr.getArcHeight()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
                this.affine = at;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
                if (w < 0 || h < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
                    // Don't draw anything...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
                    ctrlpts = new double[0][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
                    types = new int[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
                    int corners = rr.getCornerFlags();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
                    int numedges = 5;  // 4xCORNER_POINT, CLOSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
                    for (int i = 1; i < 0x10; i <<= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
                        // Add one for each corner that has a curve
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
                        if ((corners & i) != 0) numedges++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                    ctrlpts = new double[numedges][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                    types = new int[numedges];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
                    int j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                    for (int i = 0; i < 4; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
                        types[j] = SEG_LINETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
                        if ((corners & CornerFlags[i]) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
                            ctrlpts[j++] = CtrlPtTemplate[i*3+0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
                            ctrlpts[j++] = CtrlPtTemplate[i*3+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
                            types[j] = SEG_CUBICTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
                            ctrlpts[j++] = CtrlPtTemplate[i*3+2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
                    types[j] = SEG_CLOSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
                    ctrlpts[j++] = CtrlPtTemplate[12];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
                    types[0] = SEG_MOVETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
            public int getWindingRule() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
                return WIND_NON_ZERO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
            public boolean isDone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
                return index >= ctrlpts.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
            public void next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
                index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
            public int currentSegment(float[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
                if (isDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
                    throw new NoSuchElementException("roundrect iterator out of bounds");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
                }
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
  2129
                double[] ctrls = ctrlpts[index];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
                int nc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
                for (int i = 0; i < ctrls.length; i += 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
                    coords[nc++] = (float) (x + ctrls[i + 0] * w + ctrls[i + 1] * aw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
                    coords[nc++] = (float) (y + ctrls[i + 2] * h + ctrls[i + 3] * ah);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
                if (affine != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
                    affine.transform(coords, 0, coords, 0, nc / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
                return types[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
            public int currentSegment(double[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
                if (isDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
                    throw new NoSuchElementException("roundrect iterator out of bounds");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
                }
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
  2145
                double[] ctrls = ctrlpts[index];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
                int nc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
                for (int i = 0; i < ctrls.length; i += 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
                    coords[nc++] = x + ctrls[i + 0] * w + ctrls[i + 1] * aw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
                    coords[nc++] = y + ctrls[i + 2] * h + ctrls[i + 3] * ah;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
                if (affine != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
                    affine.transform(coords, 0, coords, 0, nc / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
                return types[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
}