Package generic.gui.document.media.image

Source Code of generic.gui.document.media.image.PanelViewImage

package generic.gui.document.media.image;

import java.awt.BorderLayout;
import java.awt.image.BufferedImage;
import java.io.IOException;

import net.alteiar.beans.media.ImageBean;
import net.alteiar.campaign.player.gui.documents.PanelViewDocument;
import net.alteiar.campaign.player.logger.ExceptionTool;
import net.alteiar.documents.BeanDocument;
import net.alteiar.zoom.MoveZoomListener;
import net.alteiar.zoom.PanelMoveZoom;

public class PanelViewImage extends PanelViewDocument {
  private static final long serialVersionUID = 1L;

  public PanelViewImage() {
    this.setLayout(new BorderLayout());
  }

  @Override
  public void setDocument(BeanDocument doc) {
    this.removeAll();

    ImageBean imgBean = doc.getBean();
    if (imgBean != null) {
      try {
        BufferedImage img = imgBean.getImage().restoreImage();

        PanelImage imgPane = new PanelImage(img);
        PanelMoveZoom<PanelImage> scroll = new PanelMoveZoom<PanelImage>(
            imgPane);

        MoveZoomListener listener = new MoveZoomListener(scroll);
        scroll.addMouseListener(listener);
        scroll.addMouseMotionListener(listener);
        scroll.addMouseWheelListener(listener);

        imgPane.addMouseListener(listener);
        imgPane.addMouseMotionListener(listener);
        imgPane.addMouseWheelListener(listener);

        this.add(scroll, BorderLayout.CENTER);
      } catch (IOException e) {
        // TODO
        // set image to a default not able to read image message
        // img = null;
        ExceptionTool.showError(e);
      }
    }
  }

}
TOP

Related Classes of generic.gui.document.media.image.PanelViewImage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.