1 23 24 package com.sun.enterprise.tools.upgrade.gui; 25 26 import java.awt.*; 27 import java.awt.image.ImageObserver ; 28 29 32 public class ImagePanel extends InsetsPanel 33 { 34 35 public static final int LEFT = 1; 36 public static final int CENTER = 2; 37 public static final int RIGHT = 3; 38 public static final int TOP = 1; 39 public static final int BOTTOM = 3; 40 protected Image image; 41 protected int hAlign; 42 protected int vAlign; 43 protected boolean loaded; 44 45 public ImagePanel() 46 { 47 image = null; 48 hAlign = 2; 49 vAlign = 2; 50 loaded = false; 51 } 52 53 public ImagePanel(int i, int j) 54 { 55 image = null; 56 hAlign = 2; 57 vAlign = 2; 58 loaded = false; 59 hAlign = i; 60 vAlign = j; 61 } 62 63 public ImagePanel(Insets insets) 64 { 65 image = null; 67 hAlign = 2; 68 vAlign = 2; 69 loaded = false; 70 } 71 72 public ImagePanel(LayoutManager layoutmanager) 73 { 74 super(layoutmanager); 75 image = null; 76 hAlign = 2; 77 vAlign = 2; 78 loaded = false; 79 } 80 81 public Dimension getMinimumSize() 82 { 83 return getPreferredSize(); 84 } 85 86 public Dimension getPreferredSize() 87 { 88 Dimension dimension = new Dimension(0, 0); 89 if(image != null) 90 { 91 dimension.width = image.getWidth(this); 92 dimension.height = image.getHeight(this); 93 } 94 return dimension; 95 } 96 97 public synchronized boolean imageUpdate(Image image1, int i, int j, int k, int l, int i1) 98 { 99 if((i & 0x20) != 0) 100 { 101 loaded = true; 102 repaint(); 103 return false; 104 } else 105 { 106 return true; 107 } 108 } 109 110 public void paint(Graphics g) 111 { 112 super.paint(g); 113 if(loaded) 114 { 115 int i = 0; 116 int j = 0; 117 int k = image.getWidth(this); 118 int l = image.getHeight(this); 119 Dimension dimension = getSize(); 120 g.setClip(0, 0, dimension.width, dimension.height); 121 switch(hAlign) 122 { 123 case 1: i = super.insets.left; 125 break; 126 127 case 2: i = (dimension.width - (super.insets.left + super.insets.right) - k) / 2 + super.insets.left; 129 break; 130 131 case 3: i = dimension.width - k - super.insets.right; 133 break; 134 } 135 switch(vAlign) 136 { 137 case 1: j = super.insets.top; 139 break; 140 141 case 2: j = (dimension.height - (super.insets.top + super.insets.bottom) - l) / 2 + super.insets.top; 143 break; 144 145 case 3: j = dimension.height - l - super.insets.bottom; 147 break; 148 } 149 g.drawImage(image, i, j, this); 150 } 151 } 152 153 public void setAlignment(int i, int j) 154 { 155 hAlign = i; 156 vAlign = j; 157 } 158 159 public void setImage(Image image1) 160 { 161 loaded = false; 162 image = image1; 163 prepareImage(image1, this); 164 } 165 } 166 | Popular Tags |