下面列出了javax.swing.plaf.synth.SynthContext#getComponent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public int getIconHeight(SynthContext context) {
if (context == null) {
return height;
}
JComponent c = context.getComponent();
if (c instanceof JToolBar){
JToolBar toolbar = (JToolBar)c;
if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {
//we only do the -1 hack for UIResource borders, assuming
//that the border is probably going to be our border
if (toolbar.getBorder() instanceof UIResource) {
return c.getHeight() - 1;
} else {
return c.getHeight();
}
} else {
return scale(context, width);
}
} else {
return scale(context, height);
}
}
@Override
public int getIconHeight(SynthContext context) {
if (context == null) {
return height;
}
JComponent c = context.getComponent();
if (c instanceof JToolBar){
JToolBar toolbar = (JToolBar)c;
if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {
//we only do the -1 hack for UIResource borders, assuming
//that the border is probably going to be our border
if (toolbar.getBorder() instanceof UIResource) {
return c.getHeight() - 1;
} else {
return c.getHeight();
}
} else {
return scale(context, width);
}
} else {
return scale(context, height);
}
}
/**
* Scale a size based on the "JComponent.sizeVariant" client property of the
* component that is using this icon
*
* @param context The synthContext to get the component from
* @param size The size to scale
* @return The scaled size or original if "JComponent.sizeVariant" is not
* set
*/
private int scale(SynthContext context, int size) {
if (context == null || context.getComponent() == null){
return size;
}
// The key "JComponent.sizeVariant" is used to match Apple's LAF
String scaleKey = (String) context.getComponent().getClientProperty(
"JComponent.sizeVariant");
if (scaleKey != null) {
if (NimbusStyle.LARGE_KEY.equals(scaleKey)) {
size *= NimbusStyle.LARGE_SCALE;
} else if (NimbusStyle.SMALL_KEY.equals(scaleKey)) {
size *= NimbusStyle.SMALL_SCALE;
} else if (NimbusStyle.MINI_KEY.equals(scaleKey)) {
// mini is not quite as small for icons as full mini is
// just too tiny
size *= NimbusStyle.MINI_SCALE + 0.07;
}
}
return size;
}
@Override
public int getIconWidth(SynthContext context) {
if (context == null) {
return width;
}
JComponent c = context.getComponent();
if (c instanceof JToolBar && ((JToolBar)c).getOrientation() == JToolBar.VERTICAL) {
//we only do the -1 hack for UIResource borders, assuming
//that the border is probably going to be our border
if (c.getBorder() instanceof UIResource) {
return c.getWidth() - 1;
} else {
return c.getWidth();
}
} else {
return scale(context, width);
}
}
@Override
public int getIconHeight(SynthContext context) {
if (context == null) {
return height;
}
JComponent c = context.getComponent();
if (c instanceof JToolBar){
JToolBar toolbar = (JToolBar)c;
if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {
//we only do the -1 hack for UIResource borders, assuming
//that the border is probably going to be our border
if (toolbar.getBorder() instanceof UIResource) {
return c.getHeight() - 1;
} else {
return c.getHeight();
}
} else {
return scale(context, width);
}
} else {
return scale(context, height);
}
}
/**
* Scale a size based on the "JComponent.sizeVariant" client property of the
* component that is using this icon
*
* @param context The synthContext to get the component from
* @param size The size to scale
* @return The scaled size or original if "JComponent.sizeVariant" is not
* set
*/
private int scale(SynthContext context, int size) {
if (context == null || context.getComponent() == null){
return size;
}
// The key "JComponent.sizeVariant" is used to match Apple's LAF
String scaleKey = (String) context.getComponent().getClientProperty(
"JComponent.sizeVariant");
if (scaleKey != null) {
if (NimbusStyle.LARGE_KEY.equals(scaleKey)) {
size *= NimbusStyle.LARGE_SCALE;
} else if (NimbusStyle.SMALL_KEY.equals(scaleKey)) {
size *= NimbusStyle.SMALL_SCALE;
} else if (NimbusStyle.MINI_KEY.equals(scaleKey)) {
// mini is not quite as small for icons as full mini is
// just too tiny
size *= NimbusStyle.MINI_SCALE + 0.07;
}
}
return size;
}
/**
* Scale a size based on the "JComponent.sizeVariant" client property of the
* component that is using this icon
*
* @param context The synthContext to get the component from
* @param size The size to scale
* @return The scaled size or original if "JComponent.sizeVariant" is not
* set
*/
private int scale(SynthContext context, int size) {
if (context == null || context.getComponent() == null){
return size;
}
// The key "JComponent.sizeVariant" is used to match Apple's LAF
String scaleKey = (String) context.getComponent().getClientProperty(
"JComponent.sizeVariant");
if (scaleKey != null) {
if (NimbusStyle.LARGE_KEY.equals(scaleKey)) {
size *= NimbusStyle.LARGE_SCALE;
} else if (NimbusStyle.SMALL_KEY.equals(scaleKey)) {
size *= NimbusStyle.SMALL_SCALE;
} else if (NimbusStyle.MINI_KEY.equals(scaleKey)) {
// mini is not quite as small for icons as full mini is
// just too tiny
size *= NimbusStyle.MINI_SCALE + 0.07;
}
}
return size;
}
@Override
public int getIconWidth(SynthContext context) {
if (context == null) {
return width;
}
JComponent c = context.getComponent();
if (c instanceof JToolBar && ((JToolBar)c).getOrientation() == JToolBar.VERTICAL) {
//we only do the -1 hack for UIResource borders, assuming
//that the border is probably going to be our border
if (c.getBorder() instanceof UIResource) {
return c.getWidth() - 1;
} else {
return c.getWidth();
}
} else {
return scale(context, width);
}
}
@Override
public int getIconHeight(SynthContext context) {
if (context == null) {
return height;
}
JComponent c = context.getComponent();
if (c instanceof JToolBar){
JToolBar toolbar = (JToolBar)c;
if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {
//we only do the -1 hack for UIResource borders, assuming
//that the border is probably going to be our border
if (toolbar.getBorder() instanceof UIResource) {
return c.getHeight() - 1;
} else {
return c.getHeight();
}
} else {
return scale(context, width);
}
} else {
return scale(context, height);
}
}
/**
* Scale a size based on the "JComponent.sizeVariant" client property of the
* component that is using this icon
*
* @param context The synthContext to get the component from
* @param size The size to scale
* @return The scaled size or original if "JComponent.sizeVariant" is not
* set
*/
private int scale(SynthContext context, int size) {
if (context == null || context.getComponent() == null){
return size;
}
// The key "JComponent.sizeVariant" is used to match Apple's LAF
String scaleKey = (String) context.getComponent().getClientProperty(
"JComponent.sizeVariant");
if (scaleKey != null) {
if (NimbusStyle.LARGE_KEY.equals(scaleKey)) {
size *= NimbusStyle.LARGE_SCALE;
} else if (NimbusStyle.SMALL_KEY.equals(scaleKey)) {
size *= NimbusStyle.SMALL_SCALE;
} else if (NimbusStyle.MINI_KEY.equals(scaleKey)) {
// mini is not quite as small for icons as full mini is
// just too tiny
size *= NimbusStyle.MINI_SCALE + 0.07;
}
}
return size;
}
@Override
public int getIconHeight(SynthContext context) {
if (context == null) {
return height;
}
JComponent c = context.getComponent();
if (c instanceof JToolBar){
JToolBar toolbar = (JToolBar)c;
if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {
//we only do the -1 hack for UIResource borders, assuming
//that the border is probably going to be our border
if (toolbar.getBorder() instanceof UIResource) {
return c.getHeight() - 1;
} else {
return c.getHeight();
}
} else {
return scale(context, width);
}
} else {
return scale(context, height);
}
}
/**
* Paints the specified component.
*
* @param context
* context for the component being painted
* @param g
* the {@code Graphics} object used for painting
* @see #update(Graphics,JComponent)
*/
protected void paint(SynthContext context, Graphics g) {
JToolTip tip = (JToolTip) context.getComponent();
Insets insets = tip.getInsets();
View v = (View) tip.getClientProperty(BasicHTML.propertyKey);
if (v != null) {
Rectangle paintTextR = new Rectangle(insets.left, insets.top, tip.getWidth() - (insets.left + insets.right), tip.getHeight()
- (insets.top + insets.bottom));
v.paint(g, paintTextR);
} else {
g.setColor(context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND));
g.setFont(style.getFont(context));
context.getStyle().getGraphicsUtils(context).paintText(context, g, tip.getTipText(), insets.left, insets.top, -1);
}
}
/**
* Paint the object's background.
*
* @param ctx the SynthContext.
* @param g the Graphics context.
* @param x the x location corresponding to the upper-left
* coordinate to paint.
* @param y the y location corresponding to the upper left
* coordinate to paint.
* @param w the width to paint.
* @param h the height to paint.
* @param transform the affine transform to apply, or {@code null} if none
* is to be applied.
*/
private void paintBackground(SynthContext ctx, Graphics g, int x, int y, int w, int h, AffineTransform transform) {
// if the background color of the component is 100% transparent
// then we should not paint any background graphics. This is a solution
// for there being no way of turning off Nimbus background painting as
// basic components are all non-opaque by default.
Component c = ctx.getComponent();
Color bg = (c != null) ? c.getBackground() : null;
if (bg == null || bg.getAlpha() > 0) {
SeaGlassPainter backgroundPainter = style.getBackgroundPainter(ctx);
if (backgroundPainter != null) {
paint(backgroundPainter, ctx, g, x, y, w, h, transform);
}
}
}
private void paintBackground(SynthContext ctx, Graphics g, int x, int y,
int w, int h, AffineTransform transform) {
// if the background color of the component is 100% transparent
// then we should not paint any background graphics. This is a solution
// for there being no way of turning off Nimbus background painting as
// basic components are all non-opaque by default.
Component c = ctx.getComponent();
Color bg = (c != null) ? c.getBackground() : null;
if (bg == null || bg.getAlpha() > 0){
Painter backgroundPainter = style.getBackgroundPainter(ctx);
if (backgroundPainter != null) {
paint(backgroundPainter, ctx, g, x, y, w, h,transform);
}
}
}
private void paintBackground(SynthContext ctx, Graphics g, int x, int y,
int w, int h, AffineTransform transform) {
// if the background color of the component is 100% transparent
// then we should not paint any background graphics. This is a solution
// for there being no way of turning off Nimbus background painting as
// basic components are all non-opaque by default.
Component c = ctx.getComponent();
Color bg = (c != null) ? c.getBackground() : null;
if (bg == null || bg.getAlpha() > 0){
Painter backgroundPainter = style.getBackgroundPainter(ctx);
if (backgroundPainter != null) {
paint(backgroundPainter, ctx, g, x, y, w, h,transform);
}
}
}
/**
* Returns the icon's height. This is a cover method for <code>
* getIconHeight(null)</code>.
*
* @param context the SynthContext describing the component/region, the
* style, and the state.
*
* @return an int specifying the fixed height of the icon.
*/
@Override
public int getIconHeight(SynthContext context) {
if (context == null) {
return height;
}
JComponent c = context.getComponent();
if (c instanceof JToolBar) {
JToolBar toolbar = (JToolBar) c;
if (toolbar.getOrientation() == JToolBar.HORIZONTAL) {
// we only do the -1 hack for UIResource borders, assuming
// that the border is probably going to be our border
if (toolbar.getBorder() instanceof UIResource) {
return c.getHeight() - 1;
} else {
return c.getHeight();
}
} else {
return scale(context, width);
}
} else {
return scale(context, height);
}
}
private void paintBackground(SynthContext ctx, Graphics g, int x, int y,
int w, int h, AffineTransform transform) {
// if the background color of the component is 100% transparent
// then we should not paint any background graphics. This is a solution
// for there being no way of turning off Nimbus background painting as
// basic components are all non-opaque by default.
Component c = ctx.getComponent();
Color bg = (c != null) ? c.getBackground() : null;
if (bg == null || bg.getAlpha() > 0){
Painter backgroundPainter = style.getBackgroundPainter(ctx);
if (backgroundPainter != null) {
paint(backgroundPainter, ctx, g, x, y, w, h,transform);
}
}
}
private void paintBackground(SynthContext ctx, Graphics g, int x, int y,
int w, int h, AffineTransform transform) {
// if the background color of the component is 100% transparent
// then we should not paint any background graphics. This is a solution
// for there being no way of turning off Nimbus background painting as
// basic components are all non-opaque by default.
Component c = ctx.getComponent();
Color bg = (c != null) ? c.getBackground() : null;
if (bg == null || bg.getAlpha() > 0){
Painter backgroundPainter = style.getBackgroundPainter(ctx);
if (backgroundPainter != null) {
paint(backgroundPainter, ctx, g, x, y, w, h,transform);
}
}
}
@Override
public void paintTabbedPaneTabBackground(SynthContext context, Graphics g, int x, int y, int w, int h,
int tabIndex, int orientation) {
JTabbedPane t = (JTabbedPane) context.getComponent();
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (t.getSelectedIndex() == tabIndex) {
g.setColor(BG);
}
else {
g.setColor(INACTIVE);
}
g.fillRoundRect(x, y, w - 2, h, 5, 5);
g.fillRect(x, y + 5, w - 2, h - 3);
}
private void paintBackground(SynthContext ctx, Graphics g, int x, int y,
int w, int h, AffineTransform transform) {
// if the background color of the component is 100% transparent
// then we should not paint any background graphics. This is a solution
// for there being no way of turning off Nimbus background painting as
// basic components are all non-opaque by default.
Component c = ctx.getComponent();
Color bg = (c != null) ? c.getBackground() : null;
if (bg == null || bg.getAlpha() > 0){
Painter backgroundPainter = style.getBackgroundPainter(ctx);
if (backgroundPainter != null) {
paint(backgroundPainter, ctx, g, x, y, w, h,transform);
}
}
}