1 14 package org.compiere.swing; 15 16 import java.awt.Color ; 17 import java.awt.Component ; 18 19 import javax.swing.Icon ; 20 import javax.swing.JPanel ; 21 import javax.swing.JTabbedPane ; 22 23 import org.compiere.plaf.CompiereColor; 24 import org.compiere.plaf.CompierePLAF; 25 import org.compiere.plaf.CompierePanelUI; 26 import org.compiere.util.Trace; 27 28 34 public class CTabbedPane extends JTabbedPane 35 { 36 42 public CTabbedPane() 43 { 44 super(); 45 init(); 46 } 48 56 public CTabbedPane(int tabPlacement) 57 { 58 super(tabPlacement); 59 init(); 60 } 62 75 public CTabbedPane(int tabPlacement, int tabLayoutPolicy) 76 { 77 super (tabPlacement, tabLayoutPolicy); 78 init(); 79 } 81 85 public CTabbedPane (CompiereColor bg) 86 { 87 super(); 88 init(); 89 setBackgroundColor (bg); 90 } 92 95 private void init() 96 { 97 setOpaque(false); 98 setFont(CompierePLAF.getFont_Label()); 99 setForeground(CompierePLAF.getTextColor_Label()); 100 } 102 103 104 108 public void setBackground (Color bg) 109 { 110 if (bg.equals(getBackground())) 111 return; 112 super.setBackground (bg); 113 if (!Trace.getCallerClass(1).startsWith("javax")) 115 setBackgroundColor (new CompiereColor(bg)); 116 } 118 121 public void setBackgroundColor () 122 { 123 setBackgroundColor (null); 124 } 126 130 public void setBackgroundColor (CompiereColor bg) 131 { 132 if (bg == null) 133 bg = CompierePanelUI.getDefaultBackground(); 134 setOpaque(true); 135 putClientProperty(CompierePLAF.BACKGROUND, bg); 136 super.setBackground (bg.getFlatColor()); 137 repaint(); 139 } 141 145 public CompiereColor getBackgroundColor () 146 { 147 try 148 { 149 return (CompiereColor)getClientProperty(CompierePLAF.BACKGROUND); 150 } 151 catch (Exception e) 152 { 153 System.err.println("CPanel - ClientProperty: " + e.getMessage()); 154 } 155 return null; 156 } 158 159 160 181 public void insertTab (String title, Icon icon, Component component, String tip, int index) 182 { 183 super.insertTab (title, icon, component, tip, index); 184 if (component instanceof JPanel ) 186 { 187 JPanel p = (JPanel )component; 188 if (p.getClientProperty(CompierePLAF.BACKGROUND) == null) 189 { 190 CompiereColor.setBackground(p); 191 p.setOpaque(true); 192 } 193 } 194 } 196 200 public String toString() 201 { 202 StringBuffer sb = new StringBuffer ("CTabbedPane ["); 203 sb.append(super.toString()); 204 CompiereColor bg = getBackgroundColor(); 205 if (bg != null) 206 sb.append(bg.toString()); 207 sb.append("]"); 208 return sb.toString(); 209 } 211 } | Popular Tags |