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

📄 typedimages.java

📁 java写的图片浏览器,类似acds
💻 JAVA
字号:
package org.net9.oops.jsee;import java.io.File;import java.util.Calendar;import java.util.Date;import javax.swing.ImageIcon;import java.awt.Color;/** * <p> * This class contain the information about all images supported by JCDSee * </p> * @author Neoya M <neoyaa@yahoo.com> * @version 2002-03-07 */public class TypedImages{    //Image types:    final int dirImage=1;   //Directory,not a image    final int jpgImage=2;    final int gifImage=3;    final int bmpImage=4;    final int pngImage=5;    final int pcxImage=6;    final int tifImage=7;    final int pnmImage=8;    final int xpmImage=9;    final int mediaImage=10;    //Image type strings:    final String [] imageStrings={        "",        "File Folder",  //1        "JPEG Image",   //2        "GIF Image",    //3        "Bitmap Image", //4        "Potable Image",//5        "PCX Image",    //6        "TIF Image",    //7        "PNM Image",    //8        "XPM Image",     //9        "Media file"     //10        };    //Image colors:    final Color jpgColor=new Color(239,235,206);//EFEBCE    final Color gifColor=new Color(214,235,214);//D6EBD6    final Color bmpColor=new Color(231,231,255);//E7E7FF    final Color pngColor=new Color(231,223,214);//E7DFD6    final Color pcxColor=new Color(239,231,231);//EfE7E7    final Color tifColor=new Color(214,214,239);//D6D6EF    final Color pnmColor=new Color(239,239,255);//EFEFFF    final Color xpmColor=new Color(239,214,239);//EFD6EF    final Color ukColor=Color.white;    //Image icons:    final ImageIcon jpgIcon = new ImageIcon(getClass().getResource("/org/net9/oops/jsee/image/jpgIcon.gif"));    final ImageIcon gifIcon = new ImageIcon(getClass().getResource("/org/net9/oops/jsee/image/gifIcon.gif"));    final ImageIcon bmpIcon = new ImageIcon(getClass().getResource("/org/net9/oops/jsee/image/bmpIcon.gif"));    final ImageIcon pngIcon = new ImageIcon(getClass().getResource("/org/net9/oops/jsee/image/pngIcon.gif"));    final ImageIcon pcxIcon = new ImageIcon(getClass().getResource("/org/net9/oops/jsee/image/pcxIcon.gif"));    final ImageIcon tifIcon = new ImageIcon(getClass().getResource("/org/net9/oops/jsee/image/tifIcon.jpg"));    final ImageIcon pnmIcon = new ImageIcon(getClass().getResource("/org/net9/oops/jsee/image/pnmIcon.jpg"));    final ImageIcon xpmIcon = new ImageIcon(getClass().getResource("/org/net9/oops/jsee/image/xpmIcon.jpg"));    final ImageIcon mediaIcon = new ImageIcon(getClass().getResource("/org/net9/oops/jsee/image/tinymedia.PNG"));    final ImageIcon diskIcon= new ImageIcon(getClass().getResource("/org/net9/oops/jsee/image/diskIcon.gif"));    final ImageIcon dirIcon = new ImageIcon(getClass().getResource("/org/net9/oops/jsee/image/dirIcon.gif"));    final ImageIcon ukIcon  = new ImageIcon(getClass().getResource("/org/net9/oops/jsee/image/ukIcon.gif"));    /**     * Get image type by File argument     */    public int getImageType(File file){        if (file==null || !file.exists())            return 0;        if (file.isDirectory())            return  dirImage;        String filename=file.toString();        String lowerFilename=filename.toLowerCase();        if (lowerFilename.endsWith(".jpg"))            return  jpgImage;        else if (lowerFilename.endsWith(".gif"))            return  gifImage;        else if (lowerFilename.endsWith(".bmp"))            return  bmpImage;        else if (lowerFilename.endsWith(".png"))            return  pngImage;        else if (lowerFilename.endsWith(".pcx"))            return  pcxImage;        else if (lowerFilename.endsWith(".tif"))            return  tifImage;        else if (lowerFilename.endsWith(".xpm"))            return  xpmImage;        else if (lowerFilename.endsWith(".pnm"))            return  pnmImage;        else if (lowerFilename.endsWith(".mpeg"))            return  mediaImage;        else if (lowerFilename.endsWith(".mpg"))            return  mediaImage;        else if (lowerFilename.endsWith(".mov"))            return  mediaImage;        else if (lowerFilename.endsWith(".avi"))            return  mediaImage;        else if (lowerFilename.endsWith(".mp3"))            return  mediaImage;        else if (lowerFilename.endsWith(".wav"))            return  mediaImage;        else            return 0 ;    }    /**     * Get image type by a String of filename,Use the overloaded method of     * argument File     */    public int getImageType(String filename){        File file=new File(filename);        return getImageType(file);    }    /**     * Get image color according to type     */    public Color getImageColor(String filename){        int imageType=getImageType(filename);        //System.out.println(imageType);        switch(imageType){            case jpgImage:                return jpgColor;            case  gifImage:                return gifColor;            case  bmpImage:                return bmpColor;            case  pngImage:                return pngColor;            case  pcxImage:                return pcxColor;            case  tifImage:                return tifColor;            case  pnmImage:                return pnmColor;            case  xpmImage:                return xpmColor;            default:                return ukColor;        }    }    /**     * Get image icon according to file name     */    public ImageIcon getImageIcon(String filename){        int imageType=getImageType(filename);        return getImageIcon(imageType);    }    /**     * Get image icon according to iamge type     */    public ImageIcon getImageIcon(int imageType){        switch(imageType){            case jpgImage:                return jpgIcon;            case  gifImage:                return gifIcon;            case  bmpImage:                return bmpIcon;            case  pngImage:                return pngIcon;            case  pcxImage:                return pcxIcon;            case  tifImage:                return tifIcon;            case  pnmImage:                return pnmIcon;            case  xpmImage:                return xpmIcon;            case mediaImage:                return mediaIcon;            case dirImage: //Directory                return dirIcon;            default: //Unknow image type icon                return ukIcon;        }    }    /**     * Get image type descript string     */    public String getImageString(int fileType){        return imageStrings[fileType];    }    /**     * Get a object descript the image(include other file or directory information     */    public ImageInfo getImageInfo(String filename){        ImageInfo imageInfo=new ImageInfo();        File file=new File(filename);        if (file==null || !file.exists())            return imageInfo;        int imageType=getImageType(file);        //Set imageIcon        imageInfo.setImageIcon(getImageIcon(imageType));        //Set name        imageInfo.setName(filename);        //Set size        long size=file.length();        if (size==0)            imageInfo.setSize(ImageInfo.LONG_ZERO);        else if (size<=1000)            imageInfo.setSize(ImageInfo.LONG_ONE);        else            imageInfo.setSize(new Long(size / 1000));        //Set date        Calendar calendar=Calendar.getInstance();        calendar.setTime(new Date(file.lastModified()));        int time;        String date="";        date=date+String.valueOf(calendar.get(Calendar.YEAR))+"-";        time=calendar.get(Calendar.MONTH)+1;        if (time<10)            date=date+"0";        date=date+String.valueOf(time)+"-";        time=calendar.get(Calendar.DAY_OF_MONTH);        if(time<10)            date=date+"0";        date=date+String.valueOf(time)+" ";        time=calendar.get(Calendar.HOUR_OF_DAY);        if(time<10)            date=date+"0";        date=date+String.valueOf(time)+":";        time=calendar.get(Calendar.MINUTE);        if(time<10)            date=date+"0";        date=date+String.valueOf(time);        imageInfo.setDate(date);        //Set type        imageInfo.setType(this.getImageString(imageType));        //Set Property        imageInfo.setProperty("");        return imageInfo;    }}

⌨️ 快捷键说明

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