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