Exemplo n.º 1
0
 /**
  * This method sets the floating location of the JToolBar.
  *
  * @param x The x coordinate for the floating frame.
  * @param y The y coordinate for the floating frame.
  */
 public void setFloatingLocation(int x, int y) {
   // x,y are the coordinates of the new JFrame created to store the toolbar
   // XXX: The floating location is bogus is not floating.
   floatFrame.setLocation(x, y);
   floatFrame.invalidate();
   floatFrame.validate();
   floatFrame.repaint();
 }
Exemplo n.º 2
0
 private static void repaintUI(Window window) {
   if (!window.isDisplayable()) {
     return;
   }
   window.repaint();
   Window[] children = window.getOwnedWindows();
   for (Window aChildren : children) {
     repaintUI(aChildren);
   }
 }
  private void setSizeAndDimensions(
      @NotNull JTable table,
      @NotNull JBPopup popup,
      @NotNull RelativePoint popupPosition,
      @NotNull List<UsageNode> data) {
    JComponent content = popup.getContent();
    Window window = SwingUtilities.windowForComponent(content);
    Dimension d = window.getSize();

    int width = calcMaxWidth(table);
    width = (int) Math.max(d.getWidth(), width);
    Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize();
    width = Math.max((int) headerSize.getWidth(), width);
    width = Math.max(myWidth, width);

    if (myWidth == -1) myWidth = width;
    int newWidth = Math.max(width, d.width + width - myWidth);

    myWidth = newWidth;

    int rowsToShow = Math.min(30, data.size());
    Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow);
    Rectangle rectangle = fitToScreen(dimension, popupPosition, table);
    dimension = rectangle.getSize();
    Point location = window.getLocation();
    if (!location.equals(rectangle.getLocation())) {
      window.setLocation(rectangle.getLocation());
    }

    if (!data.isEmpty()) {
      TableScrollingUtil.ensureSelectionExists(table);
    }
    table.setSize(dimension);
    // table.setPreferredSize(dimension);
    // table.setMaximumSize(dimension);
    // table.setPreferredScrollableViewportSize(dimension);

    Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize();

    int newHeight =
        (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight())
            + 4 /* invisible borders, margins etc*/;
    Dimension newDim = new Dimension(dimension.width, newHeight);
    window.setSize(newDim);
    window.setMinimumSize(newDim);
    window.setMaximumSize(newDim);

    window.validate();
    window.repaint();
    table.revalidate();
    table.repaint();
  }
    public void actionPerformed(ActionEvent ae) {
      Dimension contentSize = null;
      if (w instanceof JDialog) {
        contentSize = ((JDialog) w).getContentPane().getSize();
      } else {
        contentSize = ((JFrame) w).getContentPane().getSize();
      }

      Dimension dialogSize = w.getSize();
      int ydiff = dialogSize.height - contentSize.height;
      Dimension paneSize = pane.getSize();
      w.setSize(new Dimension(dialogSize.width, paneSize.height + ydiff));
      w.validate();
      w.repaint();
    }
Exemplo n.º 5
0
  /**
   * Create a frame for this DockPanel. The frame will either be a JFrame or a JDialog depending on
   * the isDialog flag.
   */
  public void createFrame() {

    if (isDialog) {
      frame =
          new JDialog(app.getFrame(), false) {
            private static final long serialVersionUID = 1L;

            // Send window closing event when dialog is set invisible.
            // This allows a dock panel view to close properly.
            @Override
            public void setVisible(boolean isVisible) {
              if (!isVisible && frame != null) {
                windowClosing(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
              }
              super.setVisible(isVisible);
            }
          };
    } else {
      frame = new JFrame(getPlainTitle());
      // needs the higher res as used by Windows 7 for the Toolbar
      ((JFrame) frame).setIconImage(app.getInternalImage("geogebra64.png"));
    }

    frame.addWindowListener(this);

    frame.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentResized(ComponentEvent event) {
            setFrameBounds(event.getComponent().getBounds());
          }

          @Override
          public void componentMoved(ComponentEvent event) {
            setFrameBounds(event.getComponent().getBounds());
          }
        });

    if (isDialog) {
      (((JDialog) frame).getContentPane()).add(this);
    } else {
      (((JFrame) frame).getContentPane()).add(this);
      menubar = loadMenuBar();
      if (menubar != null) {
        ((JFrame) frame).setJMenuBar(menubar);
      }
    }

    // TODO multimonitor supported?
    Rectangle screenSize =
        GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();

    // Use the previous dimension of this view
    Rectangle windowBounds = getFrameBounds();

    // resize window if necessary
    if (windowBounds.width > screenSize.width) windowBounds.width = screenSize.width - 50;
    if (windowBounds.height > screenSize.height) windowBounds.height = windowBounds.height - 50;

    // center window if necessary
    if (isNewDialog) {
      // frame.pack();
      frame.setSize(windowBounds.getSize());
      frame.setLocationRelativeTo(app.getMainComponent());
      isNewDialog = false;
    } else if (windowBounds.x + windowBounds.width > screenSize.width
        || windowBounds.y + windowBounds.height > screenSize.height) {
      frame.setLocationRelativeTo(null);

    } else {
      frame.setLocation(windowBounds.getLocation());
    }
    setOpenInFrame(true);

    frame.setSize(windowBounds.getSize());
    frame.setVisible(true);

    // make titlebar visible if necessary
    updatePanel();

    frame.repaint();
  }