📄 compieretheme.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.plaf;
import java.io.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.metal.*;
import sun.awt.AppContext;
import org.compiere.util.Ini;
/**
* Compiere User definable Theme (if used in Metal L&F).
* In other Environments, it provides UI extensions (e.g. Error Color)
*
* @author Jorg Janke
* @version $Id: CompiereTheme.java,v 1.9 2002/08/12 01:55:15 danb Exp $
*/
public class CompiereTheme extends MetalTheme
{
/**
* Constructor - nop
*/
public CompiereTheme()
{
} // CompiereTheme
/**
* Return Theme Name
* @return Theme Name
*/
public String getName()
{
return NAME;
} // getName
public static final String NAME = "Compiere Theme";
/** Blue 51,51,102 */
protected static ColorUIResource primary0 = new ColorUIResource(51, 51, 102);
/** Blue 102, 102, 153 */
protected static ColorUIResource primary1;
/** Blue 153, 153, 204 */
protected static ColorUIResource primary2;
/** Blue 204, 204, 255 */
protected static ColorUIResource primary3;
/** Black */
protected final ColorUIResource secondary0 = new ColorUIResource(0, 0, 0);
/** Gray 102, 102, 102 */
protected static ColorUIResource secondary1;
/** Gray 153, 153, 153 */
protected static ColorUIResource secondary2;
/** Gray 204, 204, 204 */
protected static ColorUIResource secondary3;
/** White */
protected final ColorUIResource secondary4 = new ColorUIResource(255, 255, 255);
/** Black */
protected static ColorUIResource black;
/** White */
protected static ColorUIResource white;
/** Background for mandatory fields */
protected static ColorUIResource mandatory;
/** Background for fields in error */
protected static ColorUIResource error;
/** Background for inactive fields */
protected static ColorUIResource inactive;
/** Background for info fields */
protected static ColorUIResource info;
/** Foreground Text OK */
protected static ColorUIResource txt_ok;
/** Foreground Text Error */
protected static ColorUIResource txt_error;
/** Control font */
protected static FontUIResource controlFont;
/** System font */
protected static FontUIResource systemFont;
/** User font */
protected static FontUIResource userFont;
/** Small font */
protected static FontUIResource smallFont;
/** Window Title font */
protected static FontUIResource windowFont;
/** Menu font */
protected static FontUIResource menuFont;
/** Default Font */
public static final String FONT_DEFAULT = "Dialog";
/** Default Font Size */
public static final int FONT_SIZE = 12;
/**
* Set Defaults
*/
private static void setDefault ()
{
/** Blue 102, 102, 153 */
primary1 = new ColorUIResource(102, 102, 153);
/** Blue 153, 153, 204 */
primary2 = new ColorUIResource(153, 153, 204);
/** Blue 204, 204, 255 */
primary3 = new ColorUIResource(204, 204, 255);
/** Gray 102, 102, 102 */
secondary1 = new ColorUIResource(102, 102, 102);
/** Gray 153, 153, 153 */
secondary2 = new ColorUIResource(153, 153, 153);
/** Gray 204, 204, 204 */
secondary3 = new ColorUIResource(204, 204, 204);
/** Black */
black = new ColorUIResource(Color.black);
/** White */
white = new ColorUIResource(Color.white);
/** Background for mandatory fields */
mandatory = new ColorUIResource(224, 224, 255); // blue-isch
/** Background for fields in error */
error = new ColorUIResource(255, 204, 204); // red-isch
/** Background for inactive fields */
inactive = new ColorUIResource(234, 234, 234); // light gray
/** Background for info fields */
info = new ColorUIResource(253, 237, 207); // light yellow
/** Foreground Text OK */
txt_ok = new ColorUIResource(51, 51, 102); // dark blue
/** Foreground Text Error */
txt_error = new ColorUIResource(204, 0, 0); // dark red
/** Control font */
controlFont = null;
_getControlTextFont();
/** System font */
systemFont = null;
_getSystemTextFont();
/** User font */
userFont = null;
_getUserTextFont();
/** Small font */
smallFont = null;
_getSubTextFont();
/** Window Title font */
windowFont = null;
_getWindowTitleFont();
/** Menu font */
menuFont = null;
_getMenuTextFont();
} // setDefault
/**
* Static Init
*/
static
{
setDefault();
}
/**
* Set Theme to current Metal Theme and copy it
*/
public static void setTheme ()
{
AppContext context = AppContext.getAppContext();
MetalTheme copyFrom = (MetalTheme)context.get("currentMetalTheme");
setTheme (copyFrom);
} // setTheme
/**
* Set Theme to current Metal Theme and copy it
* @param copyFrom
*/
public static void setTheme (MetalTheme copyFrom)
{
if (copyFrom == null || copyFrom instanceof CompiereTheme)
return;
// May not be correct, if Themes overwrites default methods
primary1 = copyFrom.getPrimaryControlDarkShadow();
primary2 = copyFrom.getPrimaryControlShadow();
primary3 = copyFrom.getPrimaryControl();
secondary1 = copyFrom.getControlDarkShadow();
secondary2 = copyFrom.getControlShadow();
secondary3 = copyFrom.getControl();
CompierePanelUI.setDefaultBackground(new CompiereColor(secondary3, true));
white = copyFrom.getPrimaryControlHighlight();
black = copyFrom.getPrimaryControlInfo();
//
controlFont = copyFrom.getControlTextFont();
systemFont = copyFrom.getSystemTextFont();
userFont = copyFrom.getUserTextFont();
smallFont = copyFrom.getSubTextFont();
menuFont = copyFrom.getMenuTextFont();
windowFont = copyFrom.getWindowTitleFont();
} // setTheme
/*************************************************************************/
/**
* Get Primary 1 (blue in default Metal Theme)
* @return color
*/
public ColorUIResource getPrimary1()
{
return ColorBlind.getDichromatColorUIResource(primary1);
}
public ColorUIResource getPrimary2()
{
return ColorBlind.getDichromatColorUIResource(primary2);
}
public ColorUIResource getPrimary3()
{
return ColorBlind.getDichromatColorUIResource(primary3);
}
/**
* Get Seconary 1 (gray in default Metal Theme)
* @return color
*/
public ColorUIResource getSecondary0()
{
return ColorBlind.getDichromatColorUIResource(secondary0);
}
public ColorUIResource getSecondary1()
{
return ColorBlind.getDichromatColorUIResource(secondary1);
}
public ColorUIResource getSecondary2()
{
return ColorBlind.getDichromatColorUIResource(secondary2);
}
public ColorUIResource getSecondary3()
{
return ColorBlind.getDichromatColorUIResource(secondary3);
}
public ColorUIResource getSecondary4()
{
return ColorBlind.getDichromatColorUIResource(secondary4);
}
public ColorUIResource getBlack()
{
return ColorBlind.getDichromatColorUIResource(black);
}
public ColorUIResource getWhite()
{
return ColorBlind.getDichromatColorUIResource(white);
}
/**
* Control Font (plain)
* @return font
*/
private static FontUIResource _getControlTextFont()
{
if (controlFont == null)
{
try
{
controlFont = new FontUIResource(Font.getFont("swing.plaf.metal.controlFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
}
catch (Exception e)
{
controlFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
}
}
return controlFont;
}
public FontUIResource getControlTextFont() {return _getControlTextFont();}
/**
* System Font
* @return font
*/
private static FontUIResource _getSystemTextFont()
{
if (systemFont == null)
{
try
{
systemFont = new FontUIResource(Font.getFont("swing.plaf.metal.systemFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
}
catch (Exception e)
{
systemFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
}
}
return systemFont;
}
public FontUIResource getSystemTextFont() {return _getSystemTextFont();}
/**
* User Font
* @return font
*/
private static FontUIResource _getUserTextFont()
{
if (userFont == null)
{
try
{
userFont = new FontUIResource(Font.getFont("swing.plaf.metal.userFont",
new Font(FONT_DEFAULT, Font.PLAIN, FONT_SIZE)));
}
catch (Exception e)
{
userFont = new FontUIResource(FONT_DEFAULT, Font.PLAIN, FONT_SIZE);
}
}
return userFont;
}
public FontUIResource getUserTextFont() {return _getUserTextFont();}
/**
* Menu
* @return font
*/
private static FontUIResource _getMenuTextFont()
{
if (menuFont == null)
{
try
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -