01: /*
02: * TabbedPaneUIFactory.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.components;
13:
14: import java.awt.Insets;
15:
16: import javax.swing.JTabbedPane;
17: import javax.swing.LookAndFeel;
18: import javax.swing.UIManager;
19: import javax.swing.plaf.TabbedPaneUI;
20:
21: /**
22: *
23: * @author support@sql-workbench.net
24: */
25: public class TabbedPaneUIFactory {
26: private static Insets topInsets = new Insets(2, 1, 1, 1);
27: private static Insets bottomInsets = new Insets(1, 1, 2, 1);
28: private static Insets leftInsets = new Insets(1, 3, 1, 1);
29: private static Insets rightInsets = new Insets(1, 1, 1, 3);
30: private static Insets defaultInsets = new Insets(1, 1, 1, 1);
31:
32: static Insets getBorderLessInsets(int tabPlacement) {
33: switch (tabPlacement) {
34: case JTabbedPane.TOP:
35: return topInsets;
36: case JTabbedPane.BOTTOM:
37: return bottomInsets;
38: case JTabbedPane.LEFT:
39: return leftInsets;
40: case JTabbedPane.RIGHT:
41: return rightInsets;
42: default:
43: return defaultInsets;
44: }
45: }
46:
47: public static String getTabbedPaneUIClass() {
48: LookAndFeel lnf = UIManager.getLookAndFeel();
49: String lnfClass = lnf.getClass().getName();
50: if (lnfClass.equals("javax.swing.plaf.metal.MetalLookAndFeel")) {
51: return "workbench.gui.components.BorderLessMetalTabbedPaneUI";
52: } else if (lnfClass
53: .startsWith("com.sun.java.swing.plaf.windows.Windows")) {
54: return "workbench.gui.components.BorderLessWindowsTabbedPaneUI";
55: } else if (lnfClass
56: .equals("com.sun.java.swing.plaf.motif.MotifLookAndFeel")) {
57: return "workbench.gui.components.BorderLessMotifTabbedPaneUI";
58: } else if (lnfClass
59: .startsWith("com.jgoodies.looks.plastic.Plastic")) {
60: if ("Metal".equals(System.getProperty("Plastic.tabStyle"))) {
61: return "workbench.gui.components.BorderLessMetalTabbedPaneUI";
62: }
63: }
64: return null;
65: }
66:
67: public static TabbedPaneUI getBorderLessUI() {
68: String uiClass = getTabbedPaneUIClass();
69: if (uiClass == null)
70: return null;
71: return getClassInstance(uiClass);
72: }
73:
74: private static TabbedPaneUI getClassInstance(String className) {
75: TabbedPaneUI ui = null;
76: try {
77: Class cls = Class.forName(className);
78: ui = (TabbedPaneUI) cls.newInstance();
79: } catch (Exception e) {
80: JTabbedPane pane = new JTabbedPane();
81: ui = (TabbedPaneUI) UIManager.getUI(pane);
82: UIManager.getDefaults().put("TabbedPaneUI",
83: ui.getClass().getName());
84: }
85: return ui;
86: }
87: }
|