private void setHeaderComponent(JComponent c) {
    boolean doRevalidate = false;
    if (myHeaderComponent != null) {
      myHeaderPanel.remove(myHeaderComponent);
      myHeaderPanel.add(myCaption, BorderLayout.NORTH);
      myHeaderComponent = null;
      doRevalidate = true;
    }

    if (c != null) {
      myHeaderPanel.remove(myCaption);
      myHeaderPanel.add(c, BorderLayout.NORTH);
      myHeaderComponent = c;

      final Dimension size = myContent.getSize();
      if (size.height < c.getPreferredSize().height * 2) {
        size.height += c.getPreferredSize().height;
        setSize(size);
      }

      doRevalidate = true;
    }

    if (doRevalidate) myContent.revalidate();
  }
Exemplo n.º 2
0
    /**
     * Instructs the layout manager to perform the layout for the specified container.
     *
     * @param 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 (root.getWindowDecorationStyle() != JRootPane.NONE
          && (root.getUI() instanceof RootPaneUI)) {
        JComponent titlePane = ((RootPaneUI) 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.getContentPane() != null) {

        root.getContentPane().setBounds(0, nextY, w, h < nextY ? 0 : h - nextY);
      }
    }
Exemplo n.º 3
0
    /**
     * Returns the amount of space the layout would like to have.
     *
     * @param the Container for which this layout manager is being used
     * @return a Dimension object containing the layout's preferred size
     */
    public Dimension preferredLayoutSize(Container parent) {
      Dimension cpd, tpd;
      int cpWidth = 0;
      int cpHeight = 0;
      int mbWidth = 0;
      int mbHeight = 0;
      int tpWidth = 0;
      Insets i = parent.getInsets();
      JRootPane root = (JRootPane) parent;

      if (root.getContentPane() != null) {
        cpd = root.getContentPane().getPreferredSize();
      } else {
        cpd = root.getSize();
      }
      if (cpd != null) {
        cpWidth = cpd.width;
        cpHeight = cpd.height;
      }

      if (root.getWindowDecorationStyle() != JRootPane.NONE
          && (root.getUI() instanceof RootPaneUI)) {
        JComponent titlePane = ((RootPaneUI) root.getUI()).getTitlePane();
        if (titlePane != null) {
          tpd = titlePane.getPreferredSize();
          if (tpd != null) {
            tpWidth = tpd.width;
          }
        }
      }

      return new Dimension(
          Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right,
          cpHeight + mbHeight + tpWidth + i.top + i.bottom);
    }
Exemplo n.º 4
0
    QuickDocInfoPane(
        @NotNull PsiElement documentationAnchor,
        @NotNull PsiElement elementUnderMouse,
        @NotNull JComponent baseDocControl) {
      myBaseDocControl = baseDocControl;

      PresentationFactory presentationFactory = new PresentationFactory();
      for (AbstractDocumentationTooltipAction action : ourTooltipActions) {
        Icon icon = action.getTemplatePresentation().getIcon();
        Dimension minSize = new Dimension(icon.getIconWidth(), icon.getIconHeight());
        myButtons.add(
            new ActionButton(
                action,
                presentationFactory.getPresentation(action),
                IdeTooltipManager.IDE_TOOLTIP_PLACE,
                minSize));
        action.setDocInfo(documentationAnchor, elementUnderMouse);
      }
      Collections.reverse(myButtons);

      setPreferredSize(baseDocControl.getPreferredSize());
      setMaximumSize(baseDocControl.getMaximumSize());
      setMinimumSize(baseDocControl.getMinimumSize());
      setBackground(baseDocControl.getBackground());

      add(baseDocControl, Integer.valueOf(0));
      int minWidth = 0;
      int minHeight = 0;
      int buttonWidth = 0;
      for (JComponent button : myButtons) {
        button.setBorder(null);
        button.setBackground(baseDocControl.getBackground());
        add(button, Integer.valueOf(1));
        button.setVisible(false);
        Dimension preferredSize = button.getPreferredSize();
        minWidth += preferredSize.width;
        minHeight = Math.max(minHeight, preferredSize.height);
        buttonWidth = Math.max(buttonWidth, preferredSize.width);
      }
      myButtonWidth = buttonWidth;

      int margin = 2;
      myMinWidth = minWidth + margin * 2 + (myButtons.size() - 1) * BUTTON_HGAP;
      myMinHeight = minHeight + margin * 2;
    }
  public static Point getCenterOf(final Component aContainer, final JComponent content) {
    final JComponent component = getTargetComponent(aContainer);

    Point containerScreenPoint = component.getVisibleRect().getLocation();
    SwingUtilities.convertPointToScreen(containerScreenPoint, aContainer);

    return UIUtil.getCenterPoint(
        new Rectangle(containerScreenPoint, component.getVisibleRect().getSize()),
        content.getPreferredSize());
  }
Exemplo n.º 6
0
  /*
   *  Create a BufferedImage for Swing components.
   *  The entire component will be captured to an image.
   *
   *  @param	 component Swing component to create image from
   *  @param	 fileName name of file to be created or null
   *  @return	image the image for the given region
   *  @exception IOException if an error occurs during writing
   */
  public static BufferedImage createImage(JComponent component, String fileName)
      throws IOException {
    Dimension d = component.getSize();

    if (d.width == 0) {
      d = component.getPreferredSize();
      component.setSize(d);
    }

    Rectangle region = new Rectangle(0, 0, d.width, d.height);
    return ScreenCapture.createImage(component, region, fileName);
  }
Exemplo n.º 7
0
 private void addRow(String label, JComponent component) {
   JLabel l = new JLabel(label);
   l.setFont(Theme.SMALL_BOLD_FONT);
   l.setBounds(18, y, 400, 18);
   add(l);
   y += 18;
   int componentHeight = (int) component.getPreferredSize().getHeight();
   component.setBounds(16, y, 400, componentHeight);
   y += componentHeight;
   y += 2; // vertical gap
   add(component);
 }
Exemplo n.º 8
0
    @Override
    public void doLayout() {
      Rectangle bounds = getBounds();
      myBaseDocControl.setBounds(new Rectangle(0, 0, bounds.width, bounds.height));

      int x = bounds.width;
      for (JComponent button : myButtons) {
        Dimension buttonSize = button.getPreferredSize();
        x -= buttonSize.width;
        button.setBounds(x, 0, buttonSize.width, buttonSize.height);
        x -= BUTTON_HGAP;
      }
    }
Exemplo n.º 9
0
  /**
   * Create the GUI and show it. For thread safety, this method should be invoked from the
   * event-dispatching thread.
   */
  private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("ListDataEventDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create and set up the content pane.
    JComponent newContentPane = new ListDataEventDemo();
    newContentPane.setOpaque(true); // content panes must be opaque
    frame.setContentPane(newContentPane);

    // Don't let the content pane get too small.
    // (Works if the Java look and feel provides
    // the window decorations.)
    newContentPane.setMinimumSize(new Dimension(newContentPane.getPreferredSize().width, 100));

    // Display the window.
    frame.pack();
    frame.setVisible(true);
  }
  private void doHandleSelectionChange(@NotNull KeyType selected, boolean processIfUnfocused) {
    if (!isHandleSelectionEnabled(selected, processIfUnfocused)) {
      hideHint();
      return;
    }

    myKey = selected;

    Point location = createToolTipImage(myKey);

    if (location == null) {
      hideHint();
    } else {
      Rectangle bounds = new Rectangle(location, myTipComponent.getPreferredSize());
      myPopup.setBounds(bounds);
      myPopup.setVisible(noIntersections(bounds));
      repaintKeyItem();
    }
  }
Exemplo n.º 11
0
  /**
   * Creates preview for the (video) device in the video container.
   *
   * @param device the device
   * @param videoContainer the video container
   * @throws IOException a problem accessing the device
   * @throws MediaException a problem getting preview
   */
  private static void createVideoPreview(CaptureDeviceInfo device, JComponent videoContainer)
      throws IOException, MediaException {
    videoContainer.removeAll();

    videoContainer.revalidate();
    videoContainer.repaint();

    if (device == null) return;

    for (MediaDevice mediaDevice : mediaService.getDevices(MediaType.VIDEO, MediaUseCase.ANY)) {
      if (((MediaDeviceImpl) mediaDevice).getCaptureDeviceInfo().equals(device)) {
        Dimension videoContainerSize = videoContainer.getPreferredSize();
        Component preview =
            (Component)
                mediaService.getVideoPreviewComponent(
                    mediaDevice, videoContainerSize.width, videoContainerSize.height);

        if (preview != null) videoContainer.add(preview);
        break;
      }
    }
  }
Exemplo n.º 12
0
 @Override
 public Dimension getPreferredSize() {
   return expandIfNecessary(myBaseDocControl.getPreferredSize());
 }
Exemplo n.º 13
0
  public void ellipsifyValues(int width) {
    int maxKeyWidth = 0;
    int[] maxAdditionalColumnsWidth = new int[additionalColumns];

    for (JComponent keyComp : keyKeyComponentMap.values()) {
      maxKeyWidth = Math.max(maxKeyWidth, keyComp.getPreferredSize().width);
    }

    for (String k : keyValueComponentMap.keySet()) {
      for (int i = 0; i < additionalColumns; i++) {
        JComponent extraComp = getAdditionalColumn(k, i);
        if (extraComp != null) {
          maxAdditionalColumnsWidth[i] =
              Math.max(maxAdditionalColumnsWidth[i], extraComp.getPreferredSize().width);
        }
      }
    }

    width -= maxKeyWidth;
    for (int i : maxAdditionalColumnsWidth) {
      width -= i;
    }

    for (String k : keyValueComponentMap.keySet()) {
      JComponent comp = getComponent(k);
      if (comp != null) {
        int avail = width;
        /*for (int i = 0; i < additionalColumns; i++) {
        JComponent extraComp = getAdditionalColumn(k, i);
        if (extraComp != null) {
        avail -= extraComp.getPreferredSize().width;
        }
        }*/

        if (comp instanceof JLabel) {

          while (avail < comp.getPreferredSize().width) {
            String text = ((JLabel) comp).getText();
            if (text.endsWith("…")) {
              if (text.length() > 2) {
                // Already truncated.
                text = text.substring(0, text.length() - 2);
              } else {
                break; // As short as we can get.  Can't truncate any more.
              }
            } else {
              // Reasonable first truncation is to trim off the last word.
              int spacePos = text.lastIndexOf(' ');
              if (spacePos > 0) {
                text = text.substring(0, spacePos);
              } else {
                FontMetrics fm = comp.getFontMetrics(comp.getFont());

                while (fm.stringWidth(text + "…") > avail) {
                  // causes StringIndexOutOfBoundsException if text is empty.
                  if (text == null || text.length() < 2) {
                    LOG.info("Text is null or empty in KeyValuePairPanel");
                    break;
                  }
                  text = text.substring(0, text.length() - 2);
                }
                // text = text + "…";

                // text = text.substring(0, text.length() - 1);
              }
            }
            ((JLabel) comp).setText(text + "…");
          }
        } else {
          // Can't truncate, but we can force the preferred size.
          comp.setMaximumSize(new Dimension(avail, comp.getPreferredSize().height));
        }
      }
    }
  }
Exemplo n.º 14
0
    /**
     * Paints the border for the specified component with the specified position and size.
     *
     * @param c the component for which this border is being painted
     * @param g the paint graphics
     * @param x the x position of the painted border
     * @param y the y position of the painted border
     * @param width the width of the painted border
     * @param height the height of the painted border
     */
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

      Border border = getBorder();

      if (label == null) {
        if (border != null) {
          border.paintBorder(c, g, x, y, width, height);
        }
        return;
      }

      Rectangle grooveRect =
          new Rectangle(
              x + EDGE_SPACING,
              y + EDGE_SPACING,
              width - (EDGE_SPACING * 2),
              height - (EDGE_SPACING * 2));

      Dimension labelDim = label.getPreferredSize();
      int baseline = label.getBaseline(labelDim.width, labelDim.height);
      int ascent = Math.max(0, baseline);
      int descent = labelDim.height - ascent;
      int diff;
      Insets insets;

      if (border != null) {
        insets = border.getBorderInsets(c);
      } else {
        insets = new Insets(0, 0, 0, 0);
      }

      diff = Math.max(0, ascent / 2 + TEXT_SPACING - EDGE_SPACING);
      grooveRect.y += diff;
      grooveRect.height -= diff;
      compLoc.y = grooveRect.y + insets.top / 2 - (ascent + descent) / 2 - 1;

      int justification;
      if (c.getComponentOrientation().isLeftToRight()) {
        justification = LEFT;
      } else {
        justification = RIGHT;
      }

      switch (justification) {
        case LEFT:
          compLoc.x = grooveRect.x + TEXT_INSET_H + insets.left;
          break;
        case RIGHT:
          compLoc.x =
              (grooveRect.x + grooveRect.width - (labelDim.width + TEXT_INSET_H + insets.right));
          break;
      }

      // If title is positioned in middle of border AND its fontsize
      // is greater than the border's thickness, we'll need to paint
      // the border in sections to leave space for the component's background
      // to show through the title.
      //
      if (border != null) {
        if (grooveRect.y > compLoc.y - ascent) {
          Rectangle clipRect = new Rectangle();

          // save original clip
          Rectangle saveClip = g.getClipBounds();

          // paint strip left of text
          clipRect.setBounds(saveClip);
          if (computeIntersection(clipRect, x, y, compLoc.x - 1 - x, height)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // paint strip right of text
          clipRect.setBounds(saveClip);
          if (computeIntersection(
              clipRect,
              compLoc.x + labelDim.width + 1,
              y,
              x + width - (compLoc.x + labelDim.width + 1),
              height)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // paint strip below text
          clipRect.setBounds(saveClip);
          if (computeIntersection(
              clipRect,
              compLoc.x - 1,
              compLoc.y + ascent + descent,
              labelDim.width + 2,
              y + height - compLoc.y - ascent - descent)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // restore clip
          g.setClip(saveClip);

        } else {
          border.paintBorder(c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
        }

        label.setLocation(compLoc);
        label.setSize(labelDim);
      }
    }