basicinternalframeui.java

来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 1,697 行 · 第 1/4 页

JAVA
1,697
字号
            {              MouseEvent newEvt = SwingUtilities.convertMouseEvent(                                                                   frame.getGlassPane(),                                                                   me,                                                                   mouseEventTarget);              mouseEventTarget.dispatchEvent(newEvt);              switch (e.getID())                {                case MouseEvent.MOUSE_PRESSED:                  if (pressCount++ == 0)                    pressedComponent = mouseEventTarget;                  break;                case MouseEvent.MOUSE_RELEASED:                  // Clear our memory of the original PRESSED event, only if                  // we're not expecting a CLICKED event after this. If                  // there is a CLICKED event after this, it will do clean up.                  if (--pressCount == 0 && mouseEventTarget != pressedComponent)                    pressedComponent = null;                  break;                }            }        }    }  }  /**   * This helper class listens for PropertyChangeEvents from the   * JInternalFrame.   */  public class InternalFramePropertyChangeListener    implements PropertyChangeListener  {    /**     * This method is called when one of the JInternalFrame's properties change.     *      * @param evt     *          The PropertyChangeEvent.     */    public void propertyChange(PropertyChangeEvent evt)    {      if (evt.getPropertyName().equals(JInternalFrame.IS_MAXIMUM_PROPERTY))        {          if (frame.isMaximum())            maximizeFrame(frame);          else            minimizeFrame(frame);        }      else if (evt.getPropertyName().equals(JInternalFrame.IS_ICON_PROPERTY))        {          if (frame.isIcon())            iconifyFrame(frame);          else            deiconifyFrame(frame);        }      else if (evt.getPropertyName().equals(JInternalFrame.IS_SELECTED_PROPERTY))        {          if (frame.isSelected())            activateFrame(frame);          else            deactivateFrame(frame);        }      else if (evt.getPropertyName().equals(JInternalFrame.ROOT_PANE_PROPERTY)               || evt.getPropertyName().equals(                                               JInternalFrame.GLASS_PANE_PROPERTY))        {          Component old = (Component) evt.getOldValue();          old.removeMouseListener(glassPaneDispatcher);          old.removeMouseMotionListener(glassPaneDispatcher);          Component newPane = (Component) evt.getNewValue();          newPane.addMouseListener(glassPaneDispatcher);          newPane.addMouseMotionListener(glassPaneDispatcher);          frame.revalidate();        }      /*       * FIXME: need to add ancestor properties to JComponents. else if       * (evt.getPropertyName().equals(JComponent.ANCESTOR_PROPERTY)) { if       * (desktopPane != null)       * desktopPane.removeComponentListener(componentListener); desktopPane =       * frame.getDesktopPane(); if (desktopPane != null)       * desktopPane.addComponentListener(componentListener); }       */    }  }  /**   * This helper class is the border for the JInternalFrame.   */  private class InternalFrameBorder extends AbstractBorder implements      UIResource  {    /** The width of the border. */    private static final int bSize = 5;    /** The size of the corners. */    private static final int offset = 10;    /**     * This method returns whether the border is opaque.     *      * @return Whether the border is opaque.     */    public boolean isBorderOpaque()    {      return true;    }    /**     * This method returns the insets of the border.     *      * @param c     *          The Component to find border insets for.     * @return The border insets.     */    public Insets getBorderInsets(Component c)    {      return new Insets(bSize, bSize, bSize, bSize);    }    /**     * This method paints the border.     *      * @param c     *          The Component that owns the border.     * @param g     *          The Graphics object to paint with.     * @param x     *          The x coordinate to paint at.     * @param y     *          The y coordinate to paint at.     * @param width     *          The width of the Component.     * @param height     *          The height of the Component.     */    public void paintBorder(Component c, Graphics g, int x, int y, int width,                            int height)    {      g.translate(x, y);      Color saved = g.getColor();      Rectangle b = frame.getBounds();      Color d = c.getBackground();      g.setColor(d);      g.fillRect(0, 0, bSize, b.height);      g.fillRect(0, 0, b.width, bSize);      g.fillRect(0, b.height - bSize, b.width, bSize);      g.fillRect(b.width - bSize, 0, bSize, b.height);      int x1 = 0;      int x2 = bSize;      int x3 = b.width - bSize;      int x4 = b.width;      int y1 = 0;      int y2 = bSize;      int y3 = b.height - bSize;      int y4 = b.height;      g.setColor(Color.GRAY);      g.fillRect(0, 0, bSize, y4);      g.fillRect(0, 0, x4, bSize);      g.fillRect(0, y3, b.width, bSize);      g.fillRect(x3, 0, bSize, b.height);      g.fill3DRect(0, offset, bSize, b.height - 2 * offset, false);      g.fill3DRect(offset, 0, b.width - 2 * offset, bSize, false);      g.fill3DRect(offset, b.height - bSize, b.width - 2 * offset, bSize, false);      g.fill3DRect(b.width - bSize, offset, bSize, b.height - 2 * offset, false);      g.translate(-x, -y);      g.setColor(saved);    }  }  /**   * The MouseListener that is responsible for dragging and resizing the   * JInternalFrame in response to MouseEvents.   */  protected MouseInputAdapter borderListener;  /**   * The ComponentListener that is responsible for resizing the JInternalFrame   * in response to ComponentEvents from the JDesktopPane.   */  protected ComponentListener componentListener;  /**   * The MouseListener that is responsible for activating the JInternalFrame   * when the mouse press activates one of its descendents.   */  protected MouseInputListener glassPaneDispatcher;  /**   * The PropertyChangeListener that is responsible for listening to   * PropertyChangeEvents from the JInternalFrame.   */  protected PropertyChangeListener propertyChangeListener;  /** The InternalFrameListener that listens to the JInternalFrame. */  private transient BasicInternalFrameListener internalFrameListener;  /** The JComponent placed at the east region of the JInternalFrame. */  protected JComponent eastPane;  /** The JComponent placed at the north region of the JInternalFrame. */  protected JComponent northPane;  /** The JComponent placed at the south region of the JInternalFrame. */  protected JComponent southPane;  /** The JComponent placed at the west region of the JInternalFrame. */  protected JComponent westPane;  /**   * The Keystroke bound to open the menu.   * @deprecated   */  protected KeyStroke openMenuKey;  /** The TitlePane displayed at the top of the JInternalFrame. */  protected BasicInternalFrameTitlePane titlePane;  /** The JInternalFrame this UI is responsible for. */  protected JInternalFrame frame;  /** The LayoutManager used in the JInternalFrame. */  protected LayoutManager internalFrameLayout;  /** The JDesktopPane that is the parent of the JInternalFrame. */  private transient JDesktopPane desktopPane;  /**   * Creates a new BasicInternalFrameUI object.   *   * @param b The JInternalFrame this UI will represent.   */  public BasicInternalFrameUI(JInternalFrame b)  {    // Nothing to do here.  }  /**   * This method will create a new BasicInternalFrameUI for the given   * JComponent.   *   * @param b The JComponent to create a BasicInternalFrameUI for.   *   * @return A new BasicInternalFrameUI.   */  public static ComponentUI createUI(JComponent b)  {    return new BasicInternalFrameUI((JInternalFrame) b);  }  /**   * This method installs a UI for the JInternalFrame.   *   * @param c The JComponent to install this UI on.   */  public void installUI(JComponent c)  {    if (c instanceof JInternalFrame)      {        frame = (JInternalFrame) c;        installDefaults();        installListeners();        installComponents();        installKeyboardActions();        if (! frame.isSelected())          frame.getGlassPane().setVisible(true);      }  }  /**   * This method reverses the work done by installUI.   *   * @param c The JComponent to uninstall this UI for.   */  public void uninstallUI(JComponent c)  {    uninstallKeyboardActions();    uninstallComponents();    uninstallListeners();    uninstallDefaults();    frame.getRootPane().getGlassPane().setVisible(false);    frame = null;  }  /**   * This method installs the defaults specified by the look and feel.   */  protected void installDefaults()    {      internalFrameLayout = createLayoutManager();      frame.setLayout(internalFrameLayout);      LookAndFeel.installBorder(frame, "InternalFrame.border");      frame.setFrameIcon(UIManager.getIcon("InternalFrame.icon"));  }  /**   * This method installs the keyboard actions for the JInternalFrame.   */  protected void installKeyboardActions()  {    // FIXME: Implement.  }  /**   * This method installs the Components for the JInternalFrame.   */  protected void installComponents()  {    setNorthPane(createNorthPane(frame));    setSouthPane(createSouthPane(frame));    setEastPane(createEastPane(frame));    setWestPane(createWestPane(frame));  }  /**   * This method installs the listeners for the JInternalFrame.   */  protected void installListeners()  {    glassPaneDispatcher = createGlassPaneDispatcher();    createInternalFrameListener();    borderListener = createBorderListener(frame);    componentListener = createComponentListener();    propertyChangeListener = createPropertyChangeListener();    frame.addMouseListener(borderListener);    frame.addMouseMotionListener(borderListener);    frame.addInternalFrameListener(internalFrameListener);    frame.addPropertyChangeListener(propertyChangeListener);    frame.getRootPane().getGlassPane().addMouseListener(glassPaneDispatcher);    frame.getRootPane().getGlassPane().addMouseMotionListener(glassPaneDispatcher);  }  /**   * This method uninstalls the defaults for the JInternalFrame.   */  protected void uninstallDefaults()  {    frame.setBorder(null);    frame.setLayout(null);    internalFrameLayout = null;  }  /**   * This method uninstalls the Components for the JInternalFrame.   */  protected void uninstallComponents()  {    setNorthPane(null);    setSouthPane(null);    setEastPane(null);    setWestPane(null);  }  /**   * This method uninstalls the listeners for the JInternalFrame.   */  protected void uninstallListeners()  {    if (desktopPane != null)      desktopPane.removeComponentListener(componentListener);    frame.getRootPane().getGlassPane().removeMouseMotionListener(glassPaneDispatcher);    frame.getRootPane().getGlassPane().removeMouseListener(glassPaneDispatcher);    frame.removePropertyChangeListener(propertyChangeListener);    frame.removeInternalFrameListener(internalFrameListener);    frame.removeMouseMotionListener(borderListener);    frame.removeMouseListener(borderListener);    propertyChangeListener = null;    componentListener = null;    borderListener = null;    internalFrameListener = null;    glassPaneDispatcher = null;  }  /**   * This method uninstalls the keyboard actions for the JInternalFrame.   */  protected void uninstallKeyboardActions()  {    // FIXME: Implement.  }  /**   * This method creates a new LayoutManager for the JInternalFrame.   *   * @return A new LayoutManager for the JInternalFrame.   */  protected LayoutManager createLayoutManager()  {    return new InternalFrameLayout();  }  /**   * This method creates a new PropertyChangeListener for the JInternalFrame.   *   * @return A new PropertyChangeListener for the JInternalFrame.   */  protected PropertyChangeListener createPropertyChangeListener()  {    return new InternalFramePropertyChangeListener();  }  /**   * This method returns the preferred size of the given JComponent.   *   * @param x The JComponent to find a preferred size for.   *   * @return The preferred size.   */  public Dimension getPreferredSize(JComponent x)  {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?