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