1 14 package org.compiere.swing; 15 16 import java.awt.Color ; 17 import java.awt.LayoutManager ; 18 19 import javax.swing.JPanel ; 20 21 import org.compiere.plaf.CompiereColor; 22 import org.compiere.plaf.CompierePLAF; 23 import org.compiere.plaf.CompierePanelUI; 24 import org.compiere.util.Trace; 25 26 32 public class CPanel extends JPanel  33 { 34 41 public CPanel (LayoutManager layout, boolean isDoubleBuffered) 42 { 43 super (layout, isDoubleBuffered); 44 init(); 45 } 47 51 public CPanel (LayoutManager layout) 52 { 53 super (layout); 54 init(); 55 } 57 65 public CPanel (boolean isDoubleBuffered) 66 { 67 super (isDoubleBuffered); 68 init(); 69 } 71 74 public CPanel() 75 { 76 super (); 77 init(); 78 } 80 84 public CPanel(CompiereColor bc) 85 { 86 this (); 87 init(); 88 setBackgroundColor (bc); 89 } 91 94 private void init() 95 { 96 setOpaque(false); 97 } 99 100 101 105 public void setBackground (Color bg) 106 { 107 if (bg.equals(getBackground())) 108 return; 109 super.setBackground (bg); 110 if (!Trace.getCallerClass(1).startsWith("javax")) 112 setBackgroundColor (new CompiereColor(bg)); 113 } 115 119 public void setBackgroundColor (CompiereColor bg) 120 { 121 if (bg == null) 122 bg = CompierePanelUI.getDefaultBackground(); 123 setOpaque(true); 124 putClientProperty(CompierePLAF.BACKGROUND, bg); 125 super.setBackground (bg.getFlatColor()); 126 } 128 132 public CompiereColor getBackgroundColor () 133 { 134 try 135 { 136 return (CompiereColor)getClientProperty(CompierePLAF.BACKGROUND); 137 } 138 catch (Exception e) 139 { 140 System.err.println("CPanel - ClientProperty: " + e.getMessage()); 141 } 142 return null; 143 } 145 146 147 153 public void setTabLevel (int level) 154 { 155 if (level == 0) 156 putClientProperty(CompierePLAF.TABLEVEL, null); 157 else 158 putClientProperty(CompierePLAF.TABLEVEL, new Integer (level)); 159 } 161 165 public int getTabLevel() 166 { 167 try 168 { 169 Integer ll = (Integer )getClientProperty(CompierePLAF.TABLEVEL); 170 if (ll != null) 171 return ll.intValue(); 172 } 173 catch (Exception e) 174 { 175 System.err.println("CPanel - ClientProperty: " + e.getMessage()); 176 } 177 return 0; 178 } 180 181 182 186 public String toString() 187 { 188 StringBuffer sb = new StringBuffer ("CPanel ["); 189 sb.append(super.toString()); 190 CompiereColor bg = getBackgroundColor(); 191 if (bg != null) 192 sb.append(bg.toString()); 193 sb.append("]"); 194 return sb.toString(); 195 } 197 } | Popular Tags |