ImageFrame.java

00001 /*
00002  * Created on 2-jun-2005
00003  *
00004  * TODO To change the template for this generated file go to
00005  * Window - Preferences - Java - Code Style - Code Templates
00006  */
00007 package GUI;
00008 
00009 import java.awt.BorderLayout;
00010 import java.awt.Dimension;
00011 import java.awt.Image;
00012 import java.awt.Toolkit;
00013 
00014 import javax.swing.JInternalFrame;
00015 
00022 public class ImageFrame extends JInternalFrame {
00023 
00024         private String naam;
00025         private javax.swing.JPanel jContentPane = null;
00026         private ImagePanel imagePanel = null;
00030         public ImageFrame(String naam, Dimension newSize) {
00031                 super();
00032                 this.naam = naam;
00033                 this.setSize(newSize);
00034                 initialize();
00035         }
00041         private void initialize() {
00042                 this.setPreferredSize(new java.awt.Dimension(320,240));
00043                 this.setContentPane(getJContentPane());
00044         }
00050         private javax.swing.JPanel getJContentPane() {
00051                 if(jContentPane == null) {
00052                         jContentPane = new javax.swing.JPanel();
00053                         jContentPane.setLayout(null);
00054                         jContentPane.setPreferredSize(new java.awt.Dimension(320,240));
00055                         jContentPane.add(getImagePanel(), BorderLayout.CENTER);
00056                 }
00057                 return jContentPane;
00058         }
00064         private ImagePanel getImagePanel() {
00065                 if (imagePanel == null) {
00066                         imagePanel = new ImagePanel();
00067                         imagePanel.setOpaque(false);
00068                         Image image = Toolkit.getDefaultToolkit().getImage(naam);
00069                         imagePanel.setBounds(0, 0, getContentPane().getWidth(), getContentPane().getHeight());
00070                         imagePanel.setSize(this.getSize());
00071                         imagePanel.setImage(image);
00072 
00073                         /*
00074                          * Verzorgt de size van de panel & frame adv de image, als kleiner wordt alles kleiner ;)
00075                          */
00076                         int newPanelHeight;
00077                         while (imagePanel.getImageHeight() < 1 && imagePanel.getImageWidth() < 1)
00078                         {
00079                                 //loop totdat imagesize bekend is ;)
00080                         }
00081                         if (imagePanel.getHeight() > imagePanel.getImageHeight()) // Is het panel hoger dan de image?
00082                         {
00083                                 newPanelHeight = imagePanel.getImageHeight(); // zo niet dan maak het panel even hoog al de image.
00084                         }
00085                         else {newPanelHeight = imagePanel.getHeight();} // zo wel, verander dan niets.
00086                         
00087                         int newPanelWidth;
00088                         if (imagePanel.getWidth() > imagePanel.getImageWidth())// Is het panel breeder dan de image?
00089                         {
00090                                 newPanelWidth = imagePanel.getImageWidth(); // zo niet dan maak het panel even breed al de image.
00091                         }
00092                         else {newPanelWidth = imagePanel.getWidth();} // zo wel, verander dan niets.
00093                         
00094                         imagePanel.setSize(newPanelWidth,newPanelHeight); // Set de grootte van de panel.
00095                         this.setSize(newPanelWidth,newPanelHeight);             // Set de grootte van het frame.
00097                 }
00098                 return imagePanel;
00099         }
00100  }

Generated on Mon Jul 18 21:59:05 2005 for Twee Voor Twaalf by  doxygen 1.4.3