001: /*
002: * Copyright 2005 Patrick Gotthardt
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package com.pagosoft.plaf;
017:
018: import javax.swing.*;
019: import javax.swing.border.*;
020: import javax.swing.plaf.basic.*;
021: import java.awt.*;
022:
023: public class PgsSplitPaneDivider extends BasicSplitPaneDivider {
024: public PgsSplitPaneDivider(BasicSplitPaneUI ui) {
025: super (ui);
026: }
027:
028: public void paint(Graphics g) {
029: Dimension size = getSize();
030: Color bgColor = getBackground();
031: if (bgColor != null) {
032: g.setColor(bgColor);
033: g.fillRect(0, 0, size.width, size.height);
034: }
035: super .paint(g);
036: }
037:
038: /**
039: * Creates and return an instance of JButton that can be used to
040: * collapse the left component in the metal split pane.
041: */
042: protected JButton createLeftOneTouchButton() {
043: JButton b = new JButton() {
044: // Sprite buffer for the arrow image of the left button
045: int[][] buffer = { { 0, 0, 0, 2, 2, 0, 0, 0, 0 },
046: { 0, 0, 2, 1, 1, 1, 0, 0, 0 },
047: { 0, 2, 1, 1, 1, 1, 1, 0, 0 },
048: { 2, 1, 1, 1, 1, 1, 1, 1, 0 },
049: { 0, 3, 3, 3, 3, 3, 3, 3, 3 } };
050:
051: public void setBorder(Border b) {
052: }
053:
054: public void paint(Graphics g) {
055: JSplitPane splitPane = getSplitPaneFromSuper();
056: if (splitPane != null) {
057: int oneTouchSize = getOneTouchSizeFromSuper();
058: int orientation = getOrientationFromSuper();
059: int blockSize = Math.min(getDividerSize(),
060: oneTouchSize);
061:
062: // Initialize the color array
063: Color[] colors = {
064: this .getBackground(),
065: PgsLookAndFeel
066: .getPrimaryControlDarkShadow(),
067: PgsLookAndFeel.getPrimaryControlInfo(),
068: PgsLookAndFeel.getPrimaryControlHighlight() };
069:
070: // Fill the background first ...
071: g.setColor(this .getBackground());
072: if (isOpaque()) {
073: g.fillRect(0, 0, this .getWidth(), this
074: .getHeight());
075: }
076:
077: // ... then draw the arrow.
078: if (getModel().isPressed()) {
079: // Adjust color mapping for pressed button state
080: colors[1] = colors[2];
081: } else if (getModel().isRollover()) {
082: colors[1] = PgsLookAndFeel.getPrimaryControl();
083: }
084: if (orientation == JSplitPane.VERTICAL_SPLIT) {
085: // Draw the image for a vertical split
086: for (int i = 1; i <= buffer[0].length; i++) {
087: for (int j = 1; j < blockSize; j++) {
088: if (buffer[j - 1][i - 1] == 0) {
089: continue;
090: } else {
091: g
092: .setColor(colors[buffer[j - 1][i - 1]]);
093: }
094: g.drawLine(i, j, i, j);
095: }
096: }
097: } else {
098: // Draw the image for a horizontal split
099: // by simply swaping the i and j axis.
100: // Except the drawLine() call this code is
101: // identical to the code block above. This was done
102: // in order to remove the additional orientation
103: // check for each pixel.
104: for (int i = 1; i <= buffer[0].length; i++) {
105: for (int j = 1; j < blockSize; j++) {
106: if (buffer[j - 1][i - 1] == 0) {
107: // Nothing needs
108: // to be drawn
109: continue;
110: } else {
111: // Set the color from the
112: // color map
113: g
114: .setColor(colors[buffer[j - 1][i - 1]]);
115: }
116: // Draw a pixel
117: g.drawLine(j, i, j, i);
118: }
119: }
120: }
121: }
122: }
123:
124: // Don't want the button to participate in focus traversable.
125: public boolean isFocusTraversable() {
126: return false;
127: }
128: };
129: b.setRequestFocusEnabled(false);
130: b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
131: b.setFocusPainted(false);
132: b.setBorderPainted(false);
133: maybeMakeButtonOpaque(b);
134: return b;
135: }
136:
137: /**
138: * Creates and return an instance of JButton that can be used to
139: * collapse the right component in the metal split pane.
140: */
141: protected JButton createRightOneTouchButton() {
142: JButton b = new JButton() {
143: // Sprite buffer for the arrow image of the right button
144: int[][] buffer = { { 2, 2, 2, 2, 2, 2, 2, 2 },
145: { 0, 1, 1, 1, 1, 1, 1, 3 },
146: { 0, 0, 1, 1, 1, 1, 3, 0 },
147: { 0, 0, 0, 1, 1, 3, 0, 0 },
148: { 0, 0, 0, 0, 3, 0, 0, 0 } };
149:
150: public void setBorder(Border border) {
151: }
152:
153: public void paint(Graphics g) {
154: JSplitPane splitPane = getSplitPaneFromSuper();
155: if (splitPane != null) {
156: int oneTouchSize = getOneTouchSizeFromSuper();
157: int orientation = getOrientationFromSuper();
158: int blockSize = Math.min(getDividerSize(),
159: oneTouchSize);
160:
161: // Initialize the color array
162: Color[] colors = {
163: this .getBackground(),
164: PgsLookAndFeel
165: .getPrimaryControlDarkShadow(),
166: PgsLookAndFeel.getPrimaryControlInfo(),
167: PgsLookAndFeel.getPrimaryControlHighlight() };
168:
169: // Fill the background first ...
170: g.setColor(this .getBackground());
171: if (isOpaque()) {
172: g.fillRect(0, 0, this .getWidth(), this
173: .getHeight());
174: }
175:
176: // ... then draw the arrow.
177: if (getModel().isPressed()) {
178: // Adjust color mapping for pressed button state
179: colors[1] = colors[2];
180: } else if (getModel().isRollover()) {
181: colors[1] = PgsLookAndFeel.getPrimaryControl();
182: }
183: if (orientation == JSplitPane.VERTICAL_SPLIT) {
184: // Draw the image for a vertical split
185: for (int i = 1; i <= buffer[0].length; i++) {
186: for (int j = 1; j < blockSize; j++) {
187: if (buffer[j - 1][i - 1] == 0) {
188: continue;
189: } else {
190: g
191: .setColor(colors[buffer[j - 1][i - 1]]);
192: }
193: g.drawLine(i, j, i, j);
194: }
195: }
196: } else {
197: // Draw the image for a horizontal split
198: // by simply swaping the i and j axis.
199: // Except the drawLine() call this code is
200: // identical to the code block above. This was done
201: // in order to remove the additional orientation
202: // check for each pixel.
203: for (int i = 1; i <= buffer[0].length; i++) {
204: for (int j = 1; j < blockSize; j++) {
205: if (buffer[j - 1][i - 1] == 0) {
206: // Nothing needs
207: // to be drawn
208: continue;
209: } else {
210: // Set the color from the
211: // color map
212: g
213: .setColor(colors[buffer[j - 1][i - 1]]);
214: }
215: // Draw a pixel
216: g.drawLine(j, i, j, i);
217: }
218: }
219: }
220: }
221: }
222:
223: // Don't want the button to participate in focus traversable.
224: public boolean isFocusTraversable() {
225: return false;
226: }
227: };
228: b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
229: b.setFocusPainted(false);
230: b.setBorderPainted(false);
231: b.setRequestFocusEnabled(false);
232: maybeMakeButtonOpaque(b);
233: return b;
234: }
235:
236: private void maybeMakeButtonOpaque(JComponent c) {
237: Object opaque = UIManager
238: .get("SplitPane.oneTouchButtonsOpaque");
239: if (opaque != null) {
240: c.setOpaque(((Boolean) opaque).booleanValue());
241: }
242: }
243:
244: int getOneTouchSizeFromSuper() {
245: return super .ONE_TOUCH_SIZE;
246: }
247:
248: int getOneTouchOffsetFromSuper() {
249: return super .ONE_TOUCH_OFFSET;
250: }
251:
252: int getOrientationFromSuper() {
253: return super .orientation;
254: }
255:
256: JSplitPane getSplitPaneFromSuper() {
257: return super .splitPane;
258: }
259:
260: JButton getLeftButtonFromSuper() {
261: return super .leftButton;
262: }
263:
264: JButton getRightButtonFromSuper() {
265: return super.rightButton;
266: }
267: }
|