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.awt.event.*;
034:
035: import javax.swing.*;
036:
037: import org.jvnet.lafwidget.LafWidget;
038: import org.jvnet.lafwidget.tabbed.DefaultTabPreviewPainter;
039: import org.jvnet.substance.SubstanceImageCreator;
040: import org.jvnet.substance.SubstanceLookAndFeel;
041: import org.jvnet.substance.tabbed.TabCloseCallback;
042: import org.jvnet.substance.utils.SubstanceConstants.TabCloseKind;
043:
044: import test.check.*;
045:
046: public class TestAnimations extends JFrame {
047: public TestAnimations() {
048: super (
049: "Substance test with very very very very very very very very very very very very very very long title");
050:
051: this .setIconImage(SubstanceImageCreator.getBigHexaMarker(6,
052: SubstanceLookAndFeel.getTheme()));
053: this .setLayout(new BorderLayout());
054:
055: JTabbedPane jtp = new JTabbedPane();
056: this .add(jtp, BorderLayout.CENTER);
057:
058: JPanel checkListPanel = new JPanel();
059: checkListPanel.setLayout(new BorderLayout());
060: checkListPanel.add(new ListPanel(), BorderLayout.CENTER);
061: jtp.addTab("List", Check.getIcon("JListColor16"),
062: checkListPanel);
063:
064: JPanel checkTablePanel = new JPanel();
065: checkTablePanel.setLayout(new BorderLayout());
066: checkTablePanel.add(new TablePanel(), BorderLayout.CENTER);
067: jtp.addTab("Table", Check.getIcon("JTableColor16"),
068: checkTablePanel);
069:
070: jtp.addTab("Tree", Check.getIcon("JTreeColor16"),
071: new TreePanel());
072:
073: // sample menu bar
074: JMenuBar jmb = new JMenuBar();
075:
076: if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
077:
078: jmb.add(SampleMenuFactory.getThemeMenu());
079: jmb.add(SampleMenuFactory.getSkinMenu());
080: }
081: this .setJMenuBar(jmb);
082:
083: TabCloseCallback closeCallbackMain = new TabCloseCallback() {
084: public TabCloseKind onAreaClick(JTabbedPane tabbedPane,
085: int tabIndex, MouseEvent mouseEvent) {
086: if (mouseEvent.getButton() != MouseEvent.BUTTON2)
087: return TabCloseKind.NONE;
088: if (mouseEvent.isShiftDown()) {
089: return TabCloseKind.ALL;
090: }
091: return TabCloseKind.THIS;
092: }
093:
094: public TabCloseKind onCloseButtonClick(
095: JTabbedPane tabbedPane, int tabIndex,
096: MouseEvent mouseEvent) {
097: if (mouseEvent.isAltDown()) {
098: return TabCloseKind.ALL_BUT_THIS;
099: }
100: if (mouseEvent.isShiftDown()) {
101: return TabCloseKind.ALL;
102: }
103: return TabCloseKind.THIS;
104: }
105:
106: public String getAreaTooltip(JTabbedPane tabbedPane,
107: int tabIndex) {
108: return null;
109: }
110:
111: public String getCloseButtonTooltip(JTabbedPane tabbedPane,
112: int tabIndex) {
113: StringBuffer result = new StringBuffer();
114: result.append("<html><body>");
115: result.append("Mouse click closes <b>"
116: + tabbedPane.getTitleAt(tabIndex) + "</b> tab");
117: result
118: .append("<br><b>Alt</b>-Mouse click closes all tabs but <b>"
119: + tabbedPane.getTitleAt(tabIndex)
120: + "</b> tab");
121: result
122: .append("<br><b>Shift</b>-Mouse click closes all tabs");
123: result.append("</body></html>");
124: return result.toString();
125: }
126: };
127:
128: jtp.putClientProperty(
129: SubstanceLookAndFeel.TABBED_PANE_CLOSE_CALLBACK,
130: closeCallbackMain);
131: try {
132: jtp.putClientProperty(
133: LafWidget.TABBED_PANE_PREVIEW_PAINTER,
134: new DefaultTabPreviewPainter());
135: } catch (Throwable e) {
136: }
137:
138: }
139:
140: public static void main(String[] args) {
141: boolean hasLafSpecified = false;
142: try {
143: hasLafSpecified = (System.getProperty("swing.defaultlaf") != null);
144: } catch (Throwable t) {
145: // JNLP sandbox
146: }
147:
148: try {
149: if (!hasLafSpecified) {
150: LookAndFeel laf = (LookAndFeel) Class.forName(
151: "org.jvnet.substance.SubstanceLookAndFeel")
152: .newInstance();
153: UIManager.setLookAndFeel(laf);
154: }
155: } catch (Exception e) {
156: e.printStackTrace();
157: }
158:
159: UIManager
160: .put(
161: SubstanceLookAndFeel.TABBED_PANE_CLOSE_BUTTONS_PROPERTY,
162: Boolean.TRUE);
163: TestAnimations c = new TestAnimations();
164: c.addComponentListener(new ComponentAdapter() {
165: @Override
166: public void componentResized(ComponentEvent e) {
167: super .componentResized(e);
168: ((JFrame) e.getComponent()).getRootPane().repaint();
169: }
170: });
171: c.setPreferredSize(new Dimension(400, 300));
172: c.setMinimumSize(new Dimension(150, 100));
173: c.pack();
174: Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
175: // center the frame in the physical screen
176: c.setLocation((d.width - c.getWidth()) / 2, (d.height - c
177: .getHeight()) / 2);
178:
179: c.setVisible(true);
180: c.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
181: }
182: }
|