1 19 20 package org.netbeans.bluej.welcome; 21 22 import java.awt.Color ; 23 import java.awt.Component ; 24 import java.awt.Container ; 25 import java.awt.Cursor ; 26 import java.awt.Dimension ; 27 import java.awt.GradientPaint ; 28 import java.awt.Graphics ; 29 import java.awt.Graphics2D ; 30 import java.awt.Image ; 31 import java.awt.LayoutManager ; 32 import java.awt.Paint ; 33 import java.awt.Point ; 34 import java.awt.geom.Point2D ; 35 import javax.swing.ImageIcon ; 36 import javax.swing.JComponent ; 37 import javax.swing.SwingUtilities ; 38 import org.openide.util.Utilities; 39 40 52 public class TitlePanel50 extends javax.swing.JPanel implements Runnable , java.awt.event.ActionListener , java.awt.event.MouseListener , LayoutManager { 53 54 private final ImageIcon background; 55 private int backgroundWidth = -1; 56 private int backgroundHeight = -1; 57 58 private static final Color TOP_COLOR = new Color (224,221,209); private static final Color BOT_COLOR = new Color (217,207,174); 61 private static final int BUTTONS_X_OFFSET = 380; 63 private static final int GRADIENT_WIDTH = 53; 65 private static final int GRADIENT_HEIGHT = 89; 66 67 private static final int TRANSPARENT_EDGE_WIDTH = 15; 69 70 public TitlePanel50() { 71 background = new ImageIcon (Utilities.loadImage("org/netbeans/bluej/welcome/background.png")); initComponents(); 73 74 ((OvalButton)jButton2).setScale(1.333f); 75 setLayout(this); 76 setOpaque(false); 77 } 78 79 80 public void paint(Graphics g) { 81 82 84 Graphics2D g2d = (Graphics2D )g; 85 int xx = getWidth(); 86 int yy = getHeight(); 87 88 int offset_x = (xx - backgroundWidth())/2; 89 int offset_y = (yy - backgroundHeight())/2; 90 91 g2d.setColor(TOP_COLOR); 93 g2d.fillRect(0, 0, xx, (yy-GRADIENT_HEIGHT)/2); 94 Image image = Utilities.loadImage("org/netbeans/bluej/welcome/gradient.png"); for (int i = 0; i<xx; i+=GRADIENT_WIDTH) { 96 if (i > (offset_x + TRANSPARENT_EDGE_WIDTH) && i< (offset_x + backgroundWidth() - GRADIENT_WIDTH - TRANSPARENT_EDGE_WIDTH)) { 97 continue; 98 } 99 g2d.drawImage(image, i, (yy-GRADIENT_HEIGHT)/2, this); 100 } 101 g2d.setColor(BOT_COLOR); 102 g2d.fillRect(0, (yy+GRADIENT_HEIGHT)/2, xx, yy); 103 104 105 g.drawImage(background.getImage(), offset_x, offset_y, this); 106 107 pc(jButton2, g); 108 pc(jButton3, g); 109 pc(jButton4, g); 110 pc(jLabel3, g); 111 112 } 115 116 private void pc (JComponent jc, Graphics g) { 117 int x = jc.getX(); 118 int y = jc.getY(); 119 g.translate (x, y); 120 jc.paint(g); 121 g.translate(-x, -y); 122 } 123 124 private int backgroundWidth() { 125 if (backgroundWidth == -1) { 126 backgroundWidth = background.getIconWidth(); 127 } 128 return backgroundWidth; 129 } 130 131 private int backgroundHeight() { 132 if (backgroundHeight == -1) { 133 backgroundHeight = background.getIconHeight(); 134 } 135 return backgroundHeight; 136 } 137 138 public void addNotify() { 139 super.addNotify(); 140 SwingUtilities.invokeLater(this); 142 } 143 144 public void run() { 145 Cursor cur = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); 148 jLabel3.setCursor(cur); 149 jButton2.setCursor(cur); 150 jButton3.setCursor(cur); 151 jButton4.setCursor(cur); 152 } 153 186 public void addLayoutComponent(String name, Component comp) { 188 } 189 190 public void removeLayoutComponent(Component comp) { 191 } 192 193 public Dimension preferredLayoutSize(Container parent) { 194 return new Dimension (backgroundWidth(), backgroundHeight()); 195 } 196 197 public Dimension minimumLayoutSize(Container parent) { 198 return preferredLayoutSize(parent); 199 } 200 201 public void layoutContainer(Container parent) { 202 203 int offset_x = (parent.getSize().width - backgroundWidth())/2; 204 int offset_y = (parent.getSize().height - backgroundHeight())/2; 205 206 int base_x = offset_x + BUTTONS_X_OFFSET; 207 int base_y = offset_y + 287; int SMALL_SPACE = 5; 209 int NB_LOGO_ALIGN = 4; 210 int BOT_GROUP_ALIGN = 16; int TOP_BUTTON_HEIGHT = 22; 212 int BOT_BUTTON_HEIGHT = 18; 213 214 int y = base_y; 215 int w = maxWidth(); 216 217 y -= TOP_BUTTON_HEIGHT + SMALL_SPACE + NB_LOGO_ALIGN; 218 jButton2.setLocation(base_x, y); 219 resize(jButton2, w, TOP_BUTTON_HEIGHT); 220 221 225 227 y = base_y + SMALL_SPACE + BOT_GROUP_ALIGN; 228 jButton3.setLocation(base_x, y); 229 resize(jButton3, w, BOT_BUTTON_HEIGHT); 230 231 y += BOT_BUTTON_HEIGHT + SMALL_SPACE; 232 jButton4.setLocation(base_x, y); 233 resize(jButton4, w, BOT_BUTTON_HEIGHT); 234 235 jLabel3.setSize(160, 35); jLabel3.setLocation(50 + offset_x, 246 + offset_y); 238 239 } 240 241 private void resize(JComponent target, int width, int height) { 242 target.setSize(width, height); 243 } 244 245 private int maxWidth() { 246 return backgroundWidth() - BUTTONS_X_OFFSET - TRANSPARENT_EDGE_WIDTH; } 248 249 251 252 257 private void initComponents() { 259 jButton2 = new OvalButton(); 260 jButton3 = new OvalButton(); 261 jButton4 = new OvalButton(); 262 jLabel3 = new javax.swing.JLabel (); 263 264 org.openide.awt.Mnemonics.setLocalizedText(jButton2, org.openide.util.NbBundle.getMessage(TitlePanel50.class, "BK0002")); 265 jButton2.setFocusable(false); 266 jButton2.addActionListener(this); 267 268 add(jButton2); 269 270 org.openide.awt.Mnemonics.setLocalizedText(jButton3, org.openide.util.NbBundle.getMessage(TitlePanel50.class, "BK0003")); 271 jButton3.setFocusable(false); 272 jButton3.addActionListener(this); 273 274 add(jButton3); 275 276 org.openide.awt.Mnemonics.setLocalizedText(jButton4, org.openide.util.NbBundle.getMessage(TitlePanel50.class, "BK0004")); 277 jButton4.setFocusable(false); 278 jButton4.addActionListener(this); 279 280 add(jButton4); 281 282 jLabel3.addMouseListener(this); 283 284 add(jLabel3); 285 286 } 287 288 290 public void actionPerformed(java.awt.event.ActionEvent evt) { 291 if (evt.getSource() == jButton2) { 292 TitlePanel50.this.jButton2ActionPerformed(evt); 293 } 294 else if (evt.getSource() == jButton3) { 295 TitlePanel50.this.jButton3ActionPerformed(evt); 296 } 297 else if (evt.getSource() == jButton4) { 298 TitlePanel50.this.jButton4ActionPerformed(evt); 299 } 300 } 301 302 public void mouseClicked(java.awt.event.MouseEvent evt) { 303 if (evt.getSource() == jLabel3) { 304 TitlePanel50.this.jLabel3MouseClicked(evt); 305 } 306 } 307 308 public void mouseEntered(java.awt.event.MouseEvent evt) { 309 } 310 311 public void mouseExited(java.awt.event.MouseEvent evt) { 312 } 313 314 public void mousePressed(java.awt.event.MouseEvent evt) { 315 } 316 317 public void mouseReleased(java.awt.event.MouseEvent evt) { 318 } 320 private void jLabel3MouseClicked(java.awt.event.MouseEvent evt) { BusinessLogic.perform(103, this); 322 } 324 private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { BusinessLogic.perform(4, this); 326 } 328 private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { BusinessLogic.perform(3, this); 330 } 332 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { BusinessLogic.perform(2, this); 334 } 336 337 private javax.swing.JButton jButton2; 339 private javax.swing.JButton jButton3; 340 private javax.swing.JButton jButton4; 341 private javax.swing.JLabel jLabel3; 342 344 } 345 | Popular Tags |