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 test;
031:
032: import java.awt.*;
033:
034: import javax.swing.JFrame;
035:
036: import org.jvnet.flamingo.common.icon.ResizableIcon;
037: import org.jvnet.flamingo.common.icon.StackIcon;
038: import org.jvnet.substance.flamingo.ribbon.gallery.oob.ThemeResizableIcon;
039:
040: public final class TestResizableIcon {
041:
042: /**
043: * Demo frame.
044: *
045: * @author Kirill Grouchnikov
046: */
047: private static final class ImageCreatorFrame extends JFrame {
048: /**
049: * Simple constructor. Creates all the icons.
050: */
051: public ImageCreatorFrame() {
052: super ("Image creator demo");
053: int width = 450;
054: int height = 200;
055: Dimension dim = new Dimension(width, height);
056: this .setPreferredSize(dim);
057: this .setSize(dim);
058: this .setResizable(false);
059: }
060:
061: /*
062: * (non-Javadoc)
063: *
064: * @see java.awt.Component#paint(java.awt.Graphics)
065: */
066: @Override
067: public final void paint(Graphics g) {
068: ResizableIcon ri = new ThemeResizableIcon(null, 32, 32);
069: ResizableIcon ri2 = new StackIcon(new ThemeResizableIcon(
070: null, 32, 32), 0.2);
071: g.setColor(Color.white);
072: g.fillRect(0, 0, this .getWidth(), this .getHeight());
073: int xpos = 5;
074: int[] dims = new int[] { 16, 20, 24, 28, 32, 36, 40, 44, 48 };
075: for (int dim : dims) {
076: int y = 45;
077: ri.setWidth(dim);
078: ri.setHeight(dim);
079: ri2.setWidth(dim + 8);
080: ri2.setHeight(dim + 8);
081: g.setFont(new Font("Tahoma", Font.PLAIN, 11));
082: g.setColor(Color.black);
083: String sd = "" + dim;
084: int len = g.getFontMetrics().stringWidth(sd);
085: g.drawString("" + dim, (xpos + (dim - len) / 2), 42);
086: ri.paintIcon(null, g, xpos, y);
087: ri2.paintIcon(null, g, xpos, y + 60);
088: xpos += (dim + 12);
089: }
090: }
091: }
092:
093: /**
094: * Main function for running <code>this</code> demo.
095: *
096: * @param args
097: */
098: public static void main(String[] args) {
099: ImageCreatorFrame icf = new ImageCreatorFrame();
100: icf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
101: icf.setVisible(true);
102: }
103: }
|