Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/arranger/jarl/shell/views/PreviewingAnimationView.java


1   package com.arranger.jarl.shell.views;
2   
3   import com.arranger.jarl.shell.models.BaseModel;
4   import com.arranger.jarl.shell.models.ViewAnimationModel;
5   import com.arranger.jarl.util.ImageUtil;
6   
7   import javax.swing.*;
8   import java.awt.*;
9   
10  /**
11   * PreviewingAnimationView created on Apr 25, 2003
12   */
13  public class PreviewingAnimationView extends BaseView {
14  
15      protected JarlShellFrame m_jarlShellFrame;
16      protected ImageLabel m_imageLabel;
17      protected boolean m_animationCompleted = false;
18      protected boolean m_animationAborted = false;
19  
20      public String[] getModelsToSubscribe() {
21          return new String[]{ViewAnimationModel.class.getName()};
22      }
23  
24      public void onChange(BaseModel baseModel, String propertyName) {
25          ViewAnimationModel vam = (ViewAnimationModel) baseModel;
26          if (ViewAnimationModel.ANIMATION_INITIALIZING.equals(propertyName)) {
27              initialize(vam);
28          } else if (ViewAnimationModel.CURRENT_IMAGE.equals(propertyName)) {
29              updateImage(vam);
30          } else if (ViewAnimationModel.ANIMATION_STOPPED.equals(propertyName)) {
31              m_animationCompleted = true;
32          }
33      }
34  
35      protected void initialize(ViewAnimationModel vam) {
36          Dimension dimension = vam.getDimension();
37          m_imageLabel = new ImageLabel(vam.getInitialImage(), dimension);
38          m_jarlShellFrame = JarlShellFrame.createJarlShellFrame(m_jarlShell,
39                  m_imageLabel,
40                  (int) dimension.getWidth() + RenderedImageView.SPACING_WIDTH,
41                  (int) dimension.getHeight() + RenderedImageView.SPACING_HEIGHT,
42                  "Animation series: " + vam.getAnimationDir());
43  
44          //addMenu();
45  
46          m_jarlShellFrame.setResizable(false);
47          m_jarlShellFrame.addWindowClosingListener(new WindowClosingListener());
48          m_jarlShellFrame.packAndShow();
49      }
50  
51      protected class WindowClosingListener implements JarlShellFrame.JarlShellFrameClosingListener {
52          public void onClosing() {
53              if (!m_animationCompleted) {
54                  ((ViewAnimationModel) m_jarlShell.getModel(ViewAnimationModel.class.getName())).stopAnimation();
55                  m_animationAborted = true;
56              }
57          }
58      }
59  
60      public void updateImage(ViewAnimationModel vam) {
61          m_imageLabel.updateImage(vam.getCurrentImage());
62          m_jarlShellFrame.setTitle(vam.getAnimationDir() + " frame: " + vam.getCurrentImageIndex());
63          m_imageLabel.repaint();
64      }
65  
66      protected static class ImageLabel extends JLabel {
67          protected Image m_image;
68          protected Dimension m_dimension;
69  
70          public ImageLabel(Image image, Dimension dimension) {
71              m_image = image;
72              setDimension(dimension);
73              setDoubleBuffered(false);
74          }
75  
76          protected void setDimension(Dimension dimension) {
77              m_dimension = dimension;
78              setPreferredSize(m_dimension);
79              setMinimumSize(m_dimension);
80              setMaximumSize(m_dimension);
81          }
82  
83          public void updateImage(Image image) {
84              m_image = ImageUtil.toBufferedImage(image);
85          }
86  
87          protected void paintComponent(Graphics g) {
88              ImageUtil.overlayTransparentImage(g, m_image);
89          }
90      }
91  }