squareness-2.3.0/source/ 40755 0 0 0 10563076303 12242 5ustar 0 0 squareness-2.3.0/source/net/ 40755 0 0 0 10563076303 13030 5ustar 0 0 squareness-2.3.0/source/net/beeger/ 40755 0 0 0 10563076303 14261 5ustar 0 0 squareness-2.3.0/source/net/beeger/squareness/ 40755 0 0 0 10563076303 16452 5ustar 0 0 squareness-2.3.0/source/net/beeger/squareness/delegate/ 40755 0 0 0 10563076303 20224 5ustar 0 0 squareness-2.3.0/source/net/beeger/squareness/icons/ 40755 0 0 0 10563076303 17565 5ustar 0 0 squareness-2.3.0/source/net/beeger/squareness/theme/ 40755 0 0 0 10563076303 17554 5ustar 0 0 squareness-2.3.0/source/net/beeger/squareness/util/ 40755 0 0 0 10563076303 17427 5ustar 0 0 squareness-2.3.0/source/org/ 40755 0 0 0 10334223450 13022 5ustar 0 0 squareness-2.3.0/source/org/jvnet/ 40755 0 0 0 10334223460 14151 5ustar 0 0 squareness-2.3.0/source/org/jvnet/lafplugin/ 40755 0 0 0 10563076303 16140 5ustar 0 0 squareness-2.3.0/build.xml100644 0 0 4154 10563076303 12664 0ustar 0 0 squareness-2.3.0/source/net/beeger/squareness/SquarenessConstants.java100644 0 0 5372 10563076303 23447 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness; /** *

This class contains all the constants used in this Look And Feel.

*/ public final class SquarenessConstants { // // public interface // public static final String SCROLLBAR_THUMB_PRESSED_CLIENT_PROPERTY_KEY = "SquarenessScrollBarThumbPressed"; public static final String SCROLLBAR_TRACK_PRESSED_CLIENT_PROPERTY_KEY = "SquarenessScrollBarTrackPressed"; public static final String SCROLL_ARROW_LEFT_KEY = "scrollArrowLeft"; public static final String SCROLL_ARROW_RIGHT_KEY = "scrollArrowRight"; public static final String SCROLL_ARROW_UP_KEY = "scrollArrowUp"; public static final String SCROLL_ARROW_DOWN_KEY = "scrollArrowDown"; public static final String SPIN_UP_KEY = "spinUp"; public static final String SPIN_DOWN_KEY = "spinDown"; public static final String ROLLOVER_CLENT_PROPERTY_KEY = "SquarenessRollover"; public static final String CHECKED_FOR_JEDIT_ROLLOVER ="SquarenessCheckedJEDITROLLOVER"; private SquarenessConstants () { } }squareness-2.3.0/source/net/beeger/squareness/SquarenessLookAndFeel.java100644 0 0 56766 10563076303 23653 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import java.util.Iterator; import java.util.Map; import javax.swing.LookAndFeel; import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.plaf.BorderUIResource; import javax.swing.plaf.metal.MetalLookAndFeel; import net.beeger.squareness.theme.DefaultSquarenessTheme; import net.beeger.squareness.theme.PropertiesSquarenessTheme; import net.beeger.squareness.theme.SquarenessTheme; import net.beeger.squareness.util.SquarenessBorderFactory; import net.beeger.squareness.util.SquarenessIconFactory; import org.jvnet.lafplugin.ComponentPluginManager; /** *

This is the core class of the Squareness Look And Feel.

*

It sets up the colors, fonts, ui delegates as well as other resources and defaults * used by this look and feel.

*/ public class SquarenessLookAndFeel extends MetalLookAndFeel { public static void setCurrentSquarenessTheme(SquarenessTheme theme) { _currentSquarenessTheme = theme; MetalLookAndFeel.setCurrentTheme(theme); } public static SquarenessTheme getCurrentSquarenessTheme() { if (_currentSquarenessTheme == null) { loadThemePackageTheme(); } if (_currentSquarenessTheme == null) { setCurrentSquarenessTheme(new DefaultSquarenessTheme()); } return _currentSquarenessTheme; } public static void loadThemePackageTheme () { final InputStream themeSelectorStream = SquarenessLookAndFeel.class.getResourceAsStream("/themeselector.slfts"); if (themeSelectorStream != null) { Properties themeSelector = new Properties(); try { themeSelector.load(themeSelectorStream); String themeFileName = themeSelector.getProperty("currentTheme"); if (themeFileName != null && themeFileName.trim().length() > 0) { Properties theme = new Properties(); theme.load(SquarenessLookAndFeel.class.getResourceAsStream("/" + themeFileName)); setCurrentSquarenessTheme(new PropertiesSquarenessTheme(theme)); } } catch (IOException e) { e.printStackTrace(); } catch (PropertiesSquarenessTheme.LoadException e) { e.printStackTrace(); } } } public SquarenessLookAndFeel () { } /** * Is the look and feel a native look and feel? * * @return true if the look and feel is a native look and feel, false otherwise */ public boolean isNativeLookAndFeel () { return false; } /** *

Is this look and feel supported on the underlying plattform?

*

Note: The Squareness look and feel is supported on any available plattform. So this method always * returns true.

* * @return true if the look and feel is supported on the underlying plattform, false otherwise. */ public boolean isSupportedLookAndFeel () { return true; } /** * Return the description of the look and feel. * * @return The description of the look and feel. */ public String getDescription () { return DESCRIPTION; } /** * Return the id of the look and feel. * * @return The id of the look and feel */ public String getID () { return ID; } /** * Return the name of the look and feel. * * @return The name of the look and feel. */ public String getName () { return NAME; } // // protected interface // public void initialize () { super.initialize(); _plugins.initializeAll(); } public void uninitialize() { super.uninitialize(); _plugins.uninitializeAll(); } /** * Initialize the uiClassID to BasicComponentUI mapping. * The JComponent classes define their own uiClassID constants * (see AbstractComponent.getUIClassID). This table must * map those constants to a BasicComponentUI class of the * appropriate type. * * @param table The table of defaults into which to put the defaults of this look and feel. * @see #getDefaults */ protected void initClassDefaults (UIDefaults table) { super.initClassDefaults(table); String packageName = "net.beeger.squareness.delegate."; table.put("ButtonUI", packageName + "SquarenessButtonUI"); table.put("RadioButtonUI", packageName + "SquarenessRadioButtonUI"); table.put("CheckBoxUI", packageName + "SquarenessCheckBoxUI"); table.put("ToolBarUI", packageName + "SquarenessToolBarUI"); table.put("ToggleButtonUI", packageName + "SquarenessToggleButtonUI"); table.put("ScrollBarUI", packageName + "SquarenessScrollBarUI"); table.put("TabbedPaneUI", packageName + "SquarenessTabbedPaneUI"); table.put("ComboBoxUI", packageName + "SquarenessComboBoxUI"); table.put("SliderUI", packageName + "SquarenessSliderUI"); table.put("InternalFrameUI", packageName + "SquarenessInternalFrameUI"); table.put("SpinnerUI", packageName + "SquarenessSpinnerUI"); table.put("RootPaneUI", packageName + "SquarenessRootPaneUI"); table.put("ProgressBarUI", "javax.swing.plaf.basic.BasicProgressBarUI"); table.put("SplitPaneUI", "javax.swing.plaf.basic.BasicSplitPaneUI"); } protected void initComponentDefaults (UIDefaults table) { setCurrentTheme(new DefaultSquarenessTheme()); super.initComponentDefaults(table); table.put(SquarenessConstants.SCROLL_ARROW_LEFT_KEY, new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getLeftIcon(); } }); table.put(SquarenessConstants.SCROLL_ARROW_RIGHT_KEY, new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getRightIcon(); } }); table.put(SquarenessConstants.SCROLL_ARROW_UP_KEY, new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getUpIcon(); } }); table.put(SquarenessConstants.SCROLL_ARROW_DOWN_KEY, new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getDownIcon(); } }); table.put(SquarenessConstants.SPIN_UP_KEY, new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getSpinUpIcon(); } }); table.put(SquarenessConstants.SPIN_DOWN_KEY, new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getSpinDownIcon(); } }); UIDefaults.LazyValue borderWithMargin = new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessBorderFactory.getControlBorderWithMargin(); } }; UIDefaults.LazyValue borderWithoutMargin = new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessBorderFactory.getControlBorderWithoutMargin(); } }; UIDefaults.LazyValue progressBarBorder = new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessBorderFactory.getProgressBarBorder(); } }; UIDefaults.LazyValue tableHeaderCellBorder = new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessBorderFactory.getTableHeaderCellBorder(); } }; table.put("Button.background", getCurrentSquarenessTheme().getNormalControlBackgroundColor()); table.put("Button.border", borderWithMargin); table.put("ToggleButton.background", getCurrentSquarenessTheme().getNormalControlBackgroundColor()); table.put("ToggleButton.border", borderWithMargin); table.put("RadioButton.icon", new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getRadioButtonIcon(); } }); table.put("CheckBox.icon", new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getCheckBoxIcon(); } }); UIDefaults.LazyValue emptyborder = new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return new BorderUIResource.EmptyBorderUIResource(0, 0, 0, 0); } }; UIDefaults.LazyValue menuItemBorder = new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessBorderFactory.getMenuItemBorder(); } }; UIDefaults.LazyValue menuItemCheckIcon = new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getMenuItemCheckIcon(); } }; UIDefaults.LazyValue menuItemArrowIcon = new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getMenuItemArrowIcon(); } }; table.put("TextField.border", borderWithoutMargin); table.put("FormattedTextField.border", borderWithoutMargin); table.put("PasswordField.border", borderWithoutMargin); table.put("MenuBar.background", getCurrentSquarenessTheme().getWindowBackgroundColor()); table.put("MenuBar.border", emptyborder); table.put("Menu.background", null); table.put("Menu.border", menuItemBorder); table.put("Menu.borderPainted", Boolean.TRUE); table.put("Menu.selectionForeground", table.get("textHighlightText")); table.put("Menu.selectionBackground", table.get("textHighlight")); table.put("Menu.arrowIcon", new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getMenuArrowIcon(); } }); table.put("Menu.checkIcon", menuItemCheckIcon); table.put("MenuItem.background", null); table.put("MenuItem.border", menuItemBorder); table.put("MenuItem.borderPainted", Boolean.TRUE); table.put("MenuItem.selectionForeground", table.get("textHighlightText")); table.put("MenuItem.selectionBackground", table.get("textHighlight")); table.put("MenuItem.checkIcon", menuItemCheckIcon); table.put("RadioButtonMenuItem.background", null); table.put("RadioButtonMenuItem.border", menuItemBorder); table.put("RadioButtonMenuItem.borderPainted", Boolean.TRUE); table.put("RadioButtonMenuItem.selectionForeground", table.get("textHighlightText")); table.put("RadioButtonMenuItem.selectionBackground", table.get("textHighlight")); table.put("RadioButtonMenuItem.checkIcon", new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getRadioButtonMenuItemCheckIcon(); } }); table.put("RadioButtonMenuItem.arrowIcon", menuItemArrowIcon); table.put("CheckBoxMenuItem.background", null); table.put("CheckBoxMenuItem.border", menuItemBorder); table.put("CheckBoxMenuItem.borderPainted", Boolean.TRUE); table.put("CheckBoxMenuItem.selectionForeground", table.get("textHighlightText")); table.put("CheckBoxMenuItem.selectionBackground", table.get("textHighlight")); table.put("CheckBoxMenuItem.checkIcon", new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getCheckBoxMenuItemCheckIcon(); } }); table.put("CheckBoxMenuItem.arrowIcon", menuItemArrowIcon); table.put("Separator.foreground", getCurrentSquarenessTheme().getNormalBorderColor()); table.put("Separator.background", null); table.put("PopupMenu.border", new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessBorderFactory.getNonSpacingControlBorderWithoutMargin(); } }); UIDefaults.LazyValue frameBorder = new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessBorderFactory.getInternalFrameBorder(); } }; table.put("InternalFrame.border", frameBorder); table.put("InternalFrame.icon", null); table.put("InternalFrame.maximizeIcon", new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getMaximizeFrameIcon(); } }); table.put("InternalFrame.minimizeIcon", new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getMinimizeFrameIcon(); } }); table.put("InternalFrame.iconifyIcon", new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getIconifyFrameIcon(); } }); table.put("InternalFrame.closeIcon", new UIDefaults.LazyValue() { public Object createValue (UIDefaults table) { return SquarenessIconFactory.getCloseFrameIcon(); } }); table.put("RootPane.frameBorder", frameBorder); table.put("RootPane.plainDialogBorder", frameBorder); table.put("RootPane.informationDialogBorder", frameBorder); table.put("RootPane.errorDialogBorder", frameBorder); table.put("RootPane.colorChooserDialogBorder", frameBorder); table.put("RootPane.fileChooserDialogBorder", frameBorder); table.put("RootPane.questionDialogBorder", frameBorder); table.put("RootPane.warningDialogBorder", frameBorder); table.put("ScrollBar.thumb", getCurrentSquarenessTheme().getNormalControlBackgroundColor()); table.put("ScrollBar.background", getCurrentSquarenessTheme().getProgressBarBackgroundColor()); table.put("ScrollBar.width", new Integer(17)); table.put("ScrollPane.border", borderWithoutMargin); table.put("TableHeader.background", getCurrentSquarenessTheme().getNormalControlBackgroundColor()); table.put("ToolBar.border", emptyborder); table.put("ToolBar.background", getCurrentSquarenessTheme().getWindowBackgroundColor()); table.put("ComboBox.border", borderWithoutMargin); table.put("ComboBox.background", getCurrentSquarenessTheme().getTextInputBackgroundColor()); table.put("ComboBox.selectionBackground", table.get("textHighlight")); table.put("ComboBox.selectionForeground", table.get("textHighlightText")); table.put("ProgressBar.border", progressBarBorder); table.put("ProgressBar.cellLength", new Integer(1)); table.put("ProgressBar.cellSpacing", new Integer(1)); table.put("ProgressBar.selectionForeground", getCurrentSquarenessTheme().getTextColor()); table.put("ProgressBar.selectionBackground", getCurrentSquarenessTheme().getTextColor()); table.put("ProgressBar.foreground", getCurrentSquarenessTheme().getSelectedControlBackgroundColor()); table.put("ProgressBar.background", getCurrentSquarenessTheme().getProgressBarBackgroundColor()); table.put("SplitPane.highlight", getCurrentSquarenessTheme().getNormalBorderColor()); table.put("SplitPane.shadow", getCurrentSquarenessTheme().getNormalBorderColor()); table.put("SplitPane.darkShadow", getCurrentSquarenessTheme().getNormalBorderColor()); table.put("SplitPane.border", null); table.put("SplitPaneDivider.border", null); table.put("TabbedPane.selected", getCurrentSquarenessTheme().getWindowBackgroundColor()); table.put("TabbedPane.shadow", getCurrentSquarenessTheme().getNormalBorderColor().brighter().brighter()); table.put("TabbedPane.darkShadow", getCurrentSquarenessTheme().getNormalBorderColor()); table.put("TabbedPane.highlight", getCurrentSquarenessTheme().getWindowBackgroundColor().brighter().brighter()); table.put("TabbedPane.background", getCurrentSquarenessTheme().getWindowBackgroundColor()); table.put("TabbedPane.selected", null); table.put("Viewport.background", getCurrentSquarenessTheme().getWindowBackgroundColor()); table.put("Table.scrollPaneBorder", borderWithoutMargin); table.put("TableHeader.cellBorder", tableHeaderCellBorder); table.put("Panel.background", getCurrentSquarenessTheme().getWindowBackgroundColor()); table.put("Panel.foreground", getCurrentSquarenessTheme().getTextColor()); table.put("Tree.collapsedIcon", LookAndFeel.makeIcon(getClass(), "icons/treecollapsed.gif")); table.put("Tree.expandedIcon", LookAndFeel.makeIcon(getClass(), "icons/treeexpanded.gif")); table.put("Tree.openIcon", LookAndFeel.makeIcon(getClass(), "icons/folderopened.gif")); table.put("Tree.closedIcon", LookAndFeel.makeIcon(getClass(), "icons/folderclosed.gif")); table.put("Tree.leafIcon", LookAndFeel.makeIcon(getClass(), "icons/document.gif")); table.put("FileView.directoryIcon", LookAndFeel.makeIcon(getClass(), "icons/folderclosed.gif")); table.put("FileView.fileIcon", LookAndFeel.makeIcon(getClass(), "icons/document.gif")); table.put("FileView.computerIcon", LookAndFeel.makeIcon(getClass(), "icons/computer.gif")); table.put("FileView.hardDriveIcon", LookAndFeel.makeIcon(getClass(), "icons/hd.gif")); table.put("FileView.floppyDriveIcon", LookAndFeel.makeIcon(getClass(), "icons/floppy.gif")); table.put("FileChooser.detailsViewIcon", LookAndFeel.makeIcon(getClass(), "icons/detail.gif")); table.put("FileChooser.homeFolderIcon", LookAndFeel.makeIcon(getClass(), "icons/home.gif")); table.put("FileChooser.listViewIcon", LookAndFeel.makeIcon(getClass(), "icons/list.gif")); table.put("FileChooser.newFolderIcon", LookAndFeel.makeIcon(getClass(), "icons/folderclosed.gif")); table.put("FileChooser.upFolderIcon", LookAndFeel.makeIcon(getClass(), "icons/folderup.gif")); // table.put("Spinner.background",table.get(SquarenessConstants.NORMAL_CONTROL_COLOR_KEY)); // table.put("Spinner.foreground",table.get(SquarenessConstants.TEXT_TEXT_COLOR_KEY)); // table.put("Spinner.border", borderWithoutMargin); for (Iterator iterator = table.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); if (entry.getValue() instanceof String && ((String) entry.getValue()).startsWith("sounds/")) { entry.setValue("/javax/swing/plaf/metal/" + entry.getValue()); } } _plugins.processAllDefaultsEntries(UIManager.getDefaults(), _currentSquarenessTheme); } /** * Load the SystemColors into the defaults table. The keys * for SystemColor defaults are the same as the names of * the public fields in SystemColor. If the table is being * created on a native Windows platform we use the SystemColor * values, otherwise we create color objects whose values match * the defaults Windows95 colors. * * @param table The table of defaults into which to put the defaults of this look and feel. */ protected void initSystemColorDefaults (UIDefaults table) { table.put("desktop", getCurrentSquarenessTheme().getDesktopColor()); table.put("activeCaption", getCurrentSquarenessTheme().getWindowBackgroundColor()); table.put("activeCaptionText", getCurrentSquarenessTheme().getTextColor()); table.put("activeCaptionBorder", getCurrentSquarenessTheme().getNormalBorderColor()); table.put("inactiveCaption", getCurrentSquarenessTheme().getWindowBackgroundColor()); table.put("inactiveCaptionText", getCurrentSquarenessTheme().getDisabledBorderColor()); table.put("inactiveCaptionBorder", getCurrentSquarenessTheme().getInactiveWindowBorderColor()); table.put("window", getCurrentSquarenessTheme().getTextInputBackgroundColor()); table.put("windowBorder", getCurrentSquarenessTheme().getNormalBorderColor()); table.put("windowText", getCurrentSquarenessTheme().getTextColor()); table.put("menu", getCurrentSquarenessTheme().getProgressBarBackgroundColor()); table.put("menuText", getCurrentSquarenessTheme().getTextColor()); table.put("text", getCurrentSquarenessTheme().getTextInputBackgroundColor()); table.put("textText", getCurrentSquarenessTheme().getTextColor()); table.put("textHighlight", getCurrentSquarenessTheme().getSelectedControlBackgroundColor()); table.put("textHighlightText", getCurrentSquarenessTheme().getTextColor()); table.put("textInactiveText", getCurrentSquarenessTheme().getTextColor()); table.put("control", getCurrentSquarenessTheme().getWindowBackgroundColor()); table.put("controlText", getCurrentSquarenessTheme().getTextColor()); table.put("controlHighlight", getCurrentSquarenessTheme().getSelectedControlBackgroundColor()); table.put("controlLtHighlight", getCurrentSquarenessTheme().getSelectedControlBackgroundColor()); table.put("controlShadow", getCurrentSquarenessTheme().getSelectedControlBackgroundShadowColor()); table.put("controlDkShadow", getCurrentSquarenessTheme().getSelectedControlBackgroundShadowColor()); table.put("scrollbar", getCurrentSquarenessTheme().getProgressBarBackgroundColor()); table.put("info", getCurrentSquarenessTheme().getProgressBarBackgroundColor()); table.put("infoText", getCurrentSquarenessTheme().getTextColor()); } // // private interface private static final String PLUGIN_FILE_NAME = "META-INF/squareness-plugin.xml"; private static final ComponentPluginManager _plugins = new ComponentPluginManager(PLUGIN_FILE_NAME); private static final String DESCRIPTION = "Squareness Look And Feel"; private static final String ID = "Squareness"; private static final String NAME = "Squareness"; private static SquarenessTheme _currentSquarenessTheme; }squareness-2.3.0/source/net/beeger/squareness/delegate/SquarenessButtonUI.java100644 0 0 11226 10563076303 24771 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.delegate; import java.awt.Graphics; import javax.swing.AbstractButton; import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicButtonUI; import net.beeger.squareness.SquarenessConstants; import net.beeger.squareness.util.SquarenessBorderFactory; import net.beeger.squareness.util.SquarenessButtonPainter; import net.beeger.squareness.util.SquarenessListenerFactory; /** * The Squareness Button UI delegate. */ public class SquarenessButtonUI extends BasicButtonUI { /** * Create the UI delegate for the given component * * @param component The component for which to create the ui delegate * @return The created ui delegate */ public static ComponentUI createUI (JComponent component) { return _buttonUI; } /** * Install the UI delegate for the given component * * @param component The component for which to install the ui delegate. */ public void installUI (JComponent component) { component.putClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY, Boolean.FALSE); component.addMouseListener(SquarenessListenerFactory.getButtonRolloverMouseListener()); super.installUI(component); } /** * Uninstall the UI delegate * * @param component The component from which to uninstall the UI delegate. */ public void uninstallUI (JComponent component) { component.removeMouseListener(SquarenessListenerFactory.getButtonRolloverMouseListener()); super.uninstallUI(component); } /** * Paint the component. * * @param graphics The graphics resource used to paint the component * @param component The component to paint. */ public void paint (Graphics graphics, JComponent component) { if (!"yes".equals(component.getClientProperty(SquarenessConstants.CHECKED_FOR_JEDIT_ROLLOVER))) { component.putClientProperty(SquarenessConstants.CHECKED_FOR_JEDIT_ROLLOVER, "yes"); boolean jEditRolloverButton = false; Class currentClass = component.getClass(); String currentClassName = currentClass.getName(); while (!jEditRolloverButton && currentClass != null && !(currentClassName.startsWith("java.") || currentClassName.startsWith("javax."))) { if ("org.gjt.sp.jedit.gui.RolloverButton".equals(currentClass.getName())) { jEditRolloverButton = true; } else { currentClass = currentClass.getSuperclass(); } } if (jEditRolloverButton) { component.setBorder(SquarenessBorderFactory.getButtonRolloverBorder()); } } SquarenessButtonPainter.paintButton(graphics, (AbstractButton) component); super.paint(graphics, component); } /** * One instance handles all buttons. */ private static SquarenessButtonUI _buttonUI = new SquarenessButtonUI(); }squareness-2.3.0/source/net/beeger/squareness/delegate/SquarenessCheckBoxUI.java100644 0 0 6307 10563076303 25170 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.delegate; import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicCheckBoxUI; import net.beeger.squareness.SquarenessConstants; import net.beeger.squareness.util.SquarenessListenerFactory; /** * The Squareness Check Box UI delegate. */ public class SquarenessCheckBoxUI extends BasicCheckBoxUI { /** * Create the UI delegate for the given component * * @param component The component for which to create the ui delegate * @return The created ui delegate */ public static ComponentUI createUI (JComponent component) { return _buttonUI; } /** * Install the UI delegate for the given component * * @param component The component for which to install the ui delegate. */ public void installUI (JComponent component) { component.putClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY, Boolean.FALSE); component.addMouseListener(SquarenessListenerFactory.getButtonRolloverMouseListener()); super.installUI(component); } /** * Uninstall the UI delegate. * * @param component The component from which to uninstall the UI delegate. */ public void uninstallUI (JComponent component) { component.removeMouseListener(SquarenessListenerFactory.getButtonRolloverMouseListener()); super.uninstallUI(component); } private static SquarenessCheckBoxUI _buttonUI = new SquarenessCheckBoxUI(); }squareness-2.3.0/source/net/beeger/squareness/delegate/SquarenessComboBoxUI.java100644 0 0 5615 10563076303 25213 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.delegate; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicComboBoxUI; import net.beeger.squareness.SquarenessConstants; import net.beeger.squareness.util.SquarenessBorderFactory; /** * The Squareness Combo Box UI delegate. */ public class SquarenessComboBoxUI extends BasicComboBoxUI { /** * Create the UI delegate for the given component * * @param component The component for which to create the ui delegate * @return The created ui delegate */ public static ComponentUI createUI (JComponent component) { return new SquarenessComboBoxUI(); } /** * Create the arrow button for the combo box. * * @return The created arrow button. */ protected JButton createArrowButton () { UIDefaults defaults = UIManager.getDefaults(); JButton button = new JButton(defaults.getIcon(SquarenessConstants.SCROLL_ARROW_DOWN_KEY)); button.setBorder(SquarenessBorderFactory.getNonSpacingControlBorderWithMargin()); return button; } }squareness-2.3.0/source/net/beeger/squareness/delegate/SquarenessInternalFrameUI.java100644 0 0 13566 10563076303 26256 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.delegate; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; import javax.swing.JComponent; import javax.swing.JInternalFrame; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicInternalFrameUI; import net.beeger.squareness.util.SquarenessTitlePane; /** * The Squareness Internal Frame UI delegate. */ public class SquarenessInternalFrameUI extends BasicInternalFrameUI { /** * Create the UI delegate for the given component * * @param component The component for which to create the ui delegate * @return The created ui delegate */ public static ComponentUI createUI (JComponent component) { return new SquarenessInternalFrameUI((JInternalFrame) component); } /** * Create the UI delegate. * * @param internalFrame The internal frame this delegate will be used for. */ public SquarenessInternalFrameUI (JInternalFrame internalFrame) { super(internalFrame); } /** * Create the title bar of the internal frame. * * @param internalFrame The internalframe for which to create the title bar. * @return The created title bar. */ protected JComponent createNorthPane (JInternalFrame internalFrame) { _titlePane = new SquarenessInternalFrameTitlePane(internalFrame); return _titlePane; } /** * The class for title bars of internal frames. */ protected static class SquarenessInternalFrameTitlePane extends SquarenessTitlePane { public SquarenessInternalFrameTitlePane (JInternalFrame frame) { _frame = frame; _frame.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange (PropertyChangeEvent evt) { update(); _frame.revalidate(); _frame.repaint(); } }); } public boolean isLeftToRight () { return _frame.getComponentOrientation().isLeftToRight(); } protected boolean isIconifiable () { return _frame.isIconifiable(); } protected boolean isMaximizable () { return _frame.isMaximizable(); } protected boolean isClosable () { return _frame.isClosable(); } protected void close () { if (isClosable()) { _frame.doDefaultCloseAction(); } } protected void iconify () { if (isIconifiable()) { if (!isIconified()) { try { _frame.setIcon(true); } catch (PropertyVetoException e1) { } } else { try { _frame.setIcon(false); } catch (PropertyVetoException e1) { } } } } protected void maximize () { if (isMaximizable()) { if (!isMaximized()) { try { _frame.setMaximum(true); } catch (PropertyVetoException e5) { } } else { try { _frame.setMaximum(false); } catch (PropertyVetoException e6) { } } } } protected void restore () { if (isMaximizable() && isMaximized()) { try { _frame.setMaximum(false); } catch (PropertyVetoException e4) { } } else if (isIconifiable() && isIconified()) { try { _frame.setIcon(false); } catch (PropertyVetoException e4) { } } } protected boolean isMaximized () { return _frame.isMaximum(); } protected boolean isIconified () { return _frame.isIcon(); } protected String getTitle () { return _frame.getTitle(); } private JInternalFrame _frame; } private SquarenessInternalFrameTitlePane _titlePane; }squareness-2.3.0/source/net/beeger/squareness/delegate/SquarenessRadioButtonUI.java100644 0 0 6365 10563076303 25740 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.delegate; import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicRadioButtonUI; import net.beeger.squareness.SquarenessConstants; import net.beeger.squareness.util.SquarenessListenerFactory; /** * The Squareness radio button UI delegate. */ public class SquarenessRadioButtonUI extends BasicRadioButtonUI { /** * Create the UI delegate for the given component * * @param component The component for which to create the ui delegate * @return The created ui delegate */ public static ComponentUI createUI (JComponent component) { return _buttonUI; } /** * Install the UI delegate for the given component * * @param component The component for which to install the ui delegate. */ public void installUI (JComponent component) { component.putClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY, Boolean.FALSE); component.addMouseListener(SquarenessListenerFactory.getButtonRolloverMouseListener()); super.installUI(component); } /** * Uninstall the UI component from the given component. * * @param component The component to uninstall the UI delegate from. */ public void uninstallUI (JComponent component) { component.removeMouseListener(SquarenessListenerFactory.getButtonRolloverMouseListener()); super.uninstallUI(component); } private static final SquarenessRadioButtonUI _buttonUI = new SquarenessRadioButtonUI(); }squareness-2.3.0/source/net/beeger/squareness/delegate/SquarenessRootPaneUI.java100644 0 0 115617 10563076303 25276 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.delegate; import java.awt.Component; import java.awt.Container; import java.awt.Cursor; import java.awt.Dialog; import java.awt.Dimension; import java.awt.Frame; import java.awt.Insets; import java.awt.LayoutManager; import java.awt.LayoutManager2; import java.awt.Point; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.Window; import java.awt.Graphics; import java.awt.Color; import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.event.WindowEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.JComponent; import javax.swing.JLayeredPane; import javax.swing.JRootPane; import javax.swing.LookAndFeel; import javax.swing.SwingUtilities; import javax.swing.JDialog; import javax.swing.event.MouseInputListener; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicRootPaneUI; import net.beeger.squareness.util.SquarenessTitlePane; import net.beeger.squareness.SquarenessLookAndFeel; /** *

The bigger part of this ui delegate is a copy of MetalRootPaneUI, which is unfortunately not * suited for subclassing.

*

The only Squareness-Part of this is the SquarenessFrameTitlePane which is defined as an inner class of this * one and is used in createTitlePane. Had the original authors of MetalRootPaneUI thought of making that method * protected this ui delegate would look nice and crisp.

*/ public class SquarenessRootPaneUI extends BasicRootPaneUI { public static ComponentUI createUI (JComponent c) { return new SquarenessRootPaneUI(); } /** * Keys to lookup borders in defaults table. */ private static final String[] borderKeys = new String[]{ null, "RootPane.frameBorder", "RootPane.plainDialogBorder", "RootPane.informationDialogBorder", "RootPane.errorDialogBorder", "RootPane.colorChooserDialogBorder", "RootPane.fileChooserDialogBorder", "RootPane.questionDialogBorder", "RootPane.warningDialogBorder" }; /** * The amount of space (in pixels) that the cursor is changed on. */ private static final int CORNER_DRAG_WIDTH = 16; /** * Region from edges that dragging is active from. */ private static final int BORDER_DRAG_THICKNESS = 5; /** * Window the JRootPane is in. */ private Window _window; /** * JComponent providing _window decorations. This will be * null if not providing _window decorations. */ private JComponent _titlePane; /** * MouseInputListener that is added to the parent * Window the JRootPane is contained in. */ private MouseInputListener _mouseInputListener; /** * The LayoutManager that is set on the * JRootPane. */ private LayoutManager _layoutManager; /** * LayoutManager of the JRootPane before we * replaced it. */ private LayoutManager _savedOldLayout; /** * JRootPane providing the look and feel for. */ private JRootPane _root; /** * Cursor used to track the cursor set by the user. * This is initially Cursor.DEFAULT_CURSOR. */ private Cursor _lastCursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); /** * Invokes supers implementation of installUI to install * the necessary state onto the passed in JRootPane * to render the metal look and feel implementation of * RootPaneUI. If * the windowDecorationStyle property of the * JRootPane is other than JRootPane.NONE, * this will add a custom Component to render the widgets to * JRootPane, as well as installing a custom * Border and LayoutManager on the * JRootPane. * * @param c the JRootPane to install state onto */ public void installUI (JComponent c) { super.installUI(c); _root = (JRootPane) c; int style = _root.getWindowDecorationStyle(); if (style != JRootPane.NONE) { installClientDecorations(_root); } } /** * Invokes supers implementation to uninstall any of its state. This will * also reset the LayoutManager of the JRootPane. * If a Component has been added to the JRootPane * to render the _window decoration style, this method will remove it. * Similarly, this will revert the Border and LayoutManager of the * JRootPane to what it was before installUI * was invoked. * * @param c the JRootPane to uninstall state from */ public void uninstallUI (JComponent c) { super.uninstallUI(c); uninstallClientDecorations(_root); _layoutManager = null; _mouseInputListener = null; _root = null; } /** * Installs the appropriate Border onto the * JRootPane. */ void installBorder (JRootPane root) { int style = root.getWindowDecorationStyle(); if (style == JRootPane.NONE) { LookAndFeel.uninstallBorder(root); } else { LookAndFeel.installBorder(root, borderKeys[style]); } } /** * Removes any border that may have been installed. */ private void uninstallBorder (JRootPane root) { LookAndFeel.uninstallBorder(root); } /** * Installs the necessary Listeners on the parent Window, * if there is one. *

* This takes the parent so that cleanup can be done from * removeNotify, at which point the parent hasn't been * reset yet. * * @param parent The parent of the JRootPane */ private void installWindowListeners (JRootPane root, Component parent) { if (parent instanceof Window) { _window = (Window) parent; } else { _window = SwingUtilities.getWindowAncestor(parent); } if (_window != null) { if (_mouseInputListener == null) { _mouseInputListener = createWindowMouseInputListener(); } _window.addMouseListener(_mouseInputListener); _window.addMouseMotionListener(_mouseInputListener); } } /** * Uninstalls the necessary Listeners on the Window the * Listeners were last installed on. */ private void uninstallWindowListeners () { if (_window != null) { _window.removeMouseListener(_mouseInputListener); _window.removeMouseMotionListener(_mouseInputListener); } } /** * Installs the appropriate LayoutManager on the JRootPane * to render the _window decorations. */ private void installLayout (JRootPane root) { if (_layoutManager == null) { _layoutManager = createLayoutManager(); } _savedOldLayout = root.getLayout(); root.setLayout(_layoutManager); } /** * Uninstalls the previously installed LayoutManager. */ private void uninstallLayout (JRootPane root) { if (_savedOldLayout != null) { root.setLayout(_savedOldLayout); _savedOldLayout = null; } } /** * Installs the necessary state onto the JRootPane to render client * decorations. This is ONLY invoked if the JRootPane * has a decoration style other than JRootPane.NONE. */ private void installClientDecorations (JRootPane root) { installBorder(root); JComponent titlePane = createTitlePane(root); setTitlePane(root, titlePane); installWindowListeners(root, root.getParent()); installLayout(root); if (_window != null) { root.revalidate(); root.repaint(); } } /** * Uninstalls any state that installClientDecorations has * installed. *

* NOTE: This may be called if you haven't installed client decorations * yet (ie before installClientDecorations has been invoked). */ private void uninstallClientDecorations (JRootPane root) { uninstallBorder(root); uninstallWindowListeners(); setTitlePane(root, null); uninstallLayout(root); // We have to revalidate/repaint _root if the style is JRootPane.NONE // only. When we needs to call revalidate/repaint with other styles // the installClientDecorations is always called after this method // imediatly and it will cause the revalidate/repaint at the proper // time. int style = root.getWindowDecorationStyle(); if (style == JRootPane.NONE) { root.repaint(); root.revalidate(); } // Reset the cursor, as we may have changed it to a resize cursor if (_window != null) { _window.setCursor(Cursor.getPredefinedCursor (Cursor.DEFAULT_CURSOR)); } _window = null; } /** * Returns the JComponent to render the _window decoration * style. */ private JComponent createTitlePane (JRootPane root) { return new SquarenessFrameTitlePane(root); } /** * Returns a MouseListener that will be added to the * Window containing the JRootPane. */ private MouseInputListener createWindowMouseInputListener () { return new MouseInputHandler(); } /** * Returns a LayoutManager that will be set on the * JRootPane. */ private LayoutManager createLayoutManager () { return new MetalRootLayout(); } /** * Sets the _window title pane -- the JComponent used to provide a plaf a * way to override the native operating system's _window title pane with * one whose look and feel are controlled by the plaf. The plaf creates * and sets this value; the default is null, implying a native operating * system _window title pane. */ private void setTitlePane (JRootPane root, JComponent titlePane) { JLayeredPane layeredPane = root.getLayeredPane(); JComponent oldTitlePane = getTitlePane(); if (oldTitlePane != null) { oldTitlePane.setVisible(false); layeredPane.remove(oldTitlePane); } if (titlePane != null) { layeredPane.add(titlePane, JLayeredPane.FRAME_CONTENT_LAYER); titlePane.setVisible(true); } this._titlePane = titlePane; } /** * Returns the JComponent rendering the title pane. If this * returns null, it implies there is no need to render _window decorations. * * @return the current _window title pane, or null * @see #setTitlePane */ private JComponent getTitlePane () { return _titlePane; } /** * Returns the JRootPane we're providing the look and * feel for. */ private JRootPane getRootPane () { return _root; } /** * Invoked when a property changes. MetalRootPaneUI is * primarily interested in events originating from the * JRootPane it has been installed on identifying the * property windowDecorationStyle. If the * windowDecorationStyle has changed to a value other * than JRootPane.NONE, this will add a Component * to the JRootPane to render the _window decorations, as well * as installing a Border on the JRootPane. * On the other hand, if the windowDecorationStyle has * changed to JRootPane.NONE, this will remove the * Component that has been added to the JRootPane * as well resetting the Border to what it was before * installUI was invoked. * * @param e A PropertyChangeEvent object describing the event source * and the property that has changed. */ public void propertyChange (PropertyChangeEvent e) { super.propertyChange(e); String propertyName = e.getPropertyName(); if (propertyName == null) { return; } if (propertyName.equals("windowDecorationStyle")) { JRootPane root = (JRootPane) e.getSource(); int style = root.getWindowDecorationStyle(); // This is potentially more than needs to be done, // but it rarely happens and makes the install/uninstall process // simpler. MetalTitlePane also assumes it will be recreated if // the decoration style changes. uninstallClientDecorations(root); if (style != JRootPane.NONE) { installClientDecorations(root); } } else if (propertyName.equals("ancestor")) { uninstallWindowListeners(); if (((JRootPane) e.getSource()).getWindowDecorationStyle() != JRootPane.NONE) { installWindowListeners(_root, _root.getParent()); } } return; } /** * A custom layout manager that is responsible for the layout of * layeredPane, glassPane, menuBar and _titlePane, if one has been * installed. */ // NOTE: Ideally this would extends JRootPane.RootLayout, but that // would force this to be non-static. private static class MetalRootLayout implements LayoutManager2 { /** * Returns the amount of space the layout would like to have. * * @param parent the Container for which this layout manager is being used * @return a Dimension object containing the layout's preferred size */ public Dimension preferredLayoutSize (Container parent) { Dimension cpd, mbd, tpd; int cpWidth = 0; int cpHeight = 0; int mbWidth = 0; int mbHeight = 0; int tpWidth = 0; int tpHeight = 0; Insets i = parent.getInsets(); JRootPane root = (JRootPane) parent; if (root.getContentPane() != null) { cpd = root.getContentPane().getPreferredSize(); } else { cpd = root.getSize(); } if (cpd != null) { cpWidth = cpd.width; cpHeight = cpd.height; } if (root.getJMenuBar() != null) { mbd = root.getJMenuBar().getPreferredSize(); if (mbd != null) { mbWidth = mbd.width; mbHeight = mbd.height; } } if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof SquarenessRootPaneUI)) { JComponent titlePane = ((SquarenessRootPaneUI) root.getUI()). getTitlePane(); if (titlePane != null) { tpd = titlePane.getPreferredSize(); if (tpd != null) { tpWidth = tpd.width; tpHeight = tpd.height; } } } return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right, cpHeight + mbHeight + tpHeight + i.top + i.bottom); } /** * Returns the minimum amount of space the layout needs. * * @param parent the Container for which this layout manager is being used * @return a Dimension object containing the layout's minimum size */ public Dimension minimumLayoutSize (Container parent) { Dimension cpd, mbd, tpd; int cpWidth = 0; int cpHeight = 0; int mbWidth = 0; int mbHeight = 0; int tpWidth = 0; Insets i = parent.getInsets(); JRootPane root = (JRootPane) parent; if (root.getContentPane() != null) { cpd = root.getContentPane().getMinimumSize(); } else { cpd = root.getSize(); } if (cpd != null) { cpWidth = cpd.width; cpHeight = cpd.height; } if (root.getJMenuBar() != null) { mbd = root.getJMenuBar().getMinimumSize(); if (mbd != null) { mbWidth = mbd.width; mbHeight = mbd.height; } } if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof SquarenessRootPaneUI)) { JComponent titlePane = ((SquarenessRootPaneUI) root.getUI()). getTitlePane(); if (titlePane != null) { tpd = titlePane.getMinimumSize(); if (tpd != null) { tpWidth = tpd.width; } } } return new Dimension(Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right, cpHeight + mbHeight + tpWidth + i.top + i.bottom); } /** * Returns the maximum amount of space the layout can use. * * @param target parent the Container for which this layout manager is being used * @return a Dimension object containing the layout's maximum size */ public Dimension maximumLayoutSize (Container target) { Dimension cpd, mbd, tpd; int cpWidth = Integer.MAX_VALUE; int cpHeight = Integer.MAX_VALUE; int mbWidth = Integer.MAX_VALUE; int mbHeight = Integer.MAX_VALUE; int tpWidth = Integer.MAX_VALUE; int tpHeight = Integer.MAX_VALUE; Insets i = target.getInsets(); JRootPane root = (JRootPane) target; if (root.getContentPane() != null) { cpd = root.getContentPane().getMaximumSize(); if (cpd != null) { cpWidth = cpd.width; cpHeight = cpd.height; } } if (root.getJMenuBar() != null) { mbd = root.getJMenuBar().getMaximumSize(); if (mbd != null) { mbWidth = mbd.width; mbHeight = mbd.height; } } if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof SquarenessRootPaneUI)) { JComponent titlePane = ((SquarenessRootPaneUI) root.getUI()). getTitlePane(); if (titlePane != null) { tpd = titlePane.getMaximumSize(); if (tpd != null) { tpWidth = tpd.width; tpHeight = tpd.height; } } } int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight); // Only overflows if 3 real non-MAX_VALUE heights, sum to > MAX_VALUE // Only will happen if sums to more than 2 billion units. Not likely. if (maxHeight != Integer.MAX_VALUE) { maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom; } int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth); // Similar overflow comment as above if (maxWidth != Integer.MAX_VALUE) { maxWidth += i.left + i.right; } return new Dimension(maxWidth, maxHeight); } /** * Instructs the layout manager to perform the layout for the specified * container. * * @param parent the Container for which this layout manager is being used */ public void layoutContainer (Container parent) { JRootPane root = (JRootPane) parent; Rectangle b = root.getBounds(); Insets i = root.getInsets(); int nextY = 0; int w = b.width - i.right - i.left; int h = b.height - i.top - i.bottom; if (root.getLayeredPane() != null) { root.getLayeredPane().setBounds(i.left, i.top, w, h); } if (root.getGlassPane() != null) { root.getGlassPane().setBounds(i.left, i.top, w, h); } // Note: This is laying out the children in the layeredPane, // technically, these are not our children. if (root.getWindowDecorationStyle() != JRootPane.NONE && (root.getUI() instanceof SquarenessRootPaneUI)) { JComponent titlePane = ((SquarenessRootPaneUI) root.getUI()). getTitlePane(); if (titlePane != null) { Dimension tpd = titlePane.getPreferredSize(); if (tpd != null) { int tpHeight = tpd.height; titlePane.setBounds(0, 0, w, tpHeight); nextY += tpHeight; } } } if (root.getJMenuBar() != null) { Dimension mbd = root.getJMenuBar().getPreferredSize(); root.getJMenuBar().setBounds(0, nextY, w, mbd.height); nextY += mbd.height; } if (root.getContentPane() != null) { root.getContentPane().setBounds(0, nextY, w, h < nextY ? 0 : h - nextY); } } public void addLayoutComponent (String name, Component comp) { } public void removeLayoutComponent (Component comp) { } public void addLayoutComponent (Component comp, Object constraints) { } public float getLayoutAlignmentX (Container target) { return 0.0f; } public float getLayoutAlignmentY (Container target) { return 0.0f; } public void invalidateLayout (Container target) { } } /** * Maps from positions to cursor type. Refer to calculateCorner and * calculatePosition for details of this. */ private static final int[] cursorMapping = new int[] {Cursor.NW_RESIZE_CURSOR, Cursor.NW_RESIZE_CURSOR, Cursor.N_RESIZE_CURSOR, Cursor.NE_RESIZE_CURSOR, Cursor.NE_RESIZE_CURSOR, Cursor.NW_RESIZE_CURSOR, 0, 0, 0, Cursor.NE_RESIZE_CURSOR, Cursor.W_RESIZE_CURSOR, 0, 0, 0, Cursor.E_RESIZE_CURSOR, Cursor.SW_RESIZE_CURSOR, 0, 0, 0, Cursor.SE_RESIZE_CURSOR, Cursor.SW_RESIZE_CURSOR, Cursor.SW_RESIZE_CURSOR, Cursor.S_RESIZE_CURSOR, Cursor.SE_RESIZE_CURSOR, Cursor.SE_RESIZE_CURSOR }; /** * MouseInputHandler is responsible for handling resize/moving of * the Window. It sets the cursor directly on the Window when then * mouse moves over a hot spot. */ private class MouseInputHandler implements MouseInputListener { /** * Set to true if the drag operation is moving the _window. */ private boolean isMovingWindow; /** * Used to determine the corner the resize is occuring from. */ private int dragCursor; /** * X location the mouse went down on for a drag operation. */ private int dragOffsetX; /** * Y location the mouse went down on for a drag operation. */ private int dragOffsetY; /** * Width of the _window when the drag started. */ private int dragWidth; /** * Height of the _window when the drag started. */ private int dragHeight; public void mousePressed (MouseEvent ev) { JRootPane rootPane = getRootPane(); if (rootPane.getWindowDecorationStyle() == JRootPane.NONE) { return; } Point dragWindowOffset = ev.getPoint(); Window w = (Window) ev.getSource(); if (w != null) { w.toFront(); } Point convertedDragWindowOffset = SwingUtilities.convertPoint(w, dragWindowOffset, getTitlePane()); Frame f = null; Dialog d = null; if (w instanceof Frame) { f = (Frame) w; } else if (w instanceof Dialog) { d = (Dialog) w; } int frameState = (f != null) ? f.getExtendedState() : 0; if (getTitlePane() != null && getTitlePane().contains(convertedDragWindowOffset)) { if ((f != null && ((frameState & Frame.MAXIMIZED_BOTH) == 0) || (d != null)) && dragWindowOffset.y >= BORDER_DRAG_THICKNESS && dragWindowOffset.x >= BORDER_DRAG_THICKNESS && dragWindowOffset.x < w.getWidth() - BORDER_DRAG_THICKNESS) { isMovingWindow = true; dragOffsetX = dragWindowOffset.x; dragOffsetY = dragWindowOffset.y; } } else if (f != null && f.isResizable() && ((frameState & Frame.MAXIMIZED_BOTH) == 0) || (d != null && d.isResizable())) { dragOffsetX = dragWindowOffset.x; dragOffsetY = dragWindowOffset.y; dragWidth = w.getWidth(); dragHeight = w.getHeight(); dragCursor = getCursor(calculateCorner(w, dragWindowOffset.x, dragWindowOffset.y)); } } public void mouseReleased (MouseEvent ev) { if (dragCursor != 0 && _window != null && !_window.isValid()) { // Some Window systems validate as you resize, others won't, // thus the check for validity before repainting. _window.validate(); getRootPane().repaint(); } isMovingWindow = false; dragCursor = 0; } public void mouseMoved (MouseEvent ev) { JRootPane root = getRootPane(); if (root.getWindowDecorationStyle() == JRootPane.NONE) { return; } Window w = (Window) ev.getSource(); Frame f = null; Dialog d = null; if (w instanceof Frame) { f = (Frame) w; } else if (w instanceof Dialog) { d = (Dialog) w; } // Update the cursor int cursor = getCursor(calculateCorner(w, ev.getX(), ev.getY())); if (cursor != 0 && ((f != null && (f.isResizable() && (f.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0)) || (d != null && d.isResizable()))) { w.setCursor(Cursor.getPredefinedCursor(cursor)); } else { w.setCursor(_lastCursor); } } private void adjust (Rectangle bounds, Dimension min, int deltaX, int deltaY, int deltaWidth, int deltaHeight) { bounds.x += deltaX; bounds.y += deltaY; bounds.width += deltaWidth; bounds.height += deltaHeight; if (min != null) { if (bounds.width < min.width) { int correction = min.width - bounds.width; if (deltaX != 0) { bounds.x -= correction; } bounds.width = min.width; } if (bounds.height < min.height) { int correction = min.height - bounds.height; if (deltaY != 0) { bounds.y -= correction; } bounds.height = min.height; } } } public void mouseDragged (MouseEvent ev) { Window w = (Window) ev.getSource(); Point pt = ev.getPoint(); if (isMovingWindow) { Point windowPt = w.getLocationOnScreen(); windowPt.x += pt.x - dragOffsetX; windowPt.y += pt.y - dragOffsetY; w.setLocation(windowPt); } else if (dragCursor != 0) { Rectangle r = w.getBounds(); Rectangle startBounds = new Rectangle(r); Dimension min = w.getMinimumSize(); switch (dragCursor) { case Cursor.E_RESIZE_CURSOR: adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0); break; case Cursor.S_RESIZE_CURSOR: adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height); break; case Cursor.N_RESIZE_CURSOR: adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY)); break; case Cursor.W_RESIZE_CURSOR: adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0); break; case Cursor.NE_RESIZE_CURSOR: adjust(r, min, 0, pt.y - dragOffsetY, pt.x + (dragWidth - dragOffsetX) - r.width, -(pt.y - dragOffsetY)); break; case Cursor.SE_RESIZE_CURSOR: adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, pt.y + (dragHeight - dragOffsetY) - r.height); break; case Cursor.NW_RESIZE_CURSOR: adjust(r, min, pt.x - dragOffsetX, pt.y - dragOffsetY, -(pt.x - dragOffsetX), -(pt.y - dragOffsetY)); break; case Cursor.SW_RESIZE_CURSOR: adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), pt.y + (dragHeight - dragOffsetY) - r.height); break; default: break; } if (!r.equals(startBounds)) { w.setBounds(r); // Defer repaint/validate on mouseReleased unless dynamic // layout is active. if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) { w.validate(); getRootPane().repaint(); } } } } public void mouseEntered (MouseEvent ev) { Window w = (Window) ev.getSource(); _lastCursor = w.getCursor(); mouseMoved(ev); } public void mouseExited (MouseEvent ev) { Window w = (Window) ev.getSource(); w.setCursor(_lastCursor); } public void mouseClicked (MouseEvent ev) { Window w = (Window) ev.getSource(); Frame f = null; if (w instanceof Frame) { f = (Frame) w; } else { return; } Point convertedPoint = SwingUtilities.convertPoint(w, ev.getPoint(), getTitlePane()); int state = f.getExtendedState(); if (getTitlePane() != null && getTitlePane().contains(convertedPoint)) { if ((ev.getClickCount() % 2) == 0 && ((ev.getModifiers() & InputEvent.BUTTON1_MASK) != 0)) { if (f.isResizable()) { if ((state & Frame.MAXIMIZED_BOTH) != 0) { f.setExtendedState(state & ~Frame.MAXIMIZED_BOTH); } else { f.setExtendedState(state | Frame.MAXIMIZED_BOTH); } return; } } } } /** * Returns the corner that contains the point x, * y, or -1 if the position doesn't match a corner. */ private int calculateCorner (Component c, int x, int y) { int xPosition = calculatePosition(x, c.getWidth()); int yPosition = calculatePosition(y, c.getHeight()); if (xPosition == -1 || yPosition == -1) { return -1; } return yPosition * 5 + xPosition; } /** * Returns the Cursor to render for the specified corner. This returns * 0 if the corner doesn't map to a valid Cursor */ private int getCursor (int corner) { if (corner == -1) { return 0; } return cursorMapping[corner]; } /** * Returns an integer indicating the position of spot * in width. The return value will be: * 0 if < BORDER_DRAG_THICKNESS * 1 if < CORNER_DRAG_WIDTH * 2 if >= CORNER_DRAG_WIDTH && < width - BORDER_DRAG_THICKNESS * 3 if >= width - CORNER_DRAG_WIDTH * 4 if >= width - BORDER_DRAG_THICKNESS * 5 otherwise */ private int calculatePosition (int spot, int width) { if (spot < BORDER_DRAG_THICKNESS) { return 0; } if (spot < CORNER_DRAG_WIDTH) { return 1; } if (spot >= (width - BORDER_DRAG_THICKNESS)) { return 4; } if (spot >= (width - CORNER_DRAG_WIDTH)) { return 3; } return 2; } } /** * The only Squareness part of this ui delegate - the one thing this is all about : the title pane. */ private static class SquarenessFrameTitlePane extends SquarenessTitlePane { public SquarenessFrameTitlePane (JRootPane rootPane) { _rootPane = rootPane; } public void addNotify () { super.addNotify(); _window = SwingUtilities.getWindowAncestor(this); _window.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange (PropertyChangeEvent evt) { update(); _window.repaint(); } }); _rootPane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange (PropertyChangeEvent evt) { update(); _window.repaint(); } }); } /** * Calls the UI delegate's paint method, if the UI delegate * is non-null. We pass the delegate a copy of the * Graphics object to protect the rest of the * paint code from irrevocable changes * (for example, Graphics.translate). *

* If you override this in a subclass you should not make permanent * changes to the passed in Graphics. For example, you * should not alter the clip Rectangle or modify the * transform. If you need to do these operations you may find it * easier to create a new Graphics from the passed in * Graphics and manipulate it. Further, if you do not * invoker super's implementation you must honor the opaque property, * that is * if this component is opaque, you must completely fill in the background * in a non-opaque color. If you do not honor the opaque property you * will likely see visual artifacts. * * @param g the Graphics object to protect * @see #paint * @see javax.swing.plaf.ComponentUI */ protected void paintComponent (Graphics g) { update(); Color oldColor = g.getColor(); g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getWindowBackgroundColor()); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(oldColor); } public boolean isLeftToRight () { return _window != null ? _window.getComponentOrientation().isLeftToRight() : true; } protected boolean isIconifiable () { return isFrame(); } protected boolean isMaximizable () { return isFrame() && getFrame().isResizable(); } protected boolean isClosable () { return true; } protected void close () { if (_window != null) { _window.dispatchEvent(new WindowEvent(_window, WindowEvent.WINDOW_CLOSING)); } } protected void iconify () { if (isFrame()) { Frame frame = getFrame(); frame.setExtendedState(getFrame().getExtendedState() | Frame.ICONIFIED); } } protected void maximize () { if (isFrame()) { Frame frame = getFrame(); frame.setExtendedState(getFrame().getExtendedState() | Frame.MAXIMIZED_BOTH); } } protected void restore () { if (isFrame()) { Frame frame = getFrame(); if (isIconified()) { frame.setExtendedState(getFrame().getExtendedState() & ~Frame.ICONIFIED); } else { frame.setExtendedState(getFrame().getExtendedState() & ~Frame.MAXIMIZED_BOTH); } } } protected boolean isMaximized () { return isFrame() && (getFrame().getExtendedState() & Frame.MAXIMIZED_BOTH) != 0; } protected boolean isIconified () { return isFrame() && (getFrame().getExtendedState() & Frame.ICONIFIED) != 0; } protected String getTitle () { String result = null; if (isFrame()) { result = getFrame().getTitle(); } else if (isDialog()) { result = getDialog().getTitle(); } return result; } protected boolean isFrame () { return _window instanceof Frame; } protected Frame getFrame () { return (Frame) _window; } protected boolean isDialog () { return _window instanceof JDialog; } protected JDialog getDialog () { return (JDialog) _window; } private JRootPane _rootPane; private Window _window; } }squareness-2.3.0/source/net/beeger/squareness/delegate/SquarenessScrollBarUI.java100644 0 0 43324 10563076303 25405 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.delegate; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Rectangle; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JScrollBar; import javax.swing.SwingConstants; import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicScrollBarUI; import net.beeger.squareness.SquarenessConstants; import net.beeger.squareness.SquarenessLookAndFeel; import net.beeger.squareness.util.SquarenessBorderFactory; /** * The Squareness Scroll Bar UI delegate. */ public class SquarenessScrollBarUI extends BasicScrollBarUI { /** * Create the ui delegate for the given component * * @param component The component for which to create the ui delegate * @return The created ui delegate */ public static ComponentUI createUI (JComponent component) { return new SquarenessScrollBarUI(); } /** * Install this UI delegate for the given component. * * @param component The component to install this UI delegate for,. */ public void installUI (JComponent component) { component.putClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY, Boolean.FALSE); component.putClientProperty(SquarenessConstants.SCROLLBAR_THUMB_PRESSED_CLIENT_PROPERTY_KEY, Boolean.FALSE); component.putClientProperty(SquarenessConstants.SCROLLBAR_TRACK_PRESSED_CLIENT_PROPERTY_KEY, Boolean.FALSE); _scrollBarMouseMotionListener = new ScrollBarMouseMotionListener(); _scrollBarMouseListener = new ScrollBarMouseListener(); component.addMouseMotionListener(_scrollBarMouseMotionListener); component.addMouseListener(_scrollBarMouseListener); super.installUI(component); } /** * Uninstall this UI delegate from the given component. * * @param component The component to uninstall this UI delegate from. */ public void uninstallUI (JComponent component) { component.removeMouseMotionListener(_scrollBarMouseMotionListener); component.removeMouseListener(_scrollBarMouseListener); super.uninstallUI(component); } /** * Paint the thumb of the scroll bar. * * @param graphics The graphics object used to paint the thumb. * @param component The component (the scroll bar) to paint the thumb for. * @param thumbBounds The bounds of the thumb. */ protected void paintThumb (Graphics graphics, JComponent component, Rectangle thumbBounds) { Color oldColor = graphics.getColor(); boolean isRollover = scrollbar.getClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY).equals( Boolean.TRUE); boolean isPressed = scrollbar.getClientProperty(SquarenessConstants.SCROLLBAR_THUMB_PRESSED_CLIENT_PROPERTY_KEY) .equals(Boolean.TRUE); Color thumbFillColor; if (isRollover || isPressed) { thumbFillColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getSelectedControlBackgroundColor(); } else { thumbFillColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalControlBackgroundColor(); } graphics.setColor(thumbFillColor); graphics.fillRect(thumbBounds.x, thumbBounds.y, thumbBounds.width - 1, thumbBounds.height - 1); if (isPressed) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getSelectedControlBackgroundShadowColor()); graphics.fillRect(thumbBounds.x + 1, thumbBounds.y + 1, thumbBounds.width - 2, 2); graphics.fillRect(thumbBounds.x + 1, thumbBounds.y + 1, 2, thumbBounds.height - 2); } graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); graphics.drawRect(thumbBounds.x, thumbBounds.y, thumbBounds.width - 1, thumbBounds.height - 1); paintGripper(graphics, thumbBounds, thumbFillColor, isPressed, isRollover); graphics.setColor(oldColor); } /** * Paint the gripper for the scroll bar. * * @param graphics The graphics object used to paint the gripper. * @param thumbBounds The bounds of the thumb to paint the gripper on. * @param thumbFillColor The color with which the thumb is currently filled. * @param isThumbPressed Is the thumb currently pressed? * @param isThumbRollover Is the thumb currently in rollover mode? */ private void paintGripper (Graphics graphics, Rectangle thumbBounds, Color thumbFillColor, boolean isThumbPressed, boolean isThumbRollover) { boolean isHorizontal = scrollbar.getOrientation() == SwingConstants.HORIZONTAL; if ((isHorizontal && thumbBounds.getWidth() > 16) || (!isHorizontal && thumbBounds.getHeight() > 16)) { int translatedX = 0; int translatedY = 0; Color shadow = thumbFillColor.darker(); Color highlight = thumbFillColor.brighter(); translatedX = thumbBounds.x + (thumbBounds.width >> 1) - 3; translatedY = thumbBounds.y + (thumbBounds.height >> 1) - 3; graphics.translate(translatedX, translatedY); if(isHorizontal) { if (isThumbPressed || isThumbRollover) { graphics.translate(0, 1); graphics.setColor(shadow); paintHorizontalGripperPart(graphics); graphics.setColor(highlight); graphics.translate(1, 1); paintHorizontalGripperPart(graphics); graphics.translate(- 1, - 1); graphics.translate(0, - 1); } else { graphics.setColor(highlight); paintHorizontalGripperPart(graphics); graphics.setColor(shadow); graphics.translate(1, 1); paintHorizontalGripperPart(graphics); graphics.translate(- 1, - 1); } } else { if (isThumbPressed || isThumbRollover) { graphics.translate(1, 0); graphics.setColor(shadow); paintVerticalGripperPart(graphics); graphics.setColor(highlight); graphics.translate(1, 1); paintVerticalGripperPart(graphics); graphics.translate(- 1, - 1); graphics.translate(-1, 0); } else { graphics.setColor(highlight); paintVerticalGripperPart(graphics); graphics.setColor(shadow); graphics.translate(1, 1); paintVerticalGripperPart(graphics); graphics.translate(- 1, - 1); } } graphics.translate(-translatedX, -translatedY); } } /** * Paint one part of the gripper for a vertical scroll bar. * A gripper conists of two parts, the highlight and the shadow part. They have the same structure. * The only difference is that they are painted on different positions. * * @param graphics The graphics object used to paint the part. */ protected void paintVerticalGripperPart (Graphics graphics) { paintVerticalGripperPartColumn(graphics); graphics.translate(4, 0); paintVerticalGripperPartColumn(graphics); graphics.translate(-4, 0); } /** * Each vertical gripper part consists of two columns that look the same. The operation * calling this operation has to translate the graphics to the right position. * * @param graphics The graphics object used to paint the part column. */ protected void paintVerticalGripperPartColumn (Graphics graphics) { graphics.drawLine(0, 0, 1, 0); graphics.drawLine(0, 2, 1, 2); graphics.drawLine(0, 4, 1, 4); graphics.drawLine(0, 6, 1, 6); } /** * Paint one part of the gripper for a horizontal scroll bar. * A gripper conists of two parts, the highlight and the shadow part. They have the same structure. * The only difference is that they are painted on different positions. * * @param graphics The graphics object used to paint the part. */ protected void paintHorizontalGripperPart (Graphics graphics) { paintHorizontalGripperPartRow(graphics); graphics.translate(0, 4); paintHorizontalGripperPartRow(graphics); graphics.translate(0, -4); } /** * Each horizontal gripper part consists of two columns that look the same. The operation * calling this operation has to translate the graphics to the right position. * * @param graphics The graphics object used to paint the part column. */ protected void paintHorizontalGripperPartRow (Graphics graphics) { graphics.drawLine(0, 0 , 0, 1); graphics.drawLine(2, 0 , 2, 1); graphics.drawLine(4, 0 , 4, 1); graphics.drawLine(6, 0 , 6, 1); } /** * Paint the track of the scroll bar. * * @param graphics The graphics object used to paint the track. * @param component The component (the scroll bar) to paint the track for. * @param trackBounds The bounds of the track to paint. */ protected void paintTrack (Graphics graphics, JComponent component, Rectangle trackBounds) { Color oldColor = graphics.getColor(); if (Boolean.TRUE.equals(scrollbar.getClientProperty(SquarenessConstants.SCROLLBAR_TRACK_PRESSED_CLIENT_PROPERTY_KEY))) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getPressedScrollBarTrackBackgroundColor()); } else { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getProgressBarBackgroundColor()); } graphics.fillRect(trackBounds.x, trackBounds.y, trackBounds.width - 1, trackBounds.height - 1); graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { graphics.drawLine(trackBounds.x, 0, trackBounds.x, scrollbar.getHeight() - 1); graphics.drawLine(trackBounds.width - 1, 0, trackBounds.width - 1, scrollbar.getHeight() - 1); } else { graphics.drawLine(0, trackBounds.y, scrollbar.getWidth() - 1, trackBounds.y); graphics.drawLine(0, trackBounds.height - 1, scrollbar.getWidth() - 1, trackBounds.height - 1); } graphics.setColor(oldColor); } /** * Create the button that is used to scroll down or right the scroll bar. * * @param orientation The orientation of the scrollbar (JScrollBar.HORIZONTAL or JScrollBar.VERTICAL) * @return The created button */ protected JButton createIncreaseButton (int orientation) { UIDefaults defaults = UIManager.getDefaults(); int scrollbarWidth = defaults.getInt("ScrollBar.width"); final JButton button = new SquarenessScrollBarButton(); Dimension dimension = new Dimension(scrollbarWidth, scrollbarWidth); button.setPreferredSize(dimension); button.setMinimumSize(dimension); if (scrollbar.getOrientation() == JScrollBar.HORIZONTAL) { button.setIcon(defaults.getIcon(SquarenessConstants.SCROLL_ARROW_RIGHT_KEY)); } else { button.setIcon(defaults.getIcon(SquarenessConstants.SCROLL_ARROW_DOWN_KEY)); } button.setHorizontalAlignment(SwingConstants.CENTER); button.setVerticalAlignment(SwingConstants.CENTER); return button; } /** * Create the button that is used to scroll up or left the scroll bar. * * @param orientation The orientation of the scrollbar (JScrollBar.HORIZONTAL or JScrollBar.VERTICAL) * @return The created button */ protected JButton createDecreaseButton (int orientation) { UIDefaults defaults = UIManager.getDefaults(); int scrollbarWidth = defaults.getInt("ScrollBar.width"); final JButton button = new SquarenessScrollBarButton(); Dimension dimension = new Dimension(scrollbarWidth, scrollbarWidth); button.setPreferredSize(dimension); button.setMinimumSize(dimension); if (scrollbar.getOrientation() == JScrollBar.HORIZONTAL) { button.setIcon(defaults.getIcon(SquarenessConstants.SCROLL_ARROW_LEFT_KEY)); } else { button.setIcon(defaults.getIcon(SquarenessConstants.SCROLL_ARROW_UP_KEY)); } button.setHorizontalAlignment(SwingConstants.CENTER); button.setVerticalAlignment(SwingConstants.CENTER); return button; } private static class SquarenessScrollBarButton extends JButton { public Border getBorder () { return _border; } private Border _border = SquarenessBorderFactory.getNonSpacingControlBorderWithMargin(); } /** * The mouse motion listener that observes wheter the scroll bar enters or exits roll over mode. * The client property SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY is changed on the scroll bar accordingly. */ private class ScrollBarMouseMotionListener extends MouseMotionAdapter { public void mouseMoved (MouseEvent mouseEvent) { Rectangle thumbBounds = getThumbBounds(); if (thumbBounds.contains(mouseEvent.getPoint())) { if (scrollbar.getClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY).equals(Boolean.FALSE)) { scrollbar.putClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY, Boolean.TRUE); scrollbar.repaint(thumbBounds); } } else { if (scrollbar.getClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY).equals(Boolean.TRUE)) { scrollbar.putClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY, Boolean.FALSE); scrollbar.repaint(thumbBounds); } } } } /** * The mouse listener that observes whether the thumb or track are clicked and sets the according * client properties SquarenessConstants.SCROLLBAR_THUMB_PRESSED_CLIENT_PROPERTY_KEY */ private class ScrollBarMouseListener extends MouseAdapter { public void mousePressed (MouseEvent mouseEvent) { Rectangle thumbBounds = getThumbBounds(); Rectangle trackBounds = getTrackBounds(); if (thumbBounds.contains(mouseEvent.getPoint()) && scrollbar.getClientProperty(SquarenessConstants.SCROLLBAR_THUMB_PRESSED_CLIENT_PROPERTY_KEY).equals( Boolean.FALSE)) { scrollbar.putClientProperty(SquarenessConstants.SCROLLBAR_THUMB_PRESSED_CLIENT_PROPERTY_KEY, Boolean.TRUE); scrollbar.repaint(thumbBounds); } else if (trackBounds.contains(mouseEvent.getPoint()) && scrollbar.getClientProperty(SquarenessConstants.SCROLLBAR_TRACK_PRESSED_CLIENT_PROPERTY_KEY).equals( Boolean.FALSE)) { scrollbar.putClientProperty(SquarenessConstants.SCROLLBAR_TRACK_PRESSED_CLIENT_PROPERTY_KEY, Boolean.TRUE); scrollbar.repaint(trackBounds); } } public void mouseReleased (MouseEvent mouseEvent) { Rectangle thumbBounds = getThumbBounds(); Rectangle trackBounds = getTrackBounds(); if (scrollbar.getClientProperty(SquarenessConstants.SCROLLBAR_THUMB_PRESSED_CLIENT_PROPERTY_KEY).equals( Boolean.TRUE)) { scrollbar.putClientProperty(SquarenessConstants.SCROLLBAR_THUMB_PRESSED_CLIENT_PROPERTY_KEY, Boolean.FALSE); scrollbar.repaint(thumbBounds); } else if (scrollbar.getClientProperty(SquarenessConstants.SCROLLBAR_TRACK_PRESSED_CLIENT_PROPERTY_KEY).equals( Boolean.TRUE)) { scrollbar.putClientProperty(SquarenessConstants.SCROLLBAR_TRACK_PRESSED_CLIENT_PROPERTY_KEY, Boolean.FALSE); scrollbar.repaint(trackBounds); } } public void mouseExited (MouseEvent mouseEvent) { if (scrollbar.getClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY).equals(Boolean.TRUE)) { scrollbar.putClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY, Boolean.FALSE); scrollbar.repaint(getThumbBounds()); } } } private ScrollBarMouseMotionListener _scrollBarMouseMotionListener; private ScrollBarMouseListener _scrollBarMouseListener; }squareness-2.3.0/source/net/beeger/squareness/delegate/SquarenessSliderUI.java100644 0 0 20045 10563076303 24737 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.delegate; import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import javax.swing.JComponent; import javax.swing.JSlider; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicSliderUI; import net.beeger.squareness.SquarenessLookAndFeel; /** * The Squareness Slider UI delegate. */ public class SquarenessSliderUI extends BasicSliderUI { /** * Create an UI delegate for the given component. * * @param component The component for which to create the UI delegate. * @return The created UI delegate. */ public static ComponentUI createUI (JComponent component) { return new SquarenessSliderUI((JSlider) component); } /** * Create the UI delegate. * * @param slider The slider for which this delegate will be used. */ public SquarenessSliderUI (JSlider slider) { super(slider); } /** * Paint the track of the slider. * * @param graphics The graphics object to use for painting the track. */ public void paintTrack (Graphics graphics) { Color oldColor = graphics.getColor(); int x, y, width, height; if (slider.getOrientation() == JSlider.HORIZONTAL) { x = trackRect.x; y = trackRect.y + (trackRect.height >> 1) - 2; width = trackRect.width; height = 5; } else { x = trackRect.x + (trackRect.width >> 1) - 2; y = trackRect.y; width = 5; height = trackRect.height; } graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getProgressBarBackgroundColor()); graphics.fillRect(x, y, width, height); graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); graphics.drawRect(x, y, width - 1, height - 1); if (slider.getClientProperty("JSlider.isFilled") != null && ((Boolean) slider.getClientProperty("JSlider.isFilled")).booleanValue()) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getSelectedControlBackgroundColor()); if (slider.getOrientation() == JSlider.HORIZONTAL) { if (drawInverted()) { graphics.fillRect(thumbRect.x, y + 1, width - 2 - (thumbRect.x - x), height - 2); } else { graphics.fillRect(x + 1, y + 1, thumbRect.x - x, height - 2); } } else { if (drawInverted()) { graphics.fillRect(x + 1, thumbRect.y, width - 2 - (thumbRect.y - y), height - 2); } else { graphics.fillRect(x + 1, y + 1, width - 2, thumbRect.y - y); } } } graphics.setColor(oldColor); } /** * Paint the thumb of the slider. * * @param graphics The graphics object to use for the painting. */ public void paintThumb (Graphics graphics) { Color oldColor = graphics.getColor(); graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalControlBackgroundColor()); graphics.fillRect(thumbRect.x, thumbRect.y, thumbRect.width, thumbRect.height); if (slider.isEnabled()) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } graphics.drawRect(thumbRect.x, thumbRect.y, thumbRect.width - 1, thumbRect.height - 1); if (slider.getPaintTicks()) { int yBot = thumbRect.y + thumbRect.height - 1; int xRight = thumbRect.x + thumbRect.width - 1; if (slider.getOrientation() == JSlider.HORIZONTAL) { graphics.drawLine(thumbRect.x + 2, yBot - 5, thumbRect.x + 5, yBot - 2); graphics.drawLine(thumbRect.x + 3, yBot - 5, thumbRect.x + 5, yBot - 3); graphics.drawLine(thumbRect.x + 3, yBot - 6, thumbRect.x + 5, yBot - 4); graphics.drawLine(xRight - 2, yBot - 5, thumbRect.x + 5, yBot - 2); graphics.drawLine(xRight - 3, yBot - 5, thumbRect.x + 5, yBot - 3); graphics.drawLine(xRight - 3, yBot - 6, thumbRect.x + 5, yBot - 4); } else { graphics.drawLine(xRight - 5, thumbRect.y + 2, xRight - 2, thumbRect.y + 5); graphics.drawLine(xRight - 5, thumbRect.y + 3, xRight - 3, thumbRect.y + 5); graphics.drawLine(xRight - 6, thumbRect.y + 3, xRight - 4, thumbRect.y + 5); graphics.drawLine(xRight - 5, yBot - 2, xRight - 2, thumbRect.y + 5); graphics.drawLine(xRight - 5, yBot - 3, xRight - 3, thumbRect.y + 5); graphics.drawLine(xRight - 6, yBot - 3, xRight - 4, thumbRect.y + 5); } } graphics.setColor(oldColor); } /** * Paint a minor tick for a horizontal slider. * * @param graphics The graphics object to use for painting. * @param tickBounds The bounds of the tick. * @param x The x position at which to paint the tick. */ protected void paintMinorTickForHorizSlider (Graphics graphics, Rectangle tickBounds, int x) { graphics.drawLine(x, 1, x, (tickBounds.height >> 1) - 1); } /** * Paint a major tick for a horizontal slider. * * @param graphics The graphics object to use for painting. * @param tickBounds The bounds of the tick. * @param x The x position at which to paint the tick. */ protected void paintMajorTickForHorizSlider (Graphics graphics, Rectangle tickBounds, int x) { graphics.drawLine(x, 1, x, tickBounds.height - 2); } /** * Paint a minor tick for a vertical slider. * * @param graphics The graphics object to use for painting. * @param tickBounds The bounds of the tick. * @param y The y position at which to paint the tick. */ protected void paintMinorTickForVertSlider (Graphics graphics, Rectangle tickBounds, int y) { graphics.drawLine(1, y, (tickBounds.width >> 1) - 1, y); } /** * Paint a major tick for a vertical slider. * * @param graphics The graphics object to use for painting. * @param tickBounds The bounds of the tick. * @param y The y position at which to paint the tick. */ protected void paintMajorTickForVertSlider (Graphics graphics, Rectangle tickBounds, int y) { graphics.drawLine(1, y, tickBounds.width - 2, y); } }squareness-2.3.0/source/net/beeger/squareness/delegate/SquarenessSpinnerUI.java100644 0 0 10465 10563076303 25140 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.delegate; import java.awt.Component; import java.awt.Dimension; import java.awt.event.MouseListener; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicSpinnerUI; import net.beeger.squareness.SquarenessConstants; /** * The Squareness Spinner UI Delegate. */ public class SquarenessSpinnerUI extends BasicSpinnerUI { /** * Create the UI delegate for the given component * * @param component The component for which to create the ui delegate * @return The created ui delegate */ public static ComponentUI createUI (JComponent component) { return new SquarenessSpinnerUI(); } /** * Install the UI delegate for the given component. * * @param component The component for which to install the UI delegate. */ public void installUI (JComponent component) { super.installUI(component); _nextButton.addActionListener(SwingUtilities.getUIActionMap(spinner).get("increment")); _nextButton.addMouseListener((MouseListener) SwingUtilities.getUIActionMap(spinner).get("increment")); _previousButton.addActionListener(SwingUtilities.getUIActionMap(spinner).get("decrement")); _previousButton.addMouseListener((MouseListener) SwingUtilities.getUIActionMap(spinner).get("decrement")); } /** * Create the button which increases the value of the spinner. * * @return The created button */ protected Component createNextButton () { _nextButton = new JButton(UIManager.getIcon(SquarenessConstants.SPIN_UP_KEY)); _nextButton.setPreferredSize(new Dimension(16, 16)); _nextButton.setMinimumSize(new Dimension(5, 5)); _nextButton.setHorizontalAlignment(SwingConstants.CENTER); _nextButton.setVerticalAlignment(SwingConstants.CENTER); return _nextButton; } /** * Create the button which decreases the value of the spinner. * * @return The create button */ protected Component createPreviousButton () { _previousButton = new JButton(UIManager.getIcon(SquarenessConstants.SPIN_DOWN_KEY)); _previousButton.setPreferredSize(new Dimension(16, 16)); _previousButton.setMinimumSize(new Dimension(5, 5)); _previousButton.setHorizontalAlignment(SwingConstants.CENTER); _previousButton.setVerticalAlignment(SwingConstants.CENTER); return _previousButton; } private JButton _previousButton; private JButton _nextButton; }squareness-2.3.0/source/net/beeger/squareness/delegate/SquarenessTabbedPaneUI.java100644 0 0 43447 10563076303 25515 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.delegate; import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; import javax.swing.JComponent; import javax.swing.JTabbedPane; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicTabbedPaneUI; import net.beeger.squareness.SquarenessLookAndFeel; /** * The Squareness Tabbed Pane UI delegate. */ public class SquarenessTabbedPaneUI extends BasicTabbedPaneUI { /** * Create the UI delegate for the given component. * * @param component The component for which to create an UI delegate. * @return The created UI delegate. */ public static ComponentUI createUI(JComponent component) { return new SquarenessTabbedPaneUI(); } /** * Install the UI delegate for the given component. * * @param component The component for which to install the UI delegate. */ public void installUI(JComponent component) { super.installUI(component); _tabbedBarMouseListener = new TabbedPaneMouseListener(); _tabbedBarMouseMotionListener = new TabbedPaneMouseMotionListener(); tabPane.addMouseListener(_tabbedBarMouseListener); tabPane.addMouseMotionListener(_tabbedBarMouseMotionListener); } /** * Uninstall the UI delegate from the given component. *

* param component The component from which to uninstall the UI delegate. */ public void uninstallUI(JComponent component) { tabPane.removeMouseListener(_tabbedBarMouseListener); tabPane.removeMouseMotionListener(_tabbedBarMouseMotionListener); super.uninstallUI(component); } /** * Paint the background of the tab at index tabIndex. * * @param graphics The graphics object to use for painting. * @param tabPlacement The placement of the tabs (TOP, BOTTOM, LEFT, RIGHT) * @param tabIndex The index of the tab to paint the background for. * @param x The x position of the tab * @param y The y position of the tab * @param width The width of the tab * @param height The height of the tab * @param isSelected Is the tab currently selected? */ protected void paintTabBackground(Graphics graphics, int tabPlacement, int tabIndex, int x, int y, int width, int height, boolean isSelected) { Color oldColor = graphics.getColor(); Color background; if (!isSelected && _mouseOverTab == tabIndex) { background = SquarenessLookAndFeel.getCurrentSquarenessTheme().getSelectedControlBackgroundColor(); } else { background = SquarenessLookAndFeel.getCurrentSquarenessTheme().getWindowBackgroundColor(); } graphics.setColor(background); graphics.fillRect(x, y, width, height); graphics.setColor(oldColor); } /** * Paint the border of the tab at tabIndex. * * @param graphics The graphics object to use for painting. * @param tabPlacement The placement of the tabs (TOP, BOTTOM, LEFT, RIGHT) * @param tabIndex The index of the tab to paint the border for. * @param x The x position of the tab * @param y The y position of the tab * @param width The width of the tab * @param height The height of the tab * @param isSelected Is the tab currently selected? */ protected void paintTabBorder(Graphics graphics, int tabPlacement, int tabIndex, int x, int y, int width, int height, boolean isSelected) { Color oldColor = graphics.getColor(); Color borderColor; if (!isSelected && _mouseOverTab == tabIndex) { borderColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getSelectedControlBackgroundColor().darker(); } else { borderColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor(); } graphics.setColor(borderColor); graphics.translate(x, y); if (isSelected || _mouseOverTab == tabIndex) { switch (tabPlacement) { case JTabbedPane.TOP: paintHorizontalTabBorder(graphics, height, width, true); break; case JTabbedPane.BOTTOM: paintHorizontalTabBorder(graphics, height, width, false); break; case JTabbedPane.LEFT: paintVerticalTabBorder(graphics, height, width, true); break; case JTabbedPane.RIGHT: paintVerticalTabBorder(graphics, height, width, false); break; } } else { int tabCount = tabPane.getTabCount(); if (lastTabInRun(tabCount, getRunForTab(tabCount, tabIndex)) != tabIndex && tabPane.getSelectedIndex() - tabIndex != 1) { switch (tabPlacement) { case JTabbedPane.TOP: case JTabbedPane.BOTTOM: graphics.drawLine(width - 1, 3, width - 1, height - 1 - 3); break; case JTabbedPane.LEFT: case JTabbedPane.RIGHT: graphics.drawLine(4, height - 1, width - 1 - 4, height - 1); break; } } } graphics.translate(-x, -y); graphics.setColor(oldColor); } /** * Paint a border for a vertical tab that is either selected or in mouse over mode. * * @param graphics The graphics object to use for painting. * @param height The height of the tab * @param width The width of the tab. * @param isPlacedLeft Are the tabs placed on the left side? */ private void paintVerticalTabBorder(Graphics graphics, int height, int width, boolean isPlacedLeft) { graphics.drawLine(0, 0, width - 1, 0); if (isPlacedLeft) { graphics.drawLine(0, 0, 0, height - 1); graphics.drawLine(0, height - 1, width - 1, height - 1); } else { graphics.drawLine(width - 1, 0, width - 1, height - 1); graphics.drawLine(0, height - 1, width - 1, height - 1); } } /** * Paint a border for a horizontal tab that is either selected or in mouse over mode. * * @param graphics The graphics object to use for painting. * @param height The height of the tab * @param width The width of the tab. * @param isPlacedTop Are the tabs placed at the top? */ private void paintHorizontalTabBorder(Graphics graphics, int height, int width, boolean isPlacedTop) { graphics.drawLine(0, 0, 0, height - 1); graphics.drawLine(width - 1, 0, width - 1, height - 1); if (isPlacedTop) { graphics.drawLine(0, 0, width - 1, 0); } else { graphics.drawLine(0, height - 1, width - 1, height - 1); } } /** * Paint the top border of the content of the tabbed pane. * * @param graphics The graphics object to use for painting * @param tabPlacement The placement of the tabs (TOP,BOTTOM,LEFT,RIGHT) * @param selectedIndex The index of the selected tab * @param x The x position of the content pane. * @param y The y position of the content pane * @param width The width of the content pane * @param height The height of the content pane */ protected void paintContentBorderTopEdge(Graphics graphics, int tabPlacement, int selectedIndex, int x, int y, int width, int height) { Color oldColor = graphics.getColor(); Color borderColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor(); graphics.setColor(borderColor); // Rectangle selRect = selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect); Rectangle selRect = selectedIndex < 0 ? null : getTabBoundsNoCheckLayout(selectedIndex); if (tabPlacement != TOP || selectedIndex < 0 || (selRect.y + selRect.height + 1 < y) || (selRect.x < x || selRect.x > x + width)) { graphics.drawLine(x, y, x + width - 1, y); } else { graphics.drawLine(x, y, selRect.x, y); if (selRect.x + selRect.width < x + width - 1) { graphics.drawLine(selRect.x + selRect.width - 1, y, x + width - 1, y); } } graphics.setColor(oldColor); } /** * Paint the right border of the content of the tabbed pane. * * @param graphics The graphics object to use for painting * @param tabPlacement The placement of the tabs (TOP,BOTTOM,LEFT,RIGHT) * @param selectedIndex The index of the selected tab * @param x The x position of the content pane. * @param y The y position of the content pane * @param width The width of the content pane * @param height The height of the content pane */ protected void paintContentBorderRightEdge(Graphics graphics, int tabPlacement, int selectedIndex, int x, int y, int width, int height) { Color oldColor = graphics.getColor(); Color borderColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor(); graphics.setColor(borderColor); // Rectangle selRect = selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect); Rectangle selRect = selectedIndex < 0 ? null : getTabBoundsNoCheckLayout(selectedIndex); if (tabPlacement != RIGHT || selectedIndex < 0 || (selRect.x - 1 > width) || (selRect.y < y || selRect.y > y + height)) { graphics.drawLine(x + width - 1, y, x + width - 1, y + height - 1); } else { graphics.drawLine(x + width - 1, y, x + width - 1, selRect.y); if (selRect.y + selRect.height < y + height - 1) { graphics.drawLine(x + width - 1, selRect.y + selRect.height - 1, x + width - 1, y + height - 1); } } graphics.setColor(oldColor); } /** * Paint the left border of the content of the tabbed pane. * * @param graphics The graphics object to use for painting * @param tabPlacement The placement of the tabs (TOP,BOTTOM,LEFT,RIGHT) * @param selectedIndex The index of the selected tab * @param x The x position of the content pane. * @param y The y position of the content pane * @param width The width of the content pane * @param height The height of the content pane */ protected void paintContentBorderLeftEdge(Graphics graphics, int tabPlacement, int selectedIndex, int x, int y, int width, int height) { Color oldColor = graphics.getColor(); Color borderColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor(); graphics.setColor(borderColor); // Rectangle selRect = selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect); Rectangle selRect = selectedIndex < 0 ? null : getTabBoundsNoCheckLayout(selectedIndex); if (tabPlacement != LEFT || selectedIndex < 0 || (selRect.x + selRect.width + 1 < x) || (selRect.y < y || selRect.y > y + height)) { graphics.drawLine(x, y, x, y + height - 1); } else { graphics.drawLine(x, y, x, selRect.y); if (selRect.y + selRect.height < y + height - 1) { graphics.drawLine(x, selRect.y + selRect.height - 1, x, y + height - 1); } } graphics.setColor(oldColor); } /** * Paint the bottom border of the content of the tabbed pane. * * @param graphics The graphics object to use for painting * @param tabPlacement The placement of the tabs (TOP,BOTTOM,LEFT,RIGHT) * @param selectedIndex The index of the selected tab * @param x The x position of the content pane. * @param y The y position of the content pane * @param width The width of the content pane * @param height The height of the content pane */ protected void paintContentBorderBottomEdge(Graphics graphics, int tabPlacement, int selectedIndex, int x, int y, int width, int height) { Color oldColor = graphics.getColor(); Color borderColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor(); graphics.setColor(borderColor); // Rectangle selRect = selectedIndex < 0 ? null : getTabBounds(selectedIndex, calcRect); Rectangle selRect = selectedIndex < 0 ? null : getTabBoundsNoCheckLayout(selectedIndex); if (tabPlacement != BOTTOM || selectedIndex < 0 || (selRect.y - 1 > height) || (selRect.x < x || selRect.x > x + width)) { graphics.drawLine(x, y + height - 1, x + width - 1, y + height - 1); } else { graphics.drawLine(x, y + height - 1, selRect.x, y + height - 1); if (selRect.x + selRect.width < x + width - 1) { graphics.drawLine(selRect.x + selRect.width - 1, y + height - 1, x + width - 1, y + height - 1); } } graphics.setColor(oldColor); } protected boolean isTabVisible(int index) { return index < rects.length && rects[index] != null; } protected Rectangle getTabBoundsNoCheckLayout(int index) { Rectangle result = new Rectangle(); getTabBounds(index, result); return result; } public void paint(Graphics g, JComponent c) { Rectangle allTabBounds = null; for (int i = 0; i < tabPane.getTabCount(); i++) { if (isTabVisible(i)) { Rectangle tabBounds = getTabBoundsNoCheckLayout(i); if (allTabBounds == null) { allTabBounds = tabBounds; } else { allTabBounds.add(tabBounds); } } } if (allTabBounds != null && allTabBounds.contains(g.getClipBounds())) { if (!(tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT)) { paintTabArea(g, tabPane.getTabPlacement(), tabPane.getSelectedIndex()); } } else { super.paint(g, c); } } /** * The mouse motion listener that observes wheter the tabbed pane enters or exits roll over mode. */ private class TabbedPaneMouseMotionListener extends MouseMotionAdapter { public void mouseMoved(MouseEvent mouseEvent) { boolean found = false; for (int i = 0; !found && i < tabPane.getTabCount(); i++) { if (isTabVisible(i)) { Rectangle tabBounds = getTabBoundsNoCheckLayout(i); if (tabBounds.contains(mouseEvent.getPoint())) { found = true; if (_mouseOverTab != i) { if (_mouseOverTab >= 0 && isTabVisible(_mouseOverTab) && tabPane.getSelectedIndex() != _mouseOverTab) { tabPane.repaint(getTabBoundsNoCheckLayout(_mouseOverTab)); } if (tabPane.getSelectedIndex() != i) { tabPane.repaint(tabBounds); } _mouseOverTab = i; } } } } if (!found && _mouseOverTab >= 0) { if (_mouseOverTab < tabPane.getTabCount() && isTabVisible(_mouseOverTab) && tabPane.getSelectedIndex() != _mouseOverTab) { tabPane.repaint(getTabBoundsNoCheckLayout(_mouseOverTab)); } _mouseOverTab = -1; } } } /** * The mouse listener that observes whether the tabbed pane exits rollover mode. */ private class TabbedPaneMouseListener extends MouseAdapter { public void mouseExited(MouseEvent mouseEvent) { if (_mouseOverTab >= 0) { if (_mouseOverTab < tabPane.getTabCount() && isTabVisible(_mouseOverTab) && tabPane.getSelectedIndex() != _mouseOverTab) { tabPane.repaint(getTabBoundsNoCheckLayout(_mouseOverTab)); } _mouseOverTab = -1; } } } private TabbedPaneMouseMotionListener _tabbedBarMouseMotionListener; private TabbedPaneMouseListener _tabbedBarMouseListener; private int _mouseOverTab = -1; }squareness-2.3.0/source/net/beeger/squareness/delegate/SquarenessToggleButtonUI.java100644 0 0 13571 10563076303 26140 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.delegate; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Insets; import java.awt.Rectangle; import javax.swing.AbstractButton; import javax.swing.ButtonModel; import javax.swing.JComponent; import javax.swing.SwingUtilities; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicHTML; import javax.swing.plaf.basic.BasicToggleButtonUI; import javax.swing.text.View; import net.beeger.squareness.SquarenessConstants; import net.beeger.squareness.util.SquarenessButtonPainter; import net.beeger.squareness.util.SquarenessListenerFactory; /** * The Squareness Toggle Button UI delegate. */ public class SquarenessToggleButtonUI extends BasicToggleButtonUI { /** * Create the UI delegate for the given component * * @param component The component for which to create the ui delegate * @return The created ui delegate */ public static ComponentUI createUI (JComponent component) { return _buttonUI; } /** * Install the UI delegate for the given component * * @param component The component for which to install the ui delegate. */ public void installUI (JComponent component) { component.putClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY, Boolean.FALSE); component.addMouseListener(SquarenessListenerFactory.getButtonRolloverMouseListener()); super.installUI(component); } /** * Uninstall the UI delegate from the given component. * * @param component The component from which to uninstall the UI delegate. */ public void uninstallUI (JComponent component) { component.removeMouseListener(SquarenessListenerFactory.getButtonRolloverMouseListener()); super.uninstallUI(component); } /** * Paint the component. * * @param graphics The graphics resource used to paint the component * @param component The component to paint. */ public void paint (Graphics graphics, JComponent component) { Color oldColor = graphics.getColor(); SquarenessButtonPainter.paintButton(graphics, (AbstractButton) component); AbstractButton b = (AbstractButton) component; ButtonModel model = b.getModel(); Dimension size = b.getSize(); FontMetrics fm = graphics.getFontMetrics(); Insets i = component.getInsets(); Rectangle viewRect = new Rectangle(size); viewRect.x += i.left; viewRect.y += i.top; viewRect.width -= (i.right + viewRect.x); viewRect.height -= (i.bottom + viewRect.y); Rectangle iconRect = new Rectangle(); Rectangle textRect = new Rectangle(); Font f = component.getFont(); graphics.setFont(f); // layout the text and icon String text = SwingUtilities.layoutCompoundLabel(component, fm, b.getText(), b.getIcon(), b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, b.getText() == null ? 0 : b.getIconTextGap()); graphics.setColor(b.getBackground()); if (model.isArmed() && model.isPressed() || model.isSelected()) { paintButtonPressed(graphics, b); } // Paint the Icon if (b.getIcon() != null) { paintIcon(graphics, b, iconRect); } // Draw the Text if (text != null && !text.equals("")) { View v = (View) component.getClientProperty(BasicHTML.propertyKey); if (v != null) { v.paint(graphics, textRect); } else { paintText(graphics, b, textRect, text); } } // draw the dashed focus line. if (b.isFocusPainted() && b.hasFocus()) { paintFocus(graphics, b, viewRect, textRect, iconRect); } graphics.setColor(oldColor); } private static SquarenessToggleButtonUI _buttonUI = new SquarenessToggleButtonUI(); }squareness-2.3.0/source/net/beeger/squareness/delegate/SquarenessToolBarUI.java100644 0 0 10403 10563076303 25054 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.delegate; import java.awt.Component; import java.awt.event.ContainerEvent; import java.awt.event.ContainerListener; import javax.swing.AbstractButton; import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JToggleButton; import javax.swing.border.Border; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicToolBarUI; import net.beeger.squareness.util.SquarenessBorderFactory; /** * The Squareness Tool Bar UI delegate. */ public class SquarenessToolBarUI extends BasicToolBarUI { /** * Create the ui delegate for the given component * * @param component The component for which to create the ui delegate * @return The created ui delegate */ public static ComponentUI createUI (JComponent component) { return new SquarenessToolBarUI(); } /** * Install the UI delegate for the given component. * * @param component The component for which to install the UI delegate. */ public void installUI (JComponent component) { super.installUI(component); toolBar.addContainerListener(new ContainerListener() { public void componentAdded (ContainerEvent e) { JComponent child = (JComponent) e.getChild(); } public void componentRemoved (ContainerEvent e) { } }); } /** * Create a rollover border. This border will be used if rollover borders are enabled. */ protected Border createRolloverBorder () { return SquarenessBorderFactory.getButtonRolloverBorder(); } /** * Create a non rollover border. This border will be used if rollover borders are disabled. */ protected Border createNonRolloverBorder () { return SquarenessBorderFactory.getButtonNonRolloverBorder(); } /** * Set the non rollover border on the given component. * * @param component The component to set the non rollover border on. */ protected void setBorderToNonRollover (Component component) { super.setBorderToNonRollover(component); if (component instanceof AbstractButton) { AbstractButton button = (AbstractButton) component; if (button.getBorder() instanceof UIResource) { if (button instanceof JToggleButton && !(button instanceof JCheckBox)) { // only install this border for the ToggleButton button.setBorder(SquarenessBorderFactory.getButtonNonRolloverBorder()); } } } } }squareness-2.3.0/source/net/beeger/squareness/icons/Error.gif100644 0 0 234 10563076303 21421 0ustar 0 0 GIF89a €"9Iö˜Ÿ!ùÿ, @s„©›áÞž„hš‰ƒÊÈÈQÇç=WÈT˜Úf•ÁèÝáz.Ú,­)Å|®ÙqÖÊW3(sF½]ueÝù²©'w9ÛþT°ârJŸb—ÛEþp›d²>ŸÞpÒ´çeÃÈ%&E¦t˜×÷¥Ç Y;squareness-2.3.0/source/net/beeger/squareness/icons/Inform.gif100644 0 0 206 10563076303 21561 0ustar 0 0 GIF89a €"9I°áì!ùÿ, @]„©›áŠ4˜'~wËæY@HV§¡c˜ng ¿0)› Jßîª"yîcñvAœ°¸›ÍjJ ³IyBZÎaY~P¡Vʱڰ¶¯8zÎè²Ç­· þ˜¹ÝdÈÈë;squareness-2.3.0/source/net/beeger/squareness/icons/Question.gif100644 0 0 213 10563076303 22134 0ustar 0 0 GIF89a €"9I¢íe!ùÿ, @b„©›áÁb{æY+§«—êÞqàHb@Y*&™© ƒbLÏ­žÞ½¬ô…ƒèd<Û0‡øÍ€Ôò—:B£Ó˜±(}í°߆›ÔVƒÏÚ§lºy‘¼5³èNwͬ&utf«9¾|S;squareness-2.3.0/source/net/beeger/squareness/icons/Warn.gif100644 0 0 205 10563076303 21235 0ustar 0 0 GIF89a €"9Iþ÷6!ùÿ, @\„©›áŠ4˜'~wËæY@HV§¡cÉ~m{¾aŒ¥m‚*i׫Šàýn:¢08ÊŒËdÓ™Dî¢á± b§ZÅ›)ú®`H™#Î=¹D)³«T¯ÇóãŽG;squareness-2.3.0/source/net/beeger/squareness/icons/computer.gif100644 0 0 214 10563076303 22164 0ustar 0 0 GIF89aƒ"9IËšûÒEÀÀÀÿÿÿ!ù,9H0ª½A±×œ÷mÔdžälÛJéêºp(Ïl]â/¸ó ô Â.yj¦.èÓ¥F›§;squareness-2.3.0/source/net/beeger/squareness/icons/detail.gif100644 0 0 173 10563076303 21574 0ustar 0 0 GIF89aƒ"9IËšûÒEÀÀÀÿÿÿ!ù,(pÈI«½h\!7y_¨™J‚bz†m,[§LÂâjnjú±¹×l8‹;squareness-2.3.0/source/net/beeger/squareness/icons/document.gif100644 0 0 203 10563076303 22142 0ustar 0 0 GIF89aƒ"9IËšûÒEÀÀÀÿÿÿ!ù,0ÈI‡½€è­åµ·eÀGR]‡‰ã²©{NEì„ç³}ë;0X#ølEbRylJ";squareness-2.3.0/source/net/beeger/squareness/icons/floppy.gif100644 0 0 214 10563076303 21637 0ustar 0 0 GIF89aƒ"9IËšûÒEÀÀÀÿÿÿ!ù,9ÈIé@ˆ ˆÏ¦q‘m'ùiU¶,'±Zmß3*Ã[é›´‰×ù­P£×ˆì™¹Î0X4¶v²;squareness-2.3.0/source/net/beeger/squareness/icons/folderclosed.gif100644 0 0 112 10563076303 22770 0ustar 0 0 GIF89a€ûÒE"9I!ùÿ,!ŒiÀí¾ždq¾jÎ`go)|%ž¨*©°K;squareness-2.3.0/source/net/beeger/squareness/icons/folderopened.gif100644 0 0 203 10563076303 22772 0ustar 0 0 GIF89aƒ"9IËšûÒEÀÀÀÿÿÿ!ùÿ,0ÈI« 8k}-ØAGŒäÇ}©š˜¨ŽlèÍ’`ß8^ç¼½÷¹ð& ŠC$PÙ£Í";squareness-2.3.0/source/net/beeger/squareness/icons/folderup.gif100644 0 0 117 10563076303 22150 0ustar 0 0 GIF89a€"9IûÒE!ùÿ,&„iÁí¾x,¶CmXzÏúyPHIdy%(­Ý™fe*0Jãö;squareness-2.3.0/source/net/beeger/squareness/icons/hd.gif100644 0 0 213 10563076303 20720 0ustar 0 0 GIF89aƒ"9IÿCÿAûÒE!ùÿ,8ÈI«8k}qdãhiŠ$¨$èQìfÏ÷Ý­êT—2€` ‡‚¢QäûäH«'N µX%;squareness-2.3.0/source/net/beeger/squareness/icons/home.gif100644 0 0 213 10563076303 21255 0ustar 0 0 GIF89aƒ"9IûÒEÿÿÿ!ùÿ,8ÈI« 8k}·Ç—e¡`ž(@ªê ,û¦ë*Nõç…8HÕ-X&(, A§ɤòáŒÍTg Þ&;squareness-2.3.0/source/net/beeger/squareness/icons/list.gif100644 0 0 206 10563076303 21302 0ustar 0 0 GIF89aƒ"9IËšûÒEÀÀÀÿÿÿ!ù,3pÈI«½h«A&„÷…’¢ zÚ)J*9t[Icx~u\ ¯Õ+Æú[À’ v³ñtÐ\;squareness-2.3.0/source/net/beeger/squareness/icons/treecollapsed.gif100644 0 0 71 10563076303 23135 0ustar 0 0 GIF89a €"9IÛÄc!ùÿ, „¡ aÍVtÙ‰q…õš;squareness-2.3.0/source/net/beeger/squareness/icons/treeexpanded.gif100644 0 0 70 10563076303 22756 0ustar 0 0 GIF89a €"9IÛÄc!ùÿ, „¡Æë^CÈy㫨;squareness-2.3.0/source/net/beeger/squareness/theme/DefaultSquarenessTheme.java100644 0 0 7157 10563076303 25147 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.theme; import javax.swing.plaf.ColorUIResource; /** * Created by IntelliJ IDEA. * User: Robert F. Beeger * Date: 22.08.2004 * Time: 20:12:55 * To change this template use File | Settings | File Templates. */ public class DefaultSquarenessTheme extends SquarenessTheme { public String getName () { return "Original"; } public ColorUIResource getDesktopColor () { return new ColorUIResource(234, 216, 164); } public ColorUIResource getWindowBackgroundColor () { return new ColorUIResource(247,242,225); } public ColorUIResource getDisabledBorderColor () { return new ColorUIResource(134, 144, 150); } public ColorUIResource getNormalBorderColor () { return new ColorUIResource(34, 57, 73); } public ColorUIResource getSelectedControlBackgroundColor () { return new ColorUIResource(211, 211, 42); } public ColorUIResource getInactiveWindowBorderColor () { return new ColorUIResource(184,175,119); } public ColorUIResource getDefaultButtonBorderColor () { return new ColorUIResource(170,59,34); } public ColorUIResource getNormalControlBackgroundColor () { return new ColorUIResource(219,196,99); } public ColorUIResource getSelectedControlBackgroundShadowColor () { return new ColorUIResource(163,159,28); } public ColorUIResource getProgressBarBackgroundColor () { return new ColorUIResource(245,246,220); } public ColorUIResource getPressedScrollBarTrackBackgroundColor () { return new ColorUIResource(237,225,185); } public ColorUIResource getTextInputBackgroundColor () { return new ColorUIResource(255,255,255); } public ColorUIResource getTextColor () { return new ColorUIResource(0,0,0); } public boolean isDark () { return false; } }squareness-2.3.0/source/net/beeger/squareness/theme/PropertiesSquarenessTheme.java100644 0 0 26566 10563076303 25744 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.theme; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Enumeration; import java.util.Properties; import java.util.ResourceBundle; import java.util.StringTokenizer; import javax.swing.plaf.ColorUIResource; /** *

This SquarenessTheme implementation can be configured from some sort of property bundle - * be it a resource bundle, a properties object or a properties file.

*

A file matching the original Squareness theme would look like this:

*
 * 
 *
 * themeName                            = Original
 * desktopColor                         = 234, 216, 164
 * windowBackgroundColor                = 247,242,225
 * inactiveWindowBorderColor            = 184,175,119
 * normalBorderColor                    = 34, 57, 73
 * disabledBorderColor                  = 134, 144, 150
 * defaultButtonBorderColor             = 170,59,34
 * normalControlBackgroundColor         = 219,196,99
 * selectedControlBackgroundColor       = 211, 211, 42
 * selectedControlBackgroundShadowColor = 163,159,28
 * progressBarBackgroundColor           = 245,246,220
 * pressedScrollBarTrackBackgroundColor = 237,225,185
 * textInputBackgroundColor             = 255,255,255
 * textColor                            = 0,0,0
 * 
 * 
*

Note: The colors are defined in RGB format r,g,b where r, g and b * define the red, green and blue components of the color. Each of those * must be in the range from 0 to 255.

*/ public class PropertiesSquarenessTheme extends SquarenessTheme { public PropertiesSquarenessTheme (File propertiesFile) throws LoadException { Properties properties = new Properties(); try { properties.load(new FileInputStream(propertiesFile)); processProperties(properties); if (_themeName == null) { _themeName = propertiesFile.getName(); if (_themeName.indexOf('.') > -1) { _themeName = _themeName.substring(0, _themeName.indexOf('.')); } } } catch (IOException e) { e.printStackTrace(); } } public PropertiesSquarenessTheme (Properties properties) throws LoadException { processProperties(properties); } public PropertiesSquarenessTheme(ResourceBundle resourceBundle) throws LoadException { Properties properties = new Properties(); final Enumeration keysEnumeration = resourceBundle.getKeys(); while (keysEnumeration.hasMoreElements()) { String key = (String) resourceBundle.getKeys().nextElement(); properties.put(key, resourceBundle.getString(key)); } processProperties(properties); } /** * Return the name of the theme. */ public String getName () { return _themeName; } public ColorUIResource getDesktopColor () { return _desktopColor; } public ColorUIResource getWindowBackgroundColor () { return _windowBackgroundColor; } public ColorUIResource getInactiveWindowBorderColor () { return _inactiveWindowBorderColor; } public ColorUIResource getNormalBorderColor () { return _normalBorderColor; } public ColorUIResource getDisabledBorderColor () { return _disabledBorderColor; } public ColorUIResource getDefaultButtonBorderColor () { return _defaultButtonBorderColor; } public ColorUIResource getNormalControlBackgroundColor () { return _normalControlBackgroundColor; } public ColorUIResource getSelectedControlBackgroundColor () { return _selectedControlBackgroundColor; } public ColorUIResource getSelectedControlBackgroundShadowColor () { return _selectedControlBackgroundShadowColor; } public ColorUIResource getProgressBarBackgroundColor () { return _progressBarBackgroundColor; } public ColorUIResource getPressedScrollBarTrackBackgroundColor () { return _pressedScrollBarTrackBackgroundColor; } public ColorUIResource getTextInputBackgroundColor () { return _textInputBackgroundColor; } public ColorUIResource getTextColor () { return _textColor; } public boolean isDark () { return _isDark; } private void processProperties(Properties properties) throws LoadException { DefaultSquarenessTheme defaultTheme = new DefaultSquarenessTheme(); _desktopColor = getColor("desktopColor", defaultTheme.getDesktopColor(), properties); _windowBackgroundColor = getColor("windowBackgroundColor", defaultTheme.getWindowBackgroundColor(), properties); _inactiveWindowBorderColor = getColor("inactiveWindowBorderColor", defaultTheme.getInactiveWindowBorderColor(), properties); _normalBorderColor = getColor("normalBorderColor", defaultTheme.getNormalBorderColor(), properties); _disabledBorderColor = getColor("disabledBorderColor", defaultTheme.getDisabledBorderColor(), properties); _defaultButtonBorderColor = getColor("defaultButtonBorderColor", defaultTheme.getDefaultButtonBorderColor(), properties); _normalControlBackgroundColor = getColor("normalControlBackgroundColor", defaultTheme.getNormalControlBackgroundColor(), properties); _selectedControlBackgroundColor = getColor("selectedControlBackgroundColor", defaultTheme.getSelectedControlBackgroundColor(), properties); _selectedControlBackgroundShadowColor = getColor("selectedControlBackgroundShadowColor", defaultTheme.getSelectedControlBackgroundShadowColor(), properties); _progressBarBackgroundColor = getColor("progressBarBackgroundColor", defaultTheme.getProgressBarBackgroundColor(), properties); _pressedScrollBarTrackBackgroundColor = getColor("pressedScrollBarTrackBackgroundColor", defaultTheme.getPressedScrollBarTrackBackgroundColor(), properties); _textInputBackgroundColor = getColor("textInputBackgroundColor", defaultTheme.getTextInputBackgroundColor(), properties); _textColor = getColor("textColor", defaultTheme.getTextColor(), properties); _themeName = properties.getProperty("themeName"); _isDark = Boolean.valueOf(properties.getProperty("isDark", "false")).booleanValue(); } private ColorUIResource getColor(String colorName, ColorUIResource defaultValue, Properties properties) throws LoadException { ColorUIResource result = null; String colorString = properties.getProperty(colorName); if (colorString != null) { StringTokenizer tokenizer = new StringTokenizer(colorString, ",", false); if (tokenizer.countTokens() == 3) { try { final int red = Integer.parseInt((String) tokenizer.nextElement()); final int green = Integer.parseInt((String) tokenizer.nextElement()); final int blue = Integer.parseInt((String) tokenizer.nextElement()); if ( isValidColorComponent(red) && isValidColorComponent(green) && isValidColorComponent(blue)) { result = new ColorUIResource(red, green, blue); } else { throw new LoadException(colorName, "The colordefinition contains one or more wrong color components. " + "A colordefinition looks like \"colornamw=r,g,b\" where r, g and b " + "define the red, green and blue components of the color. Each of those " + "must be in the range from 0 to 255."); } } catch (NumberFormatException e) { throw new LoadException(colorName, "The colordefinition \""+ colorName + " = " + colorString + "\" is incorrect. " + "A colordefinition looks like \"colornamw=r,g,b\" where r, g and b " + "define the red, green and blue components of the color. Each of those " + "must be in the range from 0 to 255."); } } else { throw new LoadException(colorName, "The colordefinition \""+ colorName + " = " + colorString + "\" is incorrect. " + "A colordefinition looks like \"colornamw=r,g,b\" where r, g and b " + "define the red, green and blue components of the color. Each of those " + "must be in the range from 0 to 255."); } } else { result = defaultValue; } return result; } private boolean isValidColorComponent(int colorComponent) { return colorComponent >= 0 && colorComponent <= 255; } private ColorUIResource _desktopColor; private ColorUIResource _windowBackgroundColor; private ColorUIResource _inactiveWindowBorderColor; private ColorUIResource _normalBorderColor; private ColorUIResource _disabledBorderColor; private ColorUIResource _defaultButtonBorderColor; private ColorUIResource _normalControlBackgroundColor; private ColorUIResource _selectedControlBackgroundColor; private ColorUIResource _selectedControlBackgroundShadowColor; private ColorUIResource _progressBarBackgroundColor; private ColorUIResource _pressedScrollBarTrackBackgroundColor; private ColorUIResource _textInputBackgroundColor; private ColorUIResource _textColor; private String _themeName; private boolean _isDark; public static class LoadException extends Exception { /** */ public LoadException (String propertyEntryName, String message) { super("Error on loading property " + propertyEntryName + " : " + message); } } }squareness-2.3.0/source/net/beeger/squareness/theme/SquarenessTheme.java100644 0 0 24245 10563076303 23657 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.theme; import java.awt.Font; import javax.swing.plaf.ColorUIResource; import javax.swing.plaf.FontUIResource; import javax.swing.plaf.metal.MetalTheme; /** * The common abstract superclass for all Squareness theme classes. */ public abstract class SquarenessTheme extends MetalTheme { public FontUIResource getControlTextFont () { if (_controlTextFont == null) { _controlTextFont = new FontUIResource("Dialog", Font.PLAIN, 11); } return _controlTextFont; } public FontUIResource getMenuTextFont () { if (_menuTextFont == null) { _menuTextFont = new FontUIResource("Dialog", Font.PLAIN, 11); } return _menuTextFont; } public FontUIResource getSubTextFont () { if (_subTextFont == null) { _subTextFont = new FontUIResource("Dialog", Font.PLAIN, 9); } return _subTextFont; } public FontUIResource getSystemTextFont () { if (_systemTextFont == null) { _systemTextFont = new FontUIResource("Dialog", Font.PLAIN, 11); } return _systemTextFont; } public FontUIResource getUserTextFont () { if (_userTextFont == null) { _userTextFont = new FontUIResource("Dialog", Font.PLAIN, 11); } return _userTextFont; } public FontUIResource getWindowTitleFont () { if (_windowTitleFont == null) { _windowTitleFont = new FontUIResource("Dialog", Font.BOLD, 11); } return _windowTitleFont; } /** * Since some applications explicitely use those metal colors, we define them to matching colors * in the Squareness color space. Still some applications may look funny since the Squareness colors have other * meanings and usages than the Metal colors and cannot be mapped totally correctly. * @return The Squarness normal border color */ protected ColorUIResource getPrimary1 () { return getNormalBorderColor(); } /** * Since some applications explicitely use those metal colors, we define them to matching colors * in the Squareness color space. Still some applications may look funny since the Squareness colors have other * meanings and usages than the Metal colors and cannot be mapped totally correctly. * @return The Squarness selected control background color */ protected ColorUIResource getPrimary2 () { return getSelectedControlBackgroundColor(); } /** * Since some applications explicitely use those metal colors, we define them to matching colors * in the Squareness color space. Still some applications may look funny since the Squareness colors have other * meanings and usages than the Metal colors and cannot be mapped totally correctly. * @return The Squarness selected control background color */ protected ColorUIResource getPrimary3 () { return getSelectedControlBackgroundColor(); } /** * Since some applications explicitely use those metal colors, we define them to matching colors * in the Squareness color space. Still some applications may look funny since the Squareness colors have other * meanings and usages than the Metal colors and cannot be mapped totally correctly. * @return The Squarness normal border color */ protected ColorUIResource getSecondary1 () { return getNormalBorderColor(); } /** * Since some applications explicitely use those metal colors, we define them to matching colors * in the Squareness color space. Still some applications may look funny since the Squareness colors have other * meanings and usages than the Metal colors and cannot be mapped totally correctly. * @return The Squarness disabled border color */ protected ColorUIResource getSecondary2 () { return getDisabledBorderColor(); } /** * Since some applications explicitely use those metal colors, we define them to matching colors * in the Squareness color space. Still some applications may look funny since the Squareness colors have other * meanings and usages than the Metal colors and cannot be mapped totally correctly. * @return The Squarness window background color */ protected ColorUIResource getSecondary3 () { return getWindowBackgroundColor(); } /** *

Return the desktop color.

*

This color is used as the background color of desktop panes.

* @return the desktop color */ public abstract ColorUIResource getDesktopColor(); /** *

Return the window background color.

*

This color is used as the background color of windows of all sorts.

* @return the window background color */ public abstract ColorUIResource getWindowBackgroundColor(); /** *

Return the inactive window border color.

*

This color is used for the border of inactive frames.

* @return the inactive window border color */ public abstract ColorUIResource getInactiveWindowBorderColor(); /** *

Return the normal border color.

*

This color is used for borders of all sorts: control borders, window, menu etc. borders.

* @return the normal border color */ public abstract ColorUIResource getNormalBorderColor(); /** *

Return the disabled border color.

*

This color is used for borders of all sorts where the component to which the border is applied is disabled.

* @return the disabled border color */ public abstract ColorUIResource getDisabledBorderColor(); /** *

Return the default button border color.

*

This color is used for the border of default buttons.

* @return the default button border color */ public abstract ColorUIResource getDefaultButtonBorderColor(); /** *

Return the normal control background color.

*

This color is used for the background of normal unselected and not disabled controls * such as buttons and scroll bar thumbs

* @return the normal control background color */ public abstract ColorUIResource getNormalControlBackgroundColor(); /** *

Return the selected control background color.

*

This color is used for the background of selected controls and controls over which the mouse pointer hovers.

* @return the selected control background color */ public abstract ColorUIResource getSelectedControlBackgroundColor(); /** *

Return the selected control background shadow color.

*

This color is used for the shadow in the background of selected controls.

* @return the selected control background shadow color */ public abstract ColorUIResource getSelectedControlBackgroundShadowColor(); /** *

Return the progress bar background color.

*

This color is used for the background of progress bars and for the tracks of scroll bars.

* @return the progress bar background color */ public abstract ColorUIResource getProgressBarBackgroundColor(); /** *

Return the pressed scroll bar track background color.

*

This color is used for the background of scroll bar tracks when the track is pressed (i.e. you clicked the left * mouse button while the mouse pointer was over the track have not released it yet.).

* @return the pressed scroll bar track background color */ public abstract ColorUIResource getPressedScrollBarTrackBackgroundColor(); /** *

Return the text input background color.

*

This color is used for the background of controls where text can be typed in (text fields, text areas etc.)

* @return the text input background color */ public abstract ColorUIResource getTextInputBackgroundColor(); /** *

Return the text color.

*

All text - no matter where it is printed on - is printed in this color.)

* @return the text color */ public abstract ColorUIResource getTextColor(); /** * Is this theme a dark theme.
* The information whether a theme is dark can be useful for component plugin writers * needing to come up with new colors that fit into the theme. * @return true if this theme is a dark theme, false otherwise */ public abstract boolean isDark(); private FontUIResource _controlTextFont; private FontUIResource _menuTextFont; private FontUIResource _subTextFont; private FontUIResource _systemTextFont; private FontUIResource _userTextFont; private FontUIResource _windowTitleFont; }squareness-2.3.0/source/net/beeger/squareness/util/SquarenessBorderFactory.java100644 0 0 53133 10563076303 25233 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.util; import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import java.awt.Insets; import javax.swing.AbstractButton; import javax.swing.ButtonModel; import javax.swing.JButton; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.UIManager; import javax.swing.JComponent; import javax.swing.JInternalFrame; import javax.swing.JFrame; import javax.swing.border.AbstractBorder; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; import javax.swing.plaf.BorderUIResource; import javax.swing.plaf.UIResource; import javax.swing.plaf.basic.BasicBorders; import net.beeger.squareness.SquarenessConstants; import net.beeger.squareness.SquarenessLookAndFeel; /** * The SquarenessBorderFactory is a static factory that creates all the borders that are needed by the Look And Feel. */ public class SquarenessBorderFactory { /** * Return the border for the controls.
* The returned border also contains an outer border with the color of the parent of the component for which * it is used, which creates a little space between neighboring components. * * @return The border for the controls. */ public static Border getControlBorderWithMargin () { return new BorderUIResource.CompoundBorderUIResource(new ParentBackgroundBorder(), new BorderUIResource.CompoundBorderUIResource( new ControlBorder(), new BorderUIResource.CompoundBorderUIResource( new BorderUIResource.EmptyBorderUIResource(1, 1, 1, 1), new BasicBorders.MarginBorder()))); } /** * Return the border for the controls.
* The same as {@link #getControlBorderWithMargin()} but without the parent color outer border. * * @return The border for the controls. */ public static Border getNonSpacingControlBorderWithMargin () { return new BorderUIResource.CompoundBorderUIResource(new ControlBorder(), new BorderUIResource.CompoundBorderUIResource( new BorderUIResource.EmptyBorderUIResource(1, 1, 1, 1), new BasicBorders.MarginBorder())); } /** * Return the border for the controls.
* The same as {@link #getControlBorderWithMargin()} but without the inner margin border. * * @return The border for the controls. */ public static Border getControlBorderWithoutMargin () { return new BorderUIResource.CompoundBorderUIResource(new ParentBackgroundBorder(), new BorderUIResource.CompoundBorderUIResource( new ControlBorder(), new BorderUIResource.EmptyBorderUIResource(1, 1, 1, 1))); } public static Border getProgressBarBorder () { return new BorderUIResource.CompoundBorderUIResource(new ParentBackgroundBorder(),new ControlBorder()); } /** * Return the border for the controls.
* The same as {@link #getControlBorderWithMargin()} but without the inner margin border. * * @return The border for the controls. */ public static Border getNonSpacingControlBorderWithoutMargin () { return new BorderUIResource.CompoundBorderUIResource(new ControlBorder(), new BorderUIResource.EmptyBorderUIResource(1, 1, 1, 1)); } /** * Return the rollover border for buttons
* Used for rollover buttons on tool bars. * * @return The created border. */ public static Border getButtonRolloverBorder () { return new BorderUIResource.CompoundBorderUIResource(new ParentBackgroundBorder(), new BorderUIResource.CompoundBorderUIResource( new ButtonRolloverBorder(), new RolloverMarginBorder())); } /** * Return the non rollover border for buttons
* Used for non rollover buttons on tool bars. * * @return The created border. */ public static Border getButtonNonRolloverBorder () { return new BorderUIResource.CompoundBorderUIResource(new ParentBackgroundBorder(), new BorderUIResource.CompoundBorderUIResource( new ControlBorder(), new RolloverMarginBorder())); } /** * Return the border for table headers. * * @return The created border. */ public static Border getTableHeaderCellBorder () { return new BorderUIResource.CompoundBorderUIResource(new TableHeaderCellBorder(), new BorderUIResource.EmptyBorderUIResource(1, 2, 1, 2)); } /** * Return the border for menu items. * * @return The created border. */ public static Border getMenuItemBorder () { return new MenuItemBorder(); } /** * Return the border for the controls.
* The same as {@link #getControlBorderWithMargin()} but without the inner margin border. * * @return The border for the controls. */ public static Border getInternalFrameBorder () { return new BorderUIResource.CompoundBorderUIResource(new InternalFrameBorder(), new BorderUIResource.LineBorderUIResource(SquarenessLookAndFeel.getCurrentSquarenessTheme().getWindowBackgroundColor(),1)); } /** * The control border.
* The color of the border changes to reflect the status of the control (disabled, default button, normal) */ private static class ControlBorder extends AbstractBorder implements UIResource { /** * Paint the border for the given component. * * @param component The component for which to paint the border. * @param graphics The graphics object to use for painting. * @param x The x position of the component. * @param y The y position of the component. * @param width The width of the component. * @param height The height of the component. */ public void paintBorder (Component component, Graphics graphics, int x, int y, int width, int height) { Color oldColor = graphics.getColor(); if (!component.isEnabled()) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } else if (component instanceof JButton && ((JButton) component).isDefaultButton()) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDefaultButtonBorderColor()); } else { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } graphics.drawLine(x, y, x + width - 1, y); graphics.drawLine(x, y, x, y + height - 1); graphics.drawLine(x, y + height - 1, x + width - 1, y + height - 1); graphics.drawLine(x + width - 1, y, x + width - 1, y + height - 1); graphics.setColor(oldColor); } /** * Return the insets of this border. * * @param component The component for which to return the insets of this border. * @return The calculated insets. */ public Insets getBorderInsets (Component component) { return getBorderInsets(component, new Insets(0, 0, 0, 0)); } /** * Return the insets of this border. * * @param component The component for which to return the insets of this border. * @param insets The object to put the newly calculated insets into. * @return The calculated insets. */ public Insets getBorderInsets (Component component, Insets insets) { insets.top = insets.left = insets.bottom = insets.right = 1; return insets; } /** * Is this border opaque? * * @return true, if this border is opaque, false otherwise */ public boolean isBorderOpaque () { return true; } } /** * This border has the color of the parent of the component for which it is painted. */ private static class ParentBackgroundBorder extends AbstractBorder implements UIResource { /** * Paint the border for the given component. * * @param component The component for which to paint the border. * @param graphics The graphics object to use for painting. * @param x The x position of the component. * @param y The y position of the component. * @param width The width of the component. * @param height The height of the component. */ public void paintBorder (Component component, Graphics graphics, int x, int y, int width, int height) { Color oldColor = graphics.getColor(); graphics.setColor(component.getParent() != null ? component.getParent().getBackground() : SquarenessLookAndFeel.getCurrentSquarenessTheme().getWindowBackgroundColor()); graphics.drawLine(x, y, x + width - 1, y); graphics.drawLine(x, y, x, y + height - 1); graphics.drawLine(x, y + height - 1, x + width - 1, y + height - 1); graphics.drawLine(x + width - 1, y, x + width - 1, y + height - 1); graphics.setColor(oldColor); } /** * Return the insets of this border. * * @param component The component for which to return the insets of this border. * @return The calculated insets. */ public Insets getBorderInsets (Component component) { return getBorderInsets(component, new Insets(0, 0, 0, 0)); } /** * Return the insets of this border. * * @param component The component for which to return the insets of this border. * @param insets The object to put the newly calculated insets into. * @return The calculated insets. */ public Insets getBorderInsets (Component component, Insets insets) { insets.top = insets.left = insets.bottom = insets.right = 1; return insets; } /** * Is this border opaque? * * @return true, if this border is opaque, false otherwise */ public boolean isBorderOpaque () { return true; } } private static class InternalFrameBorder extends AbstractBorder implements UIResource { /** * Paint the border for the given component. * * @param component The component for which to paint the border. * @param graphics The graphics object to use for painting. * @param x The x position of the component. * @param y The y position of the component. * @param width The width of the component. * @param height The height of the component. */ public void paintBorder (Component component, Graphics graphics, int x, int y, int width, int height) { Color oldColor = graphics.getColor(); if (component instanceof JInternalFrame) { JInternalFrame internalFrame = (JInternalFrame) component; if (internalFrame.isSelected()) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getInactiveWindowBorderColor()); } } else if (component instanceof JFrame) { JFrame frame = (JFrame) component; if (frame.isActive()) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getInactiveWindowBorderColor()); } } graphics.translate(x, y); graphics.drawLine(0, 0, width - 1, 0); graphics.drawLine(0, 0, 0, height - 1); graphics.drawLine(0, height - 1, width - 1, height - 1); graphics.drawLine(width - 1, y, width - 1, height - 1); if (getBorderInsets(component).top == 2) { graphics.drawLine(1, 1, width - 2, 1); graphics.drawLine(1, 1, 1, height - 2); graphics.drawLine(1, height - 2, width - 2, height - 2); graphics.drawLine(width - 2, y, width - 2, height - 2); } graphics.translate(-x,-y); graphics.setColor(oldColor); } /** * Return the insets of this border. * * @param component The component for which to return the insets of this border. * @return The calculated insets. */ public Insets getBorderInsets (Component component) { return getBorderInsets(component, new Insets(0, 0, 0, 0)); } /** * Return the insets of this border. * * @param component The component for which to return the insets of this border. * @param insets The object to put the newly calculated insets into. * @return The calculated insets. */ public Insets getBorderInsets (Component component, Insets insets) { if (component instanceof JInternalFrame && (((JInternalFrame)component).getClientProperty("JInternalFrame.isPalette") != null)) { insets.top = 1; } else { insets.top = 2; } insets.bottom = insets.top; insets.right = insets.top; insets.left = insets.top; return insets; } /** * Is this border opaque? * * @return true, if this border is opaque, false otherwise */ public boolean isBorderOpaque () { return true; } } /** * The border for table headers. */ private static class TableHeaderCellBorder extends AbstractBorder implements UIResource { /** * Paint the border for the given component. * * @param component The component for which to paint the border. * @param graphics The graphics object to use for painting. * @param x The x position of the component. * @param y The y position of the component. * @param width The width of the component. * @param height The height of the component. */ public void paintBorder (Component component, Graphics graphics, int x, int y, int width, int height) { Color oldColor = graphics.getColor(); graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); graphics.drawLine(x, y + height - 1, x + width - 1, y + height - 1); graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalControlBackgroundColor().darker()); graphics.drawLine(x + width - 2, y + 3, x + width - 2, y + height - 4); graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalControlBackgroundColor().brighter()); graphics.drawLine(x + width - 1, y + 3, x + width - 1, y + height - 4); graphics.setColor(oldColor); } /** * Return the insets of this border. * * @param component The component for which to return the insets of this border. * @return The calculated insets. */ public Insets getBorderInsets (Component component) { return getBorderInsets(component, new Insets(0, 0, 0, 0)); } /** * Return the insets of this border. * * @param component The component for which to return the insets of this border. * @param insets The object to put the newly calculated insets into. * @return The calculated insets. */ public Insets getBorderInsets (Component component, Insets insets) { insets.top = insets.left = insets.bottom = insets.right = 1; return insets; } /** * Is this border opaque? * * @return true, if this border is opaque, false otherwise */ public boolean isBorderOpaque () { return true; } } /** * The rollover border for buttons. */ private static class ButtonRolloverBorder extends ControlBorder { /** * Paint the border for the given component. * * @param component The component for which to paint the border. * @param graphics The graphics object to use for painting. * @param x The x position of the component. * @param y The y position of the component. * @param width The width of the component. * @param height The height of the component. */ public void paintBorder (Component component, Graphics graphics, int x, int y, int width, int height) { AbstractButton button = (AbstractButton) component; ButtonModel model = button.getModel(); boolean isRollover = ((Boolean) button.getClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY)).booleanValue(); if (button.isEnabled() && (isRollover || model.isArmed() && model.isPressed() || button.hasFocus() || button.isSelected())) { super.paintBorder(component, graphics, x, y, width, height); } } } /** * Margin Border for rollover borders. */ private static class RolloverMarginBorder extends EmptyBorder { /** * Create object. */ public RolloverMarginBorder () { super(3, 3, 3, 3); } /** * Return the insets of this border. * * @param component The component for which to return the insets of this border. * @return The calculated insets. */ public Insets getBorderInsets (Component component) { return getBorderInsets(component, new Insets(0, 0, 0, 0)); } /** * Return the insets of this border. * * @param component The component for which to return the insets of this border. * @param insets The object to put the newly calculated insets into. * @return The calculated insets. */ public Insets getBorderInsets (Component component, Insets insets) { Insets margin = null; if (component instanceof AbstractButton) { margin = ((AbstractButton) component).getMargin(); } if (margin == null || margin instanceof UIResource) { insets.left = left; insets.top = top; insets.right = right; insets.bottom = bottom; } else { insets.left = margin.left; insets.top = margin.top; insets.right = margin.right; insets.bottom = margin.bottom; } return insets; } } /** * Menu item border. */ private static class MenuItemBorder extends ControlBorder { /** * Paint the border for the given component. * * @param component The component for which to paint the border. * @param graphics The graphics object to use for painting. * @param x The x position of the component. * @param y The y position of the component. * @param width The width of the component. * @param height The height of the component. */ public void paintBorder (Component component, Graphics graphics, int x, int y, int width, int height) { JMenuItem menuItem = (JMenuItem) component; ButtonModel model = menuItem.getModel(); if (model.isArmed() || (menuItem instanceof JMenu && menuItem.isSelected())) { super.paintBorder(component, graphics, x, y, width, height); } } } }squareness-2.3.0/source/net/beeger/squareness/util/SquarenessButtonPainter.java100644 0 0 16730 10563076303 25266 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.util; import java.awt.Color; import java.awt.Graphics; import java.awt.Insets; import javax.swing.AbstractButton; import javax.swing.ButtonModel; import javax.swing.JComponent; import javax.swing.JToolBar; import javax.swing.border.Border; import javax.swing.border.CompoundBorder; import javax.swing.plaf.UIResource; import net.beeger.squareness.SquarenessConstants; import net.beeger.squareness.SquarenessLookAndFeel; /** * Utility class used by UI delegates for all kinds of buttons. */ public class SquarenessButtonPainter { /** * Paint a button. * * @param graphics The graphics object to be used for painting. * @param button The button to paint */ public static void paintButton (Graphics graphics, AbstractButton button) { Color oldColor = graphics.getColor(); ButtonModel model = button.getModel(); Insets buttonInsets = getInnermostOpaqueBorderInsets(button.getBorder(), button); if (buttonInsets == null) { buttonInsets = new Insets(0, 0, 0, 0); } boolean isRollover = ((Boolean) button.getClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY)).booleanValue(); if (buttonInsets.top == 0 && buttonInsets.bottom == 0 && buttonInsets.right == 0 && buttonInsets.left == 0 && button.getBackground() instanceof UIResource) { paintBorderlessButton(graphics, button); } else if (button.isEnabled() && (isRollover || model.isArmed() && model.isPressed() || button.hasFocus() || button.isSelected())) { boolean paintShadow = model.isArmed() && model.isPressed() || button.isSelected() && !isRollover; paintNormalButton(graphics, buttonInsets, button, paintShadow); } else if (button.getParent() != null && button.getParent() instanceof JToolBar && ((JToolBar) button.getParent()).getClientProperty("JToolBar.isRollover") != null && ((Boolean) ((JToolBar) button.getParent()).getClientProperty("JToolBar.isRollover")).booleanValue()) { paintBorderlessButton(graphics, button); } graphics.setColor(oldColor); } /** * Paint a normal button that has a border. * * @param graphics The graphics object used for painting * @param buttonInsets The insets of the visible part of the border of the button. * @param button The button to paint * @param paintShadow Shall the shadow for pressed buttons be painted. */ private static void paintNormalButton (Graphics graphics, Insets buttonInsets, AbstractButton button, boolean paintShadow) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getSelectedControlBackgroundColor()); graphics.fillRect(buttonInsets.left, buttonInsets.top, button.getWidth() - buttonInsets.right, button.getHeight() - buttonInsets.bottom); if (paintShadow) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getSelectedControlBackgroundShadowColor()); graphics.fillRect(buttonInsets.left, buttonInsets.top, 2, button.getHeight() - buttonInsets.bottom); graphics.fillRect(buttonInsets.left, buttonInsets.top, button.getWidth() - buttonInsets.right, 2); } } /** * Paint a button that doesn't have a border. Such buttons take the background color of their parents as their * background color. Only when they are pressed or in rollover mode - in which case they have a border - * they have the same color like buttons with borders in the same state. * * @param graphics The graphics object used for painting. * @param button The button to paint. */ private static void paintBorderlessButton (Graphics graphics, AbstractButton button) { graphics.setColor(button.getParent() != null ? button.getParent().getBackground() : SquarenessLookAndFeel.getCurrentSquarenessTheme().getWindowBackgroundColor()); graphics.fillRect(0, 0, button.getWidth(), button.getHeight()); } /** * Return the insets of the border of the component up to the innermost opaque border * @param border * @param component * @return */ private static Insets getInnermostOpaqueBorderInsets (Border border, JComponent component) { Insets result = null; if (border != null) { if (border instanceof CompoundBorder) { CompoundBorder compoundBorder = ((CompoundBorder) border); Insets insets = getInnermostOpaqueBorderInsets(compoundBorder.getInsideBorder(), component); if (insets != null) { result = new Insets(0, 0, 0, 0); addInsets(result, compoundBorder.getOutsideBorder().getBorderInsets(component)); addInsets(result, insets); } else { insets = getInnermostOpaqueBorderInsets(compoundBorder.getOutsideBorder(), component); if (insets != null) { result = new Insets(0, 0, 0, 0); addInsets(result, insets); } } } else if (border.isBorderOpaque()) { result = border.getBorderInsets(component); } } return result; } /** * Add the two given insets. * * @param insetsToAddTo The insets to add the other one to. * @param insetsToAdd The insets to add. */ private static void addInsets (Insets insetsToAddTo, Insets insetsToAdd) { insetsToAddTo.top += insetsToAdd.top; insetsToAddTo.bottom += insetsToAdd.bottom; insetsToAddTo.right += insetsToAdd.right; insetsToAddTo.left += insetsToAdd.left; } }squareness-2.3.0/source/net/beeger/squareness/util/SquarenessIconFactory.java100644 0 0 111015 10563076303 24720 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.util; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Component; import java.awt.ComponentOrientation; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.GeneralPath; import java.io.Serializable; import javax.swing.AbstractButton; import javax.swing.ButtonModel; import javax.swing.Icon; import javax.swing.JCheckBox; import javax.swing.JCheckBoxMenuItem; import javax.swing.JRadioButton; import javax.swing.JRadioButtonMenuItem; import javax.swing.plaf.UIResource; import net.beeger.squareness.SquarenessConstants; import net.beeger.squareness.SquarenessLookAndFeel; /** * The SquarenessIconFactory is a static factory that creates all painted icons. */ public class SquarenessIconFactory implements Serializable { /** * Return the icon for radio buttons. * * @return The radio button icon */ public static Icon getRadioButtonIcon () { if (_radioButtonIcon == null) { _radioButtonIcon = new RadioButtonIcon(); } return _radioButtonIcon; } /** * Return the icon for check boxes. * * @return The check box icon */ public static Icon getCheckBoxIcon () { if (_checBoxIcon == null) { _checBoxIcon = new CheckBoxIcon(); } return _checBoxIcon; } /** * Return the icon for radio buttons. * * @return The radio button icon */ public static Icon getRadioButtonMenuItemCheckIcon () { if (_radioButtonMenuItemCheckIcon == null) { _radioButtonMenuItemCheckIcon = new RadioButtonMenuItemCheckIcon(); } return _radioButtonMenuItemCheckIcon; } /** * Return the icon for check boxes. * * @return The check box icon */ public static Icon getCheckBoxMenuItemCheckIcon () { if (_checBoxMenuItemCheckIcon == null) { _checBoxMenuItemCheckIcon = new CheckBoxMenuItemCheckIcon(); } return _checBoxMenuItemCheckIcon; } /** * Return the icon for check boxes. * * @return The check box icon */ public static Icon getMenuItemCheckIcon () { if (_menuItemCheckIcon == null) { _menuItemCheckIcon = new MenuItemCheckIcon(); } return _menuItemCheckIcon; } /** * Return the icon for check boxes. * * @return The check box icon */ public static Icon getMenuArrowIcon () { if (_menuArrowIcon == null) { _menuArrowIcon = new MenuArrowIcon(); } return _menuArrowIcon; } /** * Return the icon for check boxes. * * @return The check box icon */ public static Icon getMenuItemArrowIcon () { if (_menuItemArrowIcon == null) { _menuItemArrowIcon = new MenuItemArrowIcon(); } return _menuItemArrowIcon; } /** * Return the close icon for frames. * * @return The close icon for frames. */ public static Icon getCloseFrameIcon () { if (_closeFrameIcon == null) { _closeFrameIcon = new CloseFrameIcon(); } return _closeFrameIcon; } /** * Return the iconify icon for frames. * * @return The iconify icon for frames. */ public static Icon getIconifyFrameIcon () { if (_iconifyFrameIcon == null) { _iconifyFrameIcon = new IconifyFrameIcon(); } return _iconifyFrameIcon; } /** * Return the maximize icon for frames. * * @return The maximize icon for frames. */ public static Icon getMaximizeFrameIcon () { if (_maximizeFrameIcon == null) { _maximizeFrameIcon = new MaximizeFrameIcon(); } return _maximizeFrameIcon; } /** * Return the minimize icon for frames. * * @return The minimize icon for frames. */ public static Icon getMinimizeFrameIcon () { if (_minimizeFrameIcon == null) { _minimizeFrameIcon = new MinimizeFrameIcon(); } return _minimizeFrameIcon; } /** * Return the icon with the up arrow (Used on scroll bars). * * @return The up arrow icon. */ public static Icon getUpIcon () { if (_upIcon == null) { _upIcon = new UpIcon(); } return _upIcon; } /** * Return the icon with the down arrow (Used on scroll bars). * * @return The down arrow icon. */ public static Icon getDownIcon () { if (_downIcon == null) { _downIcon = new DownIcon(); } return _downIcon; } /** * Return the icon with the left arrow (Used on scroll bars). * * @return The left arrow icon. */ public static Icon getLeftIcon () { if (_leftIcon == null) { _leftIcon = new LeftIcon(); } return _leftIcon; } /** * Return the icon with the right arrow (Used on scroll bars). * * @return The right arrow icon. */ public static Icon getRightIcon () { if (_rightIcon == null) { _rightIcon = new RightIcon(); } return _rightIcon; } /** * Return the icon with the up arrow for the spinner control. * * @return The up arrow icon for spinner controls. */ public static Icon getSpinUpIcon () { if (_spinUpIcon == null) { _spinUpIcon = new SpinUpIcon(); } return _spinUpIcon; } /** * Return the icon with the down arrow for the spinner control. * * @return The down arrow icon for spinner controls. */ public static Icon getSpinDownIcon () { if (_spinDownIcon == null) { _spinDownIcon = new SpinDownIcon(); } return _spinDownIcon; } // // private interface // /** * The radio buttton icon. */ private static class RadioButtonIcon implements Icon, UIResource, Serializable { /** * Return the icon's height. * * @return an int specifying the fixed height of the icon. */ public int getIconHeight () { return 13; } /** * Return the icon's width. * * @return an int specifying the fixed width of the icon. */ public int getIconWidth () { return 13; } /** * Draw the icon at the specified location. * * @param component The component to paint the icon on. * @param graphics The graphics to use for the painting. * @param x The x position at which to paint the icon * @param y The y position at which to paint the icon. */ public void paintIcon (Component component, Graphics graphics, int x, int y) { Color oldColor = graphics.getColor(); Color borderColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor(); Color disabledBorderColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor(); Color normalColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalControlBackgroundColor(); Color selectedColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getSelectedControlBackgroundColor(); Color selectedShadowColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getSelectedControlBackgroundShadowColor(); int middle = 6; int min = 0; int max = 12; Graphics2D graphics2D = (Graphics2D) graphics; graphics2D.translate(x, y); graphics2D.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL)); GeneralPath borderPath = new GeneralPath(GeneralPath.WIND_NON_ZERO); borderPath.moveTo(middle, min); borderPath.lineTo(max, middle); borderPath.lineTo(middle, max); borderPath.lineTo(min, middle); borderPath.closePath(); JRadioButton radioButton = (JRadioButton) component; ButtonModel model = radioButton.getModel(); boolean isRollover = ((Boolean) radioButton.getClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY)).booleanValue(); if ((isRollover || model.isPressed() || radioButton.hasFocus()) && model.isEnabled()) { graphics2D.setPaint(selectedColor); } else { graphics2D.setPaint(normalColor); } graphics2D.fill(borderPath); if (model.isPressed()) { GeneralPath shadowPath = new GeneralPath(GeneralPath.WIND_NON_ZERO); shadowPath.moveTo(middle, min); shadowPath.lineTo(middle + 1, min + 1); shadowPath.lineTo(min + 1, middle + 1); shadowPath.lineTo(min, middle); shadowPath.closePath(); graphics2D.setPaint(selectedShadowColor); graphics2D.fill(shadowPath); graphics2D.draw(shadowPath); } if (model.isEnabled()) { graphics2D.setPaint(borderColor); } else { graphics2D.setPaint(disabledBorderColor); } graphics2D.draw(borderPath); if (model.isSelected()) { GeneralPath markPath = new GeneralPath(GeneralPath.WIND_NON_ZERO); markPath.moveTo(middle, min + 3); markPath.lineTo(max - 3, middle); markPath.lineTo(middle, max - 3); markPath.lineTo(min + 3, middle); markPath.closePath(); if (model.isEnabled()) { graphics2D.setPaint(borderColor); } else { graphics2D.setPaint(disabledBorderColor); } graphics2D.fill(markPath); graphics2D.draw(markPath); } graphics2D.translate(-x, -y); graphics.setColor(oldColor); } } /** * The radio buttton icon. */ private static class RadioButtonMenuItemCheckIcon implements Icon, UIResource, Serializable { /** * Return the icon's height. * * @return an int specifying the fixed height of the icon. */ public int getIconHeight () { return 7; } /** * Return the icon's width. * * @return an int specifying the fixed width of the icon. */ public int getIconWidth () { return 7; } /** * Draw the icon at the specified location. * * @param component The component to paint the icon on. * @param graphics The graphics to use for the painting. * @param x The x position at which to paint the icon * @param y The y position at which to paint the icon. */ public void paintIcon (Component component, Graphics graphics, int x, int y) { Color oldColor = graphics.getColor(); Color borderColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor(); Color disabledBorderColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor(); int middle = 3; int min = 0; int max = 6; Graphics2D graphics2D = (Graphics2D) graphics; graphics2D.translate(x, y); JRadioButtonMenuItem radioButton = (JRadioButtonMenuItem) component; ButtonModel model = radioButton.getModel(); GeneralPath markPath = new GeneralPath(GeneralPath.WIND_NON_ZERO); markPath.moveTo(middle, min); markPath.lineTo(max, middle); markPath.lineTo(middle, max); markPath.lineTo(min, middle); markPath.closePath(); if (model.isEnabled()) { graphics2D.setPaint(borderColor); } else { graphics2D.setPaint(disabledBorderColor); } if (model.isSelected()) { graphics2D.fill(markPath); } graphics2D.draw(markPath); graphics2D.translate(-x, -y); graphics.setColor(oldColor); } } /** * The check box icon. */ private static class CheckBoxIcon implements Icon, UIResource, Serializable { /** * Return the icon's height. * * @return an int specifying the fixed height of the icon. */ public int getIconHeight () { return 13; } /** * Return the icon's width. * * @return an int specifying the fixed width of the icon. */ public int getIconWidth () { return 13; } /** * Draw the icon at the specified location. * * @param component The component to paint the icon on. * @param graphics The graphics to use for the painting. * @param x The x position at which to paint the icon * @param y The y position at which to paint the icon. */ public void paintIcon (Component component, Graphics graphics, int x, int y) { Color oldColor = graphics.getColor(); Color selectedShadowColor = SquarenessLookAndFeel.getCurrentSquarenessTheme().getSelectedControlBackgroundShadowColor(); Graphics2D graphics2D = (Graphics2D) graphics; graphics2D.translate(x, y); int min = 0; int max = 12; GeneralPath borderPath = new GeneralPath(GeneralPath.WIND_NON_ZERO); borderPath.moveTo(min, min); borderPath.lineTo(max, min); borderPath.lineTo(max, max); borderPath.lineTo(min, max); borderPath.closePath(); JCheckBox checkBox = (JCheckBox) component; ButtonModel model = checkBox.getModel(); boolean isRollover = ((Boolean) checkBox.getClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY)).booleanValue(); if ((isRollover || model.isPressed() || checkBox.hasFocus()) && model.isEnabled()) { graphics2D.setPaint(SquarenessLookAndFeel.getCurrentSquarenessTheme().getSelectedControlBackgroundColor()); } else { graphics2D.setPaint(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalControlBackgroundColor()); } graphics2D.fill(borderPath); if (model.isPressed()) { GeneralPath shadowPath = new GeneralPath(GeneralPath.WIND_NON_ZERO); shadowPath.moveTo(min, min); shadowPath.lineTo(max, min); shadowPath.lineTo(max, min + 2); shadowPath.lineTo(min + 2,min + 2); shadowPath.lineTo(min + 2,max); shadowPath.lineTo(min, max); shadowPath.closePath(); graphics2D.setPaint(selectedShadowColor); graphics2D.fill(shadowPath); graphics2D.draw(shadowPath); } if (model.isEnabled()) { graphics2D.setPaint(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { graphics2D.setPaint(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } graphics2D.draw(borderPath); if (model.isSelected()) { if (model.isEnabled()) { graphics2D.setPaint(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { graphics2D.setPaint(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } graphics2D.drawLine(min + 4, min + 3, max - 3, max - 4); graphics2D.drawLine(min + 3, min + 3, max - 3, max - 3); graphics2D.drawLine(min + 3, min + 4, max - 4, max - 3); graphics2D.drawLine(max - 4, min + 3, min + 3, max - 4); graphics2D.drawLine(max - 3, min + 3, min + 3, max - 3); graphics2D.drawLine(max - 3, min + 4, min + 4, max - 3); } graphics2D.translate(-x, -y); graphics.setColor(oldColor); } } /** * The check box icon. */ private static class CheckBoxMenuItemCheckIcon implements Icon, UIResource, Serializable { /** * Return the icon's height. * * @return an int specifying the fixed height of the icon. */ public int getIconHeight () { return 7; } /** * Return the icon's width. * * @return an int specifying the fixed width of the icon. */ public int getIconWidth () { return 7; } /** * Draw the icon at the specified location. * * @param component The component to paint the icon on. * @param graphics The graphics to use for the painting. * @param x The x position at which to paint the icon * @param y The y position at which to paint the icon. */ public void paintIcon (Component component, Graphics graphics, int x, int y) { Color oldColor = graphics.getColor(); graphics.translate(x, y); int min = 0; int max = 6; JCheckBoxMenuItem checkBox = (JCheckBoxMenuItem) component; ButtonModel model = checkBox.getModel(); if (model.isEnabled()) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } if (model.isSelected()) { graphics.drawLine(min + 2, min + 1, max - 1, max - 2); graphics.drawLine(min + 1, min + 1, max - 1, max - 1); graphics.drawLine(min + 1, min + 2, max - 2, max - 1); graphics.drawLine(min + 1, max - 2, max - 2, min + 1); graphics.drawLine(min + 1, max - 1, max - 1, min + 1); graphics.drawLine(min + 2, max - 1, max - 1, min + 2); } else { graphics.drawLine(min, min, min, max); graphics.drawLine(min, min, max, min); graphics.drawLine(max, min, max, max); graphics.drawLine(min, max, max, max); } graphics.translate(-x, -y); graphics.setColor(oldColor); } } /** * The check box icon. */ private static class MenuItemCheckIcon implements Icon, UIResource, Serializable { /** * Return the icon's height. * * @return an int specifying the fixed height of the icon. */ public int getIconHeight () { return 7; } /** * Return the icon's width. * * @return an int specifying the fixed width of the icon. */ public int getIconWidth () { return 7; } /** * Draw the icon at the specified location. * * @param component The component to paint the icon on. * @param graphics The graphics to use for the painting. * @param x The x position at which to paint the icon * @param y The y position at which to paint the icon. */ public void paintIcon (Component component, Graphics graphics, int x, int y) { } } /** * The check box icon. */ private static class MenuArrowIcon implements Icon, UIResource, Serializable { /** * Return the icon's height. * * @return an int specifying the fixed height of the icon. */ public int getIconHeight () { return 7; } /** * Return the icon's width. * * @return an int specifying the fixed width of the icon. */ public int getIconWidth () { return 7; } /** * Draw the icon at the specified location. * * @param component The component to paint the icon on. * @param graphics The graphics to use for the painting. * @param x The x position at which to paint the icon * @param y The y position at which to paint the icon. */ public void paintIcon (Component component, Graphics graphics, int x, int y) { Color oldColor = graphics.getColor(); if (component.isEnabled()) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } int startLine1X = 2; int startLine2X = 1; int startLine3X = 1; int endLine1X = 5; int endLine2X = 4; int endLine3X = 3; if (component.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) { startLine1X = 4; startLine2X = 5; startLine3X = 5; endLine1X = 1; endLine2X = 2; endLine3X = 3; } graphics.translate(x, y); graphics.drawLine(startLine1X, 0, endLine1X, 3); graphics.drawLine(startLine2X, 0, endLine2X, 3); graphics.drawLine(startLine3X, 1, endLine3X, 3); graphics.drawLine(startLine1X, 6, endLine1X, 3); graphics.drawLine(startLine2X, 6, endLine2X, 3); graphics.drawLine(startLine3X, 5, endLine3X, 3); graphics.translate(-x, -y); graphics.setColor(oldColor); } } /** * The check box icon. */ private static class MenuItemArrowIcon implements Icon, UIResource, Serializable { /** * Return the icon's height. * * @return an int specifying the fixed height of the icon. */ public int getIconHeight () { return 7; } /** * Return the icon's width. * * @return an int specifying the fixed width of the icon. */ public int getIconWidth () { return 7; } /** * Draw the icon at the specified location. * * @param component The component to paint the icon on. * @param graphics The graphics to use for the painting. * @param x The x position at which to paint the icon * @param y The y position at which to paint the icon. */ public void paintIcon (Component component, Graphics graphics, int x, int y) { } } /** * The close icon for frames. */ private static class CloseFrameIcon implements Icon, UIResource, Serializable { /** * Return the icon's width. * * @return The icon#s width. */ public int getIconWidth () { return 11; } /** * Return the icon's height. * * @return The icon's height. */ public int getIconHeight () { return 11; } /** * Draw the icon at the specified location. * * @param component The component to paint the icon on. * @param graphics The graphics to use for the painting. * @param x The x position at which to paint the icon * @param y The y position at which to paint the icon. */ public void paintIcon (Component component, Graphics graphics, int x, int y) { Color oldColor = graphics.getColor(); AbstractButton button = (AbstractButton) component; ButtonModel model = button.getModel(); boolean isRollover = ((Boolean) button.getClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY)).booleanValue(); if (!model.isEnabled()) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } else if (model.isPressed() || !isRollover) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getSelectedControlBackgroundColor()); } graphics.translate(x, y); graphics.drawLine(1, 1, 9, 9); graphics.drawLine(9, 1, 1, 9); if (!model.isEnabled() || !model.isPressed()) { graphics.drawLine(2, 1, 9, 8); graphics.drawLine(1, 2, 8, 9); graphics.drawLine(8, 1, 1, 8); graphics.drawLine(9, 2, 2, 9); } graphics.translate(-x, -y); graphics.setColor(oldColor); } } /** * The iconify icon for frames. */ private static class IconifyFrameIcon implements Icon, UIResource, Serializable { /** * Return the icon's width. * * @return The icon#s width. */ public int getIconWidth () { return 11; //To change body of implemented methods use Options | File Templates. } /** * Return the icon's height. * * @return The icon#s height. */ public int getIconHeight () { return 11; //To change body of implemented methods use Options | File Templates. } /** * Draw the icon at the specified location. * * @param component The component to paint the icon on. * @param graphics The graphics to use for the painting. * @param x The x position at which to paint the icon * @param y The y position at which to paint the icon. */ public void paintIcon (Component component, Graphics graphics, int x, int y) { Color oldColor = graphics.getColor(); AbstractButton button = (AbstractButton) component; ButtonModel model = button.getModel(); boolean isRollover = ((Boolean) button.getClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY)).booleanValue(); if (!model.isEnabled()) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } else if (model.isPressed() || !isRollover) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getSelectedControlBackgroundColor()); } if (!model.isEnabled() || !model.isPressed()) { graphics.fillRect(x + 4, y + 4, 3, 3); } else { graphics.drawLine(x + 5, y + 5, x + 5, y + 5); } graphics.setColor(oldColor); } } /** * The maximize icon for frames. */ private static class MaximizeFrameIcon implements Icon, UIResource, Serializable { /** * Return the icon's width. * * @return The icon#s width. */ public int getIconWidth () { return 11; } /** * Return the icon's height. * * @return The icon#s height. */ public int getIconHeight () { return 11; } /** * Draw the icon at the specified location. * * @param component The component to paint the icon on. * @param graphics The graphics to use for the painting. * @param x The x position at which to paint the icon * @param y The y position at which to paint the icon. */ public void paintIcon (Component component, Graphics graphics, int x, int y) { Color oldColor = graphics.getColor(); AbstractButton button = (AbstractButton) component; ButtonModel model = button.getModel(); boolean isRollover = ((Boolean) button.getClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY)).booleanValue(); if (!model.isEnabled()) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } else if (model.isPressed() || !isRollover) { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { graphics.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getSelectedControlBackgroundColor()); } if (!model.isEnabled() || !model.isPressed()) { graphics.fillRect(x + 4, y + 2, 3, 7); graphics.fillRect(x + 2, y + 4, 7, 3); } else { graphics.drawLine(x + 5, y + 2, x + 5, y + 8); graphics.drawLine(x + 2, y + 5, x + 8, y + 5); } graphics.setColor(oldColor); } } private static class MinimizeFrameIcon implements Icon, UIResource, Serializable { public int getIconWidth () { return 11; //To change body of implemented methods use Options | File Templates. } public int getIconHeight () { return 11; //To change body of implemented methods use Options | File Templates. } public void paintIcon (Component c, Graphics g, int x, int y) { Color oldColor = g.getColor(); AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); boolean isRollover = ((Boolean) button.getClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY)).booleanValue(); if (!model.isEnabled()) { g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } else if (model.isPressed() || !isRollover) { g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getSelectedControlBackgroundColor()); } if (!model.isEnabled() || !model.isPressed()) { g.fillRect(x + 2, y + 4, 7, 3); } else { g.drawLine(x + 2, y + 5, x + 8, y + 5); } g.setColor(oldColor); } } private static class UpIcon implements Icon, UIResource, Serializable { public int getIconHeight () { return 6; } public int getIconWidth () { return 11; } public void paintIcon (Component c, Graphics g, int x, int y) { Color oldColor = g.getColor(); if (c.isEnabled()) { g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } g.drawLine(x + 4, y, x, y + 4); g.drawLine(x + 4, y + 1, x + 1, y + 4); g.drawLine(x + 4, y + 2, x + 1, y + 5); g.drawLine(x + 4, y, x + 8, y + 4); g.drawLine(x + 4, y + 1, x + 7, y + 4); g.drawLine(x + 4, y + 2, x + 7, y + 5); g.setColor(oldColor); } } private static class DownIcon implements Icon, UIResource, Serializable { public int getIconHeight () { return 6; } public int getIconWidth () { return 11; } public void paintIcon (Component c, Graphics g, int x, int y) { Color oldColor = g.getColor(); if (c.isEnabled()) { g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } g.drawLine(x + 4, y + 5, x, y + 5 - 4); g.drawLine(x + 4, y + 5 - 1, x + 1, y + 5 - 4); g.drawLine(x + 4, y + 5 - 2, x + 1, y + 5 - 5); g.drawLine(x + 4, y + 5, x + 8, y + 5 - 4); g.drawLine(x + 4, y + 5 - 1, x + 7, y + 5 - 4); g.drawLine(x + 4, y + 5 - 2, x + 7, y + 5 - 5); g.setColor(oldColor); } } private static class LeftIcon implements Icon, UIResource, Serializable { public int getIconHeight () { return 9; } public int getIconWidth () { return 6; } public void paintIcon (Component c, Graphics g, int x, int y) { Color oldColor = g.getColor(); if (c.isEnabled()) { g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } g.drawLine(x, y + 4, x + 4, y); g.drawLine(x + 1, y + 4, x + 4, y + 1); g.drawLine(x + 2, y + 4, x + 5, y + 1); g.drawLine(x, y + 4, x + 4, y + 8); g.drawLine(x + 1, y + 4, x + 4, y + 7); g.drawLine(x + 2, y + 4, x + 5, y + 7); g.setColor(oldColor); } } private static class RightIcon implements Icon, UIResource, Serializable { public int getIconHeight () { return 9; } public int getIconWidth () { return 6; } public void paintIcon (Component c, Graphics g, int x, int y) { Color oldColor = g.getColor(); if (c.isEnabled()) { g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } g.drawLine(x + 5, y + 4, x + 5 - 4, y); g.drawLine(x + 5 - 1, y + 4, x + 5 - 4, y + 1); g.drawLine(x + 5 - 2, y + 4, x + 5 - 5, y + 1); g.drawLine(x + 5, y + 4, x + 5 - 4, y + 8); g.drawLine(x + 5 - 1, y + 4, x + 5 - 4, y + 7); g.drawLine(x + 5 - 2, y + 4, x + 5 - 5, y + 7); g.setColor(oldColor); } } private static class SpinUpIcon implements Icon, UIResource, Serializable { public int getIconHeight () { return 4; } public int getIconWidth () { return 7; } public void paintIcon (Component c, Graphics g, int x, int y) { Color oldColor = g.getColor(); if (c.isEnabled()) { g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } g.drawLine(x + 3, y, x, y + 3); g.drawLine(x + 3, y + 1, x + 1, y + 3); g.drawLine(x + 3, y + 2, x + 2, y + 3); g.drawLine(x + 3, y, x + 6, y + 3); g.drawLine(x + 3, y + 1, x + 5, y + 3); g.drawLine(x + 3, y + 2, x + 4, y + 3); g.setColor(oldColor); } } private static class SpinDownIcon implements Icon, UIResource, Serializable { public int getIconHeight () { return 4; } public int getIconWidth () { return 7; } public void paintIcon (Component c, Graphics g, int x, int y) { Color oldColor = g.getColor(); if (c.isEnabled()) { g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getNormalBorderColor()); } else { g.setColor(SquarenessLookAndFeel.getCurrentSquarenessTheme().getDisabledBorderColor()); } g.drawLine(x + 3, y + 3, x, y + 3 - 3); g.drawLine(x + 3, y + 3 - 1, x + 1, y + 3 - 3); g.drawLine(x + 3, y + 3 - 2, x + 2, y + 3 - 3); g.drawLine(x + 3, y + 3, x + 6, y + 3 - 3); g.drawLine(x + 3, y + 3 - 1, x + 5, y + 3 - 3); g.drawLine(x + 3, y + 3 - 2, x + 4, y + 3 - 3); g.setColor(oldColor); } } private static Icon _radioButtonIcon; private static Icon _checBoxIcon; private static Icon _closeFrameIcon; private static Icon _iconifyFrameIcon; private static Icon _maximizeFrameIcon; private static Icon _minimizeFrameIcon; private static Icon _upIcon; private static Icon _downIcon; private static Icon _leftIcon; private static Icon _rightIcon; private static Icon _spinUpIcon; private static Icon _spinDownIcon; private static Icon _radioButtonMenuItemCheckIcon; private static Icon _checBoxMenuItemCheckIcon; private static Icon _menuItemCheckIcon; private static Icon _menuArrowIcon; private static Icon _menuItemArrowIcon; }squareness-2.3.0/source/net/beeger/squareness/util/SquarenessListenerFactory.java100644 0 0 6272 10563076303 25565 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.util; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.AbstractButton; import net.beeger.squareness.SquarenessConstants; /** * SquarenessListenerFactory is a static factory that creates and manages all general purpose listeners used by * the Look And Feel such as the button rollover listener. */ public class SquarenessListenerFactory { public static MouseListener getButtonRolloverMouseListener () { if (_buttonRolloverMouseListener == null) { _buttonRolloverMouseListener = new ButtonRolloverMouseListener(); } return _buttonRolloverMouseListener; } private static MouseListener _buttonRolloverMouseListener; private static class ButtonRolloverMouseListener extends MouseAdapter { /** * Invoked when the mouse enters a component. */ public void mouseEntered (MouseEvent e) { AbstractButton button = ((AbstractButton) e.getSource()); button.putClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY, Boolean.TRUE); button.repaint(); } /** * Invoked when the mouse exits a component. */ public void mouseExited (MouseEvent e) { AbstractButton button = ((AbstractButton) e.getSource()); button.putClientProperty(SquarenessConstants.ROLLOVER_CLENT_PROPERTY_KEY, Boolean.FALSE); button.repaint(); } } }squareness-2.3.0/source/net/beeger/squareness/util/SquarenessTitlePane.java100644 0 0 24654 10563076303 24361 0ustar 0 0 /* Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit http://squareness.beeger.net/ for new releases of Squareness Look And Feel and other skins from the Squareness series. */ package net.beeger.squareness.util; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Font; import java.awt.Insets; import java.awt.LayoutManager; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.UIManager; import net.beeger.squareness.SquarenessLookAndFeel; /** *

Common super class for title panes.

*

This class is currently subclassed in inner classes in SquarenessInternalFrameUI and SquarenessRootPaneUI. * Those inner classes add the specific details of handling an internal frame viz. a frame.

*/ public abstract class SquarenessTitlePane extends JComponent { /** * Create the title pane and equip it with the frame buttons. */ public SquarenessTitlePane () { _firstUpdate = true; _maximizeIcon = UIManager.getIcon("InternalFrame.maximizeIcon"); _minimizeIcon = UIManager.getIcon("InternalFrame.minimizeIcon"); _closeButton = new FrameButton(); _closeButton.setIcon(UIManager.getIcon("InternalFrame.closeIcon")); _closeButton.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent e) { close(); } }); _maxButton = new FrameButton(); _maxButton.setIcon(_maximizeIcon); _maxButton.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent e) { if(isMaximized()) { restore(); } else { maximize(); } } }); _iconifyButton = new FrameButton(); _iconifyButton.setIcon(UIManager.getIcon("InternalFrame.iconifyIcon")); _iconifyButton.addActionListener(new ActionListener() { public void actionPerformed (ActionEvent e) { iconify(); } }); add(_iconifyButton); add(_maxButton); add(_closeButton); _titleLabel = new JLabel(); _titleLabel.setFont(UIManager.getFont("InternalFrame.titleFont", getLocale())); _titleLabel.setForeground(SquarenessLookAndFeel.getCurrentSquarenessTheme().getTextColor()); add(_titleLabel); setLayout(new SquarenessTitlePaneLayout()); setBackground(SquarenessLookAndFeel.getCurrentSquarenessTheme().getWindowBackgroundColor()); } /** *

Update the title pane

*

This updates the title, the enabled state of the buttons and the icon on the maximize/restore button.

*/ protected void update() { boolean closeable = isClosable(); boolean iconifiable = isIconifiable(); boolean maximized = isMaximized(); boolean maximizable = isMaximizable(); Font font = UIManager.getFont("InternalFrame.titleFont", getLocale()); String title = getTitle(); if (_firstUpdate || _lastCloseable != closeable) { _closeButton.setEnabled(closeable); } if (_firstUpdate || _lastIconifiable != iconifiable) { _iconifyButton.setEnabled(iconifiable); } if (_firstUpdate || _lastMaximized != maximized) { _maxButton.setIcon(maximized ? _minimizeIcon : _maximizeIcon); } if (_firstUpdate || _lastMaximizable != maximizable) { _maxButton.setEnabled(maximizable); } if (_firstUpdate || !font.equals(_lastFont)) { _titleLabel.setFont(font); } if (_firstUpdate || (title == null && _lastTitle != null) || (title != null && !title.equals(_lastTitle))) { _titleLabel.setText(title); } _lastCloseable = closeable; _lastIconifiable = iconifiable; _lastMaximized = maximized; _lastMaximizable = maximizable; _lastFont = font; _lastTitle = title; _firstUpdate = false; } /** * Do we have a left to right orientation? * * @return True if we are in left to right orientation, false otherwise. */ public abstract boolean isLeftToRight(); protected abstract boolean isIconifiable (); protected abstract boolean isMaximizable (); protected abstract boolean isClosable (); /** * Close the (internal) frame. */ protected abstract void close(); /** * Iconify the (internal) frame. */ protected abstract void iconify(); /** * Maximize the (internal) frame. */ protected abstract void maximize(); /** * Restore the (internal) frame. */ protected abstract void restore(); /** * Can the (internal) frame this title pane belongs to be maximized? * @return true if the (internal) frame can be maximized. */ protected abstract boolean isMaximized(); /** * Can the (internal) frame this title pane belongs to be iconified? * @return true if the (internal) frame can be iconified. */ protected abstract boolean isIconified(); /** * Return the title of the (internal) frame. * @return The title of the (internal) frame. */ protected abstract String getTitle(); private Icon _maximizeIcon; private Icon _minimizeIcon; private JButton _closeButton; private JButton _maxButton; private JButton _iconifyButton; private JLabel _titleLabel; /** * The layout manager of the Squareness title pane. It puts the buttons and the title on their right places. */ protected class SquarenessTitlePaneLayout implements LayoutManager { /** * Removes the specified component from the layout. * * @param comp the component to be removed */ public void removeLayoutComponent (Component comp) { } /** * If the layout manager uses a per-component string, * adds the component comp to the layout, * associating it * with the string specified by name. * * @param name the string to be associated with the component * @param comp the component to be added */ public void addLayoutComponent (String name, Component comp) { } /** * Calculates the minimum size dimensions for the specified * container, given the components it contains. * * @param parent the component to be laid out * @see #preferredLayoutSize */ public Dimension minimumLayoutSize (Container parent) { return new Dimension(_closeButton.getIcon().getIconWidth() + 60, _closeButton.getIcon().getIconHeight() + 2); } /** * Calculates the preferred size dimensions for the specified * container, given the components it contains. * * @param parent the container to be laid out * @see #minimumLayoutSize */ public Dimension preferredLayoutSize (Container parent) { return minimumLayoutSize(parent); } public void layoutContainer (Container container) { boolean leftToRight = isLeftToRight(); int width = getWidth(); int height = getHeight(); int x; int buttonHeight = _closeButton.getIcon().getIconHeight(); int buttonWidth = _closeButton.getIcon().getIconWidth(); int y = (height - buttonHeight) >> 1; x = (leftToRight) ? width - buttonWidth - 2 : 2; _closeButton.setBounds(x, y, buttonWidth, buttonHeight); x += (leftToRight) ? -(buttonWidth + 2) : buttonWidth + 2; _maxButton.setBounds(x, y, buttonWidth, buttonHeight); x += (leftToRight) ? -(buttonWidth + 2) : buttonWidth + 2; _iconifyButton.setBounds(x, y, buttonWidth, buttonHeight); int maxX = leftToRight ? x - 2 : width - 2; x = leftToRight ? 2 : x + 2; _titleLabel.setBounds(x, y, maxX - x, buttonHeight); } } /** * A convenience class used for the frame buttons. * Instances of this class have no borders, no margins and are not focusable. */ protected static class FrameButton extends JButton { /** * Creates a button with no set text or icon. */ public FrameButton () { setMargin(new Insets(0,0,0,0)); setBorder(BorderFactory.createEmptyBorder(0,0,0,0)); setOpaque(true); setFocusPainted(false); } /** * Returns whether this Component can be focused. * * @return true if this Component is focusable; * false otherwise. * @see #setFocusable * @since 1.4 */ public boolean isFocusable () { return false; } } private boolean _lastCloseable; private boolean _lastIconifiable; private boolean _lastMaximized; private boolean _lastMaximizable; private Font _lastFont; private String _lastTitle; private boolean _firstUpdate; }squareness-2.3.0/source/org/jvnet/lafplugin/ComponentPluginManager.java100644 0 0 6124 10401612330 23502 0ustar 0 0 package org.jvnet.lafplugin; import java.util.Iterator; import java.util.Set; import javax.swing.UIDefaults; /** * Plugin manager for look-and-feels. * * @author Kirill Grouchnikov * @author Erik Vickroy * @author Robert Beeger * @author Frederic Lavigne * @author Pattrick Gotthardt */ public class ComponentPluginManager extends PluginManager { /** * Simple constructor. * * @param xmlName * The name of XML file that contains plugin configuration. * @param mainTag * The main tag in the XML configuration file. * @param pluginTag * The tag that corresponds to a single plugin kind. Specifies * the plugin kind that will be located in * {@link #getAvailablePlugins(boolean)}. */ public ComponentPluginManager(String xmlName) { super(xmlName, LafComponentPlugin.TAG_MAIN, LafComponentPlugin.COMPONENT_TAG_PLUGIN_CLASS); } /** * Helper function to initialize all available component plugins of * this plugin manager. Calls the * {@link LafComponentPlugin#initialize()} of all available component * plugins. */ public void initializeAll() { Set availablePlugins = this.getAvailablePlugins(); for (Iterator iterator = availablePlugins.iterator(); iterator .hasNext();) { Object pluginObject = iterator.next(); if (pluginObject instanceof LafComponentPlugin) ((LafComponentPlugin) pluginObject).initialize(); } } /** * Helper function to uninitialize all available component plugins of * this plugin manager. Calls the * {@link LafComponentPlugin#uninitialize()} of all available component * plugins. */ public void uninitializeAll() { Set availablePlugins = this.getAvailablePlugins(); for (Iterator iterator = availablePlugins.iterator(); iterator .hasNext();) { Object pluginObject = iterator.next(); if (pluginObject instanceof LafComponentPlugin) ((LafComponentPlugin) pluginObject).uninitialize(); } } /** * Helper function to process the (possibly) theme-dependent default * settings of all available component plugins of this plugin * manager. Calls the {@link LafComponentPlugin#getDefaults(Object)} of all * available plugins and puts the respective results in the specified table. * * @param table * The table that will be updated with the (possibly) * theme-dependent default settings of all available component * plugins. * @param themeInfo * LAF-specific information on the current theme. */ public void processAllDefaultsEntries(UIDefaults table, Object themeInfo) { Set availablePlugins = this.getAvailablePlugins(); for (Iterator iterator = availablePlugins.iterator(); iterator .hasNext();) { Object pluginObject = iterator.next(); if (pluginObject instanceof LafComponentPlugin) { Object[] defaults = ((LafComponentPlugin) pluginObject) .getDefaults(themeInfo); if (defaults != null) { table.putDefaults(defaults); } } } } } squareness-2.3.0/source/org/jvnet/lafplugin/LafComponentPlugin.java100644 0 0 2460 10401612724 22640 0ustar 0 0 package org.jvnet.lafplugin; import javax.swing.plaf.metal.MetalTheme; /** * Basic interface for look-and-feel plugins. * * @author Kirill Grouchnikov * @author Erik Vickroy * @author Robert Beeger * @author Frederic Lavigne * @author Pattrick Gotthardt */ public interface LafComponentPlugin extends LafPlugin { /** * XML tag for look-and-feel plugins that specify component UI delegates. */ public static final String COMPONENT_TAG_PLUGIN_CLASS = "component-plugin-class"; /** * Initializes this plugin. */ public void initialize(); /** * Unitializes this plugin. */ public void uninitialize(); /** * Retrieves a collection of custom settings based on the specified theme. * The entries in the array should be pairwise, odd being symbolic name of a * setting, and even being the setting value. * * @param themeInfo * Theme information object. Can be {@link MetalTheme}, for * instance or any other LAF-specific object. * @return Collection of custom settings based on the specified theme. The * entries in the array should be pairwise, odd being symbolic name * of a setting, and even being the setting value. */ public Object[] getDefaults(Object themeInfo); } squareness-2.3.0/source/org/jvnet/lafplugin/LafPlugin.java100644 0 0 652 10401612706 20736 0ustar 0 0 package org.jvnet.lafplugin; /** * Basic interface for look-and-feel plugins. * * @author Kirill Grouchnikov * @author Erik Vickroy * @author Robert Beeger * @author Frederic Lavigne * @author Pattrick Gotthardt */ public interface LafPlugin { /** * Main XML tag. See * {@link PluginManager#PluginManager(String, String, String)}. */ public static final String TAG_MAIN = "laf-plugin"; } squareness-2.3.0/source/org/jvnet/lafplugin/LafPlugin.license100644 0 0 3043 10357023212 21452 0ustar 0 0 Copyright (c) 2005, Kirill Grouchnikov and Erik Vickroy All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Kirill Grouchnikov and Erik Vickroy nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.squareness-2.3.0/source/org/jvnet/lafplugin/NanoXML.license100644 0 0 2005 10356765732 21065 0ustar 0 0 NanoXML is distributed under the zlib/libpng license, which is OSS (Open Source Software) compliant. Copyright ©2000-2002 Marc De Scheemaecker, All Rights Reserved. This software is provided 'as-is', without any express or implied warranty. In no event will the author be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. squareness-2.3.0/source/org/jvnet/lafplugin/PluginManager.java100644 0 0 11600 10401615424 21641 0ustar 0 0 package org.jvnet.lafplugin; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; import java.util.Enumeration; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import javax.swing.UIDefaults; /** * Plugin manager for look-and-feels. * * @author Kirill Grouchnikov * @author Erik Vickroy * @author Robert Beeger * @author Frederic Lavigne * @author Pattrick Gotthardt */ public class PluginManager { private String mainTag; private String pluginTag; private String xmlName; private Set plugins; /** * Simple constructor. * * @param xmlName * The name of XML file that contains plugin configuration. * @param mainTag * The main tag in the XML configuration file. * @param pluginTag * The tag that corresponds to a single plugin kind. Specifies * the plugin kind that will be located in * {@link #getAvailablePlugins(boolean)}. */ public PluginManager(String xmlName, String mainTag, String pluginTag) { this.xmlName = xmlName; this.mainTag = mainTag; this.pluginTag = pluginTag; this.plugins = null; } // protected String getPluginClass(URL pluginUrl) { // InputStream is = null; // try { // DocumentBuilder builder = DocumentBuilderFactory.newInstance() // .newDocumentBuilder(); // is = pluginUrl.openStream(); // Document doc = builder.parse(is); // Node root = doc.getFirstChild(); // if (!this.mainTag.equals(root.getNodeName())) // return null; // NodeList children = root.getChildNodes(); // for (int i = 0; i < children.getLength(); i++) { // Node child = children.item(i); // if (!this.pluginTag.equals(child.getNodeName())) // continue; // if (child.getChildNodes().getLength() != 1) // return null; // Node text = child.getFirstChild(); // if (text.getNodeType() != Node.TEXT_NODE) // return null; // return text.getNodeValue(); // } // return null; // } catch (Exception exc) { // return null; // } finally { // if (is != null) { // try { // is.close(); // } catch (Exception e) { // } // } // } // } // protected String getPluginClass(URL pluginUrl) { InputStream is = null; InputStreamReader isr = null; try { XMLElement xml = new XMLElement(); is = pluginUrl.openStream(); isr = new InputStreamReader(is); xml.parseFromReader(isr); if (!this.mainTag.equals(xml.getName())) return null; Enumeration children = xml.enumerateChildren(); while (children.hasMoreElements()) { XMLElement child = (XMLElement) children.nextElement(); if (!this.pluginTag.equals(child.getName())) continue; if (child.countChildren() != 0) return null; return child.getContent(); } return null; } catch (Exception exc) { return null; } finally { if (isr != null) { try { isr.close(); } catch (Exception e) { } } if (is != null) { try { is.close(); } catch (Exception e) { } } } } protected Object getPlugin(URL pluginUrl) throws Exception { String pluginClassName = this.getPluginClass(pluginUrl); if (pluginClassName == null) return null; Class pluginClass = Class.forName(pluginClassName); if (pluginClass == null) return null; Object pluginInstance = pluginClass.newInstance(); if (pluginInstance == null) return null; return pluginInstance; } /** * Returns a collection of all available plugins. * * @return Collection of all available plugins. The classpath is scanned * only once. * @see #getAvailablePlugins(boolean) */ public Set getAvailablePlugins() { return this.getAvailablePlugins(false); } /** * Returns a collection of all available plugins. The parameter specifies * whether the classpath should be rescanned or whether to return the * already found plugins (after first-time scan). * * @param toReload * If true, the classpath is scanned for * available plugins every time this function is * called. If false, the classpath scan is * performed only once. The consecutive calls return the cached * result. * @return Collection of all available plugins. */ public Set getAvailablePlugins(boolean toReload) { if (toReload && (this.plugins != null)) return this.plugins; this.plugins = new HashSet(); ClassLoader cl = PluginManager.class.getClassLoader(); try { Enumeration urls = cl.getResources(this.xmlName); while (urls.hasMoreElements()) { URL pluginUrl = (URL) urls.nextElement(); Object pluginInstance = this.getPlugin(pluginUrl); if (pluginInstance != null) this.plugins.add(pluginInstance); } } catch (Exception exc) { return null; } return plugins; } } squareness-2.3.0/source/org/jvnet/lafplugin/XMLElement.java100644 0 0 276407 10377705472 21143 0ustar 0 0 /* XMLElement.java * * $Revision: 1.4 $ * $Date: 2002/03/24 10:27:59 $ * $Name: RELEASE_2_2_1 $ * * This file is part of NanoXML 2 Lite. * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved. * * This software is provided 'as-is', without any express or implied warranty. * In no event will the authors be held liable for any damages arising from the * use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software in * a product, an acknowledgment in the product documentation would be * appreciated but is not required. * * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * * 3. This notice may not be removed or altered from any source distribution. *****************************************************************************/ package org.jvnet.lafplugin; import java.io.ByteArrayOutputStream; import java.io.CharArrayReader; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.StringReader; import java.io.Writer; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; /** * XMLElement is a representation of an XML object. The object is able to parse * XML code. *

*
Parsing XML Data
*
* You can parse XML data using the following code: *
*
Retrieving Attributes
*
* You can enumerate the attributes of an element using the method * {@link #enumerateAttributeNames() enumerateAttributeNames}. * The attribute values can be retrieved using the method * {@link #getStringAttribute(java.lang.String) getStringAttribute}. * The following example shows how to list the attributes of an element: *
*
Retrieving Child Elements
*
* You can enumerate the children of an element using * {@link #enumerateChildren() enumerateChildren}. * The number of child elements can be retrieved using * {@link #countChildren() countChildren}. *
*
Elements Containing Character Data
*
* If an elements contains character data, like in the following example: * * you can retrieve that data using the method * {@link #getContent() getContent}. *
*
Subclassing XMLElement
*
* When subclassing XMLElement, you need to override the method * {@link #createAnotherElement() createAnotherElement} * which has to return a new copy of the receiver. *
*

* * @see nanoxml.XMLParseException * * @author Marc De Scheemaecker * <cyberelf@mac.com> * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $ */ public class XMLElement { /** * Serialization serial version ID. */ static final long serialVersionUID = 6685035139346394777L; /** * Major version of NanoXML. Classes with the same major and minor * version are binary compatible. Classes with the same major version * are source compatible. If the major version is different, you may * need to modify the client source code. * * @see nanoxml.XMLElement#NANOXML_MINOR_VERSION */ public static final int NANOXML_MAJOR_VERSION = 2; /** * Minor version of NanoXML. Classes with the same major and minor * version are binary compatible. Classes with the same major version * are source compatible. If the major version is different, you may * need to modify the client source code. * * @see nanoxml.XMLElement#NANOXML_MAJOR_VERSION */ public static final int NANOXML_MINOR_VERSION = 2; /** * The attributes given to the element. * *

Invariants:
*
*/ private Hashtable attributes; /** * Child elements of the element. * *
Invariants:
*
*/ private Vector children; /** * The name of the element. * *
Invariants:
*
*/ private String name; /** * The #PCDATA content of the object. * *
Invariants:
*
*/ private String contents; /** * Conversion table for &...; entities. The keys are the entity names * without the & and ; delimiters. * *
Invariants:
*
*/ private Hashtable entities; /** * The line number where the element starts. * *
Invariants:
*
*/ private int lineNr; /** * true if the case of the element and attribute names * are case insensitive. */ private boolean ignoreCase; /** * true if the leading and trailing whitespace of #PCDATA * sections have to be ignored. */ private boolean ignoreWhitespace; /** * Character read too much. * This character provides push-back functionality to the input reader * without having to use a PushbackReader. * If there is no such character, this field is '\0'. */ private char charReadTooMuch; /** * The reader provided by the caller of the parse method. * *
Invariants:
*
*/ private Reader reader; /** * The current line number in the source content. * *
Invariants:
*
*/ private int parserLineNr; /** * Creates and initializes a new XML element. * Calling the construction is equivalent to: * * *
Postconditions:
*
* * @see nanoxml.XMLElement#XMLElement(java.util.Hashtable) * XMLElement(Hashtable) * @see nanoxml.XMLElement#XMLElement(boolean) * @see nanoxml.XMLElement#XMLElement(java.util.Hashtable,boolean) * XMLElement(Hashtable, boolean) */ public XMLElement() { this(new Hashtable(), false, true, true); } /** * Creates and initializes a new XML element. * Calling the construction is equivalent to: * * * @param entities * The entity conversion table. * *
Preconditions:
*
* *
Postconditions:
*
* * @see nanoxml.XMLElement#XMLElement() * @see nanoxml.XMLElement#XMLElement(boolean) * @see nanoxml.XMLElement#XMLElement(java.util.Hashtable,boolean) * XMLElement(Hashtable, boolean) */ public XMLElement(Hashtable entities) { this(entities, false, true, true); } /** * Creates and initializes a new XML element. * Calling the construction is equivalent to: * * * @param skipLeadingWhitespace * true if leading and trailing whitespace in PCDATA * content has to be removed. * *
Postconditions:
*
* * @see nanoxml.XMLElement#XMLElement() * @see nanoxml.XMLElement#XMLElement(java.util.Hashtable) * XMLElement(Hashtable) * @see nanoxml.XMLElement#XMLElement(java.util.Hashtable,boolean) * XMLElement(Hashtable, boolean) */ public XMLElement(boolean skipLeadingWhitespace) { this(new Hashtable(), skipLeadingWhitespace, true, true); } /** * Creates and initializes a new XML element. * Calling the construction is equivalent to: * * * @param entities * The entity conversion table. * @param skipLeadingWhitespace * true if leading and trailing whitespace in PCDATA * content has to be removed. * *
Preconditions:
*
* *
Postconditions:
*
* * @see nanoxml.XMLElement#XMLElement() * @see nanoxml.XMLElement#XMLElement(boolean) * @see nanoxml.XMLElement#XMLElement(java.util.Hashtable) * XMLElement(Hashtable) */ public XMLElement(Hashtable entities, boolean skipLeadingWhitespace) { this(entities, skipLeadingWhitespace, true, true); } /** * Creates and initializes a new XML element. * * @param entities * The entity conversion table. * @param skipLeadingWhitespace * true if leading and trailing whitespace in PCDATA * content has to be removed. * @param ignoreCase * true if the case of element and attribute names have * to be ignored. * *
Preconditions:
*
* *
Postconditions:
*
* * @see nanoxml.XMLElement#XMLElement() * @see nanoxml.XMLElement#XMLElement(boolean) * @see nanoxml.XMLElement#XMLElement(java.util.Hashtable) * XMLElement(Hashtable) * @see nanoxml.XMLElement#XMLElement(java.util.Hashtable,boolean) * XMLElement(Hashtable, boolean) */ public XMLElement(Hashtable entities, boolean skipLeadingWhitespace, boolean ignoreCase) { this(entities, skipLeadingWhitespace, true, ignoreCase); } /** * Creates and initializes a new XML element. *

* This constructor should only be called from * {@link #createAnotherElement() createAnotherElement} * to create child elements. * * @param entities * The entity conversion table. * @param skipLeadingWhitespace * true if leading and trailing whitespace in PCDATA * content has to be removed. * @param fillBasicConversionTable * true if the basic entities need to be added to * the entity list. * @param ignoreCase * true if the case of element and attribute names have * to be ignored. * *

Preconditions:
*
* *
Postconditions:
*
* * @see nanoxml.XMLElement#createAnotherElement() */ protected XMLElement(Hashtable entities, boolean skipLeadingWhitespace, boolean fillBasicConversionTable, boolean ignoreCase) { this.ignoreWhitespace = skipLeadingWhitespace; this.ignoreCase = ignoreCase; this.name = null; this.contents = ""; this.attributes = new Hashtable(); this.children = new Vector(); this.entities = entities; this.lineNr = 0; Enumeration enum = this.entities.keys(); while (enum.hasMoreElements()) { Object key = enum.nextElement(); Object value = this.entities.get(key); if (value instanceof String) { value = ((String) value).toCharArray(); this.entities.put(key, value); } } if (fillBasicConversionTable) { this.entities.put("amp", new char[] { '&' }); this.entities.put("quot", new char[] { '"' }); this.entities.put("apos", new char[] { '\'' }); this.entities.put("lt", new char[] { '<' }); this.entities.put("gt", new char[] { '>' }); } } /** * Adds a child element. * * @param child * The child element to add. * *
Preconditions:
*
* *
Postconditions:
*
* * @see nanoxml.XMLElement#countChildren() * @see nanoxml.XMLElement#enumerateChildren() * @see nanoxml.XMLElement#getChildren() * @see nanoxml.XMLElement#removeChild(nanoxml.XMLElement) * removeChild(XMLElement) */ public void addChild(XMLElement child) { this.children.addElement(child); } /** * Adds or modifies an attribute. * * @param name * The name of the attribute. * @param value * The value of the attribute. * *
Preconditions:
*
* *
Postconditions:
*
* * @see nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) * setDoubleAttribute(String, double) * @see nanoxml.XMLElement#setIntAttribute(java.lang.String, int) * setIntAttribute(String, int) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getAttribute(java.lang.String) * getAttribute(String) * @see nanoxml.XMLElement#getAttribute(java.lang.String, java.lang.Object) * getAttribute(String, Object) * @see nanoxml.XMLElement#getAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getAttribute(String, Hashtable, String, boolean) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String) * getStringAttribute(String) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String, * java.lang.String) * getStringAttribute(String, String) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getStringAttribute(String, Hashtable, String, boolean) */ public void setAttribute(String name, Object value) { if (this.ignoreCase) { name = name.toUpperCase(); } this.attributes.put(name, value.toString()); } /** * Adds or modifies an attribute. * * @param name * The name of the attribute. * @param value * The value of the attribute. * * @deprecated Use {@link #setAttribute(java.lang.String, java.lang.Object) * setAttribute} instead. */ public void addProperty(String name, Object value) { this.setAttribute(name, value); } /** * Adds or modifies an attribute. * * @param name * The name of the attribute. * @param value * The value of the attribute. * *
Preconditions:
*
* *
Postconditions:
*
* * @see nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) * setDoubleAttribute(String, double) * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getIntAttribute(java.lang.String) * getIntAttribute(String) * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, int) * getIntAttribute(String, int) * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getIntAttribute(String, Hashtable, String, boolean) */ public void setIntAttribute(String name, int value) { if (this.ignoreCase) { name = name.toUpperCase(); } this.attributes.put(name, Integer.toString(value)); } /** * Adds or modifies an attribute. * * @param name * The name of the attribute. * @param value * The value of the attribute. * * @deprecated Use {@link #setIntAttribute(java.lang.String, int) * setIntAttribute} instead. */ public void addProperty(String key, int value) { this.setIntAttribute(key, value); } /** * Adds or modifies an attribute. * * @param name * The name of the attribute. * @param value * The value of the attribute. * *
Preconditions:
*
* *
Postconditions:
*
* * @see nanoxml.XMLElement#setIntAttribute(java.lang.String, int) * setIntAttribute(String, int) * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String) * getDoubleAttribute(String) * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, double) * getDoubleAttribute(String, double) * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getDoubleAttribute(String, Hashtable, String, boolean) */ public void setDoubleAttribute(String name, double value) { if (this.ignoreCase) { name = name.toUpperCase(); } this.attributes.put(name, Double.toString(value)); } /** * Adds or modifies an attribute. * * @param name * The name of the attribute. * @param value * The value of the attribute. * * @deprecated Use {@link #setDoubleAttribute(java.lang.String, double) * setDoubleAttribute} instead. */ public void addProperty(String name, double value) { this.setDoubleAttribute(name, value); } /** * Returns the number of child elements of the element. * *
Postconditions:
*
  • result >= 0 *
* * @see nanoxml.XMLElement#addChild(nanoxml.XMLElement) * addChild(XMLElement) * @see nanoxml.XMLElement#enumerateChildren() * @see nanoxml.XMLElement#getChildren() * @see nanoxml.XMLElement#removeChild(nanoxml.XMLElement) * removeChild(XMLElement) */ public int countChildren() { return this.children.size(); } /** * Enumerates the attribute names. * *
Postconditions:
*
  • result != null *
* * @see nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) * setDoubleAttribute(String, double) * @see nanoxml.XMLElement#setIntAttribute(java.lang.String, int) * setIntAttribute(String, int) * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#getAttribute(java.lang.String) * getAttribute(String) * @see nanoxml.XMLElement#getAttribute(java.lang.String, java.lang.Object) * getAttribute(String, String) * @see nanoxml.XMLElement#getAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getAttribute(String, Hashtable, String, boolean) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String) * getStringAttribute(String) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String, * java.lang.String) * getStringAttribute(String, String) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getStringAttribute(String, Hashtable, String, boolean) * @see nanoxml.XMLElement#getIntAttribute(java.lang.String) * getIntAttribute(String) * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, int) * getIntAttribute(String, int) * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getIntAttribute(String, Hashtable, String, boolean) * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String) * getDoubleAttribute(String) * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, double) * getDoubleAttribute(String, double) * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getDoubleAttribute(String, Hashtable, String, boolean) * @see nanoxml.XMLElement#getBooleanAttribute(java.lang.String, * java.lang.String, * java.lang.String, boolean) * getBooleanAttribute(String, String, String, boolean) */ public Enumeration enumerateAttributeNames() { return this.attributes.keys(); } /** * Enumerates the attribute names. * * @deprecated Use {@link #enumerateAttributeNames() * enumerateAttributeNames} instead. */ public Enumeration enumeratePropertyNames() { return this.enumerateAttributeNames(); } /** * Enumerates the child elements. * *
Postconditions:
*
  • result != null *
* * @see nanoxml.XMLElement#addChild(nanoxml.XMLElement) * addChild(XMLElement) * @see nanoxml.XMLElement#countChildren() * @see nanoxml.XMLElement#getChildren() * @see nanoxml.XMLElement#removeChild(nanoxml.XMLElement) * removeChild(XMLElement) */ public Enumeration enumerateChildren() { return this.children.elements(); } /** * Returns the child elements as a Vector. It is safe to modify this * Vector. * *
Postconditions:
*
  • result != null *
* * @see nanoxml.XMLElement#addChild(nanoxml.XMLElement) * addChild(XMLElement) * @see nanoxml.XMLElement#countChildren() * @see nanoxml.XMLElement#enumerateChildren() * @see nanoxml.XMLElement#removeChild(nanoxml.XMLElement) * removeChild(XMLElement) */ public Vector getChildren() { try { return (Vector) this.children.clone(); } catch (Exception e) { // this never happens, however, some Java compilers are so // braindead that they require this exception clause return null; } } /** * Returns the PCDATA content of the object. If there is no such content, * null is returned. * * @deprecated Use {@link #getContent() getContent} instead. */ public String getContents() { return this.getContent(); } /** * Returns the PCDATA content of the object. If there is no such content, * null is returned. * * @see nanoxml.XMLElement#setContent(java.lang.String) * setContent(String) */ public String getContent() { return this.contents; } /** * Returns the line nr in the source data on which the element is found. * This method returns 0 there is no associated source data. * *
Postconditions:
*
  • result >= 0 *
*/ public int getLineNr() { return this.lineNr; } /** * Returns an attribute of the element. * If the attribute doesn't exist, null is returned. * * @param name The name of the attribute. * *
Preconditions:
*
* * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getAttribute(java.lang.String, java.lang.Object) * getAttribute(String, Object) * @see nanoxml.XMLElement#getAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getAttribute(String, Hashtable, String, boolean) */ public Object getAttribute(String name) { return this.getAttribute(name, null); } /** * Returns an attribute of the element. * If the attribute doesn't exist, defaultValue is returned. * * @param name The name of the attribute. * @param defaultValue Key to use if the attribute is missing. * *
Preconditions:
*
* * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getAttribute(java.lang.String) * getAttribute(String) * @see nanoxml.XMLElement#getAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getAttribute(String, Hashtable, String, boolean) */ public Object getAttribute(String name, Object defaultValue) { if (this.ignoreCase) { name = name.toUpperCase(); } Object value = this.attributes.get(name); if (value == null) { value = defaultValue; } return value; } /** * Returns an attribute by looking up a key in a hashtable. * If the attribute doesn't exist, the value corresponding to defaultKey * is returned. *

* As an example, if valueSet contains the mapping "one" => * "1" * and the element contains the attribute attr="one", then * getAttribute("attr", mapping, defaultKey, false) returns * "1". * * @param name * The name of the attribute. * @param valueSet * Hashtable mapping keys to values. * @param defaultKey * Key to use if the attribute is missing. * @param allowLiterals * true if literals are valid. * *

Preconditions:
*
* * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getAttribute(java.lang.String) * getAttribute(String) * @see nanoxml.XMLElement#getAttribute(java.lang.String, java.lang.Object) * getAttribute(String, Object) */ public Object getAttribute(String name, Hashtable valueSet, String defaultKey, boolean allowLiterals) { if (this.ignoreCase) { name = name.toUpperCase(); } Object key = this.attributes.get(name); Object result; if (key == null) { key = defaultKey; } result = valueSet.get(key); if (result == null) { if (allowLiterals) { result = key; } else { throw this.invalidValue(name, (String) key); } } return result; } /** * Returns an attribute of the element. * If the attribute doesn't exist, null is returned. * * @param name The name of the attribute. * *
Preconditions:
*
* * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getStringAttribute(java.lang.String, * java.lang.String) * getStringAttribute(String, String) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getStringAttribute(String, Hashtable, String, boolean) */ public String getStringAttribute(String name) { return this.getStringAttribute(name, null); } /** * Returns an attribute of the element. * If the attribute doesn't exist, defaultValue is returned. * * @param name The name of the attribute. * @param defaultValue Key to use if the attribute is missing. * *
Preconditions:
*
* * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getStringAttribute(java.lang.String) * getStringAttribute(String) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getStringAttribute(String, Hashtable, String, boolean) */ public String getStringAttribute(String name, String defaultValue) { return (String) this.getAttribute(name, defaultValue); } /** * Returns an attribute by looking up a key in a hashtable. * If the attribute doesn't exist, the value corresponding to defaultKey * is returned. *

* As an example, if valueSet contains the mapping "one" => * "1" * and the element contains the attribute attr="one", then * getAttribute("attr", mapping, defaultKey, false) returns * "1". * * @param name * The name of the attribute. * @param valueSet * Hashtable mapping keys to values. * @param defaultKey * Key to use if the attribute is missing. * @param allowLiterals * true if literals are valid. * *

Preconditions:
*
* * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getStringAttribute(java.lang.String) * getStringAttribute(String) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String, * java.lang.String) * getStringAttribute(String, String) */ public String getStringAttribute(String name, Hashtable valueSet, String defaultKey, boolean allowLiterals) { return (String) this.getAttribute(name, valueSet, defaultKey, allowLiterals); } /** * Returns an attribute of the element. * If the attribute doesn't exist, 0 is returned. * * @param name The name of the attribute. * *
Preconditions:
*
* * @see nanoxml.XMLElement#setIntAttribute(java.lang.String, int) * setIntAttribute(String, int) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, int) * getIntAttribute(String, int) * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getIntAttribute(String, Hashtable, String, boolean) */ public int getIntAttribute(String name) { return this.getIntAttribute(name, 0); } /** * Returns an attribute of the element. * If the attribute doesn't exist, defaultValue is returned. * * @param name The name of the attribute. * @param defaultValue Key to use if the attribute is missing. * *
Preconditions:
*
* * @see nanoxml.XMLElement#setIntAttribute(java.lang.String, int) * setIntAttribute(String, int) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getIntAttribute(java.lang.String) * getIntAttribute(String) * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getIntAttribute(String, Hashtable, String, boolean) */ public int getIntAttribute(String name, int defaultValue) { if (this.ignoreCase) { name = name.toUpperCase(); } String value = (String) this.attributes.get(name); if (value == null) { return defaultValue; } else { try { return Integer.parseInt(value); } catch (NumberFormatException e) { throw this.invalidValue(name, value); } } } /** * Returns an attribute by looking up a key in a hashtable. * If the attribute doesn't exist, the value corresponding to defaultKey * is returned. *

* As an example, if valueSet contains the mapping "one" => 1 * and the element contains the attribute attr="one", then * getIntAttribute("attr", mapping, defaultKey, false) returns * 1. * * @param name * The name of the attribute. * @param valueSet * Hashtable mapping keys to values. * @param defaultKey * Key to use if the attribute is missing. * @param allowLiteralNumbers * true if literal numbers are valid. * *

Preconditions:
*
* * @see nanoxml.XMLElement#setIntAttribute(java.lang.String, int) * setIntAttribute(String, int) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getIntAttribute(java.lang.String) * getIntAttribute(String) * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, int) * getIntAttribute(String, int) */ public int getIntAttribute(String name, Hashtable valueSet, String defaultKey, boolean allowLiteralNumbers) { if (this.ignoreCase) { name = name.toUpperCase(); } Object key = this.attributes.get(name); Integer result; if (key == null) { key = defaultKey; } try { result = (Integer) valueSet.get(key); } catch (ClassCastException e) { throw this.invalidValueSet(name); } if (result == null) { if (! allowLiteralNumbers) { throw this.invalidValue(name, (String) key); } try { result = Integer.valueOf((String) key); } catch (NumberFormatException e) { throw this.invalidValue(name, (String) key); } } return result.intValue(); } /** * Returns an attribute of the element. * If the attribute doesn't exist, 0.0 is returned. * * @param name The name of the attribute. * *
Preconditions:
*
* * @see nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) * setDoubleAttribute(String, double) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, double) * getDoubleAttribute(String, double) * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getDoubleAttribute(String, Hashtable, String, boolean) */ public double getDoubleAttribute(String name) { return this.getDoubleAttribute(name, 0.); } /** * Returns an attribute of the element. * If the attribute doesn't exist, defaultValue is returned. * * @param name The name of the attribute. * @param defaultValue Key to use if the attribute is missing. * *
Preconditions:
*
* * @see nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) * setDoubleAttribute(String, double) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String) * getDoubleAttribute(String) * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getDoubleAttribute(String, Hashtable, String, boolean) */ public double getDoubleAttribute(String name, double defaultValue) { if (this.ignoreCase) { name = name.toUpperCase(); } String value = (String) this.attributes.get(name); if (value == null) { return defaultValue; } else { try { return Double.valueOf(value).doubleValue(); } catch (NumberFormatException e) { throw this.invalidValue(name, value); } } } /** * Returns an attribute by looking up a key in a hashtable. * If the attribute doesn't exist, the value corresponding to defaultKey * is returned. *

* As an example, if valueSet contains the mapping "one" => * 1.0 * and the element contains the attribute attr="one", then * getDoubleAttribute("attr", mapping, defaultKey, false) * returns 1.0. * * @param name * The name of the attribute. * @param valueSet * Hashtable mapping keys to values. * @param defaultKey * Key to use if the attribute is missing. * @param allowLiteralNumbers * true if literal numbers are valid. * *

Preconditions:
*
* * @see nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) * setDoubleAttribute(String, double) * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String) * getDoubleAttribute(String) * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, double) * getDoubleAttribute(String, double) */ public double getDoubleAttribute(String name, Hashtable valueSet, String defaultKey, boolean allowLiteralNumbers) { if (this.ignoreCase) { name = name.toUpperCase(); } Object key = this.attributes.get(name); Double result; if (key == null) { key = defaultKey; } try { result = (Double) valueSet.get(key); } catch (ClassCastException e) { throw this.invalidValueSet(name); } if (result == null) { if (! allowLiteralNumbers) { throw this.invalidValue(name, (String) key); } try { result = Double.valueOf((String) key); } catch (NumberFormatException e) { throw this.invalidValue(name, (String) key); } } return result.doubleValue(); } /** * Returns an attribute of the element. * If the attribute doesn't exist, defaultValue is returned. * If the value of the attribute is equal to trueValue, * true is returned. * If the value of the attribute is equal to falseValue, * false is returned. * If the value doesn't match trueValue or * falseValue, an exception is thrown. * * @param name The name of the attribute. * @param trueValue The value associated with true. * @param falseValue The value associated with true. * @param defaultValue Value to use if the attribute is missing. * *
Preconditions:
*
* * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#removeAttribute(java.lang.String) * removeAttribute(String) * @see nanoxml.XMLElement#enumerateAttributeNames() */ public boolean getBooleanAttribute(String name, String trueValue, String falseValue, boolean defaultValue) { if (this.ignoreCase) { name = name.toUpperCase(); } Object value = this.attributes.get(name); if (value == null) { return defaultValue; } else if (value.equals(trueValue)) { return true; } else if (value.equals(falseValue)) { return false; } else { throw this.invalidValue(name, (String) value); } } /** * Returns an attribute by looking up a key in a hashtable. * * @deprecated Use {@link #getIntAttribute(java.lang.String, * java.util.Hashtable, java.lang.String, boolean) * getIntAttribute} instead. */ public int getIntProperty(String name, Hashtable valueSet, String defaultKey) { return this.getIntAttribute(name, valueSet, defaultKey, false); } /** * Returns an attribute. * * @deprecated Use {@link #getStringAttribute(java.lang.String) * getStringAttribute} instead. */ public String getProperty(String name) { return this.getStringAttribute(name); } /** * Returns an attribute. * * @deprecated Use {@link #getStringAttribute(java.lang.String, * java.lang.String) getStringAttribute} instead. */ public String getProperty(String name, String defaultValue) { return this.getStringAttribute(name, defaultValue); } /** * Returns an attribute. * * @deprecated Use {@link #getIntAttribute(java.lang.String, int) * getIntAttribute} instead. */ public int getProperty(String name, int defaultValue) { return this.getIntAttribute(name, defaultValue); } /** * Returns an attribute. * * @deprecated Use {@link #getDoubleAttribute(java.lang.String, double) * getDoubleAttribute} instead. */ public double getProperty(String name, double defaultValue) { return this.getDoubleAttribute(name, defaultValue); } /** * Returns an attribute. * * @deprecated Use {@link #getBooleanAttribute(java.lang.String, * java.lang.String, java.lang.String, boolean) * getBooleanAttribute} instead. */ public boolean getProperty(String key, String trueValue, String falseValue, boolean defaultValue) { return this.getBooleanAttribute(key, trueValue, falseValue, defaultValue); } /** * Returns an attribute by looking up a key in a hashtable. * * @deprecated Use {@link #getAttribute(java.lang.String, * java.util.Hashtable, java.lang.String, boolean) * getAttribute} instead. */ public Object getProperty(String name, Hashtable valueSet, String defaultKey) { return this.getAttribute(name, valueSet, defaultKey, false); } /** * Returns an attribute by looking up a key in a hashtable. * * @deprecated Use {@link #getStringAttribute(java.lang.String, * java.util.Hashtable, java.lang.String, boolean) * getStringAttribute} instead. */ public String getStringProperty(String name, Hashtable valueSet, String defaultKey) { return this.getStringAttribute(name, valueSet, defaultKey, false); } /** * Returns an attribute by looking up a key in a hashtable. * * @deprecated Use {@link #getIntAttribute(java.lang.String, * java.util.Hashtable, java.lang.String, boolean) * getIntAttribute} instead. */ public int getSpecialIntProperty(String name, Hashtable valueSet, String defaultKey) { return this.getIntAttribute(name, valueSet, defaultKey, true); } /** * Returns an attribute by looking up a key in a hashtable. * * @deprecated Use {@link #getDoubleAttribute(java.lang.String, * java.util.Hashtable, java.lang.String, boolean) * getDoubleAttribute} instead. */ public double getSpecialDoubleProperty(String name, Hashtable valueSet, String defaultKey) { return this.getDoubleAttribute(name, valueSet, defaultKey, true); } /** * Returns the name of the element. * * @see nanoxml.XMLElement#setName(java.lang.String) setName(String) */ public String getName() { return this.name; } /** * Returns the name of the element. * * @deprecated Use {@link #getName() getName} instead. */ public String getTagName() { return this.getName(); } /** * Reads one XML element from a java.io.Reader and parses it. * * @param reader * The reader from which to retrieve the XML data. * *
Preconditions:
*
* *
Postconditions:
*
* * @throws java.io.IOException * If an error occured while reading the input. * @throws nanoxml.XMLParseException * If an error occured while parsing the read data. */ public void parseFromReader(Reader reader) throws IOException, XMLParseException { this.parseFromReader(reader, /*startingLineNr*/ 1); } /** * Reads one XML element from a java.io.Reader and parses it. * * @param reader * The reader from which to retrieve the XML data. * @param startingLineNr * The line number of the first line in the data. * *
Preconditions:
*
* *
Postconditions:
*
* * @throws java.io.IOException * If an error occured while reading the input. * @throws nanoxml.XMLParseException * If an error occured while parsing the read data. */ public void parseFromReader(Reader reader, int startingLineNr) throws IOException, XMLParseException { this.name = null; this.contents = ""; this.attributes = new Hashtable(); this.children = new Vector(); this.charReadTooMuch = '\0'; this.reader = reader; this.parserLineNr = startingLineNr; for (;;) { char ch = this.scanWhitespace(); if (ch != '<') { throw this.expectedInput("<"); } ch = this.readChar(); if ((ch == '!') || (ch == '?')) { this.skipSpecialTag(0); } else { this.unreadChar(ch); this.scanElement(this); return; } } } /** * Reads one XML element from a String and parses it. * * @param reader * The reader from which to retrieve the XML data. * *
Preconditions:
*
* *
Postconditions:
*
* * @throws nanoxml.XMLParseException * If an error occured while parsing the string. */ public void parseString(String string) throws XMLParseException { try { this.parseFromReader(new StringReader(string), /*startingLineNr*/ 1); } catch (IOException e) { // Java exception handling suxx } } /** * Reads one XML element from a String and parses it. * * @param reader * The reader from which to retrieve the XML data. * @param offset * The first character in string to scan. * *
Preconditions:
*
* *
Postconditions:
*
* * @throws nanoxml.XMLParseException * If an error occured while parsing the string. */ public void parseString(String string, int offset) throws XMLParseException { this.parseString(string.substring(offset)); } /** * Reads one XML element from a String and parses it. * * @param reader * The reader from which to retrieve the XML data. * @param offset * The first character in string to scan. * @param end * The character where to stop scanning. * This character is not scanned. * *
Preconditions:
*
* *
Postconditions:
*
* * @throws nanoxml.XMLParseException * If an error occured while parsing the string. */ public void parseString(String string, int offset, int end) throws XMLParseException { this.parseString(string.substring(offset, end)); } /** * Reads one XML element from a String and parses it. * * @param reader * The reader from which to retrieve the XML data. * @param offset * The first character in string to scan. * @param end * The character where to stop scanning. * This character is not scanned. * @param startingLineNr * The line number of the first line in the data. * *
Preconditions:
*
* *
Postconditions:
*
* * @throws nanoxml.XMLParseException * If an error occured while parsing the string. */ public void parseString(String string, int offset, int end, int startingLineNr) throws XMLParseException { string = string.substring(offset, end); try { this.parseFromReader(new StringReader(string), startingLineNr); } catch (IOException e) { // Java exception handling suxx } } /** * Reads one XML element from a char array and parses it. * * @param reader * The reader from which to retrieve the XML data. * @param offset * The first character in string to scan. * @param end * The character where to stop scanning. * This character is not scanned. * *
Preconditions:
*
* *
Postconditions:
*
* * @throws nanoxml.XMLParseException * If an error occured while parsing the string. */ public void parseCharArray(char[] input, int offset, int end) throws XMLParseException { this.parseCharArray(input, offset, end, /*startingLineNr*/ 1); } /** * Reads one XML element from a char array and parses it. * * @param reader * The reader from which to retrieve the XML data. * @param offset * The first character in string to scan. * @param end * The character where to stop scanning. * This character is not scanned. * @param startingLineNr * The line number of the first line in the data. * *
Preconditions:
*
* *
Postconditions:
*
* * @throws nanoxml.XMLParseException * If an error occured while parsing the string. */ public void parseCharArray(char[] input, int offset, int end, int startingLineNr) throws XMLParseException { try { Reader reader = new CharArrayReader(input, offset, end); this.parseFromReader(reader, startingLineNr); } catch (IOException e) { // This exception will never happen. } } /** * Removes a child element. * * @param child * The child element to remove. * *
Preconditions:
*
* *
Postconditions:
*
* * @see nanoxml.XMLElement#addChild(nanoxml.XMLElement) * addChild(XMLElement) * @see nanoxml.XMLElement#countChildren() * @see nanoxml.XMLElement#enumerateChildren() * @see nanoxml.XMLElement#getChildren() */ public void removeChild(XMLElement child) { this.children.removeElement(child); } /** * Removes an attribute. * * @param name * The name of the attribute. * *
Preconditions:
*
* *
Postconditions:
*
* * @see nanoxml.XMLElement#enumerateAttributeNames() * @see nanoxml.XMLElement#setDoubleAttribute(java.lang.String, double) * setDoubleAttribute(String, double) * @see nanoxml.XMLElement#setIntAttribute(java.lang.String, int) * setIntAttribute(String, int) * @see nanoxml.XMLElement#setAttribute(java.lang.String, java.lang.Object) * setAttribute(String, Object) * @see nanoxml.XMLElement#getAttribute(java.lang.String) * getAttribute(String) * @see nanoxml.XMLElement#getAttribute(java.lang.String, java.lang.Object) * getAttribute(String, Object) * @see nanoxml.XMLElement#getAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getAttribute(String, Hashtable, String, boolean) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String) * getStringAttribute(String) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String, * java.lang.String) * getStringAttribute(String, String) * @see nanoxml.XMLElement#getStringAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getStringAttribute(String, Hashtable, String, boolean) * @see nanoxml.XMLElement#getIntAttribute(java.lang.String) * getIntAttribute(String) * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, int) * getIntAttribute(String, int) * @see nanoxml.XMLElement#getIntAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getIntAttribute(String, Hashtable, String, boolean) * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String) * getDoubleAttribute(String) * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, double) * getDoubleAttribute(String, double) * @see nanoxml.XMLElement#getDoubleAttribute(java.lang.String, * java.util.Hashtable, * java.lang.String, boolean) * getDoubleAttribute(String, Hashtable, String, boolean) * @see nanoxml.XMLElement#getBooleanAttribute(java.lang.String, * java.lang.String, * java.lang.String, boolean) * getBooleanAttribute(String, String, String, boolean) */ public void removeAttribute(String name) { if (this.ignoreCase) { name = name.toUpperCase(); } this.attributes.remove(name); } /** * Removes an attribute. * * @param name * The name of the attribute. * * @deprecated Use {@link #removeAttribute(java.lang.String) * removeAttribute} instead. */ public void removeProperty(String name) { this.removeAttribute(name); } /** * Removes an attribute. * * @param name * The name of the attribute. * * @deprecated Use {@link #removeAttribute(java.lang.String) * removeAttribute} instead. */ public void removeChild(String name) { this.removeAttribute(name); } /** * Creates a new similar XML element. *

* You should override this method when subclassing XMLElement. */ protected XMLElement createAnotherElement() { return new XMLElement(this.entities, this.ignoreWhitespace, false, this.ignoreCase); } /** * Changes the content string. * * @param content * The new content string. */ public void setContent(String content) { this.contents = content; } /** * Changes the name of the element. * * @param name * The new name. * * @deprecated Use {@link #setName(java.lang.String) setName} instead. */ public void setTagName(String name) { this.setName(name); } /** * Changes the name of the element. * * @param name * The new name. * *

Preconditions:
*
* * @see nanoxml.XMLElement#getName() */ public void setName(String name) { this.name = name; } /** * Writes the XML element to a string. * * @see nanoxml.XMLElement#write(java.io.Writer) write(Writer) */ public String toString() { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); OutputStreamWriter writer = new OutputStreamWriter(out); this.write(writer); writer.flush(); return new String(out.toByteArray()); } catch (IOException e) { // Java exception handling suxx return super.toString(); } } /** * Writes the XML element to a writer. * * @param writer * The writer to write the XML data to. * *
Preconditions:
*
* * @throws java.io.IOException * If the data could not be written to the writer. * * @see nanoxml.XMLElement#toString() */ public void write(Writer writer) throws IOException { if (this.name == null) { this.writeEncoded(writer, this.contents); return; } writer.write('<'); writer.write(this.name); if (! this.attributes.isEmpty()) { Enumeration enum = this.attributes.keys(); while (enum.hasMoreElements()) { writer.write(' '); String key = (String) enum.nextElement(); String value = (String) this.attributes.get(key); writer.write(key); writer.write('='); writer.write('"'); this.writeEncoded(writer, value); writer.write('"'); } } if ((this.contents != null) && (this.contents.length() > 0)) { writer.write('>'); this.writeEncoded(writer, this.contents); writer.write('<'); writer.write('/'); writer.write(this.name); writer.write('>'); } else if (this.children.isEmpty()) { writer.write('/'); writer.write('>'); } else { writer.write('>'); Enumeration enum = this.enumerateChildren(); while (enum.hasMoreElements()) { XMLElement child = (XMLElement) enum.nextElement(); child.write(writer); } writer.write('<'); writer.write('/'); writer.write(this.name); writer.write('>'); } } /** * Writes a string encoded to a writer. * * @param writer * The writer to write the XML data to. * @param str * The string to write encoded. * *
Preconditions:
*
*/ protected void writeEncoded(Writer writer, String str) throws IOException { for (int i = 0; i < str.length(); i += 1) { char ch = str.charAt(i); switch (ch) { case '<': writer.write('&'); writer.write('l'); writer.write('t'); writer.write(';'); break; case '>': writer.write('&'); writer.write('g'); writer.write('t'); writer.write(';'); break; case '&': writer.write('&'); writer.write('a'); writer.write('m'); writer.write('p'); writer.write(';'); break; case '"': writer.write('&'); writer.write('q'); writer.write('u'); writer.write('o'); writer.write('t'); writer.write(';'); break; case '\'': writer.write('&'); writer.write('a'); writer.write('p'); writer.write('o'); writer.write('s'); writer.write(';'); break; default: int unicode = (int) ch; if ((unicode < 32) || (unicode > 126)) { writer.write('&'); writer.write('#'); writer.write('x'); writer.write(Integer.toString(unicode, 16)); writer.write(';'); } else { writer.write(ch); } } } } /** * Scans an identifier from the current reader. * The scanned identifier is appended to result. * * @param result * The buffer in which the scanned identifier will be put. * *
Preconditions:
*
* *
Postconditions:
*
*/ protected void scanIdentifier(StringBuffer result) throws IOException { for (;;) { char ch = this.readChar(); if (((ch < 'A') || (ch > 'Z')) && ((ch < 'a') || (ch > 'z')) && ((ch < '0') || (ch > '9')) && (ch != '_') && (ch != '.') && (ch != ':') && (ch != '-') && (ch <= '\u007E')) { this.unreadChar(ch); return; } result.append(ch); } } /** * This method scans an identifier from the current reader. * * @return the next character following the whitespace. */ protected char scanWhitespace() throws IOException { for (;;) { char ch = this.readChar(); switch (ch) { case ' ': case '\t': case '\n': case '\r': break; default: return ch; } } } /** * This method scans an identifier from the current reader. * The scanned whitespace is appended to result. * * @return the next character following the whitespace. * *
Preconditions:
*
*/ protected char scanWhitespace(StringBuffer result) throws IOException { for (;;) { char ch = this.readChar(); switch (ch) { case ' ': case '\t': case '\n': result.append(ch); case '\r': break; default: return ch; } } } /** * This method scans a delimited string from the current reader. * The scanned string without delimiters is appended to * string. * *
Preconditions:
*
*/ protected void scanString(StringBuffer string) throws IOException { char delimiter = this.readChar(); if ((delimiter != '\'') && (delimiter != '"')) { throw this.expectedInput("' or \""); } for (;;) { char ch = this.readChar(); if (ch == delimiter) { return; } else if (ch == '&') { this.resolveEntity(string); } else { string.append(ch); } } } /** * Scans a #PCDATA element. CDATA sections and entities are resolved. * The next < char is skipped. * The scanned data is appended to data. * *
Preconditions:
*
*/ protected void scanPCData(StringBuffer data) throws IOException { for (;;) { char ch = this.readChar(); if (ch == '<') { ch = this.readChar(); if (ch == '!') { this.checkCDATA(data); } else { this.unreadChar(ch); return; } } else if (ch == '&') { this.resolveEntity(data); } else { data.append(ch); } } } /** * Scans a special tag and if the tag is a CDATA section, append its * content to buf. * *
Preconditions:
*
*/ protected boolean checkCDATA(StringBuffer buf) throws IOException { char ch = this.readChar(); if (ch != '[') { this.unreadChar(ch); this.skipSpecialTag(0); return false; } else if (! this.checkLiteral("CDATA[")) { this.skipSpecialTag(1); // one [ has already been read return false; } else { int delimiterCharsSkipped = 0; while (delimiterCharsSkipped < 3) { ch = this.readChar(); switch (ch) { case ']': if (delimiterCharsSkipped < 2) { delimiterCharsSkipped += 1; } else { buf.append(']'); buf.append(']'); delimiterCharsSkipped = 0; } break; case '>': if (delimiterCharsSkipped < 2) { for (int i = 0; i < delimiterCharsSkipped; i++) { buf.append(']'); } delimiterCharsSkipped = 0; buf.append('>'); } else { delimiterCharsSkipped = 3; } break; default: for (int i = 0; i < delimiterCharsSkipped; i += 1) { buf.append(']'); } buf.append(ch); delimiterCharsSkipped = 0; } } return true; } } /** * Skips a comment. * *
Preconditions:
*
*/ protected void skipComment() throws IOException { int dashesToRead = 2; while (dashesToRead > 0) { char ch = this.readChar(); if (ch == '-') { dashesToRead -= 1; } else { dashesToRead = 2; } } if (this.readChar() != '>') { throw this.expectedInput(">"); } } /** * Skips a special tag or comment. * * @param bracketLevel The number of open square brackets ([) that have * already been read. * *
Preconditions:
*
*/ protected void skipSpecialTag(int bracketLevel) throws IOException { int tagLevel = 1; // < char stringDelimiter = '\0'; if (bracketLevel == 0) { char ch = this.readChar(); if (ch == '[') { bracketLevel += 1; } else if (ch == '-') { ch = this.readChar(); if (ch == '[') { bracketLevel += 1; } else if (ch == ']') { bracketLevel -= 1; } else if (ch == '-') { this.skipComment(); return; } } } while (tagLevel > 0) { char ch = this.readChar(); if (stringDelimiter == '\0') { if ((ch == '"') || (ch == '\'')) { stringDelimiter = ch; } else if (bracketLevel <= 0) { if (ch == '<') { tagLevel += 1; } else if (ch == '>') { tagLevel -= 1; } } if (ch == '[') { bracketLevel += 1; } else if (ch == ']') { bracketLevel -= 1; } } else { if (ch == stringDelimiter) { stringDelimiter = '\0'; } } } } /** * Scans the data for literal text. * Scanning stops when a character does not match or after the complete * text has been checked, whichever comes first. * * @param literal the literal to check. * *
Preconditions:
*
*/ protected boolean checkLiteral(String literal) throws IOException { int length = literal.length(); for (int i = 0; i < length; i += 1) { if (this.readChar() != literal.charAt(i)) { return false; } } return true; } /** * Reads a character from a reader. */ protected char readChar() throws IOException { if (this.charReadTooMuch != '\0') { char ch = this.charReadTooMuch; this.charReadTooMuch = '\0'; return ch; } else { int i = this.reader.read(); if (i < 0) { throw this.unexpectedEndOfData(); } else if (i == 10) { this.parserLineNr += 1; return '\n'; } else { return (char) i; } } } /** * Scans an XML element. * * @param elt The element that will contain the result. * *
Preconditions:
*
*/ protected void scanElement(XMLElement elt) throws IOException { StringBuffer buf = new StringBuffer(); this.scanIdentifier(buf); String name = buf.toString(); elt.setName(name); char ch = this.scanWhitespace(); while ((ch != '>') && (ch != '/')) { buf.setLength(0); this.unreadChar(ch); this.scanIdentifier(buf); String key = buf.toString(); ch = this.scanWhitespace(); if (ch != '=') { throw this.expectedInput("="); } this.unreadChar(this.scanWhitespace()); buf.setLength(0); this.scanString(buf); elt.setAttribute(key, buf); ch = this.scanWhitespace(); } if (ch == '/') { ch = this.readChar(); if (ch != '>') { throw this.expectedInput(">"); } return; } buf.setLength(0); ch = this.scanWhitespace(buf); if (ch != '<') { this.unreadChar(ch); this.scanPCData(buf); } else { for (;;) { ch = this.readChar(); if (ch == '!') { if (this.checkCDATA(buf)) { this.scanPCData(buf); break; } else { ch = this.scanWhitespace(buf); if (ch != '<') { this.unreadChar(ch); this.scanPCData(buf); break; } } } else { if ((ch != '/') || this.ignoreWhitespace) { buf.setLength(0); } if (ch == '/') { this.unreadChar(ch); } break; } } } if (buf.length() == 0) { while (ch != '/') { if (ch == '!') { ch = this.readChar(); if (ch != '-') { throw this.expectedInput("Comment or Element"); } ch = this.readChar(); if (ch != '-') { throw this.expectedInput("Comment or Element"); } this.skipComment(); } else { this.unreadChar(ch); XMLElement child = this.createAnotherElement(); this.scanElement(child); elt.addChild(child); } ch = this.scanWhitespace(); if (ch != '<') { throw this.expectedInput("<"); } ch = this.readChar(); } this.unreadChar(ch); } else { if (this.ignoreWhitespace) { elt.setContent(buf.toString().trim()); } else { elt.setContent(buf.toString()); } } ch = this.readChar(); if (ch != '/') { throw this.expectedInput("/"); } this.unreadChar(this.scanWhitespace()); if (! this.checkLiteral(name)) { throw this.expectedInput(name); } if (this.scanWhitespace() != '>') { throw this.expectedInput(">"); } } /** * Resolves an entity. The name of the entity is read from the reader. * The value of the entity is appended to buf. * * @param buf Where to put the entity value. * *
Preconditions:
*
*/ protected void resolveEntity(StringBuffer buf) throws IOException { char ch = '\0'; StringBuffer keyBuf = new StringBuffer(); for (;;) { ch = this.readChar(); if (ch == ';') { break; } keyBuf.append(ch); } String key = keyBuf.toString(); if (key.charAt(0) == '#') { try { if (key.charAt(1) == 'x') { ch = (char) Integer.parseInt(key.substring(2), 16); } else { ch = (char) Integer.parseInt(key.substring(1), 10); } } catch (NumberFormatException e) { throw this.unknownEntity(key); } buf.append(ch); } else { char[] value = (char[]) this.entities.get(key); if (value == null) { throw this.unknownEntity(key); } buf.append(value); } } /** * Pushes a character back to the read-back buffer. * * @param ch The character to push back. * *
Preconditions:
*
*/ protected void unreadChar(char ch) { this.charReadTooMuch = ch; } /** * Creates a parse exception for when an invalid valueset is given to * a method. * * @param name The name of the entity. * *
Preconditions:
*
*/ protected XMLParseException invalidValueSet(String name) { String msg = "Invalid value set (entity name = \"" + name + "\")"; return new XMLParseException(this.getName(), this.parserLineNr, msg); } /** * Creates a parse exception for when an invalid value is given to a * method. * * @param name The name of the entity. * @param value The value of the entity. * *
Preconditions:
*
*/ protected XMLParseException invalidValue(String name, String value) { String msg = "Attribute \"" + name + "\" does not contain a valid " + "value (\"" + value + "\")"; return new XMLParseException(this.getName(), this.parserLineNr, msg); } /** * Creates a parse exception for when the end of the data input has been * reached. */ protected XMLParseException unexpectedEndOfData() { String msg = "Unexpected end of data reached"; return new XMLParseException(this.getName(), this.parserLineNr, msg); } /** * Creates a parse exception for when a syntax error occured. * * @param context The context in which the error occured. * *
Preconditions:
*
*/ protected XMLParseException syntaxError(String context) { String msg = "Syntax error while parsing " + context; return new XMLParseException(this.getName(), this.parserLineNr, msg); } /** * Creates a parse exception for when the next character read is not * the character that was expected. * * @param charSet The set of characters (in human readable form) that was * expected. * *
Preconditions:
*
*/ protected XMLParseException expectedInput(String charSet) { String msg = "Expected: " + charSet; return new XMLParseException(this.getName(), this.parserLineNr, msg); } /** * Creates a parse exception for when an entity could not be resolved. * * @param name The name of the entity. * *
Preconditions:
*
*/ protected XMLParseException unknownEntity(String name) { String msg = "Unknown or invalid entity: &" + name + ";"; return new XMLParseException(this.getName(), this.parserLineNr, msg); } } squareness-2.3.0/source/org/jvnet/lafplugin/XMLParseException.java100644 0 0 7556 10377705476 22444 0ustar 0 0 /* XMLParseException.java * * $Revision: 1.4 $ * $Date: 2002/03/24 10:27:59 $ * $Name: RELEASE_2_2_1 $ * * This file is part of NanoXML 2 Lite. * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved. * * This software is provided 'as-is', without any express or implied warranty. * In no event will the authors be held liable for any damages arising from the * use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software in * a product, an acknowledgment in the product documentation would be * appreciated but is not required. * * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * * 3. This notice may not be removed or altered from any source distribution. *****************************************************************************/ package org.jvnet.lafplugin; /** * An XMLParseException is thrown when an error occures while parsing an XML * string. *

* $Revision: 1.4 $
* $Date: 2002/03/24 10:27:59 $

* * @see nanoxml.XMLElement * * @author Marc De Scheemaecker * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $ */ public class XMLParseException extends RuntimeException { /** * Indicates that no line number has been associated with this exception. */ public static final int NO_LINE = -1; /** * The line number in the source code where the error occurred, or * NO_LINE if the line number is unknown. * *

Invariants:
*
*/ private int lineNr; /** * Creates an exception. * * @param name The name of the element where the error is located. * @param message A message describing what went wrong. * *
Preconditions:
*
* *
Postconditions:
*
*/ public XMLParseException(String name, String message) { super("XML Parse Exception during parsing of " + ((name == null) ? "the XML definition" : ("a " + name + " element")) + ": " + message); this.lineNr = XMLParseException.NO_LINE; } /** * Creates an exception. * * @param name The name of the element where the error is located. * @param lineNr The number of the line in the input. * @param message A message describing what went wrong. * *
Preconditions:
*
* *
Postconditions:
*
*/ public XMLParseException(String name, int lineNr, String message) { super("XML Parse Exception during parsing of " + ((name == null) ? "the XML definition" : ("a " + name + " element")) + " at line " + lineNr + ": " + message); this.lineNr = lineNr; } /** * Where the error occurred, or NO_LINE if the line number is * unknown. * * @see nanoxml.XMLParseException#NO_LINE */ public int getLineNr() { return this.lineNr; } } squareness-2.3.0/license/squareness_license.txt100644 0 0 3076 10531616535 17125 0ustar 0 0 Copyright (c) 2003-2006, Robert F. Beeger (robert at beeger dot net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of 'Robert F. Beeger' nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. data reached"; return new XMLParseException(this.getName(), this.parserLineNr, msg); } /** * Creates a parse exception for when a syntax error occured. * * @param context The context in which the error occured. * *
Preconditions:
*
*/ protected XMLParseException syntaxError(String context) { String msg = "Syntax error while parsing " + context; return new XMLParseException(this.getName(), this.parserLineNr, msg); } /** * Creates a parse exception for when the next character read is not * the character that was expected. * * @param charSet The set of characters (in human readable form) that was * expected. * *
Preconditions:
*