jdk/src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java
author darcy
Mon, 10 Mar 2014 13:54:25 -0700
changeset 23632 cd7a34d12e8c
parent 23010 6dadb192ad81
permissions -rw-r--r--
8033908: Fix serial lint warnings in com.sun.java.swing.plaf Reviewed-by: serb, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4394
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package com.sun.java.swing.plaf.gtk;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import sun.awt.UNIXToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.plaf.synth.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.java.swing.plaf.gtk.GTKConstants.ArrowType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.java.swing.plaf.gtk.GTKConstants.ExpanderStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.java.swing.plaf.gtk.GTKConstants.Orientation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.java.swing.plaf.gtk.GTKConstants.PositionType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.java.swing.plaf.gtk.GTKConstants.ShadowType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author Joshua Outwater
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
// Need to support:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
// default_outside_border: Insets when default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
// interior_focus: Indicates if focus should appear inside border, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
//                       outside border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
// focus-line-width: Integer giving size of focus border
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
// focus-padding: Integer giving padding between border and focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
//        indicator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
// focus-line-pattern:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
class GTKPainter extends SynthPainter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static final PositionType[] POSITIONS = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        PositionType.BOTTOM, PositionType.RIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        PositionType.TOP, PositionType.LEFT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static final ShadowType SHADOWS[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        ShadowType.NONE, ShadowType.IN, ShadowType.OUT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        ShadowType.ETCHED_IN, ShadowType.OUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private final static GTKEngine ENGINE = GTKEngine.INSTANCE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    final static GTKPainter INSTANCE = new GTKPainter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private GTKPainter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private String getName(SynthContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        return (context.getRegion().isSubregion()) ? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
               context.getComponent().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public void paintCheckBoxBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        paintRadioButtonBackground(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public void paintCheckBoxMenuItemBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        paintRadioButtonMenuItemBackground(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    // FORMATTED_TEXT_FIELD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public void paintFormattedTextFieldBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                          Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                          int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        paintTextBackground(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    // TOOL_BAR_DRAG_WINDOW
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public void paintToolBarDragWindowBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                                     Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                     int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        paintToolBarBackground(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    // TOOL_BAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public void paintToolBarBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                     Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                     int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        int state = context.getComponentState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        int orientation = ((JToolBar)context.getComponent()).getOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            if (! ENGINE.paintCachedImage(g, x, y, w, h, id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                          state, orientation))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                ENGINE.startPainting(g, x, y, w, h, id, state, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                ENGINE.paintBox(g, context, id, gtkState, ShadowType.OUT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                "handlebox_bin", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public void paintToolBarContentBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                              Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                              int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        int orientation = ((JToolBar)context.getComponent()).getOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            if (! ENGINE.paintCachedImage(g, x, y, w, h, id, orientation)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                ENGINE.startPainting(g, x, y, w, h, id, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                ENGINE.paintBox(g, context, id, SynthConstants.ENABLED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                ShadowType.OUT, "toolbar", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    // PASSWORD_FIELD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public void paintPasswordFieldBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                     Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                     int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        paintTextBackground(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    // TEXT_FIELD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public void paintTextFieldBackground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                         int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if (getName(context) == "Tree.cellEditor") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            paintTreeCellEditorBackground(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            paintTextBackground(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    // RADIO_BUTTON
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    // NOTE: this is called for JCheckBox too
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public void paintRadioButtonBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                                     Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                                     int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        int gtkState = GTKLookAndFeel.synthStateToGTKState(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                id, context.getComponentState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (gtkState == SynthConstants.MOUSE_OVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    ENGINE.startPainting(g, x, y, w, h, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    ENGINE.paintFlatBox(g, context, id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                            SynthConstants.MOUSE_OVER, ShadowType.ETCHED_OUT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                            "checkbutton", x, y, w, h, ColorType.BACKGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    // RADIO_BUTTON_MENU_ITEM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    // NOTE: this is called for JCheckBoxMenuItem too
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public void paintRadioButtonMenuItemBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                                     Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                     int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        int gtkState = GTKLookAndFeel.synthStateToGTKState(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                id, context.getComponentState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (gtkState == SynthConstants.MOUSE_OVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    ShadowType shadow = (GTKLookAndFeel.is2_2() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                        ShadowType.NONE : ShadowType.OUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    ENGINE.startPainting(g, x, y, w, h, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                    ENGINE.paintBox(g, context, id, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                            shadow, "menuitem", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    // LABEL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public void paintLabelBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                                     Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                                     int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        String name = getName(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        JComponent c = context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        Container  container = c.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (name == "TableHeader.renderer" ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            name == "GTKFileChooser.directoryListLabel" ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            name == "GTKFileChooser.fileListLabel") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            paintButtonBackgroundImpl(context, g, Region.BUTTON, "button",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    x, y, w, h, true, false, false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
         * If the label is a ListCellRenderer and it's in a container
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
         * (CellRendererPane) which is in a JComboBox then we paint the label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
         * as a TextField like a gtk_entry for a combobox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        else if (c instanceof ListCellRenderer &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                 container != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                 container.getParent() instanceof JComboBox ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            paintTextBackground(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    // INTERNAL_FRAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public void paintInternalFrameBorder(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                                      Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                      int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        Metacity.INSTANCE.paintFrameBorder(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    // DESKTOP_PANE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public void paintDesktopPaneBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                                           Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                           int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        // Does not call into ENGINE for better performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        fillArea(context, g, x, y, w, h, ColorType.BACKGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    // DESKTOP_ICON
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public void paintDesktopIconBorder(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                                           Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                                           int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        Metacity.INSTANCE.paintFrameBorder(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public void paintButtonBackground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                                      int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        String name = getName(context);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (name != null && name.startsWith("InternalFrameTitlePane.")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            Metacity.INSTANCE.paintButtonBackground(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            AbstractButton button = (AbstractButton)context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            boolean paintBG = button.isContentAreaFilled() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                              button.isBorderPainted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            boolean paintFocus = button.isFocusPainted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            boolean defaultCapable = (button instanceof JButton) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    ((JButton)button).isDefaultCapable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            boolean toolButton = (button.getParent() instanceof JToolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            paintButtonBackgroundImpl(context, g, Region.BUTTON, "button",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                    x, y, w, h, paintBG, paintFocus, defaultCapable, toolButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    private void paintButtonBackgroundImpl(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            Region id, String detail, int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            boolean paintBackground, boolean paintFocus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            boolean defaultCapable, boolean toolButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        int state = context.getComponentState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if (ENGINE.paintCachedImage(g, x, y, w, h, id, state, detail,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    paintBackground, paintFocus, defaultCapable, toolButton)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            ENGINE.startPainting(g, x, y, w, h, id, state, detail,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                paintBackground, paintFocus, defaultCapable, toolButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            // Paint the default indicator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            GTKStyle style = (GTKStyle)context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            if (defaultCapable && !toolButton) {
1837
efd004b550b7 6771030: Code improvement and warnings removing from the com.sun.java.swing.plaf.gtk package
rupashka
parents: 2
diff changeset
   301
                Insets defaultInsets = style.getClassSpecificInsetsValue(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                        context, "default-border",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                        GTKStyle.BUTTON_DEFAULT_BORDER_INSETS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                if (paintBackground && (state & SynthConstants.DEFAULT) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    ENGINE.paintBox(g, context, id, SynthConstants.ENABLED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                            ShadowType.IN, "buttondefault", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                x += defaultInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                y += defaultInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                w -= (defaultInsets.left + defaultInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                h -= (defaultInsets.top + defaultInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            boolean interiorFocus = style.getClassSpecificBoolValue(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    context, "interior-focus", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            int focusSize = style.getClassSpecificIntValue(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    context, "focus-line-width",1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            int focusPad = style.getClassSpecificIntValue(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                    context, "focus-padding", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            int totalFocusSize = focusSize + focusPad;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            int xThickness = style.getXThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            int yThickness = style.getYThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            // Render the box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            if (!interiorFocus &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                    (state & SynthConstants.FOCUSED) == SynthConstants.FOCUSED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                x += totalFocusSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                y += totalFocusSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                w -= 2 * totalFocusSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                h -= 2 * totalFocusSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            boolean paintBg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            if (toolButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                // Toolbar buttons should only have their background painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                // in the PRESSED, SELECTED, or MOUSE_OVER states.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                paintBg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                    (gtkState != SynthConstants.ENABLED) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    (gtkState != SynthConstants.DISABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                // Otherwise, always paint the button's background, unless
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                // the user has overridden it and we're in the ENABLED state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                paintBg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    paintBackground ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    (gtkState != SynthConstants.ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            if (paintBg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                ShadowType shadowType = ShadowType.OUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                if ((state & (SynthConstants.PRESSED |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                              SynthConstants.SELECTED)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    shadowType = ShadowType.IN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                ENGINE.paintBox(g, context, id, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                        shadowType, detail, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            // focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            if (paintFocus && (state & SynthConstants.FOCUSED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                if (interiorFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    x += xThickness + focusPad;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                    y += yThickness + focusPad;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    w -= 2 * (xThickness + focusPad);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    h -= 2 * (yThickness + focusPad);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    x -= totalFocusSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    y -= totalFocusSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    w += 2 * totalFocusSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                    h += 2 * totalFocusSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                ENGINE.paintFocus(g, context, id, gtkState, detail, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    // ARROW_BUTTON
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    public void paintArrowButtonForeground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                                           int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                                           int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        Component c = context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        String name = c.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        ArrowType arrowType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        switch (direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            case SwingConstants.NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                arrowType = ArrowType.UP; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            case SwingConstants.SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                arrowType = ArrowType.DOWN; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            case SwingConstants.EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                arrowType = ArrowType.RIGHT; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            case SwingConstants.WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                arrowType = ArrowType.LEFT; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        String detail = "arrow";
6500
129126795742 6915566: Closed swing tests failing with assert errors when run with -ea -esa
malenkov
parents: 5951
diff changeset
   402
        if ((name == "ScrollBar.button") || (name == "TabbedPane.button")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            if (arrowType == ArrowType.UP || arrowType == ArrowType.DOWN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                detail = "vscrollbar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                detail = "hscrollbar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        } else if (name == "Spinner.nextButton" ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                   name == "Spinner.previousButton") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            detail = "spinbutton";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        } else if (name != "ComboBox.arrowButton") {
6500
129126795742 6915566: Closed swing tests failing with assert errors when run with -ea -esa
malenkov
parents: 5951
diff changeset
   412
            assert false : "unexpected name: " + name;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        int gtkState = GTKLookAndFeel.synthStateToGTKState(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                id, context.getComponentState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        ShadowType shadowType = (gtkState == SynthConstants.PRESSED ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            ShadowType.IN : ShadowType.OUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            if (ENGINE.paintCachedImage(g, x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    gtkState, name, direction)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            ENGINE.startPainting(g, x, y, w, h, gtkState, name, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            ENGINE.paintArrow(g, context, id, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    shadowType, arrowType, detail, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public void paintArrowButtonBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        AbstractButton button = (AbstractButton)context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        String name = button.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        String detail = "button";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        int direction = SwingConstants.CENTER;
6500
129126795742 6915566: Closed swing tests failing with assert errors when run with -ea -esa
malenkov
parents: 5951
diff changeset
   439
        if ((name == "ScrollBar.button") || (name == "TabbedPane.button")) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            Integer prop = (Integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                button.getClientProperty("__arrow_direction__");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            direction = (prop != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                prop.intValue() : SwingConstants.WEST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            switch (direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            case SwingConstants.EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            case SwingConstants.WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                detail = "hscrollbar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            case SwingConstants.NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            case SwingConstants.SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                detail = "vscrollbar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        } else if (name == "Spinner.previousButton") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            detail = "spinbutton_down";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        } else if (name == "Spinner.nextButton") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            detail = "spinbutton_up";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        } else if (name != "ComboBox.arrowButton") {
6500
129126795742 6915566: Closed swing tests failing with assert errors when run with -ea -esa
malenkov
parents: 5951
diff changeset
   460
            assert false : "unexpected name: " + name;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        int state = context.getComponentState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            if (ENGINE.paintCachedImage(g, x, y, w, h, id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                                        state, detail, direction))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            ENGINE.startPainting(g, x, y, w, h, id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                                 state, detail, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            if (detail.startsWith("spin")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                 * The ubuntulooks engine (and presumably others) expect us to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                 * first draw the full "spinbutton" background, and then draw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                 * the individual "spinbutton_up/down" buttons on top of that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                 * Note that it is the state of the JSpinner (not its arrow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                 * button) that determines how we draw this background.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                int spinState = button.getParent().isEnabled() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    SynthConstants.ENABLED : SynthConstants.DISABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                int mody = (detail == "spinbutton_up") ? y : y-h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                int modh = h*2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                ENGINE.paintBox(g, context, id, spinState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                                ShadowType.IN, "spinbutton",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                                x, mody, w, modh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            ShadowType shadowType = ShadowType.OUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            if ((gtkState & (SynthConstants.PRESSED |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                             SynthConstants.SELECTED)) != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                shadowType = ShadowType.IN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            ENGINE.paintBox(g, context, id, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                            shadowType, detail,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                            x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    // LIST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    public void paintListBackground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                                    int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        // Does not call into ENGINE for better performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        fillArea(context, g, x, y, w, h, GTKColorType.TEXT_BACKGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    public void paintMenuBarBackground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                                       int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            if (ENGINE.paintCachedImage(g, x, y, w, h, id)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            GTKStyle style = (GTKStyle)context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            int shadow = style.getClassSpecificIntValue(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                    context, "shadow-type", 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            ShadowType shadowType = SHADOWS[shadow];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            int gtkState = GTKLookAndFeel.synthStateToGTKState(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    id, context.getComponentState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            ENGINE.startPainting(g, x, y, w, h, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            ENGINE.paintBox(g, context, id, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                shadowType, "menubar", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    // MENU
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public void paintMenuBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                                     Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                                     int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        paintMenuItemBackground(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    // This is called for both MENU and MENU_ITEM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public void paintMenuItemBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                                     Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                                     int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        int gtkState = GTKLookAndFeel.synthStateToGTKState(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                context.getRegion(), context.getComponentState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        if (gtkState == SynthConstants.MOUSE_OVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            Region id = Region.MENU_ITEM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                    ShadowType shadow = (GTKLookAndFeel.is2_2() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                        ShadowType.NONE : ShadowType.OUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    ENGINE.startPainting(g, x, y, w, h, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                    ENGINE.paintBox(g, context, id, gtkState, shadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                            "menuitem", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                    ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                }
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
    public void paintPopupMenuBackground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                                        int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        int gtkState = GTKLookAndFeel.synthStateToGTKState(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                id, context.getComponentState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            if (ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            ENGINE.startPainting(g, x, y, w, h, id, gtkState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            ENGINE.paintBox(g, context, id, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                    ShadowType.OUT, "menu", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            GTKStyle style = (GTKStyle)context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            int xThickness = style.getXThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            int yThickness = style.getYThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            ENGINE.paintBackground(g, context, id, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                    style.getGTKColor(context, gtkState, GTKColorType.BACKGROUND),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                    x + xThickness, y + yThickness,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                    w - xThickness - xThickness, h - yThickness - yThickness);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    public void paintProgressBarBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                                            Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                                            int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                ENGINE.startPainting(g, x, y, w, h, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                ENGINE.paintBox(g, context, id, SynthConstants.ENABLED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                        ShadowType.IN, "trough", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    public void paintProgressBarForeground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                                            int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                                            int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            // Note that we don't call paintCachedImage() here.  Since the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            // progress bar foreground is painted differently for each value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            // it would be wasteful to try to cache an image for each state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            // so instead we simply avoid caching in this case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            if (w <= 0 || h <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            ENGINE.startPainting(g, x, y, w, h, id, "fg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            ENGINE.paintBox(g, context, id, SynthConstants.MOUSE_OVER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                            ShadowType.OUT, "bar", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            ENGINE.finishPainting(false); // don't bother caching the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    public void paintViewportBorder(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                                           int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                ENGINE.startPainting(g, x, y, w, h, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                ENGINE.paintShadow(g, context, id, SynthConstants.ENABLED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                        ShadowType.IN, "scrolled_window", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    public void paintSeparatorBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                                          Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                                          int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                                         int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        int state = context.getComponentState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        JComponent c = context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
         * Note: In theory, the style's x/y thickness values would determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
         * the width of the separator content.  In practice, however, some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
         * engines will render a line that is wider than the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
         * thickness value.  For example, ubuntulooks reports x/y thickness
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
         * values of 1 for separators, but always renders a 2-pixel wide line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
         * As a result of all this, we need to be careful not to restrict
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
         * the w/h values below too much, so that the full thickness of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
         * rendered line will be captured by our image caching code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        String detail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        if (c instanceof JToolBar.Separator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
             * GTK renders toolbar separators differently in that an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
             * artificial padding is added to each end of the separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
             * The value of 0.2f below is derived from the source code of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
             * gtktoolbar.c in the current version of GTK+ (2.8.20 at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
             * time of this writing).  Specifically, the relevant values are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
             *     SPACE_LINE_DIVISION 10.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
             *     SPACE_LINE_START     2.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
             *     SPACE_LINE_END       8.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
             * These are used to determine the distance from the top (or left)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
             * edge of the toolbar to the other edge.  So for example, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
             * starting/top point of a vertical separator is 2/10 of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
             * height of a horizontal toolbar away from the top edge, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
             * is how we arrive at 0.2f below.  Likewise, the ending/bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
             * point is 8/10 of the height away from the top edge, or in other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
             * words, it is 2/10 away from the bottom edge, which is again
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
             * how we arrive at the 0.2f value below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
             * The separator is also centered horizontally or vertically,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
             * depending on its orientation.  This was determined empirically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
             * and by examining the code referenced above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            detail = "toolbar";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            float pct = 0.2f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            JToolBar.Separator sep = (JToolBar.Separator)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            Dimension size = sep.getSeparatorSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            GTKStyle style = (GTKStyle)context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            if (orientation == JSeparator.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                x += (int)(w * pct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                w -= (int)(w * pct * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                y += (size.height - style.getYThickness()) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                y += (int)(h * pct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                h -= (int)(h * pct * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                x += (size.width - style.getXThickness()) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            // For regular/menu separators, we simply subtract out the insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            detail = "separator";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            Insets insets = c.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            x += insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            y += insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            if (orientation == JSeparator.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                w -= (insets.left + insets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                h -= (insets.top + insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            if (! ENGINE.paintCachedImage(g, x, y, w, h, id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                                          state, detail, orientation)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                ENGINE.startPainting(g, x, y, w, h, id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                                     state, detail, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                if (orientation == JSeparator.HORIZONTAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                    ENGINE.paintHline(g, context, id, state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                                      detail, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                    ENGINE.paintVline(g, context, id, state,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                                      detail, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    public void paintSliderTrackBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                                       Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                                       int x, int y, int w,int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        int state = context.getComponentState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        // For focused sliders, we paint focus rect outside the bounds passed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        // Need to adjust for that.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        boolean focused = ((state & SynthConstants.FOCUSED) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        int focusSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        if (focused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            GTKStyle style = (GTKStyle)context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            focusSize = style.getClassSpecificIntValue(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                                context, "focus-line-width", 1) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                        style.getClassSpecificIntValue(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                                context, "focus-padding", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            x -= focusSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            y -= focusSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            w += focusSize * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            h += focusSize * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        // The ubuntulooks engine paints slider troughs differently depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        // on the current slider value and its component orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        JSlider slider = (JSlider)context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        double value = slider.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        double min = slider.getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        double max = slider.getMaximum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        double visible = 20; // not used for sliders; any value will work
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            // Note that we don't call paintCachedImage() here.  Since some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            // engines (e.g. ubuntulooks) paint the slider background
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            // differently for any given slider value, it would be wasteful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            // to try to cache an image for each state, so instead we simply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            // avoid caching in this case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            if (w <= 0 || h <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            ENGINE.startPainting(g, x, y, w, h, id, state, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            ENGINE.setRangeValue(context, id, value, min, max, visible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            ENGINE.paintBox(g, context, id, gtkState, ShadowType.IN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                            "trough", x + focusSize, y + focusSize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                            w - 2 * focusSize, h - 2 * focusSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            if (focused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                ENGINE.paintFocus(g, context, id, SynthConstants.ENABLED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                                  "trough", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            ENGINE.finishPainting(false); // don't bother caching the image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    public void paintSliderThumbBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            Graphics g, int x, int y, int w, int h, int dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        int gtkState = GTKLookAndFeel.synthStateToGTKState(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                id, context.getComponentState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState, dir)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                Orientation orientation = (dir == JSlider.HORIZONTAL ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                    Orientation.HORIZONTAL : Orientation.VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                String detail = (dir == JSlider.HORIZONTAL ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                    "hscale" : "vscale");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                ENGINE.startPainting(g, x, y, w, h, id, gtkState, dir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                ENGINE.paintSlider(g, context, id, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                        ShadowType.OUT, detail, x, y, w, h, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    // SPINNER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    public void paintSpinnerBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                                        Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                                        int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        // This is handled in paintTextFieldBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    // SPLIT_PANE_DIVIDER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    public void paintSplitPaneDividerBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                                       Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                                       int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        int gtkState = GTKLookAndFeel.synthStateToGTKState(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                id, context.getComponentState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        JSplitPane splitPane = (JSplitPane)context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        Orientation orientation =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                (splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                    Orientation.VERTICAL : Orientation.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            if (! ENGINE.paintCachedImage(g, x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                    id, gtkState, orientation)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                ENGINE.startPainting(g, x, y, w, h, id, gtkState, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                ENGINE.paintHandle(g, context, id, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                        ShadowType.OUT, "paned", x, y, w, h, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    public void paintSplitPaneDragDivider(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                                       Graphics g,int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                                       int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        paintSplitPaneDividerForeground(context, g, x, y, w, h, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    public void paintTabbedPaneContentBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                                      Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        JTabbedPane pane = (JTabbedPane)context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        int selectedIndex = pane.getSelectedIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        PositionType placement = GTKLookAndFeel.SwingOrientationConstantToGTK(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                                                        pane.getTabPlacement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        int gapStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        int gapSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        if (selectedIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            Rectangle tabBounds = pane.getBoundsAt(selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            if (placement == PositionType.TOP ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                placement == PositionType.BOTTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                gapStart = tabBounds.x - x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                gapSize = tabBounds.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                gapStart = tabBounds.y - y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                gapSize = tabBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        int gtkState = GTKLookAndFeel.synthStateToGTKState(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                id, context.getComponentState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            if (! ENGINE.paintCachedImage(g, x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                    id, gtkState, placement, gapStart, gapSize)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                ENGINE.startPainting(g, x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                        id, gtkState, placement, gapStart, gapSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                ENGINE.paintBoxGap(g, context, id, gtkState, ShadowType.OUT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                        "notebook", x, y, w, h, placement, gapStart, gapSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    public void paintTabbedPaneTabBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                                           Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                                           int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                                           int tabIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        int state = context.getComponentState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        int gtkState = ((state & SynthConstants.SELECTED) != 0 ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            SynthConstants.ENABLED : SynthConstants.PRESSED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        JTabbedPane pane = (JTabbedPane)context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        int placement = pane.getTabPlacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            if (! ENGINE.paintCachedImage(g, x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
                    id, gtkState, placement, tabIndex)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                PositionType side = POSITIONS[placement - 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                ENGINE.startPainting(g, x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                        id, gtkState, placement, tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                ENGINE.paintExtension(g, context, id, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                        ShadowType.OUT, "tab", x, y, w, h, side, tabIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        }
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
    // TEXT_PANE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    public void paintTextPaneBackground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                                        int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        paintTextAreaBackground(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    // EDITOR_PANE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    public void paintEditorPaneBackground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                                          int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        paintTextAreaBackground(context, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    // TEXT_AREA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    public void paintTextAreaBackground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                                        int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        // Does not call into ENGINE for better performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        fillArea(context, g, x, y, w, h, GTKColorType.TEXT_BACKGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    // TEXT_FIELD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
    // NOTE: Combobox and Label, Password and FormattedTextField calls this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    // too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    private void paintTextBackground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                                     int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        // Text is odd in that it uses the TEXT_BACKGROUND vs BACKGROUND.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        JComponent c = context.getComponent();
13001
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   929
        Container container = c.getParent();
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   930
        Container containerParent = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        GTKStyle style = (GTKStyle)context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        int state = context.getComponentState();
13001
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   934
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   935
        if (c instanceof ListCellRenderer && container != null) {
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   936
            containerParent = container.getParent();
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   937
            if (containerParent instanceof JComboBox
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   938
                    && containerParent.hasFocus()) {
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   939
                state |= SynthConstants.FOCUSED;
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   940
            }
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   941
        }
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   942
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            if (ENGINE.paintCachedImage(g, x, y, w, h, id, state)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            int focusSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            boolean interiorFocus = style.getClassSpecificBoolValue(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                    context, "interior-focus", true);
13001
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   952
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   953
            focusSize = style.getClassSpecificIntValue(context,
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   954
                    "focus-line-width",1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            if (!interiorFocus && (state & SynthConstants.FOCUSED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                x += focusSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                y += focusSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                w -= 2 * focusSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                h -= 2 * focusSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            int xThickness = style.getXThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            int yThickness = style.getYThickness();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            ENGINE.startPainting(g, x, y, w, h, id, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            ENGINE.paintShadow(g, context, id, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                               ShadowType.IN, "entry", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            ENGINE.paintFlatBox(g, context, id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                                gtkState, ShadowType.NONE, "entry_bg",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                                x + xThickness,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                                y + yThickness,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                                w - (2 * xThickness),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                                h - (2 * yThickness),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                                ColorType.TEXT_BACKGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
13001
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   976
            if (focusSize > 0 && (state & SynthConstants.FOCUSED) != 0) {
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   977
                if (!interiorFocus) {
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   978
                    x -=  focusSize;
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   979
                    y -=  focusSize;
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   980
                    w +=  2 * focusSize;
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   981
                    h +=  2 * focusSize;
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   982
                } else {
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   983
                    if (containerParent instanceof JComboBox) {
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   984
                        x += (focusSize + 2);
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   985
                        y += (focusSize + 1);
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   986
                        w -= (2 * focusSize + 1);
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   987
                        h -= (2 * focusSize + 2);
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   988
                    } else {
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   989
                        x += focusSize;
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   990
                        y += focusSize;
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   991
                        w -= 2 * focusSize;
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   992
                        h -= 2 * focusSize;
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   993
                    }
afa8e122dcce 7155887: ComboBox does not display focus outline in GTK L&F
luchsh
parents: 6500
diff changeset
   994
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                ENGINE.paintFocus(g, context, id, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                        "entry", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    private void paintTreeCellEditorBackground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                                               int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        int gtkState = GTKLookAndFeel.synthStateToGTKState(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                id, context.getComponentState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                ENGINE.startPainting(g, x, y, w, h, id, gtkState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                ENGINE.paintFlatBox(g, context, id, gtkState, ShadowType.NONE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                        "entry_bg", x, y, w, h, ColorType.TEXT_BACKGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    }
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
    // ROOT_PANE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    public void paintRootPaneBackground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                                        int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        // Does not call into ENGINE for better performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        fillArea(context, g, x, y, w, h, GTKColorType.BACKGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    // TOGGLE_BUTTON
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    public void paintToggleButtonBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                                            Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                                            int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        JToggleButton toggleButton = (JToggleButton)context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        boolean paintBG = toggleButton.isContentAreaFilled() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                          toggleButton.isBorderPainted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        boolean paintFocus = toggleButton.isFocusPainted();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        boolean toolButton = (toggleButton.getParent() instanceof JToolBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        paintButtonBackgroundImpl(context, g, id, "button",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                                  x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                                  paintBG, paintFocus, false, toolButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    // SCROLL_BAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    public void paintScrollBarBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                                          Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                                          int x, int y, int w,int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        boolean focused =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                (context.getComponentState() & SynthConstants.FOCUSED) != 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            if (ENGINE.paintCachedImage(g, x, y, w, h, id, focused)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            ENGINE.startPainting(g, x, y, w, h, id, focused);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            // Note: the scrollbar insets already include the "trough-border",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            // which is needed to position the scrollbar buttons properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            // But when we render, we need to take the trough border out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            // of the equation so that we paint the entire area covered by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            // the trough border and the scrollbar content itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            Insets insets = context.getComponent().getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            GTKStyle style = (GTKStyle)context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            int troughBorder =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                style.getClassSpecificIntValue(context, "trough-border", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            insets.left   -= troughBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            insets.right  -= troughBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            insets.top    -= troughBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            insets.bottom -= troughBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            ENGINE.paintBox(g, context, id, SynthConstants.PRESSED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                            ShadowType.IN, "trough",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                            x + insets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                            y + insets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                            w - insets.left - insets.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                            h - insets.top - insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            if (focused) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                ENGINE.paintFocus(g, context, id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                        SynthConstants.ENABLED, "trough", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    // SCROLL_BAR_THUMB
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    public void paintScrollBarThumbBackground(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            Graphics g, int x, int y, int w, int h, int dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        int gtkState = GTKLookAndFeel.synthStateToGTKState(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                id, context.getComponentState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        // The clearlooks engine paints scrollbar thumbs differently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        // depending on the current scroll value (specifically, it will avoid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        // rendering a certain line when the thumb is at the starting or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        // ending position).  Therefore, we normalize the current value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        // the range [0,100] here and then pass it down to setRangeValue()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        // so that the native widget is configured appropriately.  Note that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        // there are really only four values that matter (min, middle, max,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        // or fill) so we restrict to one of those four values to avoid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        // blowing out the image cache.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        JScrollBar sb = (JScrollBar)context.getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        boolean rtl =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            sb.getOrientation() == JScrollBar.HORIZONTAL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            !sb.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        double min = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        double max = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        double visible = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        double value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        if (sb.getMaximum() - sb.getMinimum() == sb.getVisibleAmount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            // In this case, the thumb fills the entire track, so it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            // touching both ends at the same time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            value = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            visible = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        } else if (sb.getValue() == sb.getMinimum()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            // At minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            value = rtl ? 100 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        } else if (sb.getValue() >= sb.getMaximum() - sb.getVisibleAmount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            // At maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            value = rtl ? 0 : 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            // Somewhere in between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            value = 50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                                          dir, value, visible, rtl))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                ENGINE.startPainting(g, x, y, w, h, id, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                                     dir, value, visible, rtl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                Orientation orientation = (dir == JScrollBar.HORIZONTAL ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                    Orientation.HORIZONTAL : Orientation.VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                ENGINE.setRangeValue(context, id, value, min, max, visible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                ENGINE.paintSlider(g, context, id, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                        ShadowType.OUT, "slider", x, y, w, h, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    // TOOL_TIP
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    public void paintToolTipBackground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                                        int x, int y, int w,int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                ENGINE.startPainting(g, x, y, w, h, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                ENGINE.paintFlatBox(g, context, id, SynthConstants.ENABLED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                        ShadowType.OUT, "tooltip", x, y, w, h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                        ColorType.BACKGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    // TREE_CELL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    public void paintTreeCellBackground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                                        int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        int state = context.getComponentState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            if (! ENGINE.paintCachedImage(g, x, y, w, h, id, state)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                ENGINE.startPainting(g, x, y, w, h, id, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                // the string arg should alternate based on row being painted,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                // but we currently don't pass that in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                ENGINE.paintFlatBox(g, context, id, gtkState, ShadowType.NONE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                        "cell_odd", x, y, w, h, ColorType.TEXT_BACKGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
    public void paintTreeCellFocus(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                                    int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        Region id = Region.TREE_CELL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        int state = context.getComponentState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        paintFocus(context, g, id, state, "treeview", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
    // TREE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    public void paintTreeBackground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                                    int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        // As far as I can tell, these don't call into the ENGINE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        fillArea(context, g, x, y, w, h, GTKColorType.TEXT_BACKGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    // VIEWPORT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
    public void paintViewportBackground(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                                        int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        // As far as I can tell, these don't call into the ENGINE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        // Also note that you don't want this to call into the ENGINE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        // as if it where to paint a background JViewport wouldn't scroll
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        // correctly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        fillArea(context, g, x, y, w, h, GTKColorType.TEXT_BACKGROUND);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    void paintFocus(SynthContext context, Graphics g, Region id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            int state, String detail, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            if (! ENGINE.paintCachedImage(g, x, y, w, h, id, gtkState, "focus")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                ENGINE.startPainting(g, x, y, w, h, id, gtkState, "focus");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                ENGINE.paintFocus(g, context, id, gtkState, detail, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    void paintMetacityElement(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            int gtkState, String detail, int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            ShadowType shadow, ArrowType direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            if (! ENGINE.paintCachedImage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                    g, x, y, w, h, gtkState, detail, shadow, direction)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                ENGINE.startPainting(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                        g, x, y, w, h, gtkState, detail, shadow, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                if (detail == "metacity-arrow") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                    ENGINE.paintArrow(g, context, Region.INTERNAL_FRAME_TITLE_PANE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                            gtkState, shadow, direction, "", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                } else if (detail == "metacity-box") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                    ENGINE.paintBox(g, context, Region.INTERNAL_FRAME_TITLE_PANE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                            gtkState, shadow, "", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                } else if (detail == "metacity-vline") {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                    ENGINE.paintVline(g, context, Region.INTERNAL_FRAME_TITLE_PANE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                            gtkState, "", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    void paintIcon(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            Method paintMethod, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        int state = context.getComponentState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            if (! ENGINE.paintCachedImage(g, x, y, w, h, state, paintMethod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                ENGINE.startPainting(g, x, y, w, h, state, paintMethod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                    paintMethod.invoke(this, context, g, state, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                } catch (IllegalAccessException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                    assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                } catch (InvocationTargetException ite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                    assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    void paintIcon(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            Method paintMethod, int x, int y, int w, int h, Object direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        int state = context.getComponentState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
            if (! ENGINE.paintCachedImage(g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                    x, y, w, h, state, paintMethod, direction)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                ENGINE.startPainting(g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                        x, y, w, h, state, paintMethod, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                    paintMethod.invoke(this, context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                            g, state, x, y, w, h, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                } catch (IllegalAccessException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                    assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                } catch (InvocationTargetException ite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                    assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    // All icon painting methods are called from under GTK_LOCK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
    public void paintTreeExpandedIcon(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
            Graphics g, int state, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        ENGINE.paintExpander(g, context, Region.TREE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                GTKLookAndFeel.synthStateToGTKState(context.getRegion(), state),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                ExpanderStyle.EXPANDED, "treeview", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
    public void paintTreeCollapsedIcon(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            Graphics g, int state, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
        ENGINE.paintExpander(g, context, Region.TREE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                GTKLookAndFeel.synthStateToGTKState(context.getRegion(), state),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                ExpanderStyle.COLLAPSED, "treeview", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
    public void paintCheckBoxIcon(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            Graphics g, int state, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        GTKStyle style = (GTKStyle)context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        int size = style.getClassSpecificIntValue(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                        "indicator-size", GTKIconFactory.DEFAULT_ICON_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        int offset = style.getClassSpecificIntValue(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                        "indicator-spacing", GTKIconFactory.DEFAULT_ICON_SPACING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        ENGINE.paintCheck(g, context, Region.CHECK_BOX, "checkbutton",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                x+offset, y+offset, size, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    public void paintRadioButtonIcon(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            Graphics g, int state, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        GTKStyle style = (GTKStyle)context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        int size = style.getClassSpecificIntValue(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                        "indicator-size", GTKIconFactory.DEFAULT_ICON_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        int offset = style.getClassSpecificIntValue(context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                        "indicator-spacing", GTKIconFactory.DEFAULT_ICON_SPACING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        ENGINE.paintOption(g, context, Region.RADIO_BUTTON, "radiobutton",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                x+offset, y+offset, size, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
    public void paintMenuArrowIcon(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            int state, int x, int y, int w, int h, ArrowType dir) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        int gtkState = GTKLookAndFeel.synthStateToGTKState(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                context.getRegion(), state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        ShadowType shadow = ShadowType.OUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        if (gtkState == SynthConstants.MOUSE_OVER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            shadow = ShadowType.IN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        ENGINE.paintArrow(g, context, Region.MENU_ITEM, gtkState, shadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                dir, "menuitem", x + 3, y + 3, 7, 7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
    public void paintCheckBoxMenuItemCheckIcon(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            Graphics g, int state, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        GTKStyle style = (GTKStyle)context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        int size = style.getClassSpecificIntValue(context,"indicator-size",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
                GTKIconFactory.DEFAULT_TOGGLE_MENU_ITEM_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        ENGINE.paintCheck(g, context, Region.CHECK_BOX_MENU_ITEM, "check",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
                x + GTKIconFactory.CHECK_ICON_EXTRA_INSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                y + GTKIconFactory.CHECK_ICON_EXTRA_INSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                size, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    public void paintRadioButtonMenuItemCheckIcon(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
            Graphics g, int state, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        GTKStyle style = (GTKStyle)context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        int size = style.getClassSpecificIntValue(context,"indicator-size",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                GTKIconFactory.DEFAULT_TOGGLE_MENU_ITEM_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        ENGINE.paintOption(g, context, Region.RADIO_BUTTON_MENU_ITEM, "option",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                x + GTKIconFactory.CHECK_ICON_EXTRA_INSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                y + GTKIconFactory.CHECK_ICON_EXTRA_INSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                size, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
    public void paintToolBarHandleIcon(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            int state, int x, int y, int w, int h, Orientation orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        int gtkState = GTKLookAndFeel.synthStateToGTKState(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
                context.getRegion(), state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        // The orientation parameter passed down by Synth refers to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        // orientation of the toolbar, but the one we pass to GTK refers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        // to the orientation of the handle.  Therefore, we need to swap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        // the value here: horizontal toolbars have vertical handles, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        // vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        orientation = (orientation == Orientation.HORIZONTAL) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
            Orientation.VERTICAL : Orientation.HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        ENGINE.paintHandle(g, context, Region.TOOL_BAR, gtkState,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                ShadowType.OUT, "handlebox", x, y, w, h, orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
    public void paintAscendingSortIcon(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
            Graphics g, int state, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        ENGINE.paintArrow(g, context, Region.TABLE, SynthConstants.ENABLED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                ShadowType.IN, ArrowType.UP, "arrow", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    public void paintDescendingSortIcon(SynthContext context,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
            Graphics g, int state, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        ENGINE.paintArrow(g, context, Region.TABLE, SynthConstants.ENABLED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                ShadowType.IN, ArrowType.DOWN, "arrow", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     * Fill an area with color determined from this context's Style using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     * specified GTKColorType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    private void fillArea(SynthContext context, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                          int x, int y, int w, int h, ColorType colorType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        if (context.getComponent().isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
            Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
            int gtkState = GTKLookAndFeel.synthStateToGTKState(id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                    context.getComponentState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
            GTKStyle style = (GTKStyle)context.getStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
            g.setColor(style.getGTKColor(context, gtkState, colorType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
            g.fillRect(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
    // Refer to GTKLookAndFeel for details on this.
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 23010
diff changeset
  1417
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
    static class ListTableFocusBorder extends AbstractBorder implements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                          UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        private boolean selectedCell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
        private boolean focusedCell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
        public static ListTableFocusBorder getSelectedCellBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
            return new ListTableFocusBorder(true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        public static ListTableFocusBorder getUnselectedCellBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            return new ListTableFocusBorder(false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        public static ListTableFocusBorder getNoFocusCellBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            return new ListTableFocusBorder(false, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        public ListTableFocusBorder(boolean selectedCell, boolean focusedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            this.selectedCell = selectedCell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
            this.focusedCell = focusedCell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        private SynthContext getContext(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
            SynthContext context = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
            ComponentUI ui = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
            if (c instanceof JLabel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                ui = ((JLabel)c).getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
            if (ui instanceof SynthUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                context = ((SynthUI)ui).getContext((JComponent)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
            return context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
                                int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
            if (focusedCell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
                int state = (selectedCell? SynthConstants.SELECTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                             SynthConstants.FOCUSED | SynthConstants.ENABLED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                if (context != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                    GTKPainter.INSTANCE.paintFocus(context, g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
                            Region.TABLE, state, "", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        public Insets getBorderInsets(Component c, Insets i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
            SynthContext context = getContext(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
            if (context != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                i = context.getStyle().getInsets(context, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
            return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        public boolean isBorderOpaque() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
    // TitledBorder implementation for GTK L&F
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 23010
diff changeset
  1486
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
    static class TitledBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                                int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            SynthContext context = getContext((JComponent)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            Region id = context.getRegion();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
            int state = context.getComponentState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
            int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
            synchronized (UNIXToolkit.GTK_LOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                    ENGINE.startPainting(g, x, y, w, h, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                    ENGINE.paintShadow(g, context, id, gtkState, ShadowType.ETCHED_IN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                                      "frame", x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                    ENGINE.finishPainting();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                }
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
        public Insets getBorderInsets(Component c, Insets i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            SynthContext context = getContext((JComponent)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            return context.getStyle().getInsets(context, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
        public boolean isBorderOpaque() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
        private SynthStyle getStyle(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
            return SynthLookAndFeel.getStyle(c, GTKEngine.CustomRegion.TITLED_BORDER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        private SynthContext getContext(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
            int state = SynthConstants.DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
            return new SynthContext(c, GTKEngine.CustomRegion.TITLED_BORDER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                                    getStyle(c), state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
}