src/share/classes/com/sun/java/swing/plaf/windows/WindowsInternalFrameTitlePane.java

Print this page




  24  */
  25 
  26 package com.sun.java.swing.plaf.windows;
  27 
  28 import sun.swing.SwingUtilities2;
  29 
  30 import javax.swing.*;
  31 import javax.swing.border.*;
  32 import javax.swing.UIManager;
  33 import javax.swing.plaf.*;
  34 import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
  35 import java.awt.*;
  36 import java.awt.event.*;
  37 import java.beans.PropertyChangeEvent;
  38 import java.beans.PropertyChangeListener;
  39 import java.beans.PropertyVetoException;
  40 
  41 import static com.sun.java.swing.plaf.windows.TMSchema.*;
  42 import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
  43 

  44 public class WindowsInternalFrameTitlePane extends BasicInternalFrameTitlePane {
  45     private Color selectedTitleGradientColor;
  46     private Color notSelectedTitleGradientColor;
  47     private JPopupMenu systemPopupMenu;
  48     private JLabel systemLabel;
  49 
  50     private Font titleFont;
  51     private int titlePaneHeight;
  52     private int buttonWidth, buttonHeight;
  53     private boolean hotTrackingOn;
  54 
  55     public WindowsInternalFrameTitlePane(JInternalFrame f) {
  56         super(f);
  57     }
  58 
  59     protected void addSubComponents() {
  60         add(systemLabel);
  61         add(iconButton);
  62         add(maxButton);
  63         add(closeButton);


 250                     g2.setPaint(titleGradient);
 251                 } else {
 252                     GradientPaint titleGradient = new GradientPaint(0,0,
 253                             notSelectedTitleColor,
 254                             (int)(w*.75),0,
 255                             notSelectedTitleGradientColor);
 256                     g2.setPaint(titleGradient);
 257                 }
 258                 g2.fillRect(0, 0, getWidth(), getHeight());
 259                 g2.setPaint(savePaint);
 260             } else {
 261                 super.paintTitleBackground(g);
 262             }
 263         }
 264     }
 265 
 266     protected void assembleSystemMenu() {
 267         systemPopupMenu = new JPopupMenu();
 268         addSystemMenuItems(systemPopupMenu);
 269         enableActions();
 270         systemLabel = new JLabel(frame.getFrameIcon()) {

 271             protected void paintComponent(Graphics g) {
 272                 int x = 0;
 273                 int y = 0;
 274                 int w = getWidth();
 275                 int h = getHeight();
 276                 g = g.create();  // Create scratch graphics
 277                 if (isOpaque()) {
 278                     g.setColor(getBackground());
 279                     g.fillRect(0, 0, w, h);
 280                 }
 281                 Icon icon = getIcon();
 282                 int iconWidth;
 283                 int iconHeight;
 284                 if (icon != null &&
 285                     (iconWidth = icon.getIconWidth()) > 0 &&
 286                     (iconHeight = icon.getIconHeight()) > 0) {
 287 
 288                     // Set drawing scale to make icon scale to our desired size
 289                     double drawScale;
 290                     if (iconWidth > iconHeight) {
 291                         // Center icon vertically
 292                         y = (h - w*iconHeight/iconWidth) / 2;
 293                         drawScale = w / (double)iconWidth;
 294                     } else {
 295                         // Center icon horizontally
 296                         x = (w - h*iconWidth/iconHeight) / 2;
 297                         drawScale = h / (double)iconHeight;
 298                     }
 299                     ((Graphics2D)g).translate(x, y);
 300                     ((Graphics2D)g).scale(drawScale, drawScale);
 301                     icon.paintIcon(this, g, 0, 0);
 302                 }
 303                 g.dispose();
 304             }
 305         };

 306         systemLabel.addMouseListener(new MouseAdapter() {
 307             public void mouseClicked(MouseEvent e) {
 308                 if (e.getClickCount() == 2 && frame.isClosable() &&
 309                     !frame.isIcon()) {
 310                     systemPopupMenu.setVisible(false);
 311                     frame.doDefaultCloseAction();
 312                 }
 313                 else {
 314                     super.mouseClicked(e);
 315                 }
 316             }
 317             public void mousePressed(MouseEvent e) {
 318                 try {
 319                     frame.setSelected(true);
 320                 } catch(PropertyVetoException pve) {
 321                 }
 322                 showSystemPopupMenu(e.getComponent());
 323             }
 324         });
 325     }




  24  */
  25 
  26 package com.sun.java.swing.plaf.windows;
  27 
  28 import sun.swing.SwingUtilities2;
  29 
  30 import javax.swing.*;
  31 import javax.swing.border.*;
  32 import javax.swing.UIManager;
  33 import javax.swing.plaf.*;
  34 import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
  35 import java.awt.*;
  36 import java.awt.event.*;
  37 import java.beans.PropertyChangeEvent;
  38 import java.beans.PropertyChangeListener;
  39 import java.beans.PropertyVetoException;
  40 
  41 import static com.sun.java.swing.plaf.windows.TMSchema.*;
  42 import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
  43 
  44 @SuppressWarnings("serial") // Superclass is not serializable across versions
  45 public class WindowsInternalFrameTitlePane extends BasicInternalFrameTitlePane {
  46     private Color selectedTitleGradientColor;
  47     private Color notSelectedTitleGradientColor;
  48     private JPopupMenu systemPopupMenu;
  49     private JLabel systemLabel;
  50 
  51     private Font titleFont;
  52     private int titlePaneHeight;
  53     private int buttonWidth, buttonHeight;
  54     private boolean hotTrackingOn;
  55 
  56     public WindowsInternalFrameTitlePane(JInternalFrame f) {
  57         super(f);
  58     }
  59 
  60     protected void addSubComponents() {
  61         add(systemLabel);
  62         add(iconButton);
  63         add(maxButton);
  64         add(closeButton);


 251                     g2.setPaint(titleGradient);
 252                 } else {
 253                     GradientPaint titleGradient = new GradientPaint(0,0,
 254                             notSelectedTitleColor,
 255                             (int)(w*.75),0,
 256                             notSelectedTitleGradientColor);
 257                     g2.setPaint(titleGradient);
 258                 }
 259                 g2.fillRect(0, 0, getWidth(), getHeight());
 260                 g2.setPaint(savePaint);
 261             } else {
 262                 super.paintTitleBackground(g);
 263             }
 264         }
 265     }
 266 
 267     protected void assembleSystemMenu() {
 268         systemPopupMenu = new JPopupMenu();
 269         addSystemMenuItems(systemPopupMenu);
 270         enableActions();
 271         @SuppressWarnings("serial") // anonymous class
 272         JLabel tmp = new JLabel(frame.getFrameIcon()) {
 273             protected void paintComponent(Graphics g) {
 274                 int x = 0;
 275                 int y = 0;
 276                 int w = getWidth();
 277                 int h = getHeight();
 278                 g = g.create();  // Create scratch graphics
 279                 if (isOpaque()) {
 280                     g.setColor(getBackground());
 281                     g.fillRect(0, 0, w, h);
 282                 }
 283                 Icon icon = getIcon();
 284                 int iconWidth;
 285                 int iconHeight;
 286                 if (icon != null &&
 287                     (iconWidth = icon.getIconWidth()) > 0 &&
 288                     (iconHeight = icon.getIconHeight()) > 0) {
 289 
 290                     // Set drawing scale to make icon scale to our desired size
 291                     double drawScale;
 292                     if (iconWidth > iconHeight) {
 293                         // Center icon vertically
 294                         y = (h - w*iconHeight/iconWidth) / 2;
 295                         drawScale = w / (double)iconWidth;
 296                     } else {
 297                         // Center icon horizontally
 298                         x = (w - h*iconWidth/iconHeight) / 2;
 299                         drawScale = h / (double)iconHeight;
 300                     }
 301                     ((Graphics2D)g).translate(x, y);
 302                     ((Graphics2D)g).scale(drawScale, drawScale);
 303                     icon.paintIcon(this, g, 0, 0);
 304                 }
 305                 g.dispose();
 306             }
 307         };
 308         systemLabel = tmp;
 309         systemLabel.addMouseListener(new MouseAdapter() {
 310             public void mouseClicked(MouseEvent e) {
 311                 if (e.getClickCount() == 2 && frame.isClosable() &&
 312                     !frame.isIcon()) {
 313                     systemPopupMenu.setVisible(false);
 314                     frame.doDefaultCloseAction();
 315                 }
 316                 else {
 317                     super.mouseClicked(e);
 318                 }
 319             }
 320             public void mousePressed(MouseEvent e) {
 321                 try {
 322                     frame.setSelected(true);
 323                 } catch(PropertyVetoException pve) {
 324                 }
 325                 showSystemPopupMenu(e.getComponent());
 326             }
 327         });
 328     }