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 org.jvnet.substance.grip;
031:
032: import java.awt.*;
033:
034: import javax.swing.JComponent;
035: import javax.swing.JSplitPane;
036:
037: import org.jvnet.substance.SubstanceImageCreator;
038: import org.jvnet.substance.theme.SubstanceTheme;
039: import org.jvnet.substance.utils.SubstanceSizeUtils;
040:
041: /**
042: * Implementation of grip painter that uses drag bumps identical to those on
043: * toolbars and split pane dividers.
044: *
045: * @author Kirill Grouchnikov
046: */
047: public class DragBumpsGripPainter implements GripPainter {
048: /*
049: * (non-Javadoc)
050: *
051: * @see org.jvnet.substance.utils.GripPainter#paintGrip(javax.swing.JComponent,
052: * java.awt.Graphics, org.jvnet.substance.theme.SubstanceTheme,
053: * java.awt.Rectangle, boolean, java.awt.ComponentOrientation)
054: */
055: public void paintGrip(JComponent comp, Graphics graphics,
056: SubstanceTheme theme, Rectangle gripArea,
057: boolean isGripVertical, ComponentOrientation gripOrientation) {
058: int minSizeForGripPresence = SubstanceSizeUtils
059: .getAdjustedSize(SubstanceSizeUtils
060: .getComponentFontSize(comp), 30, 1, 2, false);
061: int maxGripSize = SubstanceSizeUtils.getAdjustedSize(
062: SubstanceSizeUtils.getComponentFontSize(comp), 40, 1,
063: 3, false);
064: if (isGripVertical) {
065: int thumbHeight = gripArea.height;
066: if (thumbHeight < minSizeForGripPresence)
067: return;
068: int gripHeight = thumbHeight / 4;
069: if (gripHeight > maxGripSize)
070: gripHeight = maxGripSize;
071:
072: int thumbWidth = gripArea.width;
073: int gripWidth = thumbWidth * 2 / 3;
074:
075: int gripX = gripArea.x + (thumbWidth - gripWidth) / 2;
076: int gripY = gripArea.y + (thumbHeight - gripHeight) / 2;
077: graphics.drawImage(SubstanceImageCreator.getDragImage(comp,
078: theme, gripWidth, gripHeight,
079: (comp instanceof JSplitPane), true, -1), gripX,
080: gripY, null);
081: } else {
082: int thumbWidth = gripArea.width;
083: if (thumbWidth < minSizeForGripPresence)
084: return;
085: int gripWidth = thumbWidth / 4;
086: if (gripWidth > maxGripSize)
087: gripWidth = maxGripSize;
088:
089: int thumbHeight = gripArea.height;
090: int gripHeight = thumbHeight * 2 / 3;
091:
092: int gripX = gripArea.x + (thumbWidth - gripWidth) / 2;
093: int gripY = 1 + gripArea.y + (thumbHeight - gripHeight) / 2;
094: graphics.drawImage(
095: SubstanceImageCreator.getRotated(
096: SubstanceImageCreator.getDragImage(
097: comp,
098: theme,// true,
099: gripHeight, gripWidth,
100: (comp instanceof JSplitPane), true,
101: -1), 3), gripX, gripY, null);
102: }
103: }
104:
105: /*
106: * (non-Javadoc)
107: *
108: * @see org.jvnet.substance.grip.GripPainter#getDisplayName()
109: */
110: public String getDisplayName() {
111: return "Drag Bumps";
112: }
113: }
|