J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
| 2 | <html>
|
| 3 | <head>
|
| 4 | <!-- |
| 5 | Copyright 2003-2004 Sun Microsystems, Inc. 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. Sun designates this |
| 11 | particular file as subject to the "Classpath" exception as provided |
| 12 | by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 25 | CA 95054 USA or visit www.sun.com if you need additional information or |
| 26 | have any questions. |
| 27 | |
| 28 | |
| 29 | --> |
| 30 | </head>
|
| 31 | <body bgcolor="white">
|
| 32 | <p>
|
| 33 | Synth is a skinnable look and feel in which all painting is
|
| 34 | delegated. Synth does not provide a default look. In
|
| 35 | order to use Synth you need to specify a
|
| 36 | <a href="doc-files/synthFileFormat.html">file</a>, or
|
| 37 | provide a {@link
|
| 38 | javax.swing.plaf.synth.SynthStyleFactory}. Both
|
| 39 | configuration options require an
|
| 40 | understanding of the synth architecture, which is described
|
| 41 | below, as well as an understanding of Swing's architecture.
|
| 42 | </p>
|
| 43 | <p>
|
| 44 | Unless otherwise specified null is not a legal value to any of
|
| 45 | the methods defined in the synth package and if passed in will
|
| 46 | result in a <code>NullPointerException</code>.
|
| 47 |
|
| 48 |
|
| 49 | <h2>Synth</h2>
|
| 50 | <p>
|
| 51 | Each {@link javax.swing.plaf.ComponentUI} implementation in Synth associates
|
| 52 | itself with one {@link
|
| 53 | javax.swing.plaf.synth.SynthStyle} per {@link
|
| 54 | javax.swing.plaf.synth.Region}, most
|
| 55 | <code>Components</code> only have one <code>Region</code> and
|
| 56 | therefor only one <code>SynthStyle</code>.
|
| 57 | <code>SynthStyle</code>
|
| 58 | is used to access all style related properties: fonts, colors
|
| 59 | and other <code>Component</code> properties. In addition
|
| 60 | <code>SynthStyle</code>s are used to obtain
|
| 61 | {@link javax.swing.plaf.synth.SynthPainter}s for painting the background, border,
|
| 62 | focus and other portions of a <code>Component</code>. The <code>ComponentUI</code>s obtain
|
| 63 | <code>SynthStyle</code>s from a
|
| 64 | {@link javax.swing.plaf.synth.SynthStyleFactory}.
|
| 65 | A <code>SynthStyleFactory</code>
|
| 66 | can be provided directly by way of
|
| 67 | {@link javax.swing.plaf.synth.SynthLookAndFeel#setStyleFactory(javax.swing.plaf.synth.SynthStyleFactory)},
|
| 68 | or indirectly by way of
|
| 69 | {@link javax.swing.plaf.synth.SynthLookAndFeel#load}. The
|
| 70 | following example uses the <code>SynthLookAndFeel.load()</code>
|
| 71 | method to configure a <code>SynthLookAndFeel</code> and sets it
|
| 72 | as the current look and feel:
|
| 73 | </p>
|
| 74 | <div class="example">
|
| 75 | <pre>
|
| 76 | SynthLookAndFeel laf = new SynthLookAndFeel();
|
| 77 | laf.load(MyClass.class.getResourceAsStream("laf.xml"), MyClass.class); |
| 78 | UIManager.setLookAndFeel(laf);
|
| 79 | </pre>
|
| 80 | </div>
|
| 81 | <p>
|
| 82 | Many <code>JComponent</code>s are broken down into smaller
|
| 83 | pieces and identified by the type safe enumeration in
|
| 84 | {@link javax.swing.plaf.synth.Region}. For example, a <code>JTabbedPane</code>
|
| 85 | consists of a <code>Region</code> for the
|
| 86 | <code>JTabbedPane</code> ({@link
|
| 87 | javax.swing.plaf.synth.Region#TABBED_PANE}), the content
|
| 88 | area ({@link
|
| 89 | javax.swing.plaf.synth.Region#TABBED_PANE_CONTENT}), the
|
| 90 | area behind the tabs ({@link
|
| 91 | javax.swing.plaf.synth.Region#TABBED_PANE_TAB_AREA}), and the
|
| 92 | tabs ({@link
|
| 93 | javax.swing.plaf.synth.Region#TABBED_PANE_TAB}). Each
|
| 94 | <code>Region</code> of each
|
| 95 | <code>JComponent</code> will have a
|
| 96 | <code>SynthStyle</code>. This allows
|
| 97 | you to customize individual pieces of each region of each
|
| 98 | <code>JComponent</code>.
|
| 99 | <p>
|
| 100 | Many of the Synth methods take a {@link javax.swing.plaf.synth.SynthContext}. This
|
| 101 | is used to provide information about the current
|
| 102 | <code>Component</code> and includes: the
|
| 103 | {@link javax.swing.plaf.synth.SynthStyle} associated with the current
|
| 104 | {@link javax.swing.plaf.synth.Region}, the state of the <code>Component</code>
|
| 105 | as a bitmask (refer to {@link
|
| 106 | javax.swing.plaf.synth.SynthConstants} for the valid
|
| 107 | states), and a {@link javax.swing.plaf.synth.Region} identifying the portion of
|
| 108 | the <code>Component</code> being painted.
|
| 109 | <p>
|
| 110 | All text rendering by non-<code>JTextComponent</code>s is
|
| 111 | delegated to a {@link
|
| 112 | javax.swing.plaf.synth.SynthGraphicsUtils}, which is
|
| 113 | obtained using the {@link javax.swing.plaf.synth.SynthStyle} method
|
| 114 | {@link javax.swing.plaf.synth.SynthStyle#getGraphicsUtils}. You can
|
| 115 | customize text rendering
|
| 116 | by supplying your own {@link javax.swing.plaf.synth.SynthGraphicsUtils}.
|
| 117 |
|
| 118 | </p>
|
| 119 |
|
| 120 | <h2>Notes on specific components</h2>
|
| 121 |
|
| 122 | <h3>JTree</h3>
|
| 123 | <p>
|
| 124 | Synth provides a region for the cells of a tree:
|
| 125 | <code>Region.TREE_CELL</code>. To specify the colors of the
|
| 126 | renderer you'll want to provide a style for the
|
| 127 | <code>TREE_CELL</code> region. The following illustrates this:
|
| 128 | <pre>
|
| 129 | <style id="treeCellStyle">
|
| 130 | <opaque value="TRUE"/>
|
| 131 | <state>
|
| 132 | <color value="WHITE" type="TEXT_FOREGROUND"/>
|
| 133 | <color value="RED" type="TEXT_BACKGROUND"/>
|
| 134 | </state>
|
| 135 | <state value="SELECTED">
|
| 136 | <color value="RED" type="TEXT_FOREGROUND"/>
|
| 137 | <color value="WHITE" type="BACKGROUND"/>
|
| 138 | </state>
|
| 139 | </style>
|
| 140 | <bind style="treeCellStyle" type="region" key="TreeCell"/>
|
| 141 | </pre>
|
| 142 | <p>
|
| 143 | This specifies a color combination of red on white, when
|
| 144 | selected, and white on red when not selected. To see the
|
| 145 | background you need to specify that labels are not opaque. The
|
| 146 | following XML fragment does that:
|
| 147 | <pre>
|
| 148 | <style id="labelStyle">
|
| 149 | <opaque value="FALSE"/>
|
| 150 | </style>
|
| 151 | <bind style="labelStyle" type="region" key="Label"/>
|
| 152 | </pre>
|
| 153 |
|
| 154 | <h3>JList and JTable</h3>
|
| 155 | <p>
|
| 156 | The colors that the renderers for JList and JTable use are
|
| 157 | specified by way of the list and table Regions. The following
|
| 158 | XML fragment illustrates how to specify red on white, when
|
| 159 | selected, and white on red when not selected:
|
| 160 | <pre>
|
| 161 | <style id="style">
|
| 162 | <opaque value="TRUE"/>
|
| 163 | <state>
|
| 164 | <color value="WHITE" type="TEXT_FOREGROUND"/>
|
| 165 | <color value="RED" type="TEXT_BACKGROUND"/>
|
| 166 | <color value="RED" type="BACKGROUND"/>
|
| 167 | </state>
|
| 168 | <state value="SELECTED">
|
| 169 | <color value="RED" type="TEXT_FOREGROUND"/>
|
| 170 | <color value="WHITE" type="TEXT_BACKGROUND"/>
|
| 171 | </state>
|
| 172 | </style>
|
| 173 | <bind style="style" type="region" key="Table"/>
|
| 174 | <bind style="style" type="region" key="List"/>
|
| 175 | </pre>
|
| 176 | </body>
|
| 177 | </html>
|