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.*;
021: import javax.swing.plaf.basic.*;
022: import javax.swing.plaf.metal.*;
023: import java.awt.*;
024:
025: public class PgsBorders {
026: private static Border buttonBorder;
027:
028: public static Border getButtonBorder() {
029: if (buttonBorder == null) {
030: buttonBorder = new BorderUIResource.CompoundBorderUIResource(
031: new ButtonBorder(), new BasicBorders.MarginBorder());
032: }
033: return buttonBorder;
034: }
035:
036: private static class ButtonBorder extends AbstractBorder implements
037: UIResource {
038: protected static final Insets INSETS = new Insets(3, 4, 3, 4);
039: protected static final Insets NO_INSETS = new Insets(0, 0, 0, 0);
040:
041: public void paintBorder(Component c, Graphics g, int x, int y,
042: int w, int h) {
043: AbstractButton button = (AbstractButton) c;
044: ButtonModel model = button.getModel();
045:
046: if (model.isEnabled()) {
047: if (model.isRollover()
048: && PlafOptions.isPaintRolloverButtonBorder()) {
049: PgsUtils.drawRolloverButtonBorder(g, x, y, w, h);
050: } else {
051: PgsUtils.drawButtonBorder(g, x, y, w, h);
052: }
053: } else { // disabled state
054: PgsUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
055: }
056: }
057:
058: public Insets getBorderInsets(Component c) {
059: if (((AbstractButton) c).isBorderPainted()) {
060: return INSETS;
061: }
062: return NO_INSETS;
063: }
064:
065: public Insets getBorderInsets(Component c, Insets newInsets) {
066: if (((AbstractButton) c).isBorderPainted()) {
067: return getBorderInsets(c, newInsets, INSETS);
068: }
069: return getBorderInsets(c, newInsets, NO_INSETS);
070: }
071:
072: public Insets getBorderInsets(Component c, Insets newInsets,
073: Insets oldInsets) {
074: newInsets.top = oldInsets.top;
075: newInsets.left = oldInsets.left;
076: newInsets.bottom = oldInsets.bottom;
077: newInsets.right = oldInsets.right;
078: return newInsets;
079: }
080: }
081:
082: private static Border textFieldBorder;
083:
084: public static Border getTextFieldBorder() {
085: if (textFieldBorder == null) {
086: textFieldBorder = new BorderUIResource.CompoundBorderUIResource(
087: new TextFieldBorder(),
088: new BasicBorders.MarginBorder());
089: }
090: return textFieldBorder;
091: }
092:
093: private static class TextFieldBorder extends AbstractBorder {
094: private static final Insets INSETS = new Insets(1, 1, 1, 1);
095:
096: //private static final Insets INSETS = new Insets(0, 0, 0, 0);
097: public void paintBorder(Component c, Graphics g, int x, int y,
098: int w, int h) {
099: if (c.isEnabled()) {
100: //PgsUtils.drawButtonBorder(g, x, y, w, h);
101: PgsUtils.drawButtonBorder(g, x, y, w - 1, h - 1, 2, 2,
102: PgsLookAndFeel.getControlDarkShadow());
103: } else {
104: PgsUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
105: }
106:
107: }
108:
109: public Insets getBorderInsets(Component c) {
110: return INSETS;
111: }
112:
113: public Insets getBorderInsets(Component c, Insets newInsets) {
114: newInsets.top = INSETS.top;
115: newInsets.left = INSETS.left;
116: newInsets.bottom = INSETS.bottom;
117: newInsets.right = INSETS.right;
118: return newInsets;
119: }
120: }
121:
122: private static Border componentBorder;
123:
124: public static Border getComponentBorder() {
125: if (componentBorder == null) {
126: componentBorder = new BorderUIResource.CompoundBorderUIResource(
127: new ComponentBorder(),
128: new BasicBorders.MarginBorder());
129: }
130: return componentBorder;
131: }
132:
133: private static class ComponentBorder extends AbstractBorder {
134: private static final Insets INSETS = new Insets(1, 1, 1, 1);
135:
136: public void paintBorder(Component c, Graphics g, int x, int y,
137: int w, int h) {
138: if (c.isEnabled()) {
139: PgsUtils.drawButtonBorder(g, x, y, w, h);
140: } else {
141: PgsUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
142: }
143: }
144:
145: public Insets getBorderInsets(Component c) {
146: return INSETS;
147: }
148:
149: public Insets getBorderInsets(Component c, Insets newInsets) {
150: newInsets.top = INSETS.top;
151: newInsets.left = INSETS.left;
152: newInsets.bottom = INSETS.bottom;
153: newInsets.right = INSETS.right;
154: return newInsets;
155: }
156: }
157:
158: private static Border toolBarBorder;
159:
160: public static Border getToolBarBorder() {
161: if (toolBarBorder == null) {
162: toolBarBorder = new BorderUIResource(new ToolBarBorder());
163: }
164: return toolBarBorder;
165: }
166:
167: public static class ToolBarBorder extends AbstractBorder implements
168: UIResource, SwingConstants {
169: public void paintBorder(Component c, Graphics g, int x, int y,
170: int w, int h) {
171: g.translate(x, y);
172:
173: if (((JToolBar) c).isFloatable()) {
174: if (((JToolBar) c).getOrientation() == HORIZONTAL) {
175: PgsUtils.drawVerticalBumps(g, 2, 4,
176: c.getHeight() - 6);
177: } else {
178: PgsUtils.drawHorizontalBumps(g, 4, 2,
179: c.getWidth() - 6);
180: }
181: }
182:
183: if (((JToolBar) c).getOrientation() == HORIZONTAL) {
184: g.setColor(MetalLookAndFeel.getControlShadow());
185: g.drawLine(0, h - 2, w, h - 2);
186: g.setColor(UIManager.getColor("ToolBar.borderColor"));
187: g.drawLine(0, h - 1, w, h - 1);
188: }
189:
190: g.translate(-x, -y);
191: }
192:
193: public Insets getBorderInsets(Component c) {
194: return getBorderInsets(c, new Insets(0, 0, 0, 0));
195: }
196:
197: public Insets getBorderInsets(Component c, Insets newInsets) {
198: newInsets.left = 2;
199: newInsets.top = 1;
200: newInsets.bottom = 3;
201: newInsets.right = 2;
202:
203: if (((JToolBar) c).isFloatable()) {
204: if (((JToolBar) c).getOrientation() == HORIZONTAL) {
205: if (c.getComponentOrientation().isLeftToRight()) {
206: newInsets.left = 16;
207: } else {
208: newInsets.right = 16;
209: }
210: } else {
211: newInsets.top = 16;
212: }
213: }
214:
215: Insets margin = ((JToolBar) c).getMargin();
216:
217: if (margin != null) {
218: newInsets.left += margin.left;
219: newInsets.top += margin.top;
220: newInsets.right += margin.right;
221: newInsets.bottom += margin.bottom;
222: }
223:
224: return newInsets;
225: }
226: }
227: }
|