1 package SnowMailClient.view.attachments; 2 3 import SnowMailClient.model.multipart.*; 4 import SnowMailClient.SnowMailClientApp; 5 import snow.utils.storage.*; 6 import snow.utils.gui.*; 7 import snow.Language.Language; 8 9 import javax.swing.*; 10 import javax.imageio.*; 11 import java.awt.*; 12 import java.awt.image.*; 13 import java.awt.event.*; 14 import java.io.*; 15 16 19 public class ImageViewer extends JDialog 20 { 21 final ImageViewerPanel imagePanel = new ImageViewerPanel(); 22 23 public ImageViewer(SnowMailClientApp ref, MimePart part) 24 { 25 super(ref, "Image viewer (Mime part "+part.getName()+")", true); 26 27 28 getContentPane().setLayout(new BorderLayout()); 29 getContentPane().add(imagePanel, BorderLayout.CENTER); 30 31 JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); 32 getContentPane().add(controlPanel, BorderLayout.SOUTH); 33 34 JButton okBt = new JButton(Language.translate("Close")); 35 controlPanel.add(okBt); 36 okBt.setBackground(Color.orange); 37 okBt.setMargin(new Insets(1,2,1,2)); 38 okBt.addActionListener(new ActionListener() 39 { 40 public void actionPerformed(ActionEvent e) 41 { 42 setVisible(false); 43 imagePanel.setImage(null); 44 dispose(); 45 } 46 }); 47 48 int sizeX = 300; 49 int sizeY = 200; 50 51 BufferedImage bim = null; 52 53 try 54 { 55 byte[] cont = part.getByteContent(); 56 ByteArrayInputStream bin = new ByteArrayInputStream(cont); 57 bim = ImageIO.read(bin); 58 59 sizeX = bim.getWidth(); 60 sizeY = bim.getHeight(); 61 } 62 catch(Exception e) 63 { 64 e.printStackTrace(); 65 } 67 75 78 ref.getProperties().setComponentSizeFromINIFile(this, "ImageViewer", 400, 400, 200,200); 79 this.setPreferredSize( this.getPreferredSize() ); 80 imagePanel.setPreferredSize( imagePanel.getPreferredSize() ); 81 imagePanel.setSize( imagePanel.getPreferredSize() ); 82 83 imagePanel.setImage(bim); 85 86 this.setVisible(true); 88 ref.getProperties().saveComponentSizeInINIFile(this, "ImageViewer"); 90 imagePanel.terminate(); 91 92 } 94 95 96 97 98 } | Popular Tags |