added Icosn & resizable Icon class
parent
073cf038a4
commit
8f4be74177
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<jardesc>
|
||||
<jar path="/Users/niclasthobaben/Desktop/DrBender_Dev/bin/libs/nt.UI.jar"/>
|
||||
<options buildIfNeeded="true" compress="true" descriptionLocation="/nt.UI/src/nt.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
|
||||
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
|
||||
<selectedProjects/>
|
||||
<manifest generateManifest="false" manifestLocation="/nt.CLI/META-INF/MANIFEST.MF" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
|
||||
<sealing sealJar="false">
|
||||
<packagesToSeal/>
|
||||
<packagesToUnSeal/>
|
||||
</sealing>
|
||||
</manifest>
|
||||
<selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
|
||||
<javaElement handleIdentifier="=nt.UI/src<nt.UI.display"/>
|
||||
<javaElement handleIdentifier="=nt.UI/src<nt.UI.util"/>
|
||||
<javaElement handleIdentifier="=nt.UI/src<nt"/>
|
||||
<file path="/nt.UI/src/.DS_Store"/>
|
||||
<file path="/nt.UI/.classpath"/>
|
||||
<javaElement handleIdentifier="=nt.UI/src<nt.UI.control"/>
|
||||
<javaElement handleIdentifier="=nt.UI/src<nt.UI.control.interfaces"/>
|
||||
<javaElement handleIdentifier="=nt.UI/src<nt.UI"/>
|
||||
<file path="/nt.UI/.gitignore"/>
|
||||
<file path="/nt.UI/.project"/>
|
||||
</selectedElements>
|
||||
</jardesc>
|
Binary file not shown.
After Width: | Height: | Size: 590 B |
Binary file not shown.
After Width: | Height: | Size: 573 B |
|
@ -15,17 +15,21 @@ public class IconResizer {
|
|||
if(icon != null && ImageIcon.class.isInstance(icon)
|
||||
&& (icon.getIconHeight() != height && icon.getIconWidth() != width)) {
|
||||
Image img = ((ImageIcon)icon).getImage();
|
||||
BufferedImage bImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g2d = bImg.createGraphics();
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
g2d.drawImage(img, 0, 0, width, height, null, null);
|
||||
g2d.dispose();
|
||||
newIcon = new ImageIcon(bImg);
|
||||
newIcon = new ImageIcon(resizeImage(img, width, height));
|
||||
}else {
|
||||
newIcon = icon;
|
||||
}
|
||||
return newIcon;
|
||||
}
|
||||
|
||||
public static Image resizeImage(Image img, int width, int height) {
|
||||
BufferedImage bImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g2d = bImg.createGraphics();
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
g2d.drawImage(img, 0, 0, width, height, null, null);
|
||||
g2d.dispose();
|
||||
return bImg;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,9 +14,11 @@ public class Icons {
|
|||
public static final URL NUMBER_SYMBOL_URL = Icons.class.getResource("/nt/UI/number_icn.png");
|
||||
public static final URL OBJECT_SYMBOL_URL = Icons.class.getResource("/nt/UI/object_icn.png");
|
||||
public static final URL SUBMODULE_SYMBOL_URL = Icons.class.getResource("/nt/UI/submodule_icn.png");
|
||||
public static final URL CHEVRO_LEFT_SYMBOL_URL = Icons.class.getResource("/nt/UI/chevron_left_icn.png");
|
||||
public static final URL CHEVRO_RIGHT_SYMBOL_URL = Icons.class.getResource("/nt/UI/chevron_right_icn.png");
|
||||
|
||||
public static Icon getIcon(URL icn) {
|
||||
return new ImageIcon(icn);
|
||||
return new ResizeableImageIcon(icn);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
package nt.UI.util;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
public class ResizeableImageIcon extends ImageIcon {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Component component;
|
||||
private boolean prepareResize = false;
|
||||
|
||||
public ResizeableImageIcon(URL url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
int width, height;
|
||||
if(this.component == null) {
|
||||
this.component = c;
|
||||
c.addComponentListener(new IconParentListener());
|
||||
width = c.getWidth()-(2*Math.abs(x));
|
||||
height = c.getHeight()-(2*Math.abs(y));
|
||||
resizeIcon(width, height);
|
||||
}
|
||||
if(prepareResize) {
|
||||
width = c.getWidth()-(2*Math.abs(x));
|
||||
height = c.getHeight()-(2*Math.abs(y));
|
||||
resizeIcon(width, height);
|
||||
prepareResize=false;
|
||||
}
|
||||
|
||||
if(getImageObserver() == null) {
|
||||
g.drawImage(getImage(), Math.abs(x), Math.abs(y), c);
|
||||
} else {
|
||||
g.drawImage(getImage(), Math.abs(x), Math.abs(y), getImageObserver());
|
||||
}
|
||||
}
|
||||
|
||||
protected void resizeIcon(int width, int height) {
|
||||
if(this.component == null) {
|
||||
return;
|
||||
}
|
||||
setImage(IconResizer.resizeImage(getImage(), width, height));
|
||||
}
|
||||
|
||||
|
||||
private class IconParentListener implements ComponentListener {
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
prepareResize=true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentMoved(ComponentEvent e) {}
|
||||
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {}
|
||||
|
||||
@Override
|
||||
public void componentHidden(ComponentEvent e) {}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue