001: /*
002: * Copyright (c) 2005-2008 Flamingo / Substance Kirill Grouchnikov. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of Flamingo Kirill Grouchnikov nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package org.jvnet.substance.flamingo.ribbon.gallery.oob;
031:
032: import java.awt.Frame;
033: import java.awt.event.MouseAdapter;
034: import java.awt.event.MouseEvent;
035: import java.util.*;
036:
037: import javax.swing.SwingUtilities;
038:
039: import org.jvnet.flamingo.common.*;
040: import org.jvnet.flamingo.common.icon.ResizableIcon;
041: import org.jvnet.flamingo.ribbon.JRibbonBand;
042: import org.jvnet.flamingo.ribbon.RibbonElementPriority;
043: import org.jvnet.substance.SubstanceLookAndFeel;
044: import org.jvnet.substance.watermark.SubstanceWatermark;
045: import org.jvnet.substance.watermark.WatermarkInfo;
046:
047: /**
048: * In-ribbon gallery that contains all available <b>Substance</b> watermarks.
049: *
050: * @author Kirill Grouchnikov
051: */
052: public class SubstanceWatermarkRibbonGallery {
053: /**
054: * Adds an in-ribbon gallery that contains all available <b>Substance</b>
055: * watermarks to the specified ribbon band.
056: *
057: * @param ribbonBand
058: * Ribbon band that will contain the newly added watermark
059: * gallery.
060: */
061: public static void addWatermarkGallery(JRibbonBand ribbonBand) {
062: Map<ElementState, Integer> prefWidths = new HashMap<ElementState, Integer>();
063: prefWidths.put(ElementState.SMALL, 1);
064: prefWidths.put(ElementState.MEDIUM, 3);
065: prefWidths.put(ElementState.BIG, 5);
066:
067: List<StringValuePair<List<JCommandToggleButton>>> watermarkGroups = new ArrayList<StringValuePair<List<JCommandToggleButton>>>();
068: List<JCommandToggleButton> watermarkButtons = new ArrayList<JCommandToggleButton>();
069:
070: Map<String, WatermarkInfo> watermarks = SubstanceLookAndFeel
071: .getAllWatermarks();
072: for (Map.Entry<String, WatermarkInfo> entry : watermarks
073: .entrySet()) {
074: final String watermarkClassName = entry.getValue()
075: .getClassName();
076: try {
077: Class<?> watermarkClass = Class
078: .forName(watermarkClassName);
079: SubstanceWatermark watermarkInstance = (SubstanceWatermark) watermarkClass
080: .newInstance();
081:
082: ResizableIcon icon = new WatermarkResizableIcon(
083: watermarkInstance, 60, 40);
084: JCommandToggleButton watermarkButton = new JCommandToggleButton(
085: entry.getKey(), icon);
086: watermarkButtons.add(watermarkButton);
087: watermarkButton.addMouseListener(new MouseAdapter() {
088: @Override
089: public void mouseClicked(MouseEvent e) {
090: SwingUtilities.invokeLater(new Runnable() {
091: public void run() {
092: SubstanceLookAndFeel
093: .setCurrentWatermark(watermarkClassName);
094: for (Frame frame : Frame.getFrames())
095: SwingUtilities
096: .updateComponentTreeUI(frame);
097: }
098: });
099: }
100: });
101: } catch (Exception e) {
102: continue;
103: }
104: }
105:
106: watermarkGroups
107: .add(new StringValuePair<List<JCommandToggleButton>>(
108: "Watermarks", watermarkButtons));
109:
110: ribbonBand.addRibbonGallery(watermarkGroups, prefWidths, 5, 3,
111: RibbonElementPriority.TOP);
112: }
113: }
|