⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 skinrootpaneui.java

📁 Skin Look And Feel 1.2.10, 给你的java程序换肤, 支持大量通用皮肤文件.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      if (maxHeight != Integer.MAX_VALUE) {
        maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom;
      }

      int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth);
      // Similar overflow comment as above
      if (maxWidth != Integer.MAX_VALUE) {
        maxWidth += i.left + i.right;
      }

      return new Dimension(maxWidth, maxHeight);
    }

    /**
     * Instructs the layout manager to perform the layout for the specified
     * container.
     * 
     * @param parent the Container for which this layout manager is being used
     */
    public void layoutContainer(Container parent) {
      JRootPane root = (JRootPane)parent;
      Rectangle b = root.getBounds();
      Insets i = root.getInsets();
      int nextY = 0;
      int w = b.width - i.right - i.left;
      int h = b.height - i.top - i.bottom;

      if (root.getLayeredPane() != null) {
        root.getLayeredPane().setBounds(i.left, i.top, w, h);
      }
      if (root.getGlassPane() != null) {
        root.getGlassPane().setBounds(i.left, i.top, w, h);
      }
      // Note: This is laying out the children in the layeredPane,
      // technically, these are not our children.
      if (getWindowDecorationStyle(root) != JRootPane_NONE
        && (root.getUI() instanceof SkinRootPaneUI)) {
        JComponent titlePane = ((SkinRootPaneUI)root.getUI()).getTitlePane();
        if (titlePane != null) {
          Dimension tpd = titlePane.getPreferredSize();
          if (tpd != null) {
            int tpHeight = tpd.height;
            titlePane.setBounds(0, 0, w, tpHeight);
            nextY += tpHeight;
          }
        }
      }
      if (root.getJMenuBar() != null) {
        Dimension mbd = root.getJMenuBar().getPreferredSize();
        root.getJMenuBar().setBounds(0, nextY, w, mbd.height);
        nextY += mbd.height;
      }
      if (root.getContentPane() != null) {
        root.getContentPane().setBounds(0, nextY, w, h < nextY ? 0 : h - nextY);
      }
    }

    public void addLayoutComponent(String name, Component comp) {
    }
    public void removeLayoutComponent(Component comp) {
    }
    public void addLayoutComponent(Component comp, Object constraints) {
    }
    public float getLayoutAlignmentX(Container target) {
      return 0.0f;
    }
    public float getLayoutAlignmentY(Container target) {
      return 0.0f;
    }
    public void invalidateLayout(Container target) {
    }
  }

  /**
   * Maps from positions to cursor type. Refer to calculateCorner and
   * calculatePosition for details of this.
   */
  private static final int[] cursorMapping =
    new int[] {
      Cursor.NW_RESIZE_CURSOR,
      Cursor.NW_RESIZE_CURSOR,
      Cursor.N_RESIZE_CURSOR,
      Cursor.NE_RESIZE_CURSOR,
      Cursor.NE_RESIZE_CURSOR,
      Cursor.NW_RESIZE_CURSOR,
      0,
      0,
      0,
      Cursor.NE_RESIZE_CURSOR,
      Cursor.W_RESIZE_CURSOR,
      0,
      0,
      0,
      Cursor.E_RESIZE_CURSOR,
      Cursor.SW_RESIZE_CURSOR,
      0,
      0,
      0,
      Cursor.SE_RESIZE_CURSOR,
      Cursor.SW_RESIZE_CURSOR,
      Cursor.SW_RESIZE_CURSOR,
      Cursor.S_RESIZE_CURSOR,
      Cursor.SE_RESIZE_CURSOR,
      Cursor.SE_RESIZE_CURSOR };

  /**
   * MouseInputHandler is responsible for handling resize/moving of the Window.
   * It sets the cursor directly on the Window when then mouse moves over a hot
   * spot.
   */
  private class MouseInputHandler implements MouseInputListener {
    /**
     * Set to true if the drag operation is moving the window.
     */
    private boolean isMovingWindow;

    /**
     * Used to determine the corner the resize is occuring from.
     */
    private int dragCursor;

    /**
     * X location the mouse went down on for a drag operation.
     */
    private int dragOffsetX;

    /**
     * Y location the mouse went down on for a drag operation.
     */
    private int dragOffsetY;

    /**
     * Width of the window when the drag started.
     */
    private int dragWidth;

    /**
     * Height of the window when the drag started.
     */
    private int dragHeight;

    public void mousePressed(MouseEvent ev) {
      if (getWindowDecorationStyle(root) == JRootPane_NONE) {
        return;
      }
      Point dragWindowOffset = ev.getPoint();
      java.awt.Window w = translateSource(ev);
      if (w != null) {
        w.toFront();
      }
      Point convertedDragWindowOffset =
        SwingUtilities.convertPoint(w, dragWindowOffset, getTitlePane());

      if (getTitlePane() != null
        && getTitlePane().contains(convertedDragWindowOffset)) {
        if (!getFrameWindow().isMaximum()
          && dragWindowOffset.y >= BORDER_DRAG_THICKNESS
          && dragWindowOffset.x >= BORDER_DRAG_THICKNESS
          && dragWindowOffset.x < w.getWidth() - BORDER_DRAG_THICKNESS) {
          isMovingWindow = true;
          dragOffsetX = dragWindowOffset.x;
          dragOffsetY = dragWindowOffset.y;
        }
      }
      //this was an else if before but the title panel would not
      //cause a resize
      if (getFrameWindow().isResizable()
        && !getFrameWindow().isShaded()
        && !getFrameWindow().isMaximum()) {
        //&& ((frameState & Frame_MAXIMIZED_BOTH) == 0)
        //|| (d != null && d.isResizable())) {
        dragOffsetX = dragWindowOffset.x;
        dragOffsetY = dragWindowOffset.y;
        dragWidth = w.getWidth();
        dragHeight = w.getHeight();
        //System.out.println("Calulation cursor");
        dragCursor =
          SkinRootPaneUI.getCursor(
            SkinRootPaneUI.calculateCorner(
              w,
              dragWindowOffset.x,
              dragWindowOffset.y));
      }
    }

    public void mouseReleased(MouseEvent ev) {
      if (dragCursor != 0 && window != null && !window.isValid()) {
        // Some Window systems validate as you resize, others won't,
        // thus the check for validity before repainting.
        window.validate();
        getRootPane().repaint();
      }
      isMovingWindow = false;
      dragCursor = 0;
    }

    public void mouseMoved(MouseEvent ev) {
      JRootPane root = getRootPane();

      if (getWindowDecorationStyle(root) == JRootPane_NONE) {
        return;
      }

      java.awt.Window w = translateSource(ev);

      // Update the cursor
      int cursor =
        SkinRootPaneUI.getCursor(
          SkinRootPaneUI.calculateCorner(w, ev.getX(), ev.getY()));

      if (cursor != 0
        && getFrameWindow().isResizable()
        && !getFrameWindow().isShaded()
        && !getFrameWindow().isMaximum()) {
        w.setCursor(Cursor.getPredefinedCursor(cursor));
      } else {
        w.setCursor(lastCursor);
      }
    }

    public void mouseDragged(MouseEvent ev) {
      java.awt.Window w = translateSource(ev);
      Point pt = ev.getPoint();
      //			System.out.println("MovingWindow:"+isMovingWindow+"
      // dragcursor:"+dragCursor);
      if (isMovingWindow) {
        Point windowPt = w.getLocationOnScreen();

        windowPt.x += pt.x - dragOffsetX;
        windowPt.y += pt.y - dragOffsetY;
        w.setLocation(windowPt);
      } else if (dragCursor != 0) {
        Rectangle r = w.getBounds();
        Rectangle startBounds = new Rectangle(r);
        Dimension min = w.getMinimumSize();

        switch (dragCursor) {
          case Cursor.E_RESIZE_CURSOR :
            SkinRootPaneUI.adjust(
              r,
              min,
              0,
              0,
              pt.x + (dragWidth - dragOffsetX) - r.width,
              0);
            break;
          case Cursor.S_RESIZE_CURSOR :
            SkinRootPaneUI.adjust(
              r,
              min,
              0,
              0,
              0,
              pt.y + (dragHeight - dragOffsetY) - r.height);
            break;
          case Cursor.N_RESIZE_CURSOR :
            SkinRootPaneUI.adjust(
              r,
              min,
              0,
              pt.y - dragOffsetY,
              0,
              - (pt.y - dragOffsetY));
            break;
          case Cursor.W_RESIZE_CURSOR :
            SkinRootPaneUI.adjust(
              r,
              min,
              pt.x - dragOffsetX,
              0,
              - (pt.x - dragOffsetX),
              0);
            break;
          case Cursor.NE_RESIZE_CURSOR :
            SkinRootPaneUI.adjust(
              r,
              min,
              0,
              pt.y - dragOffsetY,
              pt.x + (dragWidth - dragOffsetX) - r.width,
              - (pt.y - dragOffsetY));
            break;
          case Cursor.SE_RESIZE_CURSOR :
            SkinRootPaneUI.adjust(
              r,
              min,
              0,
              0,
              pt.x + (dragWidth - dragOffsetX) - r.width,
              pt.y + (dragHeight - dragOffsetY) - r.height);
            break;
          case Cursor.NW_RESIZE_CURSOR :
            SkinRootPaneUI.adjust(
              r,
              min,
              pt.x - dragOffsetX,
              pt.y - dragOffsetY,
              - (pt.x - dragOffsetX),
              - (pt.y - dragOffsetY));
            break;
          case Cursor.SW_RESIZE_CURSOR :
            SkinRootPaneUI.adjust(
              r,
              min,
              pt.x - dragOffsetX,
              0,
              - (pt.x - dragOffsetX),
              pt.y + (dragHeight - dragOffsetY) - r.height);
            break;
          default :
            break;
        }
        if (!r.equals(startBounds)) {
          if (getFrameWindow().isResizable()) {
            w.setBounds(r);
            // Defer repaint/validate on mouseReleased unless dynamic
            // layout is active.
            if (Boolean
              .TRUE
              .equals(
                AccessUtils.invoke(
                  Toolkit.getDefaultToolkit(),
                  "isDynamicLayoutActive",
                  null,
                  null))) {
              w.validate();
              getRootPane().repaint();

            }
            getFrameWindow().dispatchEvent(
              new ComponentEvent(
                getMainWindow(),
                ComponentEvent.COMPONENT_RESIZED));
          }
        }
      }
    }

    public void mouseEntered(MouseEvent ev) {
      java.awt.Window w = translateSource(ev);
      lastCursor = w.getCursor();
      mouseMoved(ev);
    }

    public void mouseExited(MouseEvent ev) {
      java.awt.Window w = translateSource(ev);
      w.setCursor(lastCursor);
    }

    public void mouseClicked(MouseEvent ev) {
      java.awt.Window w = translateSource(ev);
      Frame f;

      if (w instanceof Frame) {
        f = (Frame)w;
      } else {
        return;
      }

      Point convertedPoint =
        SwingUtilities.convertPoint(w, ev.getPoint(), getTitlePane());

      int state = getExtendedState(f);
      if (getTitlePane() != null && getTitlePane().contains(convertedPoint)) {
        if ((ev.getClickCount() % 2) == 0
          && ((ev.getModifiers() & InputEvent.BUTTON1_MASK) != 0)) {
          if (f.isResizable()) {
            if ((state & Frame_MAXIMIZED_BOTH) != 0) {
              setExtendedState(f, state & ~Frame_MAXIMIZED_BOTH);
            } else {
              setExtendedState(f, state | Frame_MAXIMIZED_BOTH);
            }
            return;
          }
        }
      }
    }

  }
}

⌨️ 快捷键说明

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