Java Code Examples for javax.swing.plaf.basic.BasicInternalFrameUI#getNorthPane()

The following examples show how to use javax.swing.plaf.basic.BasicInternalFrameUI#getNorthPane() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: java-swing-tips   File: MainPanel.java    License: MIT License 6 votes vote down vote up
private static void addFrame(JDesktopPane desktop, int idx) {
  String titleAlignment = idx == 0 ? "CENTER" : "LEADING";
  JInternalFrame frame = new JInternalFrame("title: " + titleAlignment, true, true, true, true);

  BasicInternalFrameUI ui = (BasicInternalFrameUI) frame.getUI();
  JComponent titleBar = ui.getNorthPane();
  UIDefaults d = new UIDefaults();
  d.put("InternalFrame:InternalFrameTitlePane.titleAlignment", titleAlignment);
  titleBar.putClientProperty("Nimbus.Overrides", d);

  frame.add(makePanel());
  frame.setSize(240, 100);
  frame.setVisible(true);
  frame.setLocation(10 + 60 * idx, 10 + 120 * idx);
  desktop.add(frame);
  desktop.getDesktopManager().activateFrame(frame);
}
 
Example 2
Source Project: java-swing-tips   File: MainPanel.java    License: MIT License 5 votes vote down vote up
protected static void removeSystemMenuListener(JInternalFrame modal) {
  BasicInternalFrameUI ui = (BasicInternalFrameUI) modal.getUI();
  Container titleBar = ui.getNorthPane();
  Stream.of(titleBar.getComponents())
      .filter(c -> c instanceof JLabel || "InternalFrameTitlePane.menuButton".equals(c.getName()))
      .forEach(MainPanel::removeComponentMouseListener);
  // for (Component c: titleBar.getComponents()) {
  //   if (c instanceof JLabel || "InternalFrameTitlePane.menuButton".equals(c.getName())) {
  //     removeComponentMouseListener(c);
  //   }
  // }
}
 
Example 3
Source Project: java-swing-tips   File: MainPanel.java    License: MIT License 5 votes vote down vote up
@Override public void updateUI() {
  super.updateUI();
  BasicInternalFrameUI ui = (BasicInternalFrameUI) getUI();
  Component titleBar = ui.getNorthPane();
  for (MouseMotionListener l: titleBar.getListeners(MouseMotionListener.class)) {
    titleBar.removeMouseMotionListener(l);
  }
  DragWindowListener dwl = new DragWindowListener();
  titleBar.addMouseListener(dwl);
  titleBar.addMouseMotionListener(dwl);
}
 
Example 4
/**
 * Updates the snapshot of the specified internal frame.
 * 
 * @param frame
 *            Internal frame.
 */
private void updateSnapshot(JInternalFrame frame) {
    if (!frame.isShowing())
        return;
    // Draw the current state of the internal frame to a
    // temp image (w/o border and decorations). It would be nice
    // to use Robot, but this frame may be partially obscured,
    // so we take our chances that the frame will be properly
    // drawn by the user code.
    int frameWidth = frame.getWidth();
    int frameHeight = frame.getHeight();

    int dx = 0;
    int dy = 0;
    // Now we need to remove the border and the title pane :)
    Border internalFrameBorder = UIManager.getBorder("InternalFrame.border");
    Insets borderInsets = internalFrameBorder.getBorderInsets(frame);
    dx += borderInsets.left;
    dy += borderInsets.top;
    frameWidth -= (borderInsets.left + borderInsets.right);
    frameHeight -= (borderInsets.top + borderInsets.bottom);

    BasicInternalFrameUI frameUI = (BasicInternalFrameUI) frame.getUI();
    JComponent frameTitlePane = frameUI.getNorthPane();

    if (frameTitlePane != null) {
        dy += frameTitlePane.getHeight();
        frameHeight -= frameTitlePane.getHeight();
    }

    // fix for defect 112 - checking frame height and width
    if ((frameWidth > 0) && (frameHeight > 0)) {
        // draw frame (note the canvas translation)
        BufferedImage tempCanvas = new BufferedImage(frameWidth, frameHeight,
                BufferedImage.TYPE_INT_ARGB);
        Graphics tempCanvasGraphics = tempCanvas.getGraphics();
        tempCanvasGraphics.translate(-dx, -dy);
        Map<Component, Boolean> dbSnapshot = new HashMap<>();
        WidgetUtilities.makePreviewable(frame, dbSnapshot);
        frame.paint(tempCanvasGraphics);
        WidgetUtilities.restorePreviewable(frame, dbSnapshot);

        int maxWidth = UIManager.getInt("DesktopIcon.width");
        int maxHeight = maxWidth;

        // check if need to scale down
        double coef = Math.min((double) maxWidth / (double) frameWidth,
                (double) maxHeight / (double) frameHeight);
        if (coef < 1.0) {
            int sdWidth = (int) (coef * frameWidth);
            BufferedImage scaledDown = NeonCortex.createThumbnail(tempCanvas, sdWidth);
            snapshot = scaledDown;
        } else {
            snapshot = tempCanvas;
        }
    }
}
 
Example 5
Source Project: java-swing-tips   File: MainPanel.java    License: MIT License 4 votes vote down vote up
private static JInternalFrame makeInternalFrame() {
  JInternalFrame internal = new JInternalFrame("@[email protected]");
  BasicInternalFrameUI ui = (BasicInternalFrameUI) internal.getUI();
  Component title = ui.getNorthPane();
  for (MouseMotionListener l: title.getListeners(MouseMotionListener.class)) {
    title.removeMouseMotionListener(l);
  }
  DragWindowListener dwl = new DragWindowListener();
  title.addMouseListener(dwl);
  title.addMouseMotionListener(dwl);

  KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
  focusManager.addPropertyChangeListener(e -> {
    String prop = e.getPropertyName();
    // System.out.println(prop);
    if ("activeWindow".equals(prop)) {
      try {
        internal.setSelected(Objects.nonNull(e.getNewValue()));
      } catch (PropertyVetoException ex) {
        throw new IllegalStateException(ex);
      }
      // System.out.println("---------------------");
    }
  });

  // frame.addWindowListener(new WindowAdapter() {
  //   @Override public void windowLostFocus(FocusEvent e) {
  //     System.out.println("222222222");
  //     try {
  //       internal.setSelected(false);
  //     } catch (PropertyVetoException ex) {
  //       throw new IllegalStateException(ex);
  //     }
  //   }
  //   @Override public void windowGainedFocus(FocusEvent e) {
  //     System.out.println("111111111");
  //     try {
  //       internal.setSelected(true);
  //     } catch (PropertyVetoException ex) {
  //       throw new IllegalStateException(ex);
  //     }
  //   }
  // });
  // EventQueue.invokeLater(() -> {
  //   try {
  //     internal.setSelected(true);
  //   } catch (PropertyVetoException ex) {
  //     throw new IllegalStateException(ex);
  //   }
  //   // internal.requestFocusInWindow();
  // });
  return internal;
}