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

📄 imagepreview.java

📁 Memoranda( 从前以jNotes2而闻名) 是一个日志管理和个人项目管理工具
💻 JAVA
字号:
package net.sf.memoranda.ui.htmleditor.filechooser;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Image;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.io.File;import javax.swing.BorderFactory;import javax.swing.ImageIcon;import javax.swing.JComponent;import javax.swing.JFileChooser;import javax.swing.border.TitledBorder;import net.sf.memoranda.ui.htmleditor.util.Local;public class ImagePreview extends JComponent                          implements PropertyChangeListener {    ImageIcon thumbnail = null;    File file = null;    public ImagePreview(JFileChooser fc) {        setPreferredSize(new Dimension(100, 50));        setBorder(new TitledBorder(BorderFactory.createEtchedBorder(),         Local.getString("Preview"), TitledBorder.CENTER, TitledBorder.ABOVE_TOP));        fc.addPropertyChangeListener(this);    }    public void loadImage() {        if (file == null) {            return;        }        ImageIcon tmpIcon = new ImageIcon(file.getPath());        if (tmpIcon.getIconWidth() > 90) {            thumbnail = new ImageIcon(tmpIcon.getImage().                                 getScaledInstance(90, -1,                                                   Image.SCALE_DEFAULT));        } else {            thumbnail = tmpIcon;        }    }    public void propertyChange(PropertyChangeEvent e) {        String prop = e.getPropertyName();        if (prop.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) {            file = (File) e.getNewValue();            if (isShowing()) {                loadImage();                repaint();            }        }    }    public void paintComponent(Graphics g) {        if (thumbnail == null) {            loadImage();        }        if (thumbnail != null) {            int x = getWidth()/2 - thumbnail.getIconWidth()/2;            int y = getHeight()/2 - thumbnail.getIconHeight()/2;            if (y < 0) {                y = 0;            }            if (x < 5) {                x = 5;            }            thumbnail.paintIcon(this, g, x, y);        }    }}

⌨️ 快捷键说明

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