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