Scale down button icon size
This commit is contained in:
parent
659512489a
commit
1862325189
Binary file not shown.
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.9 KiB |
@ -10,7 +10,6 @@ import java.awt.datatransfer.StringSelection;
|
|||||||
import java.awt.datatransfer.Transferable;
|
import java.awt.datatransfer.Transferable;
|
||||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.InputEvent;
|
import java.awt.event.InputEvent;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
@ -72,7 +71,6 @@ import net.sf.openrocket.startup.Application;
|
|||||||
import net.sf.openrocket.startup.Preferences;
|
import net.sf.openrocket.startup.Preferences;
|
||||||
import net.sf.openrocket.unit.UnitGroup;
|
import net.sf.openrocket.unit.UnitGroup;
|
||||||
import net.sf.openrocket.util.AlphanumComparator;
|
import net.sf.openrocket.util.AlphanumComparator;
|
||||||
import net.sf.openrocket.gui.widgets.SelectColorButton;
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class SimulationPanel extends JPanel {
|
public class SimulationPanel extends JPanel {
|
||||||
|
@ -36,7 +36,6 @@ import net.sf.openrocket.rocketvisitors.ListComponents;
|
|||||||
import net.sf.openrocket.rocketvisitors.ListMotorMounts;
|
import net.sf.openrocket.rocketvisitors.ListMotorMounts;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.util.StateChangeListener;
|
import net.sf.openrocket.util.StateChangeListener;
|
||||||
import net.sf.openrocket.gui.widgets.SelectColorButton;
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class FlightConfigurationPanel extends JPanel implements StateChangeListener {
|
public class FlightConfigurationPanel extends JPanel implements StateChangeListener {
|
||||||
|
@ -7,6 +7,9 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Image;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -123,4 +126,33 @@ public class Icons {
|
|||||||
}
|
}
|
||||||
return new ImageIcon(url, name);
|
return new ImageIcon(url, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scales an ImageIcon to the specified scale.
|
||||||
|
* @param icon icon to scale
|
||||||
|
* @param scale the scale to scale to (1 = no scale, < 1 = smaller, > 1 = bigger)
|
||||||
|
* @return scaled down icon. If <icon> is not an ImageIcon, the original icon is returned.
|
||||||
|
*/
|
||||||
|
public static Icon getScaledIcon(Icon icon, final double scale) {
|
||||||
|
if (!(icon instanceof ImageIcon)) {
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
final Image image = ((ImageIcon) icon).getImage();
|
||||||
|
return new ImageIcon(image) {
|
||||||
|
@Override
|
||||||
|
public int getIconWidth() {
|
||||||
|
return (int)(image.getWidth(null) * scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIconHeight() {
|
||||||
|
return (int)(image.getHeight(null) * scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||||
|
g.drawImage(image, x, y, getIconWidth(), getIconHeight(), c);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
package net.sf.openrocket.gui.widgets;
|
package net.sf.openrocket.gui.widgets;
|
||||||
|
|
||||||
|
import net.sf.openrocket.gui.util.Icons;
|
||||||
|
|
||||||
import javax.swing.Action;
|
import javax.swing.Action;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Button specifically for displaying an icon.
|
* Button specifically for displaying an icon.
|
||||||
|
*
|
||||||
|
* @author Sibo Van Gool <sibo.vangool@hotmail.com>
|
||||||
*/
|
*/
|
||||||
public class IconButton extends SelectColorButton {
|
public class IconButton extends SelectColorButton {
|
||||||
private static final int ICON_GAP = 10;
|
private static final int ICON_GAP = 10;
|
||||||
public static final double ICON_SCALE = 0.8;
|
private static final double ICON_SCALE = 0.9;
|
||||||
|
|
||||||
public IconButton() {
|
public IconButton() {
|
||||||
setIconTextGap(ICON_GAP);
|
setIconTextGap(ICON_GAP);
|
||||||
@ -34,4 +38,33 @@ public class IconButton extends SelectColorButton {
|
|||||||
setIconTextGap(ICON_GAP);
|
setIconTextGap(ICON_GAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Icon getIcon() {
|
||||||
|
return Icons.getScaledIcon(super.getIcon(), IconButton.ICON_SCALE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Icon getSelectedIcon() {
|
||||||
|
return Icons.getScaledIcon(super.getSelectedIcon(), IconButton.ICON_SCALE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Icon getDisabledIcon() {
|
||||||
|
return Icons.getScaledIcon(super.getDisabledIcon(), IconButton.ICON_SCALE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Icon getDisabledSelectedIcon() {
|
||||||
|
return Icons.getScaledIcon(super.getDisabledSelectedIcon(), IconButton.ICON_SCALE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Icon getRolloverIcon() {
|
||||||
|
return Icons.getScaledIcon(super.getRolloverIcon(), IconButton.ICON_SCALE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Icon getRolloverSelectedIcon() {
|
||||||
|
return Icons.getScaledIcon(super.getRolloverSelectedIcon(), IconButton.ICON_SCALE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user