1 14 package org.compiere.plaf; 15 16 import java.awt.BorderLayout ; 17 import java.awt.FlowLayout ; 18 import java.awt.GridLayout ; 19 import java.awt.event.ActionEvent ; 20 import java.awt.event.ActionListener ; 21 import java.util.ResourceBundle ; 22 23 import javax.swing.JColorChooser ; 24 import javax.swing.JDialog ; 25 import javax.swing.UIManager ; 26 import javax.swing.border.TitledBorder ; 27 import javax.swing.plaf.ColorUIResource ; 28 import javax.swing.plaf.FontUIResource ; 29 import javax.swing.plaf.metal.MetalLookAndFeel ; 30 31 import org.compiere.swing.CButton; 32 import org.compiere.swing.CPanel; 33 import org.compiere.util.Ini; 34 35 43 public class CompiereThemeEditor extends JDialog implements ActionListener 44 { 45 49 public CompiereThemeEditor (JDialog owner) 50 { 51 super(owner, s_res.getString("CompiereThemeEditor"), true); 52 try 53 { 54 jbInit(); 55 loadTheme(); 56 dynInit(); 57 CompierePLAF.showCenterScreen(this); 58 } 59 catch(Exception e) 60 { 61 System.err.println("CompiereThemeEditor"); 62 e.printStackTrace(); 63 } 64 } 66 static ResourceBundle s_res = ResourceBundle.getBundle("org.compiere.plaf.PlafRes"); 67 68 private CButton primary1 = new CButton(); 69 private CButton primary2 = new CButton(); 70 private CButton primary3 = new CButton(); 71 private CButton secondary1 = new CButton(); 72 private CButton secondary2 = new CButton(); 73 private CButton secondary3 = new CButton(); 74 private CButton controlFont = new CButton(); 75 private CButton systemFont = new CButton(); 76 private CButton userFont = new CButton(); 77 private CButton smallFont = new CButton(); 78 private CButton mandatory = new CButton(); 79 private CButton error = new CButton(); 80 private CButton windowFont = new CButton(); 81 private CButton menuFont = new CButton(); 82 private CButton white = new CButton(); 83 private CButton black = new CButton(); 84 private CPanel confirmPanel = new CPanel(); 85 86 private CButton inactive = new CButton(); 87 private CButton txt_ok = new CButton(); 88 private CButton txt_error = new CButton(); 89 private CButton bCancel = CompierePLAF.getCancelButton(); 90 private CButton bOK = CompierePLAF.getOKButton(); 91 private FlowLayout confirmLayout = new FlowLayout (); 92 private CPanel centerPanel = new CPanel(); 93 private CPanel metalColorPanel = new CPanel(); 94 private BorderLayout centerLayout = new BorderLayout (); 95 private CPanel compiereColorPanel = new CPanel(); 96 private TitledBorder metalColorBorder; 97 private TitledBorder compiereColorBorder; 98 private GridLayout metalColorLayout = new GridLayout (); 99 private GridLayout compiereColorLayout = new GridLayout (); 100 private CPanel fontPanel = new CPanel(); 101 private GridLayout fontLayout = new GridLayout (); 102 private TitledBorder fontBorder; 103 private CButton info = new CButton(); 104 105 109 private void jbInit() throws Exception 110 { 111 CompiereColor.setBackground(this); 112 metalColorBorder = new TitledBorder (s_res.getString("MetalColors")); 113 compiereColorBorder = new TitledBorder (s_res.getString("CompiereColors")); 114 fontBorder = new TitledBorder (s_res.getString("CompiereFonts")); 115 fontPanel.setBorder(fontBorder); 116 fontPanel.setOpaque(false); 117 118 this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 119 primary1.setToolTipText(s_res.getString("Primary1Info")); 121 primary1.setText(s_res.getString("Primary1")); 122 primary1.addActionListener(this); 123 primary2.setToolTipText(s_res.getString("Primary2Info")); 124 primary2.setText(s_res.getString("Primary2")); 125 primary2.addActionListener(this); 126 primary3.setToolTipText(s_res.getString("Primary3Info")); 127 primary3.setText(s_res.getString("Primary3")); 128 primary3.addActionListener(this); 129 secondary1.setToolTipText(s_res.getString("Secondary1Info")); 130 secondary1.setText(s_res.getString("Secondary1")); 131 secondary1.addActionListener(this); 132 secondary2.setToolTipText(s_res.getString("Secondary2Info")); 133 secondary2.setText(s_res.getString("Secondary2")); 134 secondary2.addActionListener(this); 135 secondary3.setToolTipText(s_res.getString("Secondary3Info")); 136 secondary3.setText(s_res.getString("Secondary3")); 137 secondary3.addActionListener(this); 138 controlFont.setToolTipText(s_res.getString("ControlFontInfo")); 139 controlFont.setText(s_res.getString("ControlFont")); 140 controlFont.addActionListener(this); 141 systemFont.setToolTipText(s_res.getString("SystemFontInfo")); 142 systemFont.setText(s_res.getString("SystemFont")); 143 systemFont.addActionListener(this); 144 userFont.setToolTipText(s_res.getString("UserFontInfo")); 145 userFont.setText(s_res.getString("UserFont")); 146 userFont.addActionListener(this); 147 smallFont.setText(s_res.getString("SmallFont")); 148 smallFont.addActionListener(this); 149 mandatory.setToolTipText(s_res.getString("MandatoryInfo")); 150 mandatory.setText(s_res.getString("Mandatory")); 151 mandatory.addActionListener(this); 152 error.setToolTipText(s_res.getString("ErrorInfo")); 153 error.setText(s_res.getString("Error")); 154 error.addActionListener(this); 155 info.setToolTipText(s_res.getString("InfoInfo")); 156 info.setText(s_res.getString("Info")); 157 info.addActionListener(this); 158 windowFont.setText(s_res.getString("WindowTitleFont")); 159 windowFont.addActionListener(this); 160 menuFont.setText(s_res.getString("MenuFont")); 161 menuFont.addActionListener(this); 162 white.setToolTipText(s_res.getString("WhiteInfo")); 163 white.setText(s_res.getString("White")); 164 white.addActionListener(this); 165 black.setToolTipText(s_res.getString("BlackInfo")); 166 black.setText(s_res.getString("Black")); 167 black.addActionListener(this); 168 inactive.setToolTipText(s_res.getString("InactiveInfo")); 169 inactive.setText(s_res.getString("Inactive")); 170 inactive.addActionListener(this); 171 txt_ok.setToolTipText(s_res.getString("TextOKInfo")); 172 txt_ok.setText(s_res.getString("TextOK")); 173 txt_ok.addActionListener(this); 174 txt_error.setToolTipText(s_res.getString("TextIssueInfo")); 175 txt_error.setText(s_res.getString("TextIssue")); 176 txt_error.addActionListener(this); 177 confirmPanel.setLayout(confirmLayout); 179 confirmLayout.setAlignment(FlowLayout.RIGHT); 180 centerPanel.setLayout(centerLayout); 181 metalColorPanel.setBorder(metalColorBorder); 182 metalColorPanel.setOpaque(false); 183 metalColorPanel.setLayout(metalColorLayout); 184 compiereColorPanel.setLayout(compiereColorLayout); 185 compiereColorPanel.setBorder(compiereColorBorder); 186 compiereColorPanel.setOpaque(false); 187 metalColorLayout.setColumns(3); 188 metalColorLayout.setHgap(5); 189 metalColorLayout.setRows(3); 190 metalColorLayout.setVgap(5); 191 compiereColorLayout.setColumns(4); 192 compiereColorLayout.setHgap(5); 193 compiereColorLayout.setRows(2); 194 compiereColorLayout.setVgap(5); 195 fontPanel.setLayout(fontLayout); 196 fontLayout.setColumns(3); 197 fontLayout.setHgap(5); 198 fontLayout.setRows(2); 199 fontLayout.setVgap(5); 200 centerLayout.setVgap(5); 201 fontBorder.setTitle(s_res.getString("Fonts")); 202 confirmPanel.setOpaque(false); 203 this.getContentPane().add(confirmPanel, BorderLayout.SOUTH); 204 confirmPanel.add(bCancel, null); 205 confirmPanel.add(bOK, null); 206 this.getContentPane().add(centerPanel, BorderLayout.CENTER); 207 centerPanel.add(metalColorPanel, BorderLayout.NORTH); 208 metalColorPanel.add(primary1, null); 209 metalColorPanel.add(primary2, null); 210 metalColorPanel.add(primary3, null); 211 metalColorPanel.add(secondary1, null); 212 metalColorPanel.add(secondary2, null); 213 metalColorPanel.add(secondary3, null); 214 metalColorPanel.add(white, null); 215 metalColorPanel.add(black, null); 216 centerPanel.add(compiereColorPanel, BorderLayout.CENTER); 217 compiereColorPanel.add(txt_error, null); 218 centerPanel.add(fontPanel, BorderLayout.SOUTH); 219 fontPanel.add(controlFont, null); 220 fontPanel.add(systemFont, null); 221 fontPanel.add(menuFont, null); 222 fontPanel.add(userFont, null); 223 fontPanel.add(windowFont, null); 224 fontPanel.add(smallFont, null); 225 compiereColorPanel.add(error, null); 226 compiereColorPanel.add(inactive, null); 227 compiereColorPanel.add(txt_ok, null); 228 compiereColorPanel.add(mandatory, null); 229 compiereColorPanel.add(info, null); 230 bCancel.addActionListener(this); 231 bOK.addActionListener(this); 232 } 234 237 private void loadTheme() 238 { 239 if (UIManager.getLookAndFeel() instanceof MetalLookAndFeel ) 240 { 241 CompiereTheme.setTheme(); 242 } 243 else { 245 primary1.setEnabled(false); 246 primary2.setEnabled(false); 247 primary3.setEnabled(false); 248 secondary1.setEnabled(false); 249 secondary2.setEnabled(false); 250 secondary3.setEnabled(false); 251 } 252 } 254 257 private void dynInit() 258 { 259 CompiereTheme ct = CompiereLookAndFeel.getCompiereTheme(); 261 primary1.setBackground(ct.getPrimary1()); 263 primary2.setBackground(ct.getPrimary2()); 264 primary3.setBackground(ct.getPrimary3()); 265 secondary1.setBackground(ct.getSecondary1()); 266 secondary2.setBackground(ct.getSecondary2()); 267 secondary3.setBackground(ct.getSecondary3()); 268 white.setBackground(ct.getWhite()); 270 black.setBackground(ct.getSecondary3()); 271 black.setForeground(ct.getBlack()); 272 error.setBackground(CompierePLAF.getFieldBackground_Error()); 274 mandatory.setBackground(CompierePLAF.getFieldBackground_Mandatory()); 275 inactive.setBackground(CompierePLAF.getFieldBackground_Inactive()); 276 info.setBackground(CompierePLAF.getInfoBackground()); 277 txt_ok.setBackground(CompierePLAF.getFieldBackground_Normal()); 279 txt_ok.setForeground(CompierePLAF.getTextColor_OK()); 280 txt_error.setBackground(CompierePLAF.getFieldBackground_Normal()); 281 txt_error.setForeground(CompierePLAF.getTextColor_Issue()); 282 283 controlFont.setFont(ct.getControlTextFont()); 285 systemFont.setFont(ct.getSystemTextFont()); 286 userFont.setFont(ct.getUserTextFont()); 287 smallFont.setFont(ct.getSubTextFont()); 288 menuFont.setFont(ct.getMenuTextFont()); 289 windowFont.setFont(ct.getWindowTitleFont()); 290 } 292 296 public void actionPerformed(ActionEvent e) 297 { 298 if (e.getSource() == bOK) 301 { 302 CompiereTheme.save(Ini.getProperties()); 303 dispose(); 304 return; 305 } 306 else if (e.getSource() == bCancel) 308 { 309 dispose(); 310 return; 311 } 312 CompiereTheme vt = new CompiereTheme(); 313 314 try { 316 if (e.getSource() == primary1) 317 { 318 CompiereTheme.primary1 = new ColorUIResource (JColorChooser.showDialog 319 (this, s_res.getString("Primary1"), CompiereTheme.primary1)); 320 } 321 else if (e.getSource() == primary2) 322 { 323 CompiereTheme.primary2 = new ColorUIResource (JColorChooser.showDialog 324 (this, s_res.getString("Primary2"), CompiereTheme.primary2)); 325 } 326 else if (e.getSource() == primary3) 327 { 328 CompiereTheme.primary3 = new ColorUIResource (JColorChooser.showDialog 329 (this, s_res.getString("Primary3"), CompiereTheme.primary3)); 330 } 331 else if (e.getSource() == secondary1) 332 { 333 CompiereTheme.secondary1 = new ColorUIResource (JColorChooser.showDialog 334 (this, s_res.getString("Secondary1"), CompiereTheme.secondary1)); 335 } 336 else if (e.getSource() == secondary2) 337 { 338 CompiereTheme.secondary2 = new ColorUIResource (JColorChooser.showDialog 339 (this, s_res.getString("Secondary2"), CompiereTheme.secondary2)); 340 } 341 else if (e.getSource() == secondary3) 342 { 343 CompiereTheme.secondary3 = new ColorUIResource (JColorChooser.showDialog 344 (this, s_res.getString("Secondary3"), CompiereTheme.secondary3)); 345 } 346 347 else if (e.getSource() == error) 348 { 349 CompiereTheme.error = new ColorUIResource (JColorChooser.showDialog 350 (this, s_res.getString("Error"), CompiereTheme.error)); 351 } 352 else if (e.getSource() == mandatory) 353 { 354 CompiereTheme.mandatory = new ColorUIResource (JColorChooser.showDialog 355 (this, s_res.getString("Mandatory"), CompiereTheme.mandatory)); 356 } 357 else if (e.getSource() == inactive) 358 { 359 CompiereTheme.inactive = new ColorUIResource (JColorChooser.showDialog 360 (this, s_res.getString("Inactive"), CompiereTheme.inactive)); 361 } 362 else if (e.getSource() == info) 363 { 364 CompiereTheme.info = new ColorUIResource (JColorChooser.showDialog 365 (this, s_res.getString("Info"), CompiereTheme.info)); 366 } 367 368 else if (e.getSource() == black) 369 { 370 CompiereTheme.black = new ColorUIResource (JColorChooser.showDialog 371 (this, s_res.getString("Black"), CompiereTheme.black)); 372 } 373 else if (e.getSource() == white) 374 { 375 CompiereTheme.white = new ColorUIResource (JColorChooser.showDialog 376 (this, s_res.getString("White"), CompiereTheme.white)); 377 } 378 else if (e.getSource() == txt_ok) 379 { 380 CompiereTheme.txt_ok = new ColorUIResource (JColorChooser.showDialog 381 (this, s_res.getString("TextOK"), CompiereTheme.txt_ok)); 382 } 383 else if (e.getSource() == txt_error) 384 { 385 CompiereTheme.txt_error = new ColorUIResource (JColorChooser.showDialog 386 (this, s_res.getString("TextIssue"), CompiereTheme.txt_error)); 387 } 388 389 else if (e.getSource() == controlFont) 390 { 391 CompiereTheme.controlFont = new FontUIResource (FontChooser.showDialog 392 (this, s_res.getString("ControlFont"), vt.getControlTextFont())); 393 } 394 else if (e.getSource() == systemFont) 395 { 396 CompiereTheme.systemFont = new FontUIResource (FontChooser.showDialog 397 (this, s_res.getString("SystemFont"), vt.getSystemTextFont())); 398 } 399 else if (e.getSource() == userFont) 400 { 401 CompiereTheme.userFont = new FontUIResource (FontChooser.showDialog 402 (this, s_res.getString("UserFont"), vt.getUserTextFont())); 403 } 404 else if (e.getSource() == smallFont) 405 { 406 CompiereTheme.smallFont = new FontUIResource (FontChooser.showDialog 407 (this, s_res.getString("SmallFont"), vt.getSubTextFont())); 408 } 409 else if (e.getSource() == menuFont) 410 { 411 CompiereTheme.menuFont = new FontUIResource (FontChooser.showDialog 412 (this, s_res.getString("MenuFont"), vt.getMenuTextFont())); 413 } 414 else if (e.getSource() == windowFont) 415 { 416 CompiereTheme.windowFont = new FontUIResource (FontChooser.showDialog 417 (this, s_res.getString("WindowTitleFont"), vt.getWindowTitleFont())); 418 } 419 420 } catch (Exception ee) {} 422 dynInit(); 423 } 425 } | Popular Tags |