src/share/classes/com/sun/java/swing/plaf/gtk/GTKPainter.java

Print this page


   1 /*
   2  * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


1397     }
1398 
1399     /*
1400      * Fill an area with color determined from this context's Style using the
1401      * specified GTKColorType
1402      */
1403     private void fillArea(SynthContext context, Graphics g,
1404                           int x, int y, int w, int h, ColorType colorType) {
1405         if (context.getComponent().isOpaque()) {
1406             Region id = context.getRegion();
1407             int gtkState = GTKLookAndFeel.synthStateToGTKState(id,
1408                     context.getComponentState());
1409             GTKStyle style = (GTKStyle)context.getStyle();
1410 
1411             g.setColor(style.getGTKColor(context, gtkState, colorType));
1412             g.fillRect(x, y, w, h);
1413         }
1414     }
1415 
1416     // Refer to GTKLookAndFeel for details on this.

1417     static class ListTableFocusBorder extends AbstractBorder implements
1418                           UIResource {
1419 
1420         private boolean selectedCell;
1421         private boolean focusedCell;
1422 
1423         public static ListTableFocusBorder getSelectedCellBorder() {
1424             return new ListTableFocusBorder(true, true);
1425         }
1426 
1427         public static ListTableFocusBorder getUnselectedCellBorder() {
1428             return new ListTableFocusBorder(false, true);
1429         }
1430 
1431         public static ListTableFocusBorder getNoFocusCellBorder() {
1432             return new ListTableFocusBorder(false, false);
1433         }
1434 
1435         public ListTableFocusBorder(boolean selectedCell, boolean focusedCell) {
1436             this.selectedCell = selectedCell;


1465                 }
1466             }
1467         }
1468 
1469         public Insets getBorderInsets(Component c, Insets i) {
1470             SynthContext context = getContext(c);
1471 
1472             if (context != null) {
1473                 i = context.getStyle().getInsets(context, i);
1474             }
1475 
1476             return i;
1477         }
1478 
1479         public boolean isBorderOpaque() {
1480             return true;
1481         }
1482     }
1483 
1484     // TitledBorder implementation for GTK L&F

1485     static class TitledBorder extends AbstractBorder implements UIResource {
1486 
1487         public void paintBorder(Component c, Graphics g, int x, int y,
1488                                 int w, int h) {
1489             SynthContext context = getContext((JComponent)c);
1490             Region id = context.getRegion();
1491             int state = context.getComponentState();
1492             int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
1493 
1494             synchronized (UNIXToolkit.GTK_LOCK) {
1495                 if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
1496                     ENGINE.startPainting(g, x, y, w, h, id);
1497                     ENGINE.paintShadow(g, context, id, gtkState, ShadowType.ETCHED_IN,
1498                                       "frame", x, y, w, h);
1499                     ENGINE.finishPainting();
1500                 }
1501             }
1502         }
1503 
1504         public Insets getBorderInsets(Component c, Insets i) {
   1 /*
   2  * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


1397     }
1398 
1399     /*
1400      * Fill an area with color determined from this context's Style using the
1401      * specified GTKColorType
1402      */
1403     private void fillArea(SynthContext context, Graphics g,
1404                           int x, int y, int w, int h, ColorType colorType) {
1405         if (context.getComponent().isOpaque()) {
1406             Region id = context.getRegion();
1407             int gtkState = GTKLookAndFeel.synthStateToGTKState(id,
1408                     context.getComponentState());
1409             GTKStyle style = (GTKStyle)context.getStyle();
1410 
1411             g.setColor(style.getGTKColor(context, gtkState, colorType));
1412             g.fillRect(x, y, w, h);
1413         }
1414     }
1415 
1416     // Refer to GTKLookAndFeel for details on this.
1417     @SuppressWarnings("serial") // Superclass is not serializable across versions
1418     static class ListTableFocusBorder extends AbstractBorder implements
1419                           UIResource {
1420 
1421         private boolean selectedCell;
1422         private boolean focusedCell;
1423 
1424         public static ListTableFocusBorder getSelectedCellBorder() {
1425             return new ListTableFocusBorder(true, true);
1426         }
1427 
1428         public static ListTableFocusBorder getUnselectedCellBorder() {
1429             return new ListTableFocusBorder(false, true);
1430         }
1431 
1432         public static ListTableFocusBorder getNoFocusCellBorder() {
1433             return new ListTableFocusBorder(false, false);
1434         }
1435 
1436         public ListTableFocusBorder(boolean selectedCell, boolean focusedCell) {
1437             this.selectedCell = selectedCell;


1466                 }
1467             }
1468         }
1469 
1470         public Insets getBorderInsets(Component c, Insets i) {
1471             SynthContext context = getContext(c);
1472 
1473             if (context != null) {
1474                 i = context.getStyle().getInsets(context, i);
1475             }
1476 
1477             return i;
1478         }
1479 
1480         public boolean isBorderOpaque() {
1481             return true;
1482         }
1483     }
1484 
1485     // TitledBorder implementation for GTK L&F
1486     @SuppressWarnings("serial") // Superclass is not serializable across versions
1487     static class TitledBorder extends AbstractBorder implements UIResource {
1488 
1489         public void paintBorder(Component c, Graphics g, int x, int y,
1490                                 int w, int h) {
1491             SynthContext context = getContext((JComponent)c);
1492             Region id = context.getRegion();
1493             int state = context.getComponentState();
1494             int gtkState = GTKLookAndFeel.synthStateToGTKState(id, state);
1495 
1496             synchronized (UNIXToolkit.GTK_LOCK) {
1497                 if (! ENGINE.paintCachedImage(g, x, y, w, h, id)) {
1498                     ENGINE.startPainting(g, x, y, w, h, id);
1499                     ENGINE.paintShadow(g, context, id, gtkState, ShadowType.ETCHED_IN,
1500                                       "frame", x, y, w, h);
1501                     ENGINE.finishPainting();
1502                 }
1503             }
1504         }
1505 
1506         public Insets getBorderInsets(Component c, Insets i) {