⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utils.java

📁 基于jxta的局域网P2P文件共享,可以实现局域网中的文件p2p共享,实现文件快速传输及交流
💻 JAVA
字号:
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;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -