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

📄 jimageviewer.java

📁 JavaExplorer是一个独立于平台的浏览器
💻 JAVA
字号:
/**  * File and FTP Explorer  * Copyright 2002  * BOESCH Vincent  *  * This program is free software; you can redistribute it and/or  * modify it under the terms of the GNU General Public License  * as published by the Free Software Foundation; either version 2  * of the License, or (at your option) any later version.  *  * This program is distributed in the hope that it will be useful,  * but WITHOUT ANY WARRANTY; without even the implied warranty of  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  * GNU General Public License for more details.  *  * You should have received a copy of the GNU General Public License  * along with this program; if not, write to the Free Software  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.  */package javaexplorer.gui.viewer;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Dimension;import java.awt.Image;import javaexplorer.gui.listener.ViewerListener;import javaexplorer.model.XFile;import javaexplorer.util.ExplorerUtil;import javaexplorer.util.ImageGrabber;//import javaexplorer.util.ImageGrabber;import javaexplorer.util.options.Options;import javax.swing.ImageIcon;import javax.swing.JComponent;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;public class JImageViewer extends JScrollPane implements Viewer {  private ImageIcon _iconView = new ImageIcon();  private ImageIcon _iconStore = null;  private JPanel _jpanel = new JPanel();  private JLabel _lblImg = new JLabel();  private float _zoomFactor = (float)1.0;  private XFile _xfile = null;  /**   *  Constructor for the JImageViewer object   */  public JImageViewer() {    super();    _jpanel.setBackground(Color.white);    _jpanel.setLayout(new BorderLayout());    _jpanel.add(_lblImg, BorderLayout.CENTER);    getViewport().add(_jpanel);  }  /**   *  Adds a feature to the ViewerListener   *  attribute of the JImageViewer object   *   *@param  vl  The feature to be added to   *      the ViewerListener attribute   */  public void addViewerListener(ViewerListener vl) {    _lblImg.addMouseListener(vl);  }  /**   *  Description of the Method   *   *@param  e_zoomFactor  Description of   *      Parameter   */  public void applyZoom(int e_zoomFactor) {    float _oldZoom = _zoomFactor;    switch (e_zoomFactor) {      case ExplorerUtil.ZOOM_FIT :        _zoomFactor = getBestZoomFactor();        break;      case ExplorerUtil.ZOOM_IN :        _zoomFactor *= Options.getOptions().getZoomFactor();        break;      case ExplorerUtil.ZOOM_OUT :        _zoomFactor /= Options.getOptions().getZoomFactor();        break;      default :      case ExplorerUtil.ZOOM_NO :        _zoomFactor = (float)1.0;        break;    }    if (_oldZoom != _zoomFactor) {      refresh();    }  }  public void freeRessource() {    //Lib閞ation des ressources    _iconStore = null;    _iconView = null;    System.gc();  }  /**   *  Gets the File attribute of the JImageViewer   *  object   *   *@return    The File value   */  public XFile getXFile() {    return _xfile;  }  /**   *  Gets the ImageSize attribute of the   *  JImageViewer object   *   *@return    The ImageSize value   */  public Dimension getImageSize() {    return new Dimension(_iconStore.getIconWidth(), _iconStore.getIconHeight());  }  /**   *  Gets the imageView attribute of the   *  JImageViewer object   *   *@return    The imageView value   */  public ImageIcon getImageView() {    return _iconView;  }  /**   *  Gets the ImageViewSize attribute of   *  the JImageViewer object   *   *@return    The ImageViewSize value   */  public Dimension getImageViewSize() {    return new Dimension(_iconView.getIconWidth(), _iconView.getIconHeight());  }  /**   *  Gets the Info attribute of the JImageViewer   *  object   *   *@return    The Info value   */  public String getInfo() {    if ((_iconStore != null)) {      return _iconStore.getDescription() + "(" + _iconStore.getIconWidth() + ", " + _iconStore.getIconHeight() + ") scaled " + (float) (_zoomFactor * (float)100) + " %";    } else {      return "Not Available";    }  }  /**   *  Gets the JComponent attribute of the   *  JImageViewer object   *   *@return    The JComponent value   */  public JComponent getJComponent() {    return this;  }  /**   *  Gets the MaximumSize attribute of the   *  JImageViewer object   *   *@return    The MaximumSize value   */  public Dimension getMaximumSize() {    Dimension d = getImageViewSize();    return new Dimension((int)Math.min(d.width, 400), (int)Math.min(d.height, 300));  }  /**   *  Gets the MinimumSize attribute of the   *  JImageViewer object   *   *@return    The MinimumSize value   */  public Dimension getMinimumSize() {    return new Dimension(25, 25);  }  /**   *  Gets the PreferredSize attribute of   *  the JImageViewer object   *   *@return    The PreferredSize value   */  public Dimension getPreferredSize() {    Dimension d = getImageViewSize();    return new Dimension((int)Math.min(d.width, 400), (int)Math.min(d.height, 300));  }  /**   *  Gets the ZoomFactor attribute of the   *  JImageViewer object   *   *@return    The ZoomFactor value   */  public float getZoomFactor() {    return _zoomFactor;  }  /**   *  Description of the Method   */  public void refresh() {    if (_iconStore != null) {      if (_zoomFactor != (float)1) {        _iconView.setImage(_iconStore.getImage().getScaledInstance((int) ((float)_iconStore.getIconWidth() * _zoomFactor), (int) ((float)_iconStore.getIconHeight() * _zoomFactor), Image.SCALE_FAST));      } else {        _iconView.setImage(_iconStore.getImage());      }      if (_iconView != null) {        _lblImg.setIcon(_iconView);        _jpanel.setSize(getImageViewSize());        _jpanel.repaint();        repaint();      }    }  }  public void setXFile(XFile xfile) {  	freeRessource();  	_iconView = new ImageIcon();    _xfile = xfile;    if (!_xfile.isLocal()) {      _xfile.getLocalFile();    }    _iconStore = ImageGrabber.getGrabber().getImage(_xfile);    float zoom = getBestZoomFactor();    if (zoom != 0) {      setZoomFactor(zoom);    }    refresh();  }  /**   *  Sets the ZoomFactor attribute of the   *  JImageViewer object   *   *@param  e_zoomFactor  The new ZoomFactor   *      value   */  public void setZoomFactor(float e_zoomFactor) {    float _oldZoom = _zoomFactor;    if (e_zoomFactor > 0) {      _zoomFactor = e_zoomFactor;    }    if (_oldZoom != _zoomFactor) {      refresh();    }  }  /**   *  Mise en oeuvre du dimensionnement automatique lors de la preview des images   */  private float getBestZoomFactor() {    Dimension d1 = getSize();    Dimension d2 = getImageSize();    float zoomFactor = (float)Math.min((double)d1.getWidth() / (double)d2.getWidth(), (double)d1.getHeight() / (double)d2.getHeight());    return zoomFactor;  }    }

⌨️ 快捷键说明

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