Index: src/main/java/common/javax/swing/plaf/synth/ColorPainter.java =================================================================== --- src/main/java/common/javax/swing/plaf/synth/ColorPainter.java (revision 0) +++ src/main/java/common/javax/swing/plaf/synth/ColorPainter.java (revision 0) @@ -0,0 +1,399 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package javax.swing.plaf.synth; + +import java.awt.Color; +import java.awt.Graphics; + +import javax.swing.plaf.synth2.ColorType; +import javax.swing.plaf.synth2.SynthContext; +import javax.swing.plaf.synth2.SynthPainter; +import javax.swing.plaf.synth2.SynthStyle; + +import org.apache.harmony.x.swing.Utilities; + +class ColorPainter extends SynthPainter { + + /** + * Method that do paints + */ + private void paintBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + SynthStyle style = context.getStyle(); + if (style.isOpaque(context)) { + Color oldColor = g.getColor(); + g.setColor(style.getColor(context, ColorType.BACKGROUND)); + g.fillRect(x, y, x + w, y + h); + g.setColor(oldColor); + } + } + + @Override + public void paintArrowButtonBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintArrowButtonForeground(SynthContext context, Graphics g, + int x, int y, int w, int h, int direction) { + SynthStyle style = context.getStyle(); + if (style.isOpaque(context)) { + Utilities.paintArrow(g, x, y, direction, w, true, style.getColor( + context, ColorType.FOREGROUND)); + } + } + + @Override + public void paintButtonBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintCheckBoxMenuItemBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintColorChooserBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintComboBoxBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintDesktopIconBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintDesktopPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintEditorPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintFileChooserBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintFormattedTextFieldBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintInternalFrameBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintInternalFrameTitlePaneBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintLabelBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintListBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintMenuBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintMenuBarBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintMenuItemBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintOptionPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintPanelBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintPasswordFieldBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintPopupMenuBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintProgressBarBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintProgressBarForeground(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + + SynthStyle style = context.getStyle(); + if (style.isOpaque(context)) { + Color oldColor = g.getColor(); + g.setColor(style.getColor(context, ColorType.FOREGROUND)); + g.fillRect(x, y, x + w, y + h); + g.setColor(oldColor); + } + } + + @Override + public void paintRadioButtonBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintRadioButtonMenuItemBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintRootPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintScrollBarBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintScrollBarThumbBackground(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintScrollBarTrackBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintScrollPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintSeparatorBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintSeparatorForeground(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintSliderBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintSliderThumbBackground(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintSliderTrackBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintSpinnerBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintSplitPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintSplitPaneDividerBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintSplitPaneDragDivider(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneContentBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneTabAreaBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, + int x, int y, int w, int h, int tabIndex) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintTableBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintTableHeaderBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintTextAreaBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintTextFieldBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintTextPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintToggleButtonBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintToolBarBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintToolBarContentBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintToolBarDragWindowBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintToolTipBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintTreeBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintTreeCellBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + + @Override + public void paintViewportBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintBackground(context, g, x, y, w, h); + } + +} Index: src/main/java/common/javax/swing/plaf/synth/XMLSynthParser.java =================================================================== --- src/main/java/common/javax/swing/plaf/synth/XMLSynthParser.java (revision 0) +++ src/main/java/common/javax/swing/plaf/synth/XMLSynthParser.java (revision 0) @@ -0,0 +1,1026 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package javax.swing.plaf.synth; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Insets; +import java.beans.XMLDecoder; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.Arrays; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; + +import javax.swing.Icon; +import javax.swing.ImageIcon; +import javax.swing.JSplitPane; +import javax.swing.SwingConstants; +import javax.swing.UIManager; +import javax.swing.plaf.synth2.ColorType; +import javax.swing.plaf.synth2.SynthConstants; +import javax.swing.plaf.synth2.SynthGraphicsUtils; +import javax.swing.plaf.synth2.SynthLookAndFeel; +import javax.swing.plaf.synth2.SynthPainter; + +import org.apache.harmony.x.swing.internal.nls.Messages; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * XMLSynthParser creates a set of SynthStyles that satisfied XML description of + * the look and feel. SynthLookAndFeel can access to the styles through + * SynthFactory + */ +class XMLSynthParser extends DefaultHandler { + + /* All the known elements */ + private static final String STYLE_ELEMENT = "style"; //$NON-NLS-1$ + + private static final String STATE_ELEMENT = "state"; //$NON-NLS-1$ + + private static final String FONT_ELEMENT = "font"; //$NON-NLS-1$ + + private static final String COLOR_ELEMENT = "color"; //$NON-NLS-1$ + + private static final String G_UTILS_ELEMENT = "graphicsUtils"; //$NON-NLS-1$ + + private static final String DEFAULTS_ELEMENT = "defaultsProperty"; //$NON-NLS-1$ + + private static final String INSETS_ELEMENT = "insets"; //$NON-NLS-1$ + + private static final String OPAQUE_ELEMENT = "opaque"; //$NON-NLS-1$ + + private static final String PROPERTY_ELEMENT = "property"; //$NON-NLS-1$ + + private static final String BIND_ELEMENT = "bind"; //$NON-NLS-1$ + + private static final String IM_PAINTER_ELEMENT = "imagePainter"; //$NON-NLS-1$ + + private static final String PAINTER_ELEMENT = "painter"; //$NON-NLS-1$ + + private static final String IMAGE_ICON_ELEMENT = "imageIcon"; //$NON-NLS-1$ + + private static final String SYNTH_ELEMENT = "synth"; //$NON-NLS-1$ + + /** + * BeansAdapter to process unknown elements + */ + private final BeansAdapter adapter = new BeansAdapter(); + + /** + * The base used for correct URL creating + */ + private final Class base; + + /** + * The marking for default state. Used in parser to mark state as default + * and indirectly in XMLSynthStyle in findColorForState, findFontForState + * methods. + */ + private final int DEFAULT_STATE = 0; + + /** + * The XMLStyleFactory to add configured styles + */ + private final DefaultStyleFactory styleFactory = new DefaultStyleFactory(); + + /** + * Map used for correct references processing. Key is Element id in xml + * style. Value is the element to be inserted in the style + */ + private final Map namedElements = new HashMap(); + + /** + * Map used for correct references processing. Key is the complex key (see + * private class below). Value is the SynthStyle to be value from + * namedElements be inserted + */ + private final Map namedReferenses = new HashMap(); + + /** + * The style under modification + */ + private XMLSynthStyle currentStyle; + + /** + * State marking + */ + private int currentState; + + /** + * The colors, that can be obtained from the string description + */ + enum Colors { + RED(Color.RED), GREEN(Color.GREEN), BLUE(Color.BLUE), CYAN(Color.CYAN), BLACK( + Color.BLACK), WHITE(Color.WHITE), GRAY(Color.GRAY), DARK_GRAY( + Color.DARK_GRAY), ORANGE(Color.ORANGE), YELLOW(Color.YELLOW); + + final Color color; + + Colors(Color color) { + + this.color = color; + } + } + + /** + * The directions used in Painters, that can be obtained from the string + * description + */ + enum Directions { + EAST(SwingConstants.EAST), NORTH(SwingConstants.NORTH), SOUTH( + SwingConstants.SOUTH), WEST(SwingConstants.WEST), TOP( + SwingConstants.TOP), BOTTOM(SwingConstants.BOTTOM), LEFT( + SwingConstants.LEFT), RIGHT(SwingConstants.RIGHT), HORIZONTAL( + SwingConstants.HORIZONTAL), VERTICAL(SwingConstants.VERTICAL), HORIZONTAL_SPLIT( + JSplitPane.HORIZONTAL_SPLIT), VERTICAL_SPLIT( + JSplitPane.VERTICAL_SPLIT); + + final int direction; + + Directions(int direction) { + + this.direction = direction; + } + } + + XMLSynthParser(Class resourseBase) { + this.base = resourseBase; + } + + /** + * Process all the known tags + */ + @Override + public void startElement(String namespaceURI, String localName, + String qName, Attributes attrs) throws SAXException { + + String element = ("".equals(localName)) ? qName.intern() : //$NON-NLS-1$ + localName.intern(); + + if (element == STYLE_ELEMENT) { + + processStyleElement(attrs); + + } else if (element == STATE_ELEMENT) { + + currentState = computeStateValue(attrs.getValue("value")); //$NON-NLS-1$ + + } else if (element == FONT_ELEMENT) { + + processFontElement(attrs); + + } else if (element == COLOR_ELEMENT) { + + processColorElement(attrs); + + } else if (element == G_UTILS_ELEMENT) { + + processGraphicsUtilsElement(attrs); + + } else if (element == DEFAULTS_ELEMENT) { + + processDefaultsProperyElement(attrs); + + } else if (element == INSETS_ELEMENT) { + + processInsetsElement(attrs); + + } else if (element == OPAQUE_ELEMENT) { + + processOpaqueElement(attrs); + + } else if (element == PROPERTY_ELEMENT) { + + processProperyElement(attrs); + + } else if (element == BIND_ELEMENT) { + + processBindElemant(attrs); + + } else if (element == IM_PAINTER_ELEMENT) { + + processImagePainterElement(attrs); + + } else if (element == PAINTER_ELEMENT) { + + processPainterElement(attrs); + + } else if (element == IMAGE_ICON_ELEMENT) { + + processIconElement(attrs); + + } else if (element == SYNTH_ELEMENT) { + + // Do nothing + + } else { + adapter.pushStartTag(element, attrs); + } + } + + /** + * Characters need to beansPersistance entities only + */ + @Override + public void characters(char[] ch, int start, int size) throws SAXException { + adapter.pushCharactres(ch, start, size); + } + + @Override + @SuppressWarnings("unused") + public void endElement(String namespaceURI, String sName, String qName) { + + String element = ("".equals(sName)) ? qName.intern() : sName //$NON-NLS-1$ + .intern(); + + if ((STYLE_ELEMENT == element)) { + currentStyle = null; + } else if (STATE_ELEMENT == element) { + currentState = DEFAULT_STATE; + } else if ((!(BIND_ELEMENT == element)) + && (!(COLOR_ELEMENT == element)) + && (!(G_UTILS_ELEMENT == element)) + && (!(DEFAULTS_ELEMENT == element)) + && (!(INSETS_ELEMENT == element)) + && (!(OPAQUE_ELEMENT == element)) + && (!(PROPERTY_ELEMENT == element)) + && (!(IM_PAINTER_ELEMENT == element)) + && (!(PAINTER_ELEMENT == element)) + && (!(IMAGE_ICON_ELEMENT == element)) + && (!(SYNTH_ELEMENT == element)) + && (!(FONT_ELEMENT == element))) { + adapter.pushEndTag(element); + } + + } + + /** + * After the xml document parsing process all the references in + * nameReferenses map + * + * All the RuntimeExceptions are internal synth exceptions + */ + @Override + public void endDocument() throws SAXException { + + adapter.putAdaptedBeansToMap(namedElements); + + fillReferences(); + + SynthLookAndFeel.setStyleFactory(styleFactory); + } + + /** + * Called in endDocument + * + * Process all the found references (idref in xml document and + * namedReferences Map in this class) and binds it with exiting objects (id + * in xml document and namedElements Map in this class) + */ + private void fillReferences() { + + for (Map.Entry entry : namedReferenses + .entrySet()) { + + XMLSynthKey key = entry.getKey(); + String element = key.getElementName().intern(); + + if (element == INSETS_ELEMENT) { + // Just put the insets with given idref to style it (idref) + // contains + entry.getValue().setInsets( + (Insets) namedElements.get(key.getReference())); + + } else if (element == FONT_ELEMENT) { + // put the font with given idref to style it (idref) + // contains, according to staieId obtained from key (key + // filling can be found in ) + entry.getValue().addFont( + (Font) namedElements.get(key.getReference()), + key.getState()); + + } else if (element == G_UTILS_ELEMENT) { + + entry.getValue().setGraphicsUtils( + (SynthGraphicsUtils) namedElements.get(key + .getReference())); + + } else if (element == COLOR_ELEMENT) { + + entry.getValue().addColor( + (Color) namedElements.get(key.getReference()), + key.getState(), + ColorType.calculateColorType(key.getFirstInfo())); + + } else if (element == PROPERTY_ELEMENT) { + if (key.getAllInfo().length == 2) { + entry.getValue().addIcon( + (Icon) namedElements.get(key.getReference()), + key.getState(), key.getFirstInfo()); + } else { + entry.getValue().setProperty(key.getFirstInfo(), + namedElements.get(key.getReference())); + } + + } else if (element == DEFAULTS_ELEMENT) { + + UIManager.put(key.getFirstInfo(), namedElements.get(key + .getReference())); + + } else if (element == PAINTER_ELEMENT) { + + String directionAttr = key.getAllInfo()[1]; + int direction = (directionAttr != null) ? Integer + .parseInt(directionAttr) : PaintersManager.NO_DIRECTION; + + entry.getValue().addPainter( + (SynthPainter) namedElements.get(key.getReference()), + key.getState(), key.getAllInfo()[0], direction); + + } else { + // impossible case because namedReferences filled by known + // Elements only + assert false : "Error in parser code"; //$NON-NLS-1$ + } + } + } + + private void processStyleElement(Attributes attrs) throws SAXException { + + String cloneAttr = attrs.getValue("clone"); //$NON-NLS-1$ + String styleName = attrs.getValue("id"); //$NON-NLS-1$ + + if (cloneAttr == null) { + + currentStyle = new XMLSynthStyle(); + namedElements.put(styleName, currentStyle); + + } else { + try { + currentStyle = (XMLSynthStyle) ((XMLSynthStyle) namedElements + .get(cloneAttr)).clone(); + + } catch (CloneNotSupportedException e) { + throw new SAXException(e); + } + + namedElements.put(styleName, currentStyle); + } + + currentState = DEFAULT_STATE; + } + + @SuppressWarnings("nls") + private void processFontElement(Attributes attrs) throws SAXException { + + String idref = attrs.getValue("idref"); + String id = attrs.getValue("id"); + String name = attrs.getValue("name"); + String styleAttr = attrs.getValue("style"); + + int size = 0; + int style = Font.PLAIN; + + if (idref != null) { + namedReferenses.put(new XMLSynthKey(FONT_ELEMENT, currentState, + idref, new String[0]), currentStyle); + return; + } + + try { + size = Integer.parseInt(attrs.getValue("size")); + } finally { + if (size == 0) { + throw new SAXException("Invalid font size:" + + attrs.getValue("size")); + } + } + + if (styleAttr != null) { + StringTokenizer tk = new StringTokenizer(styleAttr); + while (tk.hasMoreTokens()) { + String st = tk.nextToken(); + if (st.equals("BOLD")) { + style |= Font.BOLD; + } else if (st.equals("ITALIC")) { + style |= Font.ITALIC; + } + } + } + + if (name == null) { + throw new SAXException(Messages.getString("swing.err.1E")); + } + + Font currentFont = new Font(name, style, size); + + if (currentStyle != null) { + currentStyle.addFont(currentFont, currentState); + } + + if (id != null) { + namedElements.put(id, currentFont); + } + } + + private void processColorElement(Attributes attrs) throws SAXException { + + String colorTypeAttr = attrs.getValue("type"); //$NON-NLS-1$ + String idRefAttr = attrs.getValue("idref"); //$NON-NLS-1$ + String colorValueAttr = attrs.getValue("value"); //$NON-NLS-1$ + String idAttr = attrs.getValue("id"); //$NON-NLS-1$ + + if ((idRefAttr != null) && (colorTypeAttr != null)) { + namedReferenses.put(new XMLSynthKey(COLOR_ELEMENT, currentState, + idRefAttr, colorTypeAttr), currentStyle); + return; + } + + Color currentColor; + + try { + if (colorValueAttr.length() == 7) { + + currentColor = Color.decode(colorValueAttr); + + } else if (colorValueAttr.length() == 9) { + + currentColor = new Color(Integer.parseInt(colorValueAttr, 16), + true); + + } else { + + currentColor = Colors.valueOf(colorValueAttr.toUpperCase()).color; + + } + } catch (Exception e) { + throw new SAXException("Color value is incorrect", e); //$NON-NLS-1$ + } + + if (idAttr != null) { + + namedElements.put(idAttr, currentColor); + + } else { + + ColorType currentColorType = ColorType + .calculateColorType(colorTypeAttr); + + if (currentColorType == null) { + try { + Class.forName(colorTypeAttr).newInstance(); + } catch (InstantiationException e) { + throw new SAXException(Messages.getString("swing.err.1C") //$NON-NLS-1$ + + colorTypeAttr); + } catch (IllegalAccessException e) { + throw new SAXException(Messages.getString("swing.err.1C") //$NON-NLS-1$ + + colorTypeAttr); + } catch (ClassNotFoundException e) { + throw new SAXException(Messages.getString("swing.err.1C") //$NON-NLS-1$ + + colorTypeAttr); + } + } + + currentStyle.addColor(currentColor, currentState, currentColorType); + } + } + + @SuppressWarnings( { "nls", "boxing" }) + private void processProperyElement(Attributes attrs) throws SAXException { + + String propertyType = attrs.getValue("type"); + String keyAttr = attrs.getValue("key"); + + if ("idref".equals(propertyType) || propertyType == null) { + + if ((keyAttr.endsWith("icon")) || (keyAttr.endsWith("Icon"))) { + // Markup that it is icon property is XMLSynthKey.info array + // length + namedReferenses.put(new XMLSynthKey(PROPERTY_ELEMENT, + currentState, attrs.getValue("value"), new String[] { + keyAttr, "" }), currentStyle); + } else { + namedReferenses.put(new XMLSynthKey(PROPERTY_ELEMENT, + currentState, attrs.getValue("value"), keyAttr), + currentStyle); + } + + } else if ("boolean".equalsIgnoreCase(propertyType)) { + + currentStyle.setProperty(keyAttr, new Boolean(attrs + .getValue("value"))); + + } else if ("dimension".equalsIgnoreCase(propertyType)) { + + String size = attrs.getValue("value"); + int witdth = Integer.parseInt(size.substring(0, size.indexOf(" "))); + int height = Integer + .parseInt(size.substring(size.indexOf(" ") + 1)); + + currentStyle.setProperty(keyAttr, new Dimension(witdth, height)); + + } else if ("insets".equalsIgnoreCase(propertyType)) { + + currentStyle.setProperty(keyAttr, getInsetsFromString(attrs + .getValue("value"))); + + } else if ("integer".equalsIgnoreCase(propertyType)) { + + currentStyle.setProperty(keyAttr, Integer.parseInt(attrs + .getValue("value"))); + + } else { + throw new SAXException(Messages.getString("swing.err.1F", + propertyType)); + } + } + + @SuppressWarnings( { "nls", "boxing" }) + private void processDefaultsProperyElement(Attributes attrs) + throws SAXException { + + String propertyType = attrs.getValue("type"); + + if ("idref".equals(propertyType) || propertyType == null) { + namedReferenses.put(new XMLSynthKey(DEFAULTS_ELEMENT, currentState, + attrs.getValue("value"), attrs.getValue("key")), + currentStyle); + + } else if ("boolean".equalsIgnoreCase(propertyType)) { + + UIManager.put(attrs.getValue("key"), new Boolean(attrs + .getValue("value"))); + + } else if ("dimension".equalsIgnoreCase(propertyType)) { + + String size = attrs.getValue("value"); + int witdth = Integer.parseInt(size.substring(0, size.indexOf(" "))); + int height = Integer + .parseInt(size.substring(size.indexOf(" ") + 1)); + + UIManager.put(attrs.getValue("key"), new Dimension(witdth, height)); + + } else if ("insets".equalsIgnoreCase(propertyType)) { + + UIManager.put(attrs.getValue("key"), getInsetsFromString(attrs + .getValue("value"))); + + } else if ("integer".equalsIgnoreCase(propertyType)) { + + UIManager.put(attrs.getValue("key"), Integer.parseInt(attrs + .getValue("value"))); + + } else { + throw new SAXException(Messages.getString("swing.err.1F", + propertyType)); + } + } + + @SuppressWarnings("nls") + private void processBindElemant(Attributes attrs) throws SAXException { + /* + * This method works with previously defined in parsed xml SynthStyles. + * It's compatible with RI. + */ + String bindType = attrs.getValue("type"); + + if ("region".equalsIgnoreCase(bindType)) { + styleFactory.putStyle(bindType, attrs.getValue("key"), + (XMLSynthStyle) namedElements.get(attrs.getValue("style"))); + } else if ("name".equalsIgnoreCase(bindType)) { + styleFactory.putStyle(bindType, attrs.getValue("key"), + (XMLSynthStyle) namedElements.get(attrs.getValue("style"))); + } else { + throw new SAXException(Messages.getString("swing.err.22", bindType, + attrs.getValue("style"))); + } + } + + private void processImagePainterElement(Attributes attrs) + throws SAXException { + + String sourceInsetsAttr = attrs.getValue("sourceInsets"); //$NON-NLS-1$ + String pathAttr = attrs.getValue("path"); //$NON-NLS-1$ + String destinationInsetsAttr = attrs.getValue("destinationInsets"); //$NON-NLS-1$ + String methodAttr = attrs.getValue("method").toLowerCase(); //$NON-NLS-1$ + String directionAttr = attrs.getValue("direction"); //$NON-NLS-1$ + String idAttr = attrs.getValue("id"); //$NON-NLS-1$ + + boolean paintCenter = "false".equalsIgnoreCase(attrs //$NON-NLS-1$ + .getValue("paintCenter")) ? false : true; //$NON-NLS-1$ + boolean stretch = "false".equalsIgnoreCase(attrs.getValue("stretch")) ? false : true; //$NON-NLS-1$ //$NON-NLS-2$ + + Insets sourseInsets; + + // Compute SourceInsets + if (sourceInsetsAttr != null && pathAttr != null) { + sourseInsets = getInsetsFromString(sourceInsetsAttr); + } else { + throw new SAXException(Messages.getString("swing.err.23")); //$NON-NLS-1$ + } + + // Compute Direction. + int direction = PaintersManager.NO_DIRECTION; + if (directionAttr != null) { + try { + direction = Directions.valueOf(directionAttr.toUpperCase()).direction; + } catch (IllegalArgumentException e) { + throw new SAXException(Messages.getString("swing.err.20") //$NON-NLS-1$ + + directionAttr, e); + } + } + + Insets destinationInsets = destinationInsetsAttr == null ? sourseInsets + : getInsetsFromString(destinationInsetsAttr); + + ImagePainter currentPainer; + try { + currentPainer = new ImagePainter(pathAttr, sourseInsets, + destinationInsets, paintCenter, stretch, base); + + if (idAttr != null) { + namedElements.put(idAttr, currentPainer); + } + if (currentStyle != null) { + if (methodAttr == null) { + currentStyle.addPainter(currentPainer, currentState, + "default", direction); //$NON-NLS-1$ + } else { + + if ((methodAttr.contains("border"))) { //$NON-NLS-1$ + currentStyle.setProperty( + getBorgerPaintedPropertyKey(methodAttr), + Boolean.TRUE); + } + currentStyle.addPainter(currentPainer, currentState, + methodAttr, direction); + } + } + + } catch (IOException e) { + // Exception trows in ImageIo.read method and all the comments are + // in e stack + throw new SAXException(e); + } + } + + @SuppressWarnings("nls") + private void processPainterElement(Attributes attrs) { + String method = attrs.getValue("method").toLowerCase(); + + if ((method != null) && (method.contains("border"))) { + currentStyle.setProperty(getBorgerPaintedPropertyKey(method), + Boolean.TRUE); + + } + + namedReferenses.put(new XMLSynthKey(PAINTER_ELEMENT, currentState, + attrs.getValue("idref"), new String[] { method, + attrs.getValue("direction") }), currentStyle); + } + + /** + * The name of the method used as a key to let an UI know is paint border or + * not + */ + static String getBorgerPaintedPropertyKey(String method) { + return "Synth" + method; //$NON-NLS-1$ + } + + @SuppressWarnings("nls") + private void processIconElement(Attributes attrs) { + URL imageURL = base.getResource(attrs.getValue("path")); + namedElements.put(attrs.getValue("id"), new ImageIcon(imageURL)); + } + + private void processOpaqueElement(Attributes attrs) { + currentStyle.setOpaque(Boolean.parseBoolean(attrs.getValue("value"))); //$NON-NLS-1$ + } + + private void processInsetsElement(Attributes attrs) throws SAXException { + + String idref = attrs.getValue("idref"); //$NON-NLS-1$ + if (idref != null) { + namedReferenses.put(new XMLSynthKey( + "insets", currentState, idref, new String[0]), //$NON-NLS-1$ + currentStyle); + return; + } + + try { + + Insets insets = new Insets(0, 0, 0, 0); + String top = attrs.getValue("top"); //$NON-NLS-1$ + String bottom = attrs.getValue("bottom"); //$NON-NLS-1$ + String left = attrs.getValue("left"); //$NON-NLS-1$ + String right = attrs.getValue("right"); //$NON-NLS-1$ + if (top != null) { + insets.top = Integer.parseInt(top); + } + if (bottom != null) { + + insets.bottom = Integer.parseInt(bottom); + } + if (left != null) { + + insets.left = Integer.parseInt(left); + } + if (right != null) { + + insets.right = Integer.parseInt(right); + } + + currentStyle.setInsets(insets); + String id = attrs.getValue("id"); //$NON-NLS-1$ + + if (id != null) { + + namedElements.put(id, insets); + } + + } catch (NumberFormatException e) { + + throw new SAXException(e); + } + } + + @SuppressWarnings("nls") + private Insets getInsetsFromString(String source) { + + int top = Integer.parseInt(source.substring(0, source.indexOf(" "))); + source = source.substring(source.indexOf(" ") + 1); + int bottom = Integer.parseInt(source.substring(0, source.indexOf(" "))); + source = source.substring(source.indexOf(" ") + 1); + int left = Integer.parseInt(source.substring(0, source.indexOf(" "))); + source = source.substring(source.indexOf(" ") + 1); + int right = Integer.parseInt(source.substring(source.indexOf(" ") + 1)); + + return new Insets(top, left, bottom, right); + } + + /** + * GraphicsUtils that can be obtained according to beansAdapter only. + */ + private void processGraphicsUtilsElement(Attributes attrs) { + + namedReferenses.put(new XMLSynthKey(G_UTILS_ELEMENT, currentState, + attrs.getValue("idref"), new String[0]), currentStyle); //$NON-NLS-1$ + } + + private int computeStateValue(String stateName) throws SAXException { + + if (stateName == null) { + + return DEFAULT_STATE; + + } else if ("ENABLED".equals(stateName)) { //$NON-NLS-1$ + + return SynthConstants.ENABLED; + + } else if ("DISABLED".equals(stateName)) { //$NON-NLS-1$ + + return SynthConstants.DISABLED; + + } else if ("MOUSE_OVER".equals(stateName)) { //$NON-NLS-1$ + + return SynthConstants.MOUSE_OVER; + + } else if ("PRESSED".equals(stateName)) { //$NON-NLS-1$ + + return SynthConstants.PRESSED; + + } else if ("DEFAULT".equals(stateName)) { //$NON-NLS-1$ + + return SynthConstants.DEFAULT; + + } else if ("FOCUSED".equals(stateName)) { //$NON-NLS-1$ + + return SynthConstants.FOCUSED; + + } else if ("SELECTED".equals(stateName)) { //$NON-NLS-1$ + + return SynthConstants.SELECTED; + } + + int indexOfAND = stateName.indexOf(" AND "); //$NON-NLS-1$ + + if (indexOfAND != -1) { + + return computeStateValue(stateName.substring(0, indexOfAND)) + + computeStateValue(stateName.substring(indexOfAND + 5)); + + } + + throw new SAXException(Messages.getString("swing.err.21", stateName)); //$NON-NLS-1$ + } + + /** + * Beans adapter processing the unknown elements and obtains objects from + * elements known to beansAdapter. All the obtained objects should be added + * to namedElements map (parser do it in endDocument() method) + */ + private static class BeansAdapter { + + private final String lsp = System.getProperty("line.separator"); //$NON-NLS-1$ + + private final StringBuffer xmlLine = new StringBuffer(); + + private final List idList = new LinkedList(); + + /** + * The nesting depth of xml tags + */ + private int validatingCounter = 0; + + @SuppressWarnings("nls") + public BeansAdapter() { + xmlLine.append(""); + xmlLine.append(lsp); + xmlLine.append(""); + xmlLine.append(lsp); + } + + @SuppressWarnings("nls") + public void pushStartTag(String element, Attributes attrs) { + + String id = attrs.getValue("id"); + + if (id != null && validatingCounter == 0) { + idList.add(id); + } + + xmlLine.append("<"); + xmlLine.append(element); + + for (int i = 0; i < attrs.getLength(); i++) { + String localName = attrs.getLocalName(i); + xmlLine.append(" "); + xmlLine.append(("".equals(localName)) ? attrs.getQName(i) + : localName); + xmlLine.append("=\""); + xmlLine.append(attrs.getValue(i)); + xmlLine.append("\" "); + } + + xmlLine.append(">"); + xmlLine.append(lsp); + + validatingCounter++; + + } + + public void pushCharactres(char[] ch, int start, int end) { + + if (validatingCounter > 0) { + xmlLine.append(ch, start, end); + } + + } + + @SuppressWarnings("nls") + public void pushEndTag(String element) { + + xmlLine.append(""); + xmlLine.append(lsp); + + validatingCounter--; + } + + private XMLDecoder createDecoder() { + xmlLine.append(""); //$NON-NLS-1$ + return new XMLDecoder(new ByteArrayInputStream(xmlLine.toString() + .getBytes())); + } + + public void putAdaptedBeansToMap(Map elementsMap) { + XMLDecoder d = createDecoder(); + for (String id : idList) { + elementsMap.put(id, d.readObject()); + } + d.close(); + + } + } + + /** + * This class is used to represent correct keys in namedReferenses table + * which helps to unambiguously insert named element instead of reference in + * the concluding stage of parsing + */ + private static class XMLSynthKey { + + /** + * This field represents the name of element to refer. By convention (in + * this class) the type defines the additional info needed (i.e. the + * Color element needed in colorType info and stateID, Insets element + * not needed in info at all, etc) + */ + private final String elementName; + + /** + * This field represents the key to find in the namedElements table + * (idref in xml file) + */ + private final String reference; + + /** + * This field provides information about concerned Objects necessary to + * correct insertion to style (such as ColorType, method attribute for + * painters etc) + */ + private final String[] info; + + /** + * StateID is also additional info, but because it is integer it taken + * out from info array for performance reasons + */ + private final int stateID; + + XMLSynthKey(String elementName, int stateID, String reference, + String[] info) { + this.elementName = elementName; + this.reference = reference; + this.info = info; + this.stateID = stateID; + } + + XMLSynthKey(String type, int stateID, String reference, String info) { + this.elementName = type; + this.reference = reference; + this.info = new String[] { info }; + this.stateID = stateID; + } + + String getElementName() { + return elementName; + } + + String getReference() { + return reference; + } + + String[] getAllInfo() { + return info; + } + + int getState() { + return stateID; + } + + /** + * This method used if info array contains one element + * + * @return the first element in the info array + */ + String getFirstInfo() { + return info != null ? info[0] : null; + } + + @Override + public boolean equals(Object key) { + + XMLSynthKey _key = (XMLSynthKey) key; + boolean result; + result = (_key.elementName == null) ? (this.elementName == null) + : _key.elementName.equals(this.elementName); + result &= (this.stateID == _key.stateID); + result &= (_key.reference == null) ? this.reference == null + : _key.reference.equals(this.reference); + result &= Arrays.equals(_key.info, this.info); + + return result; + } + + @Override + public int hashCode() { + return elementName.hashCode() + reference.hashCode() + + info.hashCode(); + } + } + +} \ No newline at end of file Index: src/main/java/common/javax/swing/plaf/synth/ImagePainter.java =================================================================== --- src/main/java/common/javax/swing/plaf/synth/ImagePainter.java (revision 0) +++ src/main/java/common/javax/swing/plaf/synth/ImagePainter.java (revision 0) @@ -0,0 +1,1061 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package javax.swing.plaf.synth; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.geom.AffineTransform; +import java.awt.image.AffineTransformOp; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; +import javax.swing.JComponent; +import javax.swing.plaf.synth2.SynthContext; +import javax.swing.plaf.synth2.SynthPainter; + +import org.apache.harmony.x.swing.internal.nls.Messages; +import org.xml.sax.SAXException; + +class ImagePainter extends SynthPainter { + + /** + * The array of images: parts of cropped source image + */ + private BufferedImage[][] imageParts = new BufferedImage[3][3]; + + /** + * Below are painter parameters + */ + private final Insets destinationInsets; + + private final boolean paintCenter; + + private final boolean stretch; + + /** + * Below are private image parameters. Used in cropImage and paintImage + * methods only + */ + private int imageWidth; + + private int imageHeight; + + private int imageInsetsTop; + + private int imageInsetsLeft; + + private int imageInsetsRight; + + private int imageInsetsBottom; + + /** + * XMLImagePainter is single for every image and parameters. i.e. for 2 + * images (the same image but different painting parameters) there are 2 + * ImagePainters + */ + ImagePainter(String path, Insets sourceInsets, Insets destinationInsets, + boolean paintCenter, boolean stretch, Class base) + throws IOException, SAXException { + + String imagePath = base.getResource(path).getPath(); + + if ((imagePath == null) || (sourceInsets == null)) { + throw new SAXException(Messages.getString("swing.err.23")); //$NON-NLS-1$ + } + + this.destinationInsets = destinationInsets; + this.stretch = stretch; + this.paintCenter = paintCenter; + + cropImage(ImageIO.read(new File(imagePath)), sourceInsets); + } + + /** + * Cropped image according sourceInsets and place the cuts into imageParts + * array + * + * @param input + * image to crop + * @param cropping + * parameters + */ + private void cropImage(BufferedImage input, Insets insets) { + + /* Define image parameters */ + imageWidth = input.getWidth(); + imageHeight = input.getHeight(); + imageInsetsTop = insets.top; + imageInsetsLeft = insets.left; + imageInsetsRight = insets.right; + imageInsetsBottom = insets.bottom; + + if ((imageHeight < (imageInsetsTop + imageInsetsBottom)) + || (imageWidth < (imageInsetsLeft + imageInsetsRight))) { + return; + } + + /* Crop image into array of images */ + if ((imageInsetsTop > 0)) { + + if (imageInsetsLeft >= 0) + + imageParts[0][1] = input.getSubimage(imageInsetsLeft, 0, + imageWidth - imageInsetsRight - imageInsetsLeft, + imageInsetsTop); + + if (imageInsetsLeft > 0) { + + imageParts[0][0] = input.getSubimage(0, 0, imageInsetsLeft, + imageInsetsTop); + } + if ((imageInsetsRight > 0) && (imageWidth >= imageInsetsRight)) { + + imageParts[0][2] = input + .getSubimage(imageWidth - imageInsetsRight, 0, + imageInsetsRight, imageInsetsTop); + } + } + + if ((imageInsetsLeft > 0) && (imageInsetsTop >= 0)) { + + imageParts[1][0] = input.getSubimage(0, imageInsetsTop, + imageInsetsLeft, imageHeight - imageInsetsTop + - imageInsetsBottom); + + } + + if (paintCenter && (imageInsetsLeft >= 0) && (imageInsetsTop >= 0)) { + + imageParts[1][1] = input.getSubimage(imageInsetsLeft, + imageInsetsTop, imageWidth - imageInsetsLeft + - imageInsetsRight, imageHeight - imageInsetsTop + - imageInsetsBottom); + } + + if ((imageInsetsRight > 0) && (imageWidth >= imageInsetsRight) + && (imageInsetsTop >= 0)) { + + imageParts[1][2] = input.getSubimage(imageWidth - imageInsetsRight, + imageInsetsTop, imageInsetsRight, imageHeight + - imageInsetsTop - imageInsetsBottom); + } + if ((imageInsetsBottom > 0)) { + + if ((imageInsetsLeft >= 0) && (imageHeight >= imageInsetsBottom)) { + + imageParts[2][1] = input.getSubimage(imageInsetsLeft, + imageHeight - imageInsetsBottom, imageWidth + - imageInsetsRight - imageInsetsLeft, + imageInsetsBottom); + } + + if ((imageInsetsLeft > 0) && (imageHeight >= imageInsetsBottom)) { + + imageParts[2][0] = input + .getSubimage(0, imageHeight - imageInsetsBottom, + imageInsetsLeft, imageInsetsBottom); + } + + if ((imageInsetsRight > 0) && (imageWidth > imageInsetsRight) + && (imageHeight > imageInsetsBottom)) { + + imageParts[2][2] = input.getSubimage(imageWidth + - imageInsetsRight, imageHeight - imageInsetsBottom, + imageInsetsRight, imageInsetsBottom); + } + } + } + + /** + * Paints the image cropped by cropImage method into array of images + * according specified parameters, defined in constructor:
+ *
+ * paintCenter - should center of image painted
+ * stretch - either stretch or tile side parts of image
+ * destinationInsets - size of side and corner tiles
+ *
+ * Note: a,b - affineTransform coefficients: x(draw)=a*x(image) + * y(draw)=b*y(image) + */ + @SuppressWarnings("unused") + private void paintImage(SynthContext context, Graphics g, int x, int y, + int w, int h) { + + // affineTransform coefficients + double a; + double b; + + // destinationInsets - size of side and corner tiles. Defined to + // simplify readability + int insetsTop = destinationInsets.top; + int insetsLeft = destinationInsets.left; + int insetsRight = destinationInsets.right; + int insetsBottom = destinationInsets.bottom; + + // Define tiling parameters + int sourceWidth = imageWidth - imageInsetsLeft - imageInsetsRight; + int destWidth = w - insetsLeft - insetsRight; + int fullHorisontalPaintsNum = (int) Math.ceil(destWidth / sourceWidth); + int sourceHeight = imageHeight - imageInsetsBottom - imageInsetsTop; + int destHeight = h - insetsTop - insetsBottom; + int fullVerticalPaintsNum = (int) Math.ceil(destHeight / sourceHeight); + + // Define synth parameters + // JComponent c = context.getComponent(); + // Color color = context.getStyle() + // .getColor(context, ColorType.BACKGROUND); + JComponent c = null; + Color color = Color.RED; + + if ((insetsTop > 0)) { + + if ((insetsLeft > 0) && (imageParts[0][0] != null)) { + + g.drawImage(imageParts[0][0], x, y, insetsLeft, insetsTop, + color, c); + + } + + if ((w > insetsLeft - insetsRight) && (imageParts[0][1] != null) + && (insetsLeft >= 0)) { + + if (stretch) { + g.drawImage(imageParts[0][1], x + insetsLeft, y, w + - insetsLeft - insetsRight, insetsTop, c); + + } else { + + // Stretch the image horizontally + b = (double) (insetsTop) / (double) (imageInsetsTop); + BufferedImage result = new AffineTransformOp( + new AffineTransform(1, 0, 0, b, 0, 0), + AffineTransformOp.TYPE_BICUBIC).filter( + imageParts[0][1], null); + + // Draw multiple number of images + for (int i = 0; i < fullHorisontalPaintsNum + 1; i++) { + g.drawImage(result, x + insetsLeft + i * sourceWidth, + y, color, c); + } + + } + } + + if ((insetsRight > 0) && (imageParts[0][2] != null) + && (w >= insetsRight)) { + + g.drawImage(imageParts[0][2], x + w - insetsRight, y, + insetsRight, insetsTop, color, c); + } + } + + if ((insetsLeft > 0) && (imageParts[1][0] != null) && (insetsTop >= 0) + && (h > insetsTop + insetsBottom)) { + + if (stretch) { + + g.drawImage(imageParts[1][0], x, y + insetsTop, insetsLeft, h + - insetsTop - insetsBottom, color, c); + } else { + + // Stretch the image vertically + a = (double) (insetsRight) / (double) (imageInsetsRight); + BufferedImage result = new AffineTransformOp( + new AffineTransform(a, 0, 0, 1, 0, 0), + AffineTransformOp.TYPE_BICUBIC).filter( + imageParts[1][0], null); + + // draw multiple number of pictures + for (int i = 0; i < fullVerticalPaintsNum + 1; i++) { + g.drawImage(result, x, y + i * sourceHeight + insetsTop, + color, c); + } + + } + } + + if (paintCenter && (imageParts[1][1] != null) + && (w > insetsLeft + insetsRight) + && (h > insetsBottom + insetsTop)) { + + g.drawImage(imageParts[1][1], x + insetsLeft, y + insetsTop, w + - insetsLeft - insetsRight, h - insetsTop - insetsBottom, + color, c); + + } + + if ((insetsRight > 0) && (imageParts[1][2] != null) + && (h > insetsBottom + insetsTop) && (w >= insetsRight) + && (insetsTop >= 0)) { + + if (stretch) { + + g.drawImage(imageParts[1][2], x + w - insetsRight, y + + insetsTop, insetsRight, h - insetsTop - insetsBottom, + color, c); + } else { + + // Stretch the image vertically + a = (double) (insetsRight) / (double) (imageInsetsRight); + BufferedImage result = new AffineTransformOp( + new AffineTransform(a, 0, 0, 1, 0, 0), + AffineTransformOp.TYPE_BICUBIC).filter( + imageParts[1][2], null); + + // draw multiple number of pictures + for (int i = 0; i < fullVerticalPaintsNum + 1; i++) { + g.drawImage(result, x + w - insetsRight, y + i + * sourceHeight + insetsTop, color, c); + } + + } + } + + if ((insetsBottom > 0)) { + + if ((insetsLeft >= 0) && (h >= insetsBottom) + && (w > insetsRight + insetsLeft) + && (imageParts[2][0] != null)) { + + g.drawImage(imageParts[2][0], x, y + h - insetsBottom, + insetsLeft, insetsBottom, color, c); + + } + + if ((imageParts[2][1] != null) && (imageInsetsBottom > 0) + && (w > insetsRight + insetsLeft) && (insetsBottom > 0) + && (insetsLeft >= 0) && (h >= insetsBottom)) { + + if (stretch) { + + g.drawImage(imageParts[2][1], x + insetsLeft, y + h + - insetsBottom, w - insetsRight - insetsLeft, + insetsBottom, color, c); + } else { + + // Stretch the image horizontally + b = (double) (insetsBottom) / (double) (imageInsetsBottom); + BufferedImage result = new AffineTransformOp( + new AffineTransform(1, 0, 0, b, 0, 0), + AffineTransformOp.TYPE_BICUBIC).filter( + imageParts[2][1], null); + + // draw multiple number of pictures + for (int i = 0; i < fullHorisontalPaintsNum + 1; i++) { + g.drawImage(result, x + insetsLeft + i * sourceWidth, y + + h - insetsBottom, color, c); + } + + } + + } + + if ((insetsRight > 0) && (imageParts[2][2] != null) + && (insetsBottom > 0) && (w >= insetsRight) + && (h >= insetsBottom) && (imageInsetsBottom > 0)) { + + g.drawImage(imageParts[2][2], x + w - insetsRight, y + h + - insetsBottom, insetsRight, insetsBottom, color, c); + + } + } + + } + + @Override + public void paintArrowButtonBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintArrowButtonBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintArrowButtonForeground(SynthContext context, Graphics g, + int x, int y, int w, int h, int direction) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintButtonBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintButtonBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintCheckBoxBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintCheckBoxBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintCheckBoxMenuItemBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintCheckBoxMenuItemBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintColorChooserBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintColorChooserBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintComboBoxBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintComboBoxBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintDesktopIconBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintDesktopIconBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintDesktopPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintDesktopPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintEditorPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintEditorPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintFileChooserBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintFileChooserBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintFormattedTextFieldBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintFormattedTextFieldBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintInternalFrameBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintInternalFrameBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintInternalFrameTitlePaneBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintInternalFrameTitlePaneBorder(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintLabelBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + g.setColor(Color.RED); + g.fillRect(x, y, x + w, y + h); + } + + @Override + public void paintLabelBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintListBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintListBorder(SynthContext context, Graphics g, int x, int y, + int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintMenuBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintMenuBarBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintMenuBarBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintMenuBorder(SynthContext context, Graphics g, int x, int y, + int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintMenuItemBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintMenuItemBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintOptionPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintOptionPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintPanelBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintPanelBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintPasswordFieldBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintPasswordFieldBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintPopupMenuBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintPopupMenuBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintProgressBarBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintProgressBarBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintProgressBarForeground(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintRadioButtonBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintRadioButtonBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintRadioButtonMenuItemBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintRadioButtonMenuItemBorder(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintRootPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintRootPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintScrollBarBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintScrollBarBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintScrollBarThumbBackground(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintScrollBarThumbBorder(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintScrollBarTrackBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintScrollBarTrackBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintScrollPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintScrollPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSeparatorBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSeparatorBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSeparatorForeground(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSliderBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSliderBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSliderThumbBackground(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSliderThumbBorder(SynthContext context, Graphics g, int x, + int y, int w, int h, int orientation) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSliderTrackBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSliderTrackBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSpinnerBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSpinnerBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSplitPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSplitPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSplitPaneDividerBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSplitPaneDividerForeground(SynthContext context, + Graphics g, int x, int y, int w, int h, int orientation) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintSplitPaneDragDivider(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneContentBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneContentBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneTabAreaBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneTabAreaBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, + int x, int y, int w, int h, int tabIndex) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneTabBorder(SynthContext context, Graphics g, + int x, int y, int w, int h, int tabIndex) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTableBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTableBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTableHeaderBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTableHeaderBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTextAreaBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTextAreaBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTextFieldBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTextFieldBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTextPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTextPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintToggleButtonBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintToggleButtonBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintToolBarBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintToolBarBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintToolBarContentBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintToolBarContentBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintToolBarDragWindowBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintToolBarDragWindowBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintToolTipBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintToolTipBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTreeBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTreeBorder(SynthContext context, Graphics g, int x, int y, + int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTreeCellBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTreeCellBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintTreeCellFocus(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintViewportBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } + + @Override + public void paintViewportBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + paintImage(context, g, x, y, w, h); + } +} Index: src/main/java/common/javax/swing/plaf/synth/XMLSynthStyle.java =================================================================== --- src/main/java/common/javax/swing/plaf/synth/XMLSynthStyle.java (revision 0) +++ src/main/java/common/javax/swing/plaf/synth/XMLSynthStyle.java (revision 0) @@ -0,0 +1,343 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package javax.swing.plaf.synth; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Insets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import javax.swing.Icon; +import javax.swing.plaf.synth2.ColorType; +import javax.swing.plaf.synth2.SynthContext; +import javax.swing.plaf.synth2.SynthGraphicsUtils; +import javax.swing.plaf.synth2.SynthPainter; +import javax.swing.plaf.synth2.SynthStyle; + +/** + * XMLSynthStyle class represents SynthStyle, generated from XMLSynthParser. The + * setters used in parser to configure style. The getters used in UI to draw the + * component. + */ +class XMLSynthStyle extends SynthStyle implements Cloneable { + + /** + * Style properties + */ + private final HashMap propertiesMap = new HashMap(); + + /** + * Painters manager defines the correct painter to draw the UI under the + * style + */ + private final PaintersManager paintersManager = new PaintersManager(); + + /** + * Insets used in UI under the style + */ + private Insets insets = new Insets(0, 0, 0, 0); + + /** + * GraphicsUtils used in UI + */ + private SynthGraphicsUtils gUtils = new SynthGraphicsUtils(); + + /** + * isOpaque property for UI (used in painters) + */ + private boolean isOpaque = false; + + /** + * FontInfo contains all the registered fonts + */ + private List fonts = new ArrayList(); + + /** + * contains all the registered icons + */ + private List icons = new ArrayList(); + + /** + * ColorInfo contains all the registered colors according to ColorTypes + */ + private List colors = new ArrayList(); + + @Override + public Object get(@SuppressWarnings("unused") + SynthContext context, Object key) { + return propertiesMap.get(key); + } + + /** + * According to spec, graphicsUitils stated for style - not for context. + * That's why context is unused. + */ + @Override + @SuppressWarnings("unused") + public SynthGraphicsUtils getGraphicsUtils(SynthContext context) { + return gUtils; + } + + @Override + public Insets getInsets(SynthContext context, Insets modified) { + + if (modified == null) { + + return (Insets) this.insets.clone(); + } + + modified.set(insets.top, insets.left, insets.bottom, insets.right); + + return modified; + } + + @Override + @SuppressWarnings("unused") + public SynthPainter getPainter(SynthContext context) { + return paintersManager; + } + + @Override + @SuppressWarnings("unused") + public boolean isOpaque(SynthContext context) { + return isOpaque; + } + + @Override + public Icon getIcon(SynthContext context, Object key) { + Icon result = null; + + int resultState = 0; + int componentState = context.getComponentState(); + for (IconInfo info : icons) { + if (info.getKey().equalsIgnoreCase((String) key)) { + if (info.isStateFits(componentState)) { + if ((result == null) || info.getState() >= resultState) { + + resultState = info.getState(); + result = info.getIcon(); + + } + } + } + } + return result; + } + + @Override + protected Font getFontForState(SynthContext context) { + Font result = null; + int resultState = 0; + int componentState = context.getComponentState(); + for (FontInfo info : fonts) { + if (info.isStateFits(componentState)) { + if ((result == null) || (info.getState() >= resultState)) { + resultState = info.getState(); + result = info.getFont(); + } + } + } + return result; + } + + /** + * Should note that RI's behavior depends on the order, described in the xml + * file (for example either state=ENABLED before state=FOCUSED or after) and + * the (unspecified) order of UI's state verification (for example, + * if(ButtonModel.isFocused) before Button.isEnabled in SynthButtonUI). + * + * I've construct the getColorForState, getFontForState and + * PainterManager.findPainter methods according to the RI's black box + * testing (although, the RI's behavior seems incorrect for me) + * + * Anyway, if you will to deal with using coloring, fonts or painters order + * you should see the following: UI: getComponentState method, + * XMLSynthParser: processColorElement, processFontElement, + * processPainterElement, processImagePainterElement (generating the lists), + * PainterManager(for painters) and this class + */ + @Override + protected Color getColorForState(SynthContext context, ColorType type) { + Color result = null; + int resultState = 0; + int componentState = context.getComponentState(); + for (ColorInfo info : colors) { + if (info.getColorType() == type) { + if (info.isStateFits(componentState)) { + if ((result == null) || componentState > resultState) { + + resultState = info.getState(); + result = info.getColor(); + + } + } + } + } + return result; + } + + @Override + protected Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + /** Method used in parser only */ + void addFont(Font f, int state) { + fonts.add(new FontInfo(f, state)); + } + + /** Method used in parser only */ + void addColor(Color c, int state, ColorType type) { + colors.add(new ColorInfo(c, type, state)); + } + + /** + * add painter to paintersManager. Method used in parser only + */ + void addPainter(SynthPainter p, int state, String method, int direction) { + paintersManager.setPainter(p, state, method, direction); + } + + void addIcon(Icon icon, int SynthState, String key) { + icons.add(new IconInfo(icon, SynthState, key)); + } + + /** + * Method used in parser only + */ + void setGraphicsUtils(SynthGraphicsUtils proposed) { + this.gUtils = proposed; + } + + /** Method used in parser only */ + void setProperty(String key, Object value) { + propertiesMap.put(key, value); + } + + /** Method used in parser only */ + void setInsets(Insets insets) { + this.insets = insets; + } + + /** Method used in parser only */ + void setOpaque(boolean isOpaque) { + this.isOpaque = isOpaque; + } + + /** + * ColorInfo class used in SynthStyle for correct search Colors in List of + * colors. + */ + private static class ColorInfo { + + private final ColorType type; + + private final int state; + + private final Color color; + + ColorInfo(Color color, ColorType type, int state) { + this.color = color; + this.type = type; + this.state = state; + } + + ColorType getColorType() { + return type; + } + + Color getColor() { + return color; + } + + int getState() { + return state; + } + + boolean isStateFits(int comparedState) { + return (((~comparedState) & (this.state)) == 0); + } + + } + + /** + * ColorInfo class used in SynthStyle for correct search Fonts in List + */ + private static class FontInfo { + + private final int state; + + private final Font font; + + FontInfo(Font font, int state) { + this.font = font; + this.state = state; + } + + Font getFont() { + return font; + } + + int getState() { + return state; + } + + boolean isStateFits(int comparedState) { + return (((~comparedState) & (this.state)) == 0); + } + + } + + /** + * IconInfo class used in SynthStyle for correct search Icons in List + */ + private static class IconInfo { + + private final int state; + + private final Icon icon; + + private final String key; + + IconInfo(Icon icon, int state, String key) { + this.icon = icon; + this.state = state; + this.key = key; + } + + Icon getIcon() { + return icon; + } + + int getState() { + return state; + } + + String getKey() { + return key; + } + + boolean isStateFits(int comparedState) { + return (((~comparedState) & (this.state)) == 0); + } + + } + +} \ No newline at end of file Index: src/main/java/common/javax/swing/plaf/synth/PaintersManager.java =================================================================== --- src/main/java/common/javax/swing/plaf/synth/PaintersManager.java (revision 0) +++ src/main/java/common/javax/swing/plaf/synth/PaintersManager.java (revision 0) @@ -0,0 +1,1044 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package javax.swing.plaf.synth; + +import java.awt.Graphics; +import java.util.LinkedList; +import java.util.List; + +import javax.swing.plaf.synth2.SynthContext; +import javax.swing.plaf.synth2.SynthPainter; + +/** + * PaintersManager is a SynthPainter used to combine all the painters described + * in XML file. This class is similar to ColorInfo and FontInfo (inner classes + * in XMLSynthStyle) but placed separately because contains a lot of methods and + * the functionality is differs from just "info" functionality + */ +@SuppressWarnings("nls") +class PaintersManager extends SynthPainter { + + public static final int NO_DIRECTION = -1; + + /** + * PainterInfo for the search. + */ + private static class SynthPainterInfo { + + private final String method; + + private final int direction; + + private final int state; + + private final SynthPainter painter; + + SynthPainterInfo(String method, int direction, int state, + SynthPainter painter) { + this.method = method; + this.direction = direction; + this.state = state; + this.painter = painter; + } + + String getMethod() { + return method; + } + + int getDirection() { + return direction; + } + + int getState() { + return state; + } + + SynthPainter getPainter() { + return painter; + } + + boolean betterThan(SynthPainterInfo candidate, int refState, + String refMethod, int refDirection) { + + if (this.method.equalsIgnoreCase(refMethod) + || this.method.equals("default")) { + + if (stateBetterThan(candidate.getState(), refState)) { + if ((this.direction == refDirection) + || (this.direction == -1)) { + return true; + } + + } + + } + + return false; + } + + boolean stateBetterThan(int candidateState, int refState) { + if (((~refState) & (this.state)) == 0) { + if (((~refState) & (candidateState)) == 0) { + return refState >= candidateState; + } + return true; + } + return false; + } + } + + private final List painters = new LinkedList(); + + private final SynthPainterInfo firstCandidate = new SynthPainterInfo( + "default", -1, 0, new ColorPainter()); //$NON-NLS-1$ + + public SynthPainter findPainter(int state, String method, int direction) { + SynthPainterInfo bestCandidate = firstCandidate; + for (SynthPainterInfo candidate : painters) { + if (candidate.betterThan(bestCandidate, state, method, direction)) { + bestCandidate = candidate; + } + } + return bestCandidate.getPainter(); + } + + public void setPainter(SynthPainter painter, int state, String method, + int direction) { + painters.add(new SynthPainterInfo(method, direction, state, painter)); + } + + @Override + public void paintArrowButtonBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "ArrowButtonBorder", -1) + .paintArrowButtonBorder(context, g, x, y, w, h); + } + + @Override + public void paintArrowButtonForeground(SynthContext context, Graphics g, + int x, int y, int w, int h, int direction) { + + findPainter(context.getComponentState(), "ArrowButtonForeground", + direction).paintArrowButtonForeground(context, g, x, y, w, h, + direction); + + } + + @Override + public void paintButtonBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "ButtonBackground", -1) + .paintButtonBackground(context, g, x, y, w, h); + } + + @Override + public void paintButtonBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "ButtonBorder", -1) + .paintButtonBorder(context, g, x, y, w, h); + } + + @Override + public void paintCheckBoxBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "CheckBoxBackground", -1) + .paintCheckBoxBackground(context, g, x, y, w, h); + } + + @Override + public void paintCheckBoxBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "CheckBoxBorder", -1) + .paintCheckBoxBorder(context, g, x, y, w, h); + } + + @Override + public void paintCheckBoxMenuItemBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "CheckBoxMenuItemBackground", + -1).paintCheckBoxMenuItemBackground(context, g, x, y, w, h); + } + + @Override + public void paintCheckBoxMenuItemBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "CheckBoxMenuItemBorder", -1) + .paintCheckBoxMenuItemBorder(context, g, x, y, w, h); + } + + @Override + public void paintColorChooserBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "ColorChooserBackground", -1) + .paintColorChooserBackground(context, g, x, y, w, h); + } + + @Override + public void paintColorChooserBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "ColorChooserBorder", -1) + .paintColorChooserBorder(context, g, x, y, w, h); + } + + @Override + public void paintComboBoxBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "ComboBoxBackground", -1) + .paintComboBoxBackground(context, g, x, y, w, h); + } + + @Override + public void paintComboBoxBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "ComboBoxBorder", -1) + .paintComboBoxBorder(context, g, x, y, w, h); + } + + @Override + public void paintDesktopIconBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "DesktopIconBackground", -1) + .paintDesktopIconBackground(context, g, x, y, w, h); + } + + @Override + public void paintDesktopIconBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "DesktopIconBorder", -1) + .paintDesktopIconBorder(context, g, x, y, w, h); + } + + @Override + public void paintDesktopPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "DesktopPaneBackground", -1) + .paintDesktopPaneBackground(context, g, x, y, w, h); + } + + @Override + public void paintDesktopPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "DesktopPaneBorder", -1) + .paintDesktopPaneBorder(context, g, x, y, w, h); + } + + @Override + public void paintEditorPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "EditorPaneBackground", -1) + .paintEditorPaneBackground(context, g, x, y, w, h); + } + + @Override + public void paintEditorPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "EditorPaneBorder", -1) + .paintEditorPaneBorder(context, g, x, y, w, h); + } + + @Override + public void paintFileChooserBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "FileChooserBackground", -1) + .paintFileChooserBackground(context, g, x, y, w, h); + } + + @Override + public void paintFileChooserBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "FileChooserBorder", -1) + .paintFileChooserBorder(context, g, x, y, w, h); + } + + @Override + public void paintFormattedTextFieldBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + + findPainter(context.getComponentState(), + "FormattedTextFieldBackground", -1) + .paintFormattedTextFieldBackground(context, g, x, y, w, h); + } + + @Override + public void paintFormattedTextFieldBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "FormattedTextFieldBorder", -1) + .paintFormattedTextFieldBorder(context, g, x, y, w, h); + } + + @Override + public void paintInternalFrameBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "InternalFrameBackground", -1) + .paintInternalFrameBackground(context, g, x, y, w, h); + } + + @Override + public void paintInternalFrameBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "InternalFrameBorder", -1) + .paintInternalFrameBorder(context, g, x, y, w, h); + } + + @Override + public void paintInternalFrameTitlePaneBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + + findPainter(context.getComponentState(), + "InternalFrameTitlePaneBackground", -1) + .paintInternalFrameTitlePaneBackground(context, g, x, y, w, h); + } + + @Override + public void paintInternalFrameTitlePaneBorder(SynthContext context, + Graphics g, int x, int y, int w, int h) { + + findPainter(context.getComponentState(), + "InternalFrameTitlePaneBorder", -1) + .paintInternalFrameTitlePaneBorder(context, g, x, y, w, h); + } + + @Override + public void paintLabelBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "LabelBackground", -1) + .paintLabelBackground(context, g, x, y, w, h); + } + + @Override + public void paintLabelBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "LabelBorder", -1) + .paintLabelBorder(context, g, x, y, w, h); + } + + @Override + public void paintListBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "ListBackground", -1) + .paintListBackground(context, g, x, y, w, h); + } + + @Override + public void paintListBorder(SynthContext context, Graphics g, int x, int y, + int w, int h) { + + findPainter(context.getComponentState(), "ListBorder", -1) + .paintListBorder(context, g, x, y, w, h); + } + + @Override + public void paintMenuBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "MenuBackground", -1) + .paintMenuBackground(context, g, x, y, w, h); + } + + @Override + public void paintMenuBarBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "MenuBarBackground", -1) + .paintMenuBarBackground(context, g, x, y, w, h); + } + + @Override + public void paintMenuBarBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "MenuBarBorder", -1) + .paintMenuBarBorder(context, g, x, y, w, h); + } + + @Override + public void paintMenuBorder(SynthContext context, Graphics g, int x, int y, + int w, int h) { + + findPainter(context.getComponentState(), "MenuBorder", -1) + .paintMenuBorder(context, g, x, y, w, h); + } + + @Override + public void paintMenuItemBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "MenuItemBackground", -1) + .paintMenuItemBackground(context, g, x, y, w, h); + } + + @Override + public void paintMenuItemBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "MenuItemBorder", -1) + .paintMenuItemBorder(context, g, x, y, w, h); + } + + @Override + public void paintOptionPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "OptionPaneBackground", -1) + .paintOptionPaneBackground(context, g, x, y, w, h); + } + + @Override + public void paintOptionPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "OptionPaneBorder", -1) + .paintOptionPaneBorder(context, g, x, y, w, h); + } + + @Override + public void paintPanelBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "PanelBackground", -1) + .paintPanelBackground(context, g, x, y, w, h); + } + + @Override + public void paintPanelBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "PanelBorder", -1) + .paintPanelBorder(context, g, x, y, w, h); + } + + @Override + public void paintPasswordFieldBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "PasswordFieldBackground", -1) + .paintPasswordFieldBackground(context, g, x, y, w, h); + } + + @Override + public void paintPasswordFieldBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "PasswordFieldBorder", -1) + .paintPasswordFieldBorder(context, g, x, y, w, h); + } + + @Override + public void paintPopupMenuBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "PopupMenuBackground", -1) + .paintPopupMenuBackground(context, g, x, y, w, h); + } + + @Override + public void paintPopupMenuBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "PopupMenuBorder", -1) + .paintPopupMenuBorder(context, g, x, y, w, h); + } + + @Override + public void paintProgressBarBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "ProgressBarBackground", -1) + .paintProgressBarBackground(context, g, x, y, w, h); + } + + @Override + public void paintProgressBarBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "ProgressBarBorder", -1) + .paintProgressBarBorder(context, g, x, y, w, h); + } + + @Override + public void paintProgressBarForeground(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + + findPainter(context.getComponentState(), + "ProgressBarForegroundPainter", orientation) + .paintProgressBarForeground(context, g, x, y, w, h, orientation); + + } + + @Override + public void paintRadioButtonBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "RadioButtonBackground", -1) + .paintRadioButtonBackground(context, g, x, y, w, h); + } + + @Override + public void paintRadioButtonBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "RadioButtonBorder", -1) + .paintRadioButtonBorder(context, g, x, y, w, h); + } + + @Override + public void paintRadioButtonMenuItemBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + + findPainter(context.getComponentState(), + "RadioButtonMenuItemBackground", -1) + .paintRadioButtonMenuItemBackground(context, g, x, y, w, h); + } + + @Override + public void paintRadioButtonMenuItemBorder(SynthContext context, + Graphics g, int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "RadioButtonMenuItemBorder", + -1).paintRadioButtonMenuItemBorder(context, g, x, y, w, h); + } + + @Override + public void paintRootPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "RootPaneBackground", -1) + .paintRootPaneBackground(context, g, x, y, w, h); + } + + @Override + public void paintRootPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "RootPaneBorder", -1) + .paintRootPaneBorder(context, g, x, y, w, h); + } + + @Override + public void paintScrollBarBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "ScrollBarBackground", -1) + .paintScrollBarBackground(context, g, x, y, w, h); + } + + @Override + public void paintScrollBarBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "ScrollBarBorder", -1) + .paintScrollBarBorder(context, g, x, y, w, h); + } + + @Override + public void paintScrollBarThumbBackground(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + + findPainter(context.getComponentState(), + "ScrollBarThumbBackgroundPainter", orientation) + .paintScrollBarThumbBackground(context, g, x, y, w, h, + orientation); + + } + + @Override + public void paintScrollBarThumbBorder(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + + findPainter(context.getComponentState(), "ScrollBarThumbBorderPainter", + orientation).paintScrollBarThumbBorder(context, g, x, y, w, h, + orientation); + + } + + @Override + public void paintScrollBarTrackBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "ScrollBarTrackBackground", -1) + .paintScrollBarTrackBackground(context, g, x, y, w, h); + } + + @Override + public void paintScrollBarTrackBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "ScrollBarTrackBorder", -1) + .paintScrollBarTrackBorder(context, g, x, y, w, h); + } + + @Override + public void paintScrollPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "ScrollPaneBackground", -1) + .paintScrollPaneBackground(context, g, x, y, w, h); + } + + @Override + public void paintScrollPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "ScrollPaneBorder", -1) + .paintScrollPaneBorder(context, g, x, y, w, h); + } + + @Override + public void paintSeparatorBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "SeparatorBackground", -1) + .paintSeparatorBackground(context, g, x, y, w, h); + } + + @Override + public void paintSeparatorBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "SeparatorBorder", -1) + .paintSeparatorBorder(context, g, x, y, w, h); + } + + @Override + public void paintSeparatorForeground(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + findPainter(context.getComponentState(), "SeparatorForegroundPainter", + orientation).paintSeparatorForeground(context, g, x, y, w, h, + orientation); + + } + + @Override + public void paintSliderBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "SliderBackground", -1) + .paintSliderBackground(context, g, x, y, w, h); + } + + @Override + public void paintSliderBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "SliderBorder", -1) + .paintSliderBorder(context, g, x, y, w, h); + } + + @Override + public void paintSliderThumbBackground(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + + findPainter(context.getComponentState(), + "SliderThumbBackgroundPainter", orientation) + .paintSliderThumbBackground(context, g, x, y, w, h, orientation); + + } + + @Override + public void paintSliderThumbBorder(SynthContext context, Graphics g, int x, + int y, int w, int h, int orientation) { + + findPainter(context.getComponentState(), "SliderThumbBorderPainter", + orientation).paintSliderThumbBorder(context, g, x, y, w, h, + orientation); + + } + + @Override + public void paintSliderTrackBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "SliderTrackBackground", -1) + .paintSliderTrackBackground(context, g, x, y, w, h); + } + + @Override + public void paintSliderTrackBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "SliderTrackBorder", -1) + .paintSliderTrackBorder(context, g, x, y, w, h); + } + + @Override + public void paintSpinnerBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "SpinnerBackground", -1) + .paintSpinnerBackground(context, g, x, y, w, h); + } + + @Override + public void paintSpinnerBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "SpinnerBorder", -1) + .paintSpinnerBorder(context, g, x, y, w, h); + } + + @Override + public void paintSplitPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "SplitPaneBackground", -1) + .paintSplitPaneBackground(context, g, x, y, w, h); + } + + @Override + public void paintSplitPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "SplitPaneBorder", -1) + .paintSplitPaneBorder(context, g, x, y, w, h); + } + + @Override + public void paintSplitPaneDividerBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "SplitPaneDividerBackground", + -1).paintSplitPaneDividerBackground(context, g, x, y, w, h); + } + + @Override + public void paintSplitPaneDividerForeground(SynthContext context, + Graphics g, int x, int y, int w, int h, int orientation) { + + findPainter(context.getComponentState(), + "SplitPaneDividerForegroundPainter", orientation) + .paintSplitPaneDividerForeground(context, g, x, y, w, h, + orientation); + + } + + @Override + public void paintSplitPaneDragDivider(SynthContext context, Graphics g, + int x, int y, int w, int h, int orientation) { + + findPainter(context.getComponentState(), "SplitPaneDragDividerPainter", + orientation).paintSplitPaneDragDivider(context, g, x, y, w, h, + orientation); + + } + + @Override + public void paintTabbedPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "TabbedPaneBackground", -1) + .paintTabbedPaneBackground(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "TabbedPaneBorder", -1) + .paintTabbedPaneBorder(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneContentBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "TabbedPaneContentBackground", + -1).paintTabbedPaneContentBackground(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneContentBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "TabbedPaneContentBorder", -1) + .paintTabbedPaneContentBorder(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneTabAreaBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "TabbedPaneTabBackground", -1) + .paintTabbedPaneTabAreaBackground(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneTabAreaBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "TabbedPaneTabAreaBorder", -1) + .paintTabbedPaneTabAreaBorder(context, g, x, y, w, h); + } + + @Override + public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, + int x, int y, int w, int h, int tabIndex) { + + findPainter(context.getComponentState(), "TabbedPaneTabBackground", -1) + .paintTabbedPaneTabBackground(context, g, x, y, w, h, tabIndex); + } + + @Override + public void paintTabbedPaneTabBorder(SynthContext context, Graphics g, + int x, int y, int w, int h, int tabIndex) { + + findPainter(context.getComponentState(), "TabbedPaneTabBorder", -1) + .paintTabbedPaneTabBorder(context, g, x, y, w, h, tabIndex); + } + + @Override + public void paintTableBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "TableBackground", -1) + .paintTableBackground(context, g, x, y, w, h); + } + + @Override + public void paintTableBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "TableBorder", -1) + .paintTableBorder(context, g, x, y, w, h); + } + + @Override + public void paintTableHeaderBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "TableHeaderBackground", -1) + .paintTableHeaderBackground(context, g, x, y, w, h); + } + + @Override + public void paintTableHeaderBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "TableHeaderBorder", -1) + .paintTableHeaderBorder(context, g, x, y, w, h); + } + + @Override + public void paintTextAreaBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "TextAreaBackground", -1) + .paintTextAreaBackground(context, g, x, y, w, h); + } + + @Override + public void paintTextAreaBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "TextAreaBorder", -1) + .paintTextAreaBorder(context, g, x, y, w, h); + } + + @Override + public void paintTextFieldBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "TextFieldBackground", -1) + .paintTextFieldBackground(context, g, x, y, w, h); + } + + @Override + public void paintTextFieldBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "TextFieldBorder", -1) + .paintTextFieldBorder(context, g, x, y, w, h); + } + + @Override + public void paintTextPaneBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "TextPaneBackground", -1) + .paintTextPaneBackground(context, g, x, y, w, h); + } + + @Override + public void paintTextPaneBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "TextPaneBorder", -1) + .paintTextPaneBorder(context, g, x, y, w, h); + } + + @Override + public void paintToggleButtonBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "ToggleButtonBackground", -1) + .paintToggleButtonBackground(context, g, x, y, w, h); + } + + @Override + public void paintToggleButtonBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "ToggleButtonBorder", -1) + .paintToggleButtonBorder(context, g, x, y, w, h); + } + + @Override + public void paintToolBarBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "ToolBarBackground", -1) + .paintToolBarBackground(context, g, x, y, w, h); + } + + @Override + public void paintToolBarBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "ToolBarBorder", -1) + .paintToolBarBorder(context, g, x, y, w, h); + } + + @Override + public void paintToolBarContentBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "ToolBarContentBackground", -1) + .paintToolBarContentBackground(context, g, x, y, w, h); + } + + @Override + public void paintToolBarContentBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "ToolBarContentBorder", -1) + .paintToolBarContentBorder(context, g, x, y, w, h); + } + + @Override + public void paintToolBarDragWindowBackground(SynthContext context, + Graphics g, int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "ToolBarDragWindowBackground", + -1).paintToolBarDragWindowBackground(context, g, x, y, w, h); + } + + @Override + public void paintToolBarDragWindowBorder(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "ToolBarDragWindowBorder", -1) + .paintToolBarDragWindowBorder(context, g, x, y, w, h); + } + + @Override + public void paintToolTipBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "ToolTipBackground", -1) + .paintToolTipBackground(context, g, x, y, w, h); + } + + @Override + public void paintToolTipBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "ToolTipBorder", -1) + .paintToolTipBorder(context, g, x, y, w, h); + } + + @Override + public void paintTreeBackground(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "TreeBackground", -1) + .paintTreeBackground(context, g, x, y, w, h); + } + + @Override + public void paintTreeBorder(SynthContext context, Graphics g, int x, int y, + int w, int h) { + + findPainter(context.getComponentState(), "TreeBorder", -1) + .paintTreeBorder(context, g, x, y, w, h); + } + + @Override + public void paintTreeCellBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "TreeCellBackground", -1) + .paintTreeCellBackground(context, g, x, y, w, h); + } + + @Override + public void paintTreeCellBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "TreeCellBorder", -1) + .paintTreeCellBorder(context, g, x, y, w, h); + } + + @Override + public void paintTreeCellFocus(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "TreeCellFocus", -1) + .paintTreeCellFocus(context, g, x, y, w, h); + } + + @Override + public void paintViewportBackground(SynthContext context, Graphics g, + int x, int y, int w, int h) { + + findPainter(context.getComponentState(), "ViewportBackground", -1) + .paintViewportBackground(context, g, x, y, w, h); + } + + @Override + public void paintViewportBorder(SynthContext context, Graphics g, int x, + int y, int w, int h) { + + findPainter(context.getComponentState(), "ViewportBorder", -1) + .paintViewportBorder(context, g, x, y, w, h); + } + +} Index: src/main/java/common/javax/swing/plaf/synth/DefaultStyleFactory.java =================================================================== --- src/main/java/common/javax/swing/plaf/synth/DefaultStyleFactory.java (revision 0) +++ src/main/java/common/javax/swing/plaf/synth/DefaultStyleFactory.java (revision 0) @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package javax.swing.plaf.synth; + +import java.util.ArrayList; +import java.util.regex.Pattern; + +import javax.swing.JComponent; +import javax.swing.plaf.synth2.Region; +import javax.swing.plaf.synth2.SynthStyle; +import javax.swing.plaf.synth2.SynthStyleFactory; + +/** + * The defaultStyleFactory returns styles fills up by putStyle(String, String, + * SynthStyle) method + */ +class DefaultStyleFactory extends SynthStyleFactory { + + /** + * List that containing styles + */ + private final ArrayList styles = new ArrayList(); + + @Override + public SynthStyle getStyle(JComponent comp, Region reg) { + + SynthStyle result = findStyle(comp, reg); + + if (result == null) { + return SynthStyle.NULL_STYLE; + } + + return result; + } + + public void putStyle(String bindType, String bindKey, SynthStyle style) { + + styles.add(new StyleInfo(bindType, bindKey, style)); + } + + private SynthStyle findStyle(JComponent comp, Region reg) { + + String name = comp.getName(); + SynthStyle foundByName = null; + SynthStyle foundByRegion = null; + + for (StyleInfo candidate : styles) { + + if ((name != null) && ("name".equals(candidate.getBindType())) //$NON-NLS-1$ + && Pattern.matches(name, candidate.getBindKey())) { + foundByName = candidate.getStyle(); + } + + if (("region".equals(candidate.getBindType())) //$NON-NLS-1$ + && reg.getName().equals(candidate.getBindKey())) { + foundByRegion = candidate.getStyle(); + } + } + + // foundByName has a priority + if (foundByName == null) { + + return foundByRegion; + } + + return foundByName; + } + + /** + * StyleInfo can be used for representing the style and for finding a style + * from list + */ + private static class StyleInfo { + + private final String bindType; + + private final String bindKey; + + private final SynthStyle currentStyle; + + /** + * Note that the constructor lowercases type and key for the StyleKey + */ + public StyleInfo(String bindType, String bindKey, + SynthStyle currentStyle) { + this.bindKey = bindKey.toLowerCase(); + this.bindType = bindType.toLowerCase(); + this.currentStyle = currentStyle; + } + + public String getBindType() { + return bindType; + } + + public String getBindKey() { + return bindKey; + } + + public SynthStyle getStyle() { + return currentStyle; + } + + @Override + public String toString() { + return "KEY[" + bindType + " " + bindKey + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + } + +}