01: /*
02: * Copyright 2005 Patrick Gotthardt
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package com.pagosoft.plaf;
17:
18: import javax.swing.*;
19: import javax.swing.plaf.*;
20: import javax.swing.plaf.metal.*;
21: import java.awt.*;
22: import java.awt.event.*;
23:
24: public class PgsToolBarUI extends MetalToolBarUI {
25: public static ComponentUI createUI(JComponent c) {
26: return new PgsToolBarUI();
27: }
28:
29: public void installUI(JComponent c) {
30: super .installUI(c);
31: c.putClientProperty("gradientStart", UIManager
32: .get("ToolBar.gradientStart"));
33: c.putClientProperty("gradientEnd", UIManager
34: .get("ToolBar.gradientEnd"));
35:
36: int limit = c.getComponentCount();
37: for (int i = 0; i < limit; i++) {
38: setToolBarUI((JComponent) c.getComponent(i));
39: }
40: }
41:
42: public void paint(Graphics g, JComponent b) {
43: if (b.isOpaque()) {
44: if (PlafOptions.getStyle(PlafOptions.TOOLBAR) == PlafOptions.FLAT_STYLE) {
45: g.setColor(b.getBackground());
46: g.drawRect(0, 0, b.getWidth(), b.getHeight());
47: } else {
48: int orient = ((JToolBar) b).getOrientation();
49: if (orient == JToolBar.HORIZONTAL) {
50: PgsUtils.drawGradient(g, b);
51: } else {
52: PgsUtils.drawGradient(g, 0, 0, b.getWidth(), b
53: .getHeight(), (Color) b
54: .getClientProperty("gradientStart"),
55: (Color) b.getClientProperty("gradientEnd"));
56: }
57: }
58: }
59: super .paint(g, b);
60: }
61:
62: protected ContainerListener createContainerListener() {
63: return new ToolBarContListener();
64: }
65:
66: protected void setToolBarUI(JComponent c) {
67: if (c instanceof JButton) {
68: ((AbstractButton) c)
69: .setUI((ToolBarButtonUI) ToolBarButtonUI
70: .createUI(c));
71: } else if (c instanceof JToggleButton) {
72: ((AbstractButton) c)
73: .setUI((ToolBarToggleButtonUI) ToolBarToggleButtonUI
74: .createUI(c));
75: }
76: }
77:
78: protected class ToolBarContListener implements ContainerListener {
79: public void componentAdded(ContainerEvent e) {
80: setToolBarUI((JComponent) e.getChild());
81: }
82:
83: public void componentRemoved(ContainerEvent e) {
84: JComponent c = (JComponent) e.getChild();
85:
86: if (c instanceof JButton || c instanceof JToggleButton) {
87: ((AbstractButton) c).setUI((ButtonUI) UIManager
88: .getUI(c));
89: }
90: }
91: }
92: }
|