001: /*
002: * Copyright (c) 2005-2008 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 Substance 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: import java.util.Map;
034:
035: import javax.swing.*;
036:
037: import org.jvnet.substance.SubstanceLookAndFeel;
038: import org.jvnet.substance.color.ColorScheme;
039: import org.jvnet.substance.theme.SubstanceTheme;
040: import org.jvnet.substance.theme.ThemeInfo;
041:
042: /**
043: * Image creator demo.
044: *
045: * @author Kirill Grouchnikov
046: */
047: public class SchemeCreatorDemo {
048:
049: public static final int COLOR_CELL = 30;
050:
051: public static final int NAME_CELL = 120;
052:
053: private static final class SchemeCreatorFrame extends JFrame {
054: /**
055: * Simple constructor. Creates all the icons.
056: */
057: public SchemeCreatorFrame() {
058: // int width = COLOR_CELL * 6 + NAME_CELL;
059: // int height = COLOR_CELL * ColorSchemeEnum.values().length;
060: // Dimension dim = new Dimension(width, height);
061: // this.setPreferredSize(dim);
062: // this.setSize(dim);
063:
064: this .setLayout(new BorderLayout());
065: this .add(new SchemeCreatorPanel(), BorderLayout.CENTER);
066:
067: // this.setResizable(false);
068: }
069: }
070:
071: /**
072: * Demo frame.
073: *
074: * @author Kirill Grouchnikov
075: */
076: private static final class SchemeCreatorPanel extends JPanel {
077: /**
078: * Simple constructor. Creates all the icons.
079: */
080: public SchemeCreatorPanel() {
081: int width = 2 * (COLOR_CELL * 6 + NAME_CELL);
082: int height = 1 + (COLOR_CELL * SubstanceLookAndFeel
083: .getAllThemes().size()) / 2;
084: Dimension dim = new Dimension(width, height);
085: this .setPreferredSize(dim);
086: this .setMinimumSize(dim);
087: this .setSize(dim);
088: }
089:
090: /*
091: * (non-Javadoc)
092: *
093: * @see java.awt.Component#paint(java.awt.Graphics)
094: */
095: public final void paint(Graphics g) {
096: try {
097: int width = this .getWidth();
098: int height = this .getHeight();
099: g.setColor(Color.white);
100: g.fillRect(0, 0, width, height);
101: int count = 0;
102: for (Map.Entry<String, ThemeInfo> schemeEntry : SubstanceLookAndFeel
103: .getAllThemes().entrySet()) {
104: String name = schemeEntry.getKey();
105: SubstanceTheme theme = (SubstanceTheme) Class
106: .forName(
107: schemeEntry.getValue()
108: .getClassName())
109: .newInstance();
110: ColorScheme scheme = theme.getColorScheme();
111:
112: g.setColor(Color.BLACK);
113: g.setFont(new Font("Arial", Font.BOLD, 14));
114:
115: int deltaX = (count % 2 == 0) ? 0 : getWidth() / 2;
116:
117: g.drawString(name, deltaX + 5, (1 + (count / 2))
118: * COLOR_CELL
119: - (COLOR_CELL - g.getFontMetrics()
120: .getHeight()) / 2);
121:
122: int x = NAME_CELL + deltaX;
123: int y = (count / 2) * COLOR_CELL;
124:
125: g.setColor(scheme.getUltraLightColor());
126: g.fillRect(x, y, COLOR_CELL, COLOR_CELL);
127: x += COLOR_CELL;
128:
129: g.setColor(scheme.getExtraLightColor());
130: g.fillRect(x, y, COLOR_CELL, COLOR_CELL);
131: x += COLOR_CELL;
132:
133: g.setColor(scheme.getLightColor());
134: g.fillRect(x, y, COLOR_CELL, COLOR_CELL);
135: x += COLOR_CELL;
136:
137: g.setColor(scheme.getMidColor());
138: g.fillRect(x, y, COLOR_CELL, COLOR_CELL);
139: x += COLOR_CELL;
140:
141: g.setColor(scheme.getDarkColor());
142: g.fillRect(x, y, COLOR_CELL, COLOR_CELL);
143: x += COLOR_CELL;
144:
145: g.setColor(scheme.getUltraDarkColor());
146: g.fillRect(x, y, COLOR_CELL, COLOR_CELL);
147:
148: count++;
149: }
150: g.setColor(new Color(128, 128, 128));
151: g.drawLine(0, 0, width - 1, 0);
152: g.drawLine(0, height - 1, width - 1, height - 1);
153: g.drawLine(0, 0, 0, height - 1);
154: g.drawLine(width - 1, 0, width - 1, height - 1);
155:
156: for (count = 0; count < SubstanceLookAndFeel
157: .getAllThemes().size(); count++) {
158: int yPos = COLOR_CELL * count;
159: g.drawLine(0, yPos, width - 1, yPos);
160: }
161:
162: for (count = 0; count < 6; count++) {
163: int xPos = NAME_CELL + count * COLOR_CELL;
164: g.drawLine(xPos, 0, xPos, height - 1);
165: }
166: for (count = 0; count < 6; count++) {
167: int xPos = NAME_CELL + count * COLOR_CELL;
168: g.drawLine(width / 2 + xPos, 0, width / 2 + xPos,
169: height - 1);
170: }
171: } catch (Exception exc) {
172: exc.printStackTrace();
173: }
174: }
175: }
176:
177: /**
178: * Main function for running <code>this</code> demo.
179: *
180: * @param args
181: */
182: public static void main(String[] args) throws Exception {
183: UIManager.setLookAndFeel(new SubstanceLookAndFeel());
184: SchemeCreatorFrame icf = new SchemeCreatorFrame();
185: icf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
186: icf.pack();
187: icf.setVisible(true);
188: }
189: }
|