?? utils.java
字號(hào):
package connex.app.utils.fileChooserUtils;
import java.io.File;
import javax.swing.ImageIcon;
import java.awt.Image;
import java.awt.image.RenderedImage;
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
/*. */
public class Utils {
public final static String jpeg = "jpeg";
public final static String jpg = "jpg";
public final static String gif = "gif";
public final static String tiff = "tiff";
public final static String tif = "tif";
public final static String png = "png";
/*
* Get the extension of a file.
*/
public static String getExtension(File f) {
String ext = null;
String s = f.getName();
int i = s.lastIndexOf('.');
if (i > 0 && i < s.length() - 1) {
ext = s.substring(i + 1).toLowerCase();
}
return ext;
}
public static ImageIcon getThumbNail(ImageIcon tmpIcon) {
ImageIcon thumbnail = null;
if (tmpIcon.getIconWidth() > 85) {
thumbnail = new ImageIcon(tmpIcon.getImage().
getScaledInstance(85, -1,
Image.SCALE_DEFAULT));
} else { //no need to miniaturize
thumbnail = tmpIcon;
}
return thumbnail;
}
public static RenderedImage getThumbNail(BufferedImage tmpImage) {
Image thumbnail = null;
BufferedImage bufferedImage = null;
if (tmpImage.getWidth() > 85) {
thumbnail = tmpImage.getScaledInstance(85, -1,
Image.SCALE_DEFAULT);
bufferedImage = new BufferedImage(85, thumbnail.getHeight(null),
BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics2D = bufferedImage.createGraphics();
graphics2D.drawImage(thumbnail, 0, 0, null);
} else { //no need to miniaturize
bufferedImage = tmpImage;
}
return bufferedImage;
}
public static RenderedImage getRenderedImage(ImageIcon tmpIcon) {
BufferedImage bufferedImage = new BufferedImage(tmpIcon.getIconWidth(),
tmpIcon.getIconHeight(),
BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics2D = bufferedImage.createGraphics();
graphics2D.drawImage(tmpIcon.getImage(), 0, 0, null);
return bufferedImage;
}
public static BufferedImage getBufferedImage(ImageIcon tmpIcon) {
BufferedImage bufferedImage = new BufferedImage(tmpIcon.getIconWidth(),
tmpIcon.getIconHeight(),
BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics2D = bufferedImage.createGraphics();
graphics2D.drawImage(tmpIcon.getImage(), 0, 0, null);
return bufferedImage;
}
/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = Utils.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -