1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 2 <html> 3 <head> 4 <!-- 5 Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 6 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 8 This code is free software; you can redistribute it and/or modify it 9 under the terms of the GNU General Public License version 2 only, as 10 published by the Free Software Foundation. Oracle designates this 11 particular file as subject to the "Classpath" exception as provided 12 by Oracle in the LICENSE file that accompanied this code. 13 14 This code is distributed in the hope that it will be useful, but WITHOUT 15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 17 version 2 for more details (a copy is included in the LICENSE file that 18 accompanied this code). 19 20 You should have received a copy of the GNU General Public License version 21 2 along with this work; if not, write to the Free Software Foundation, 22 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 23 24 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 25 or visit www.oracle.com if you need additional information or have any 26 questions. 27 28 29 --> 30 <title></title> 31 </head> 32 <body bgcolor="white"> 33 <p> 34 Synth is a skinnable look and feel in which all painting is 35 delegated. Synth does not provide a default look. In 36 order to use Synth you need to specify a 37 <a href="doc-files/synthFileFormat.html">file</a>, or 38 provide a {@link 39 javax.swing.plaf.synth.SynthStyleFactory}. Both 40 configuration options require an 41 understanding of the synth architecture, which is described 42 below, as well as an understanding of Swing's architecture. 43 </p> 44 <p> 45 Unless otherwise specified null is not a legal value to any of 46 the methods defined in the synth package and if passed in will 47 result in a <code>NullPointerException</code>. 48 49 50 <h2>Synth</h2> 51 <p> 52 Each {@link javax.swing.plaf.ComponentUI} implementation in Synth associates 53 itself with one {@link 54 javax.swing.plaf.synth.SynthStyle} per {@link 55 javax.swing.plaf.synth.Region}, most 56 <code>Components</code> only have one <code>Region</code> and 57 therefor only one <code>SynthStyle</code>. 58 <code>SynthStyle</code> 59 is used to access all style related properties: fonts, colors 60 and other <code>Component</code> properties. In addition 61 <code>SynthStyle</code>s are used to obtain 62 {@link javax.swing.plaf.synth.SynthPainter}s for painting the background, border, 63 focus and other portions of a <code>Component</code>. The <code>ComponentUI</code>s obtain 64 <code>SynthStyle</code>s from a 65 {@link javax.swing.plaf.synth.SynthStyleFactory}. 66 A <code>SynthStyleFactory</code> 67 can be provided directly by way of 68 {@link javax.swing.plaf.synth.SynthLookAndFeel#setStyleFactory(javax.swing.plaf.synth.SynthStyleFactory)}, 69 or indirectly by way of 70 {@link javax.swing.plaf.synth.SynthLookAndFeel#load}. The 71 following example uses the <code>SynthLookAndFeel.load()</code> 72 method to configure a <code>SynthLookAndFeel</code> and sets it 73 as the current look and feel: 74 </p> 75 <div class="example"> 76 <pre> 77 SynthLookAndFeel laf = new SynthLookAndFeel(); 78 laf.load(MyClass.class.getResourceAsStream("laf.xml"), MyClass.class); 79 UIManager.setLookAndFeel(laf); 80 </pre> 81 </div> 82 <p> 83 Many <code>JComponent</code>s are broken down into smaller 84 pieces and identified by the type safe enumeration in 85 {@link javax.swing.plaf.synth.Region}. For example, a <code>JTabbedPane</code> 86 consists of a <code>Region</code> for the 87 <code>JTabbedPane</code> ({@link 88 javax.swing.plaf.synth.Region#TABBED_PANE}), the content 89 area ({@link 90 javax.swing.plaf.synth.Region#TABBED_PANE_CONTENT}), the 91 area behind the tabs ({@link 92 javax.swing.plaf.synth.Region#TABBED_PANE_TAB_AREA}), and the 93 tabs ({@link 94 javax.swing.plaf.synth.Region#TABBED_PANE_TAB}). Each 95 <code>Region</code> of each 96 <code>JComponent</code> will have a 97 <code>SynthStyle</code>. This allows 98 you to customize individual pieces of each region of each 99 <code>JComponent</code>. 100 <p> 101 Many of the Synth methods take a {@link javax.swing.plaf.synth.SynthContext}. This 102 is used to provide information about the current 103 <code>Component</code> and includes: the 104 {@link javax.swing.plaf.synth.SynthStyle} associated with the current 105 {@link javax.swing.plaf.synth.Region}, the state of the <code>Component</code> 106 as a bitmask (refer to {@link 107 javax.swing.plaf.synth.SynthConstants} for the valid 108 states), and a {@link javax.swing.plaf.synth.Region} identifying the portion of 109 the <code>Component</code> being painted. 110 <p> 111 All text rendering by non-<code>JTextComponent</code>s is 112 delegated to a {@link 113 javax.swing.plaf.synth.SynthGraphicsUtils}, which is 114 obtained using the {@link javax.swing.plaf.synth.SynthStyle} method 115 {@link javax.swing.plaf.synth.SynthStyle#getGraphicsUtils}. You can 116 customize text rendering 117 by supplying your own {@link javax.swing.plaf.synth.SynthGraphicsUtils}. 118 119 </p> 120 121 <h2>Notes on specific components</h2> 122 123 <h3>JTree</h3> 124 <p> 125 Synth provides a region for the cells of a tree: 126 <code>Region.TREE_CELL</code>. To specify the colors of the 127 renderer you'll want to provide a style for the 128 <code>TREE_CELL</code> region. The following illustrates this: 129 <pre> 130 <style id="treeCellStyle"> 131 <opaque value="TRUE"/> 132 <state> 133 <color value="WHITE" type="TEXT_FOREGROUND"/> 134 <color value="RED" type="TEXT_BACKGROUND"/> 135 </state> 136 <state value="SELECTED"> 137 <color value="RED" type="TEXT_FOREGROUND"/> 138 <color value="WHITE" type="BACKGROUND"/> 139 </state> 140 </style> 141 <bind style="treeCellStyle" type="region" key="TreeCell"/> 142 </pre> 143 <p> 144 This specifies a color combination of red on white, when 145 selected, and white on red when not selected. To see the 146 background you need to specify that labels are not opaque. The 147 following XML fragment does that: 148 <pre> 149 <style id="labelStyle"> 150 <opaque value="FALSE"/> 151 </style> 152 <bind style="labelStyle" type="region" key="Label"/> 153 </pre> 154 155 <h3>JList and JTable</h3> 156 <p> 157 The colors that the renderers for JList and JTable use are 158 specified by way of the list and table Regions. The following 159 XML fragment illustrates how to specify red on white, when 160 selected, and white on red when not selected: 161 <pre> 162 <style id="style"> 163 <opaque value="TRUE"/> 164 <state> 165 <color value="WHITE" type="TEXT_FOREGROUND"/> 166 <color value="RED" type="TEXT_BACKGROUND"/> 167 <color value="RED" type="BACKGROUND"/> 168 </state> 169 <state value="SELECTED"> 170 <color value="RED" type="TEXT_FOREGROUND"/> 171 <color value="WHITE" type="TEXT_BACKGROUND"/> 172 </state> 173 </style> 174 <bind style="style" type="region" key="Table"/> 175 <bind style="style" type="region" key="List"/> 176 </pre> 177 </body> 178 </html> | 1 /* 2 * Copyright (c) 2003, 2017, 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 23 * questions. 24 */ 25 26 /** 27 * Synth is a skinnable look and feel in which all painting is delegated. Synth 28 * does not provide a default look. In order to use Synth you need to specify a 29 * <a href="doc-files/synthFileFormat.html">file</a>, or provide a 30 * {@link javax.swing.plaf.synth.SynthStyleFactory}. Both configuration options 31 * require an understanding of the synth architecture, which is described below, 32 * as well as an understanding of Swing's architecture. 33 * <p> 34 * Unless otherwise specified null is not a legal value to any of the methods 35 * defined in the synth package and if passed in will result in a 36 * {@code NullPointerException}. 37 * 38 * <h2>Synth</h2> 39 * Each {@link javax.swing.plaf.ComponentUI} implementation in Synth associates 40 * itself with one {@link javax.swing.plaf.synth.SynthStyle} per 41 * {@link javax.swing.plaf.synth.Region}, most {@code Components} only have one 42 * {@code Region} and therefor only one {@code SynthStyle}. {@code SynthStyle} 43 * is used to access all style related properties: fonts, colors 44 * and other {@code Component} properties. In addition {@code SynthStyle}s are 45 * used to obtain {@link javax.swing.plaf.synth.SynthPainter}s for painting the 46 * background, border, focus and other portions of a {@code Component}. The 47 * {@code ComponentUI}s obtain {@code SynthStyle}s from a 48 * {@link javax.swing.plaf.synth.SynthStyleFactory}. A {@code SynthStyleFactory} 49 * can be provided directly by way of 50 * {@link javax.swing.plaf.synth.SynthLookAndFeel#setStyleFactory(javax.swing.plaf.synth.SynthStyleFactory)}, 51 * or indirectly by way of {@link javax.swing.plaf.synth.SynthLookAndFeel#load}. 52 * The following example uses the {@code SynthLookAndFeel.load()} method to 53 * configure a {@code SynthLookAndFeel} and sets it as the current look and 54 * feel: 55 * <div class="example"> 56 * <pre>{@code 57 * SynthLookAndFeel laf = new SynthLookAndFeel(); 58 * laf.load(MyClass.class.getResourceAsStream("laf.xml"), MyClass.class); 59 * UIManager.setLookAndFeel(laf); 60 * }</pre> 61 * </div> 62 * <p> 63 * Many {@code JComponent}s are broken down into smaller pieces and identified 64 * by the type safe enumeration in {@link javax.swing.plaf.synth.Region}. For 65 * example, a {@code JTabbedPane} consists of a {@code Region} for the 66 * {@code JTabbedPane}({@link javax.swing.plaf.synth.Region#TABBED_PANE}), the 67 * content area ({@link javax.swing.plaf.synth.Region#TABBED_PANE_CONTENT}), the 68 * area behind the tabs 69 * ({@link javax.swing.plaf.synth.Region#TABBED_PANE_TAB_AREA}), and the tabs 70 * ({@link javax.swing.plaf.synth.Region#TABBED_PANE_TAB}). Each 71 * {@code Region} of each {@code JComponent} will have a {@code SynthStyle}. 72 * This allows you to customize individual pieces of each region of each 73 * {@code JComponent}. 74 * <p> 75 * Many of the Synth methods take a {@link javax.swing.plaf.synth.SynthContext}. 76 * This is used to provide information about the current {@code Component} and 77 * includes: the {@link javax.swing.plaf.synth.SynthStyle} associated with the 78 * current {@link javax.swing.plaf.synth.Region}, the state of the 79 * {@code Component} as a bitmask (refer to 80 * {@link javax.swing.plaf.synth.SynthConstants} for the valid states), and a 81 * {@link javax.swing.plaf.synth.Region} identifying the portion of the 82 * {@code Component} being painted. 83 * <p> 84 * All text rendering by non-{@code JTextComponent}s is delegated to a 85 * {@link javax.swing.plaf.synth.SynthGraphicsUtils}, which is obtained using 86 * the {@link javax.swing.plaf.synth.SynthStyle} method 87 * {@link javax.swing.plaf.synth.SynthStyle#getGraphicsUtils}. You can customize 88 * text rendering by supplying your own 89 * {@link javax.swing.plaf.synth.SynthGraphicsUtils}. 90 * 91 * <h2>Notes on specific components</h2> 92 * <h3>JTree</h3> 93 * Synth provides a region for the cells of a tree: 94 * {@code Region.TREE_CELL}. To specify the colors of the 95 * renderer you'll want to provide a style for the 96 * {@code TREE_CELL} region. The following illustrates this: 97 * <pre>{@code 98 * <style id="treeCellStyle"> 99 * <opaque value="TRUE"/> 100 * <state> 101 * <color value="WHITE" type="TEXT_FOREGROUND"/> 102 * <color value="RED" type="TEXT_BACKGROUND"/> 103 * </state> 104 * <state value="SELECTED"> 105 * <color value="RED" type="TEXT_FOREGROUND"/> 106 * <color value="WHITE" type="BACKGROUND"/> 107 * </state> 108 * </style> 109 * <bind style="treeCellStyle" type="region" key="TreeCell"/> 110 * }</pre> 111 * <p> 112 * This specifies a color combination of red on white, when selected, and white 113 * on red when not selected. To see the background you need to specify that 114 * labels are not opaque. The following XML fragment does that: 115 * <pre>{@code 116 * <style id="labelStyle"> 117 * <opaque value="FALSE"/> 118 * </style> 119 * <bind style="labelStyle" type="region" key="Label"/> 120 * }</pre> 121 * 122 * <h3>JList and JTable</h3> 123 * The colors that the renderers for JList and JTable use are specified by way 124 * of the list and table Regions. The following XML fragment illustrates how to 125 * specify red on white, when selected, and white on red when not selected: 126 * <pre>{@code 127 * <style id="style"> 128 * <opaque value="TRUE"/> 129 * <state> 130 * <color value="WHITE" type="TEXT_FOREGROUND"/> 131 * <color value="RED" type="TEXT_BACKGROUND"/> 132 * <color value="RED" type="BACKGROUND"/> 133 * </state> 134 * <state value="SELECTED"> 135 * <color value="RED" type="TEXT_FOREGROUND"/> 136 * <color value="WHITE" type="TEXT_BACKGROUND"/> 137 * </state> 138 * </style> 139 * <bind style="style" type="region" key="Table"/> 140 * <bind style="style" type="region" key="List"/> 141 * }</pre> 142 */ 143 package javax.swing.plaf.synth; |