Jide comes with a couple of predefined icons.
For example for a Jide frame there are icons for toggle floating, toggle autohide and close.
There are two problems:
1) The predefined icons you have for toggle floating and close on Mac OSX "title_buttons.gif" are old style, they no longer reflect the flat layout Yosemite has + they are saved in a GIF which sometimes renders small artifacts around the borders when painted.
If you want we could give you the new set we have created to replace yours in our application.
2) When the JIDE library is used to display content on a high DPI monitor for Windows or on Retina display for Mac OSX the default icons start to look bad.
Ideally you would take into account the type of used display when painting your predefined icons.
For example on Mac OSX you can access the scaling factor used for display like:
- Code: Select all
/**
* Gets the content scale factor for the retina display.
*
* @return The float representing the scaling factor. 1.0 means no scaling.
*/
private static float getJava6ContentScaleFactor(){
float scaleFactor = 1.0f;
Object obj = Toolkit.getDefaultToolkit().getDesktopProperty("apple.awt.contentScaleFactor");
if (obj instanceof Float) {
// 1 = retina not available (regular display). Usually, for retina enabled displays returns 2.
scaleFactor = ((Float) obj);
}
return scaleFactor;
}
/**
* Checks HiDPI support for Java 7 and newer.
*
* @return <code>true<code> if the HiDPI feature is enabled.
*/
private static float getJava7OrLaterContentScaleFactor() {
float scaleFactor = 1;
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice device = env.getDefaultScreenDevice();
try {
Field field = device.getClass().getDeclaredField("scale");
if (field != null) {
field.setAccessible(true);
Object scale = field.get(device);
if (scale instanceof Integer) {
scaleFactor = (Integer) scale;
}
}
} catch (Throwable e) {
// Ignore
}
return scaleFactor;
}
So for MAC your predefined "title_buttons.gif" should be saved with a dimension at least double than it is now.
Then you would render them with a custom image icon which actually down scales the image like:
- Code: Select all
/**
* The Retina Icon is designed for the platforms supporting the
* {@link RetinaType#RETINA_SCALED_GRAPHICS_AND_HIDPI_ICONS}. Currently
* this type of retina is supported only on Mac OS X.
*
* These icons report a size of <code>(w, h)</code> but they store a
* true image of <code>(w*f, h*f)</code>, where <code>f</code> is the
* scale factor of the display.
*
* @author gabi_ionescu, dan
*/
public class RetinaIcon extends ImageIcon {
/**
* Constructor
*
* @param image is the true image to be displayed. Double or f-sized.
* @param displayScalingfactor is the current display scaling factor.
*/
public RetinaIcon(final Image image, final float displayScalingfactor) {
super(image);
this.displayScalingfactor = displayScalingfactor;
}
/**
* The display scaling factor. Mac OS X uses a factor of 2 for its Retina display.
*/
private float displayScalingfactor = 2.0f;
/**
* @see javax.swing.ImageIcon#getIconWidth()
*/
@Override
public int getIconWidth() {
return (int) (super.getIconWidth() / displayScalingfactor);
}
/**
* @see javax.swing.ImageIcon#getIconHeight()
*/
@Override
public int getIconHeight() {
return (int) (super.getIconHeight() / displayScalingfactor);
}
/**
* Paints the true image in the specified graphics device but
* uses a down-scale factor equal to the the display scaling factor.
* In this way the large image results in a displayed smaller
* image, but with a higher DPI.
*
*
* @see javax.swing.ImageIcon#paintIcon(java.awt.Component, java.awt.Graphics, int, int)
*/
@Override
public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
ImageObserver observer = getImageObserver();
if (observer == null) {
observer = c;
}
Image image = getImage();
int width = image.getWidth(observer);
int height = image.getHeight(observer);
Graphics graphics = g.create(x, y, width, height);
if (graphics instanceof Graphics2D) {
final Graphics2D g2d = (Graphics2D) graphics;
//Scale the image half it size.
g2d.scale(1/displayScalingfactor, 1/displayScalingfactor);
g2d.drawImage(image, 0, 0, observer);
g2d.dispose();
}
}
/**
* Get the display scaling factor.
*
* @return The display scaling factor.
*/
public float getDisplayScalingFactor() {
return displayScalingfactor;
}
}
Regards,
Radu