下面列出了怎么用javax.swing.plaf.InsetsUIResource的API类实例代码及写法,或者点击链接到github查看源代码。
public void register(ConverterRegistry registry) {
registry.addConverter(Dimension.class, String.class, this);
registry.addConverter(String.class, Dimension.class, this);
registry.addConverter(DimensionUIResource.class, String.class, this);
registry.addConverter(Insets.class, String.class, this);
registry.addConverter(String.class, Insets.class, this);
registry.addConverter(InsetsUIResource.class, String.class, this);
registry.addConverter(Point.class, String.class, this);
registry.addConverter(String.class, Point.class, this);
registry.addConverter(Rectangle.class, String.class, this);
registry.addConverter(String.class, Rectangle.class, this);
registry.addConverter(Font.class, String.class, this);
registry.addConverter(FontUIResource.class, String.class, this);
}
public AdrManagerFrame(AdrProfileDescriptor selectedProfile) {
super();
this.processingHideEvent = false;
this.setTitle("MercuryTrade ADR");
this.setFocusable(true);
this.setFocusableWindowState(true);
this.setAlwaysOnTop(false);
this.selectedProfile = selectedProfile;
this.exportDialog = new AdrExportDialog(this, new ArrayList<>());
this.iconSelectDialog = new AdrIconSelectDialog();
this.iconSelectDialog.setLocationRelativeTo(null);
FrameDescriptor frameDescriptor = this.framesConfig.get(this.getClass().getSimpleName());
this.setPreferredSize(frameDescriptor.getFrameSize());
UIManager.put("MenuItem.background", AppThemeColor.ADR_BG);
UIManager.put("MenuItem.selectionBackground", AppThemeColor.ADR_POPUP_BG);
UIManager.put("Menu.contentMargins", new InsetsUIResource(2, 0, 2, 0));
UIManager.put("MenuItem.opaque", true);
UIManager.put("ComboBox.selectionBackground", AppThemeColor.HEADER);
UIManager.put("ComboBox.selectionForeground", AppThemeColor.ADR_POPUP_BG);
UIManager.put("ComboBox.disabledForeground", AppThemeColor.ADR_FOOTER_BG);
}
protected void initComponentDefaults(UIDefaults table) {
super.initComponentDefaults( table );
// I'll have to copy some of the resource definitions here, since the
// original code in BasicLookAndFeel (from which we inherit) uses
// getClass() to find its resources. That will fail since my
// classloader does not have these resources.
//
// So, the trick is to replace getClass() with MetalLookAndFeel.class
Object[] defaults = {
"OptionPane.errorIcon", LookAndFeel.makeIcon(MetalLookAndFeel.class, "icons/Error.gif"),
"OptionPane.informationIcon", LookAndFeel.makeIcon(MetalLookAndFeel.class, "icons/Inform.gif"),
"OptionPane.warningIcon", LookAndFeel.makeIcon(MetalLookAndFeel.class, "icons/Warn.gif"),
"OptionPane.questionIcon", LookAndFeel.makeIcon(MetalLookAndFeel.class, "icons/Question.gif"),
"InternalFrame.icon", LookAndFeel.makeIcon(BasicLookAndFeel.class, "icons/JavaCup.gif"),
// Button margin slightly smaller than metal to save space
"Button.margin", new InsetsUIResource(1, 11, 1, 11),
};
table.putDefaults(defaults);
}
/**
* 因Windos LNF会在Vista及更新的操作系统(如win7)上对Windows LNF作附加设置,
* 以保证与Vista及更新平台的外观的一致性(如让菜单菜项高度更大等),请参见
* WindowsLookAndFeel.initVistaComponentDefaults(..)。
* <p>
* BeautyEye中因需要保证审美一致性(在所有win平台上)而不需要这些额外的设置,
* 但因该方法是private私有方法,无法进行覆盖屏蔽,所以只能在此单列方法,以便针对Vista
* 及更新的平台进行补救性重新设置以便与BeautyEye LNF的审核进行适配.
*
* @see WindowsLookAndFeel.initVistaComponentDefaults(..)
*/
protected void initForVista()
{
if(WinUtils.isOnVista())
{
UIManager.put("CheckBoxMenuItem.margin",new InsetsUIResource(0,0,0,0));
UIManager.put("RadioButtonMenuItem.margin",new InsetsUIResource(0,0,0,0));
UIManager.put("Menu.margin",new InsetsUIResource(0,0,0,0));//windows lnf xp中默认是2,2,2,2
UIManager.put("MenuItem.margin",new InsetsUIResource(0,0,0,0));//windows lnf中 xp默认是2,2,2,2
UIManager.put("Menu.border",new BorderUIResource(BorderFactory.createEmptyBorder(1,3,2,3)));//javax.swing.plaf.basic.BasicBorders.MarginBorder;
UIManager.put("MenuItem.border",new BorderUIResource(BorderFactory.createEmptyBorder(1,0,2,0)));//javax.swing.plaf.basic.BasicBorders.MarginBorder;
UIManager.put("CheckBoxMenuItem.border",new BorderUIResource(BorderFactory.createEmptyBorder(4,2,4,2)));//javax.swing.plaf.basic.BasicBorders.MarginBorder;
UIManager.put("RadioButtonMenuItem.border",new BorderUIResource(BorderFactory.createEmptyBorder(4,0,4,0)));//javax.swing.plaf.basic.BasicBorders.MarginBorder;
// UIManager.put("PopupMenu.border",new BorderUIResource(BorderFactory.createEmptyBorder(20,10,20,10)));//
UIManager.put("CheckBoxMenuItem.checkIcon"
,new org.jb2011.lnf.beautyeye.ch9_menu.BECheckBoxMenuItemUI.CheckBoxMenuItemIcon().setUsedForVista(true));//javax.swing.plaf.basic.BasicIconFactory.CheckBoxMenuItemIcon);
UIManager.put("RadioButtonMenuItem.checkIcon"
,new org.jb2011.lnf.beautyeye.ch9_menu.BERadioButtonMenuItemUI.RadioButtonMenuItemIcon().setUsedForVista(true));
}
}
/**
* Ui impl.
*/
public static void uiImpl()
{
// UIManager.put("CheckBox.border",new BorderUIResource(new BERoundBorder().setArcWidth(0)));
UIManager.put("CheckBox.margin",new InsetsUIResource(4,3,4,3));
UIManager.put("RadioButton.margin",new InsetsUIResource(4,3,4,3));//2, 2, 2, 2));
UIManager.put("RadioButton.background",new ColorUIResource(BeautyEyeLNFHelper.commonBackgroundColor));
UIManager.put("CheckBox.background",new ColorUIResource(BeautyEyeLNFHelper.commonBackgroundColor));
UIManager.put("CheckBox.foreground",new ColorUIResource(BeautyEyeLNFHelper.commonForegroundColor));
UIManager.put("RadioButton.foreground",new ColorUIResource(BeautyEyeLNFHelper.commonForegroundColor));
UIManager.put("RadioButton.icon", new RadioButtonIcon());
UIManager.put("CheckBox.icon", new CheckBoxIcon());
//衬距设定
UIManager.put("RadioButton.margin", new InsetsUIResource(1,1,1,1));//默认是2,2,2,2
UIManager.put("CheckBox.margin", new InsetsUIResource(1,1,1,1));//默认是2,2,2,2
}
private void defineOptionPane(UIDefaults d) {
//Initialize OptionPane
d.put("OptionPane.contentMargins", new InsetsUIResource(15, 15, 15, 15));
d.put("OptionPane.opaque", Boolean.TRUE);
d.put("OptionPane.background", getDerivedColor("control", 0, 0, 0, 0, true));
d.put("OptionPane.buttonOrientation", new Integer(4));
d.put("OptionPane.messageAnchor", new Integer(17));
d.put("OptionPane.separatorPadding", new Integer(0));
d.put("OptionPane.sameSizeButtons", Boolean.FALSE);
d.put("OptionPane:\"OptionPane.separator\".contentMargins", new InsetsUIResource(1, 0, 0, 0));
d.put("OptionPane:\"OptionPane.messageArea\".contentMargins", new InsetsUIResource(0, 0, 10, 0));
d.put("OptionPane:\"OptionPane.messageArea\":\"OptionPane.label\".contentMargins", new InsetsUIResource(0, 10, 10, 10));
d.put("OptionPane[Enabled].errorIconPainter", new LazyPainter("com.seaglasslookandfeel.painter.OptionPanePainter", OptionPanePainter.Which.ERRORICON_ENABLED));
d.put("OptionPane.errorIcon", new SeaGlassIcon("OptionPane", "errorIconPainter", 48, 48));
d.put("OptionPane[Enabled].informationIconPainter", new LazyPainter("com.seaglasslookandfeel.painter.OptionPanePainter", OptionPanePainter.Which.INFORMATIONICON_ENABLED));
d.put("OptionPane.informationIcon", new SeaGlassIcon("OptionPane", "informationIconPainter", 48, 48));
d.put("OptionPane[Enabled].questionIconPainter", new LazyPainter("com.seaglasslookandfeel.painter.OptionPanePainter", OptionPanePainter.Which.QUESTIONICON_ENABLED));
d.put("OptionPane.questionIcon", new SeaGlassIcon("OptionPane", "questionIconPainter", 48, 48));
d.put("OptionPane[Enabled].warningIconPainter", new LazyPainter("com.seaglasslookandfeel.painter.OptionPanePainter", OptionPanePainter.Which.WARNINGICON_ENABLED));
d.put("OptionPane.warningIcon", new SeaGlassIcon("OptionPane", "warningIconPainter", 48, 48));
// Color Chooser Dialog
d.put("ColorChooser.swatchesDefaultRecentColor", getDerivedColor("control", 0, 0, 0, 0, true));
}
private void defineFileChooser(UIDefaults d) {
//Initialize FileChooser
d.put("FileChooser.contentMargins", new InsetsUIResource(10, 10, 10, 10));
d.put("FileChooser.opaque", Boolean.TRUE);
d.put("FileChooser.usesSingleFilePane", Boolean.TRUE);
d.put("FileChooser[Enabled].fileIconPainter", new LazyPainter("com.seaglasslookandfeel.painter.FileChooserPainter", FileChooserPainter.Which.FILEICON_ENABLED));
d.put("FileChooser.fileIcon", new SeaGlassIcon("FileChooser", "fileIconPainter", 16, 16));
d.put("FileChooser[Enabled].directoryIconPainter", new LazyPainter("com.seaglasslookandfeel.painter.FileChooserPainter", FileChooserPainter.Which.DIRECTORYICON_ENABLED));
d.put("FileChooser.directoryIcon", new SeaGlassIcon("FileChooser", "directoryIconPainter", 16, 16));
d.put("FileChooser[Enabled].upFolderIconPainter", new LazyPainter("com.seaglasslookandfeel.painter.FileChooserPainter", FileChooserPainter.Which.UPFOLDERICON_ENABLED));
d.put("FileChooser.upFolderIcon", new SeaGlassIcon("FileChooser", "upFolderIconPainter", 16, 16));
d.put("FileChooser[Enabled].newFolderIconPainter", new LazyPainter("com.seaglasslookandfeel.painter.FileChooserPainter", FileChooserPainter.Which.NEWFOLDERICON_ENABLED));
d.put("FileChooser.newFolderIcon", new SeaGlassIcon("FileChooser", "newFolderIconPainter", 16, 16));
d.put("FileChooser[Enabled].hardDriveIconPainter", new LazyPainter("com.seaglasslookandfeel.painter.FileChooserPainter", FileChooserPainter.Which.HARDDRIVEICON_ENABLED));
d.put("FileChooser.hardDriveIcon", new SeaGlassIcon("FileChooser", "hardDriveIconPainter", 16, 16));
d.put("FileChooser[Enabled].floppyDriveIconPainter", new LazyPainter("com.seaglasslookandfeel.painter.FileChooserPainter", FileChooserPainter.Which.FLOPPYDRIVEICON_ENABLED));
d.put("FileChooser.floppyDriveIcon", new SeaGlassIcon("FileChooser", "floppyDriveIconPainter", 16, 16));
d.put("FileChooser[Enabled].homeFolderIconPainter", new LazyPainter("com.seaglasslookandfeel.painter.FileChooserPainter", FileChooserPainter.Which.HOMEFOLDERICON_ENABLED));
d.put("FileChooser.homeFolderIcon", new SeaGlassIcon("FileChooser", "homeFolderIconPainter", 16, 16));
d.put("FileChooser[Enabled].detailsViewIconPainter", new LazyPainter("com.seaglasslookandfeel.painter.FileChooserPainter", FileChooserPainter.Which.DETAILSVIEWICON_ENABLED));
d.put("FileChooser.detailsViewIcon", new SeaGlassIcon("FileChooser", "detailsViewIconPainter", 16, 16));
d.put("FileChooser[Enabled].listViewIconPainter", new LazyPainter("com.seaglasslookandfeel.painter.FileChooserPainter", FileChooserPainter.Which.LISTVIEWICON_ENABLED));
d.put("FileChooser.listViewIcon", new SeaGlassIcon("FileChooser", "listViewIconPainter", 16, 16));
}
/**
* Initialize the internal frame close button settings.
*
* @param d the UI defaults map.
*/
private void defineInternalFrameCloseButtons(UIDefaults d) {
String p = "InternalFrame:InternalFrameTitlePane:\"InternalFrameTitlePane.closeButton\"";
String c = PAINTER_PREFIX + "TitlePaneCloseButtonPainter";
// Set the multiplicity of states for the Close button.
d.put(p + ".States", "Enabled,MouseOver,Pressed,Disabled,Focused,Selected,WindowNotFocused");
d.put(p + ".WindowNotFocused", new TitlePaneCloseButtonWindowNotFocusedState());
d.put(p + ".contentMargins", new InsetsUIResource(0, 0, 0, 0));
d.put(p + "[Disabled].backgroundPainter", new LazyPainter(c, TitlePaneCloseButtonPainter.Which.BACKGROUND_DISABLED));
d.put(p + "[Enabled].backgroundPainter", new LazyPainter(c, TitlePaneCloseButtonPainter.Which.BACKGROUND_ENABLED));
d.put(p + "[MouseOver].backgroundPainter", new LazyPainter(c, TitlePaneCloseButtonPainter.Which.BACKGROUND_MOUSEOVER));
d.put(p + "[Pressed].backgroundPainter", new LazyPainter(c, TitlePaneCloseButtonPainter.Which.BACKGROUND_PRESSED));
d.put(p + "[Enabled+WindowNotFocused].backgroundPainter", new LazyPainter(c, TitlePaneCloseButtonPainter.Which.BACKGROUND_ENABLED_WINDOWNOTFOCUSED));
d.put(p + "[MouseOver+WindowNotFocused].backgroundPainter", new LazyPainter(c, TitlePaneCloseButtonPainter.Which.BACKGROUND_MOUSEOVER));
d.put(p + "[Pressed+WindowNotFocused].backgroundPainter", new LazyPainter(c, TitlePaneCloseButtonPainter.Which.BACKGROUND_PRESSED_WINDOWNOTFOCUSED));
d.put(p + ".icon", new SeaGlassIcon(p, "iconPainter", 43, 18));
}
/**
* Initialize the internal frame menu button settings.
*
* @param d the UI defaults map.
*/
private void defineInternalFrameMenuButtons(UIDefaults d) {
String p = "InternalFrame:InternalFrameTitlePane:\"InternalFrameTitlePane.menuButton\"";
String c = PAINTER_PREFIX + "TitlePaneMenuButtonPainter";
d.put(p + ".WindowNotFocused", new TitlePaneMenuButtonWindowNotFocusedState());
d.put(p + ".contentMargins", new InsetsUIResource(0, 0, 0, 0));
// Set the states for the Menu button.
d.put(p + "[Enabled].iconPainter", new LazyPainter(c, TitlePaneMenuButtonPainter.Which.ICON_ENABLED));
d.put(p + "[Disabled].iconPainter", new LazyPainter(c, TitlePaneMenuButtonPainter.Which.ICON_DISABLED));
d.put(p + "[MouseOver].iconPainter", new LazyPainter(c, TitlePaneMenuButtonPainter.Which.ICON_MOUSEOVER));
d.put(p + "[Pressed].iconPainter", new LazyPainter(c, TitlePaneMenuButtonPainter.Which.ICON_PRESSED));
d.put(p + "[Enabled+WindowNotFocused].iconPainter",
new LazyPainter(c,
TitlePaneMenuButtonPainter.Which.ICON_ENABLED_WINDOWNOTFOCUSED));
d.put(p + "[MouseOver+WindowNotFocused].iconPainter",
new LazyPainter(c,
TitlePaneMenuButtonPainter.Which.ICON_MOUSEOVER_WINDOWNOTFOCUSED));
d.put(p + "[Pressed+WindowNotFocused].iconPainter",
new LazyPainter(c,
TitlePaneMenuButtonPainter.Which.ICON_PRESSED_WINDOWNOTFOCUSED));
d.put(p + ".icon", new SeaGlassIcon(p, "iconPainter", 19, 18));
}
/**
* Initialize the popup settings.
*
* @param d the UI defaults map.
*/
private void definePopups(UIDefaults d) {
d.put("seaGlassPopupBorder", new ColorUIResource(0xbbbbbb));
d.put("popupMenuInteriorEnabled", Color.WHITE);
// Rossi: Changed color of popup / submenus to get better contrast to bright backgrounds.
// d.put("popupMenuBorderEnabled", new Color(0xdddddd));
d.put("popupMenuBorderEnabled", new Color(0x5b7ea4));
String c = PAINTER_PREFIX + "PopupMenuPainter";
String p = "PopupMenu";
d.put(p + ".contentMargins", new InsetsUIResource(6, 1, 6, 1));
d.put(p + ".opaque", Boolean.TRUE);
d.put(p + ".consumeEventOnClose", Boolean.TRUE);
d.put(p + "[Disabled].backgroundPainter", new LazyPainter(c, PopupMenuPainter.Which.BACKGROUND_DISABLED));
d.put(p + "[Enabled].backgroundPainter", new LazyPainter(c, PopupMenuPainter.Which.BACKGROUND_ENABLED));
// Initialize PopupMenuSeparator
c = PAINTER_PREFIX + "SeparatorPainter";
p = "PopupMenuSeparator";
d.put(p + ".contentMargins", new InsetsUIResource(1, 0, 2, 0));
d.put(p + "[Enabled].backgroundPainter", new LazyPainter(c, SeparatorPainter.Which.BACKGROUND_ENABLED));
}
/**
* Initialize the scroll pane UI
* @param d
*/
private void defineScrollPane(UIDefaults d) {
// Define ScrollPane border painters.
String c = PAINTER_PREFIX + "ScrollPanePainter";
String p = "ScrollPane";
d.put(p + ".opaque", Boolean.FALSE);
d.put(p + ".contentMargins", new InsetsUIResource(3, 3, 3, 3));
// d.put(p + ".useChildTextComponentFocus", Boolean.TRUE);
d.put(p + ".backgroundPainter", new LazyPainter(c, ScrollPanePainter.Which.BACKGROUND_ENABLED));
d.put(p + "[Enabled+Focused].borderPainter", new LazyPainter(c, ScrollPanePainter.Which.BORDER_ENABLED_FOCUSED));
d.put(p + "[Enabled].borderPainter", new LazyPainter(c, ScrollPanePainter.Which.BORDER_ENABLED));
// Store ScrollPane Corner Component
d.put(p + ".cornerPainter", new LazyPainter(c, ScrollPanePainter.Which.CORNER_ENABLED));
//Initialize Viewport
p = "Viewport";
d.put(p + ".contentMargins", new InsetsUIResource(0, 0, 0, 0));
d.put(p + ".opaque", Boolean.TRUE);
}
public void register(ConverterRegistry registry) {
registry.addConverter(Dimension.class, String.class, this);
registry.addConverter(String.class, Dimension.class, this);
registry.addConverter(DimensionUIResource.class, String.class, this);
registry.addConverter(Insets.class, String.class, this);
registry.addConverter(String.class, Insets.class, this);
registry.addConverter(InsetsUIResource.class, String.class, this);
registry.addConverter(Point.class, String.class, this);
registry.addConverter(String.class, Point.class, this);
registry.addConverter(Rectangle.class, String.class, this);
registry.addConverter(String.class, Rectangle.class, this);
registry.addConverter(Font.class, String.class, this);
registry.addConverter(FontUIResource.class, String.class, this);
}
private static void createAndShowGui() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Insets m = UIManager.getInsets("TextField.margin");
UIManager.put("TextField.margin", new InsetsUIResource(m.top, m.left + 5, m.bottom, m.right));
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
Toolkit.getDefaultToolkit().beep();
}
JFrame frame = new JFrame("@[email protected]");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.getContentPane().add(new MainPanel());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private static Object parseInsets(final String value,
final Map<Object, Object> accumulator,
final UIDefaults currentDefaults, final IconLoader iconLoader) {
List<Integer> insets = parseList((SimpleValueMapper<Integer>) Integer::parseInt, value, accumulator,
currentDefaults, iconLoader, Character.MIN_VALUE, Character.MIN_VALUE,
SEPARATOR);
return new InsetsUIResource(insets.get(0), insets.get(1), insets.get(2), insets.get(3));
}
@Override
public Insets getBorderInsets(final Component c) {
if (SpinnerConstants.isTreeOrTableCellEditor(c)) {
return CellUtil.adjustEditorInsets(new InsetsUIResource(cellInsets.top, cellInsets.left,
cellInsets.bottom, cellInsets.right),
c);
}
return new InsetsUIResource(insets.top, insets.left, insets.bottom, insets.right);
}
@Override
public Insets getBorderInsets(final Component c) {
if (c instanceof JInternalFrame && ((JInternalFrame) c).isMaximum()) {
return new InsetsUIResource(0, 0, 0, 0);
}
updateOpacity(c);
return super.getBorderInsets(c);
}
public Insets getBorderInsets(final Component c) {
if (ButtonConstants.isBorderlessRectangular(c)) {
return new InsetsUIResource(borderlessRectangularInsets.top, borderlessRectangularInsets.left,
borderlessRectangularInsets.bottom, borderlessRectangularInsets.right);
}
boolean shadowVariant = ButtonConstants.isBorderless(c);
int shadow = shadowVariant ? 0 : getShadowSize();
boolean square = ButtonConstants.isSquare(c);
Insets pad = ButtonConstants.isThin(c)
? square ? squareThinInsets : thinInsets
: square ? squareInsets : insets;
return maskInsets(new InsetsUIResource(pad.top, pad.left, pad.bottom, pad.right), c, shadow);
}
@Override
public Insets getBorderInsets(final Component c) {
if (ComboBoxConstants.isTreeOrTableCellEditor(c)) {
return CellUtil.adjustEditorInsets(new InsetsUIResource(cellPadding.top, cellPadding.left,
cellPadding.bottom, cellPadding.right),
c);
}
if (c.getComponentOrientation().isLeftToRight()) {
return new InsetsUIResource(boxPadding.top, boxPadding.left, boxPadding.bottom, borderSize);
} else {
return new InsetsUIResource(boxPadding.top, borderSize, boxPadding.bottom, boxPadding.right);
}
}
/**
* Create new TextBubbleBorder.
*
* @param color Colour of bubble.
* @param thickness Line thickness of border.
* @param radius corner radius of border.
* @param pointerSize size of pointer. You can set this size to 0 to achieve no pointer, but it is not desirable.
* The appropriate method for this is to set using {@link BubbleBorder#setPointerSide(Alignment)}
* to. {@link Alignment#CENTER}
*/
public BubbleBorder(final Color color, final int thickness,
final int radius, final int pointerSize) {
this.color = color;
this.thickness = thickness;
this.radius = radius;
this.pointerSize = pointerSize;
this.pointerWidth = pointerSize;
insets = new InsetsUIResource(0, 0, 0, 0);
setThickness(thickness);
}
public static Insets scale( Insets insets ) {
initialize();
return (insets == null || scaleFactor == 1f)
? insets
: (insets instanceof UIResource
? new InsetsUIResource( scale( insets.top ), scale( insets.left ), scale( insets.bottom ), scale( insets.right ) )
: new Insets ( scale( insets.top ), scale( insets.left ), scale( insets.bottom ), scale( insets.right ) ));
}
private static Insets parseInsets( String value ) {
List<String> numbers = split( value, ',' );
try {
return new InsetsUIResource(
Integer.parseInt( numbers.get( 0 ) ),
Integer.parseInt( numbers.get( 1 ) ),
Integer.parseInt( numbers.get( 2 ) ),
Integer.parseInt( numbers.get( 3 ) ) );
} catch( NumberFormatException ex ) {
throw new IllegalArgumentException( "invalid insets '" + value + "'" );
}
}
private void initUIPrefs() {
UIManager.put("TabbedPane.contentBorderInsets",
new InsetsUIResource(0, 0, 0, 0));
UIManager.put("TabbedPane.focus", new Color(162, 184, 205));
UIManager.put("TabbedPane.darkShadow", Color.DARK_GRAY);
UIManager.put("TabbedPane.borderHightlightColor", Color.GRAY);
UIManager.put("TabbedPane.light", Color.LIGHT_GRAY);
UIManager.put("TabbedPane.selected", Color.DARK_GRAY);
}
public WhylineTabbedPane() {
super();
setUI(new WhylineTabbedPaneUI());
setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
setFocusable(false);
// Code to respond to clicks on the close icon in a tab.
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
int index = indexAtLocation(e.getX(), e.getY());
if(index == getSelectedIndex()) {
Icon icon = getIconAt(index);
if(icon != null) {
Rectangle bounds = getBoundsAt(index);
int width = icon.getIconWidth();
Object ins = UIManager.get("TabbedPane.tabInsets");
if(ins instanceof InsetsUIResource) {
InsetsUIResource insets = (InsetsUIResource)ins;
if(e.getX() > bounds.getX() + insets.left && e.getX() < bounds.getX() + width + insets.left)
selectedTabIconPressed(index);
}
}
}
}
});
}
@Override
protected void installOther(UIDefaults table)
{
UIManager.put(HORIZONTALSIZE, getDimensionRes(160, 10));
UIManager.put(VERTICALSIZE, getDimensionRes(10, 160));
UIManager.put(CELLBAR_INSETS, new InsetsUIResource(1, 2, 1, 2));
}
@Override
protected void installOther(UIDefaults table)
{
table.put(TITLEPANEL_HEIGHT, 26);
table.put(APPLICATION_TITLE_TEXTGAP, 5);
table.put(APPLICATION_TITLE_INSETS, new InsetsUIResource(4, 6, 0, 0));
}
@Override
public void init() {
super.init();
UIDefaults lafDefaults = UIManager.getLookAndFeelDefaults();
lafDefaults.put("Nimbus.keepAlternateRowColor", true); // deny SwingX to remove alternate row color
lafDefaults.put("ComboBox:\"ComboBox.textField\".contentMargins", new InsetsUIResource(0, 6, 0, 6));
lafDefaults.put("ComboBox:\"ComboBox.textField\"[Enabled].backgroundPainter", MandatoryComboBoxTextFieldPainter.backgroundEnabledPainter());
lafDefaults.put("ComboBox:\"ComboBox.textField\"[Disabled].backgroundPainter", MandatoryComboBoxTextFieldPainter.backgroundDisabledPainter());
lafDefaults.put("ComboBox:\"ComboBox.textField\"[Selected].backgroundPainter", MandatoryComboBoxTextFieldPainter.backgroundSelectedPainter());
}
/**
* Ui impl.
*/
public static void uiImpl()
{
UIManager.put("Spinner.background",new ColorUIResource(BeautyEyeLNFHelper.commonBackgroundColor));
UIManager.put("Spinner.foreground",new ColorUIResource(BeautyEyeLNFHelper.commonForegroundColor));
UIManager.put("SpinnerUI", org.jb2011.lnf.beautyeye.ch18_spinner.BESpinnerUI.class.getName());
//Spinner组件的边框
UIManager.put("Spinner.border", new BorderUIResource(new EmptyBorder(5, 5, 10, 5)));//windows lnf中默认是3, 3, 3, 3
//Spinner组件的2个箭头按钮的内衬距
UIManager.put("Spinner.arrowButtonInsets", new InsetsUIResource(1,0,2,2));//windows lnf中默认是1,1,1,1
//Spinner组件的2个箭头按钮的默认大小
UIManager.put("Spinner.arrowButtonSize",new Dimension(17,9));//windows lnf中默认是17,9
}
public Insets getBorderInsets(Component c, Insets insets) {
insets = super.getBorderInsets(c, insets);
Insets margin = null;
if (c instanceof AbstractButton) {
Insets m = ((AbstractButton)c).getMargin();
// if this is a toolbar button then ignore getMargin()
// and subtract the padding added by the constructor
if(c.getParent() instanceof JToolBar
&& ! (c instanceof JRadioButton)
&& ! (c instanceof JCheckBox)
&& m instanceof InsetsUIResource) {
insets.top -= 2;
insets.left -= 2;
insets.bottom -= 2;
insets.right -= 2;
} else {
margin = m;
}
} else if (c instanceof JToolBar) {
margin = ((JToolBar)c).getMargin();
} else if (c instanceof JTextComponent) {
margin = ((JTextComponent)c).getMargin();
}
if (margin != null) {
insets.top = margin.top + 2;
insets.left = margin.left + 2;
insets.bottom = margin.bottom + 2;
insets.right = margin.right + 2;
}
return insets;
}
/**
* Define some settings for tool tips.
* @param d
*/
private void defineToolTips(UIDefaults d) {
String p = "ToolTip";
d.put("seaGlassToolTipBorder", new Color(0x5b7ea4));
d.put(p + ".contentMargins", new InsetsUIResource(4, 4, 4, 4));
d.put(p + ".opaque", Boolean.FALSE);
d.put(p + ".background", new ColorUIResource(0xd5, 0xe8, 0xf7));
d.put(p + ".backgroundPainter", new ToolTipPainter(ToolTipPainter.Which.BORDER_ENABLED));
}
/**
* Initialize the desktop pane UI settings.
*
* @param d the UI defaults map.
*/
private void defineDesktopPanes(UIDefaults d) {
d.put("seaGlassDesktopPane", new ColorUIResource(0x556ba6));
String c = PAINTER_PREFIX + "DesktopPanePainter";
String p = "DesktopPane";
d.put(p + "[Enabled].backgroundPainter", new LazyPainter(c, DesktopPanePainter.Which.BACKGROUND_ENABLED));
// Initialize DesktopIcon
p = "DesktopIcon";
c = PAINTER_PREFIX + "DesktopIconPainter";
d.put(p + ".contentMargins", new InsetsUIResource(0, 6, 5, 4));
d.put(p + "[Enabled].backgroundPainter", new LazyPainter(c, DesktopIconPainter.Which.BACKGROUND_ENABLED));
}