Example #1
0
 public Dimension preferredLayoutSize(Container target) {
   Insets insets = target.getInsets();
   Dimension compMax = new Dimension(0, 0);
   int maxheight = target.getBounds().height - (insets.top + insets.bottom + vgap * 2);
   int nmembers = target.getComponentCount();
   int visiblecount = 0;
   for (int i = 0; i < nmembers; i++) {
     Component m = target.getComponent(i);
     if (m.isVisible()) {
       ++visiblecount;
       Dimension d = m.getPreferredSize();
       compMax.width = Math.max(compMax.width, d.width);
       compMax.height = Math.max(compMax.height, d.height);
     }
   }
   if (visiblecount > 0) {
     int nrows = Math.max(1, (maxheight + compMax.height / 4) / compMax.height);
     int ncols = (visiblecount + nrows - 1) / nrows;
     compMax.height = compMax.height * nrows + vgap * (nrows - 1);
     compMax.width = compMax.width * ncols + hgap * (ncols - 1);
   }
   compMax.height += insets.top + insets.bottom + vgap * 2;
   compMax.width += insets.left + insets.right + hgap * 2;
   return compMax;
 }
 public void processCellResized(
     RadContainer container, final boolean isRow, final int cell, final int newSize) {
   int cellCount = isRow ? container.getGridRowCount() : container.getGridColumnCount();
   if (container.getParent().isXY() && cell == cellCount - 1) {
     processRootContainerResize(container, isRow, newSize);
   } else {
     for (RadComponent component : container.getComponents()) {
       GridConstraints c = component.getConstraints();
       if (c.getCell(isRow) == cell && c.getSpan(isRow) == 1) {
         Dimension preferredSize = new Dimension(c.myPreferredSize);
         if (isRow) {
           preferredSize.height = newSize;
           if (preferredSize.width == -1) {
             preferredSize.width = component.getDelegee().getPreferredSize().width;
           }
         } else {
           preferredSize.width = newSize;
           if (preferredSize.height == -1) {
             preferredSize.height = component.getDelegee().getPreferredSize().height;
           }
         }
         PreferredSizeProperty.getInstance(container.getProject())
             .setValueEx(component, preferredSize);
       }
     }
   }
 }
    @Override
    public void layoutContainer(final Container parent) {
      final int componentCount = parent.getComponentCount();
      if (componentCount == 0) return;
      final EditorEx history = myHistoryViewer;
      final EditorEx editor = componentCount == 2 ? myConsoleEditor : null;

      if (editor == null) {
        parent.getComponent(0).setBounds(parent.getBounds());
        return;
      }

      final Dimension panelSize = parent.getSize();
      if (panelSize.getHeight() <= 0) return;
      final Dimension historySize = history.getContentSize();
      final Dimension editorSize = editor.getContentSize();
      final Dimension newEditorSize = new Dimension();

      // deal with width
      final int width = Math.max(editorSize.width, historySize.width);
      newEditorSize.width = width + editor.getScrollPane().getHorizontalScrollBar().getHeight();
      history.getSoftWrapModel().forceAdditionalColumnsUsage();
      editor
          .getSettings()
          .setAdditionalColumnsCount(
              2 + (width - editorSize.width) / EditorUtil.getSpaceWidth(Font.PLAIN, editor));
      history
          .getSettings()
          .setAdditionalColumnsCount(
              2 + (width - historySize.width) / EditorUtil.getSpaceWidth(Font.PLAIN, history));

      // deal with height
      if (historySize.width == 0) historySize.height = 0;
      final int minHistorySize =
          historySize.height > 0
              ? 2 * history.getLineHeight() + (myShowSeparatorLine ? SEPARATOR_THICKNESS : 0)
              : 0;
      final int minEditorSize = editor.isViewer() ? 0 : editor.getLineHeight();
      final int editorPreferred =
          editor.isViewer() ? 0 : Math.max(minEditorSize, editorSize.height);
      final int historyPreferred = Math.max(minHistorySize, historySize.height);
      if (panelSize.height < minEditorSize) {
        newEditorSize.height = panelSize.height;
      } else if (panelSize.height < editorPreferred) {
        newEditorSize.height = panelSize.height - minHistorySize;
      } else if (panelSize.height < editorPreferred + historyPreferred) {
        newEditorSize.height = editorPreferred;
      } else {
        newEditorSize.height = editorPreferred == 0 ? 0 : panelSize.height - historyPreferred;
      }
      final Dimension newHistorySize =
          new Dimension(width, panelSize.height - newEditorSize.height);

      // apply
      editor
          .getComponent()
          .setBounds(0, newHistorySize.height, panelSize.width, newEditorSize.height);
      myForceScrollToEnd.compareAndSet(false, shouldScrollHistoryToEnd());
      history.getComponent().setBounds(0, 0, panelSize.width, newHistorySize.height);
    }
    /**
     * Calculates the maximum size dimensions for the specified panal given the components in the
     * specified parent container.
     */
    public Dimension maximumLayoutSize(Container target) {
      synchronized (target.getTreeLock()) {
        Dimension dim = new Dimension(0, 0);
        int size = actions.size();
        if ((grip != null) && grip.isVisible()) {
          Dimension d = grip.getPreferredSize();
          dim.width += d.width;
          dim.width += hgap;
        }
        Component last = null;
        for (int i = 0; i < size; i++) {
          Component comp = (Component) actions.elementAt(i);
          if (comp.isVisible()) {
            Dimension d = comp.getPreferredSize();
            dim.width += d.width;
            dim.height = Math.max(dim.height, d.height);
            dim.width += hgap;
            last = comp;
          }
        }
        if (last != null) {
          Dimension prefSize = last.getPreferredSize();
          Dimension maxSize = last.getMaximumSize();
          if (prefSize != maxSize) {
            dim.width = dim.width - prefSize.width + maxSize.width;
            dim.height = Math.max(dim.height, maxSize.height);
          }
        }
        Insets insets = target.getInsets();
        dim.width += insets.left + insets.right;
        dim.height += insets.top + insets.bottom;

        return dim;
      }
    }
  private void calculateWrapSize(Rectangle bounds) {
    if (myWrapSize.width == -1 || myWrapSize.height == -1) {
      try {
        Object viewObject = myComponent.getViewInfo().getViewObject();
        Class<?> viewClass = viewObject.getClass();

        viewClass.getMethod("forceLayout").invoke(viewObject);
        viewClass
            .getMethod("measure", int.class, int.class)
            .invoke(viewObject, WRAP_CONTENT, WRAP_CONTENT);

        if (myWrapSize.width == -1) {
          myWrapSize.width = (Integer) viewClass.getMethod("getMeasuredWidth").invoke(viewObject);
        }
        if (myWrapSize.height == -1) {
          myWrapSize.height = (Integer) viewClass.getMethod("getMeasuredHeight").invoke(viewObject);
        }
      } catch (Throwable e) {
        if (myWrapSize.width == -1) {
          myWrapSize.width = bounds.width;
        }
        if (myWrapSize.height == -1) {
          myWrapSize.height = bounds.height;
        }
      }
    }
  }
  private void checkSizes() {
    Dimension vsz = scroll_pane.getViewport().getViewSize();
    Dimension csz = draw_area.getSize();
    Dimension nsz = new Dimension((int) (vsz.width * x_scale), (int) (vsz.height * y_scale));
    boolean chng = false;

    if (nsz.width > csz.width) {
      if (vsz.width >= csz.width) {
        csz.width = vsz.width;
        chng = true;
        x_scale = 1;
      }
    } else if (nsz.width < csz.width) {
      if (x_scale == 1) {
        csz.width = vsz.width;
        chng = true;
      }
    }

    if (nsz.height > csz.height) {
      if (vsz.height >= csz.height) {
        csz.height = vsz.height;
        chng = true;
        y_scale = 1;
      }
    } else if (nsz.height < csz.height) {
      if (y_scale == 1) {
        csz.height = vsz.height;
        chng = true;
      }
    }

    if (chng) draw_area.setSize(csz);
  }
  /**
   * Calculates the preferred size dimensions for the specified panel given the components in the
   * specified parent container.
   *
   * @param target The component to be laid out.
   * @return A size deemed suitable for laying out the container.
   * @see #minimumLayoutSize
   */
  public Dimension preferredLayoutSize(Container target) {
    int count;
    Component component;
    Dimension dimension;
    Insets insets;
    Dimension ret;

    synchronized (target.getTreeLock()) {
      // get the the total height and maximum width component
      ret = new Dimension(0, 0);
      count = target.getComponentCount();
      for (int i = 0; i < count; i++) {
        component = target.getComponent(i);
        if (component.isVisible()) {
          dimension = component.getPreferredSize();
          ret.width = Math.max(ret.width, dimension.width);
          ret.height += dimension.height;
        }
      }
      insets = target.getInsets();
      ret.width += insets.left + insets.right;
      ret.height += insets.top + insets.bottom;
    }

    return (ret);
  }
 public void paint(Graphics g) {
   MetalBumps usedBumps;
   if (splitPane.hasFocus()) {
     usedBumps = focusBumps;
     g.setColor(primaryControlColor);
   } else {
     usedBumps = bumps;
     g.setColor(controlColor);
   }
   Rectangle clip = g.getClipBounds();
   Insets insets = getInsets();
   g.fillRect(clip.x, clip.y, clip.width, clip.height);
   Dimension size = getSize();
   size.width -= inset * 2;
   size.height -= inset * 2;
   int drawX = inset;
   int drawY = inset;
   if (insets != null) {
     size.width -= (insets.left + insets.right);
     size.height -= (insets.top + insets.bottom);
     drawX += insets.left;
     drawY += insets.top;
   }
   usedBumps.setBumpArea(size);
   usedBumps.paintIcon(this, g, drawX, drawY);
   super.paint(g);
 }
  public Dimension minimumLayoutSize(Container target) {
    Dimension dim = new Dimension(0, 0);
    int nmembers = target.getComponentCount();

    for (int i = 0; i < nmembers; i++) {
      Component m = target.getComponent(i);
      if (m.isVisible()) {
        Dimension d = m.getMinimumSize();
        if (fVerticalLayout) {
          dim.width = Math.max(dim.width, d.width);
          if (i > 0) {
            dim.height += fGap;
          }
          dim.height += d.height;
        } else {
          dim.height = Math.max(dim.height, d.height);
          if (i > 0) {
            dim.width += fGap;
          }
          dim.width += d.width;
        }
      }
    }

    Insets insets = target.getInsets();
    dim.width += insets.left + insets.right;
    dim.width += 2 * fBorder.x;
    dim.height += insets.top + insets.bottom;
    dim.height += 2 * fBorder.y;
    return dim;
  }
Example #10
0
  @Override
  public void updateMinimumSize() {
    final Dimension min;
    if (getTarget().isMinimumSizeSet()) {
      min = getTarget().getMinimumSize();
      min.width = Math.max(min.width, MINIMUM_WIDTH);
      min.height = Math.max(min.height, MINIMUM_HEIGHT);
    } else {
      min = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT);
    }

    final int maxW, maxH;
    if (graphicsConfig instanceof TextureSizeConstraining) {
      maxW = ((TextureSizeConstraining) graphicsConfig).getMaxTextureWidth();
      maxH = ((TextureSizeConstraining) graphicsConfig).getMaxTextureHeight();
    } else {
      maxW = maxH = Integer.MAX_VALUE;
    }

    final Dimension max;
    if (getTarget().isMaximumSizeSet()) {
      max = getTarget().getMaximumSize();
      max.width = Math.min(max.width, maxW);
      max.height = Math.min(max.height, maxH);
    } else {
      max = new Dimension(maxW, maxH);
    }

    platformWindow.setSizeConstraints(min.width, min.height, max.width, max.height);
  }
Example #11
0
  /**
   * Query the maximum image size allowed.
   *
   * @return the maximum image size allowed.
   */
  public Dimension getMaximumSize() {
    final Dimension retval = new Dimension();
    final Hashtable depthMap = getDepthMap();
    int item = 0;

    synchronized (getActiveVector()) {
      final Enumeration keys = getDepthMap().keys();

      while (keys.hasMoreElements()) {
        final Bookmark bookmark = (Bookmark) keys.nextElement();
        final Rectangle bounds = getTextBounds(item++, bookmark, depthMap.get(bookmark));
        final int width = bounds.x + bounds.width;

        if (width > retval.width) {
          retval.width = width;
        }

        retval.height = bounds.y + bounds.height;
      }
    }

    retval.width += (2 * getFontMetrics(getFont()).getMaxAdvance());
    retval.height += (2 * getFontHeight());

    return retval;
  }
Example #12
0
 public Dimension getAvailableSize() {
   Dimension availableSize = getSize();
   if (!cc.opts.fullScreen) {
     Insets vpInsets = VncViewer.insets;
     availableSize.width -= vpInsets.left + vpInsets.right;
     availableSize.height -= vpInsets.top + vpInsets.bottom;
   }
   if (tb.isVisible()) availableSize.height -= tb.getHeight();
   if (availableSize.width < 0) availableSize.width = 0;
   if (availableSize.height < 0) availableSize.height = 0;
   return availableSize;
 }
Example #13
0
 protected Dimension getThumbSize() {
   Dimension size = super.getThumbSize();
   if ((getThumbHorIcon() != null) && (getThumbVerIcon() != null)) {
     if (slider.getOrientation() == JSlider.HORIZONTAL) {
       size.width = getThumbHorIcon().getIconWidth();
       size.height = getThumbHorIcon().getIconHeight();
     } else {
       size.width = getThumbVerIcon().getIconWidth();
       size.height = getThumbVerIcon().getIconHeight();
     }
   }
   return size;
 }
Example #14
0
 public void reshape(int x, int y, int w, int h) {
   if (inEditMode) {
     defLoc.x = x;
     defLoc.y = y;
     defDim.width = w;
     defDim.height = h;
   }
   curLoc.x = x;
   curLoc.y = y;
   curDim.width = w;
   curDim.height = h;
   super.reshape(x, y, w, h);
 }
Example #15
0
  /**
   * The method computes a preferred size for the specified target component.
   *
   * @param target the specified layoutable container.
   */
  public Dimension calcPreferredSize(LayoutContainer target) {
    Dimension ps =
        center != null && center.isVisible() ? center.getPreferredSize() : new Dimension();

    if (label != null && label.isVisible()) {
      Dimension lps = label.getPreferredSize();
      lps.width += INDENT;
      ps.height += lps.height;
      ps.width = Math.max(ps.width, lps.width);
    }
    ps.width += (hGap * 2);
    ps.height += (vGap * 2);
    return ps;
  }
Example #16
0
 public Dimension getPreferredSize(JComponent c) {
   Dimension size = super.getPreferredSize(c);
   if (comboBox.getGraphics() != null) {
     FontMetrics fm =
         Utilities.getFontMetrics(comboBox, comboBox.getGraphics(), comboBox.getFont());
     size.height = fm.getHeight() + 2;
     if (UIManager.getLookAndFeel() instanceof BaseLookAndFeel) {
       BaseLookAndFeel laf = (BaseLookAndFeel) UIManager.getLookAndFeel();
       size.height =
           Math.max(size.height, laf.getIconFactory().getDownArrowIcon().getIconHeight() + 2);
     }
   }
   return new Dimension(size.width + 2, size.height + 2);
 }
Example #17
0
  /** Description of the Method */
  public void init() {
    // super.init();
    size = new Dimension(570, 570);
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(borderLayout1);

    Dimension d = messagePanel.getSize();
    d.height += 20;
    messagePanel.setPreferredSize(d);
    contentPane.add(messagePanel, BorderLayout.SOUTH);

    contentPane.setOpaque(true);
    userPanel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(2, 2, 2, 2);

    messagePanel.setLayout(borderLayout5);
    contentPane.setOpaque(true);
    contentPane.setBackground(Color.white);
    this.setSize(size);

    messagePanel.add(labelMessage, BorderLayout.NORTH);
    // Logg.logg("MhClient: Före XttTree-skapande", 6);
    this.mhTable = new MhTable(root, false, this.labelMessage);
    // Logg.logg("MhClient: mhTable-skapande klart", 6);
    this.contentPane.add(this.mhTable.splitPane, BorderLayout.CENTER);
  }
 @Override
 public Dimension getMinimumSize(JComponent c) {
   AbstractButton b = (AbstractButton) c;
   String style = (String) c.getClientProperty("Quaqua.Button.style");
   if (style == null) {
     style = "push";
   }
   if (style.equals("help")) {
     return getPreferredSize(c);
   }
   Dimension d = super.getMinimumSize(c);
   if (isFixedHeight(c)) {
     Dimension p = getPreferredSize(c);
     if (d != null && p != null) {
       d.height = Math.max(d.height, p.height);
     }
   }
   if (!QuaquaUtilities.isSmallSizeVariant(c)
       && style.equals("push") //
       && b.getIcon() == null
       && b.getText() != null) {
     if (d != null) {
       d.width = Math.max(d.width, UIManager.getInt("Button.minimumWidth"));
     }
   }
   return d;
 }
 @Override
 public Dimension getPreferredSize() {
   final Dimension size = super.getPreferredSize();
   size.width += (myMoreRec.width + myDownIconInsets.left + myDownIconInsets.right);
   size.height += (myDownIconInsets.top + myDownIconInsets.bottom);
   return size;
 }
Example #20
0
 /**
  * Returns whether the input Object is equivalent to this Dimension. <code>true</code> if the
  * Object is a Dimension and its width and height are equal to this Dimension's width and height,
  * <code>false</code> otherwise.
  *
  * @param o the Object being tested for equality
  * @return <code>true</code> if the given object is equal to this dimension
  * @since 2.0
  */
 public boolean equals(Object o) {
   if (o instanceof Dimension) {
     Dimension d = (Dimension) o;
     return (d.width() == width && d.height() == height);
   }
   return false;
 }
Example #21
0
  /** Is called when the applet wants to be resized. */
  @Override
  public void appletResize(int width, int height) {
    currentAppletSize.width = width;
    currentAppletSize.height = height;
    final Dimension currentSize = new Dimension(currentAppletSize.width, currentAppletSize.height);

    if (loader != null) {
      AppContext appCtxt = loader.getAppContext();
      if (appCtxt != null) appEvtQ = (java.awt.EventQueue) appCtxt.get(AppContext.EVENT_QUEUE_KEY);
    }

    final AppletPanel ap = this;
    if (appEvtQ != null) {
      appEvtQ.postEvent(
          new InvocationEvent(
              Toolkit.getDefaultToolkit(),
              new Runnable() {
                @Override
                public void run() {
                  if (ap != null) {
                    ap.dispatchAppletEvent(APPLET_RESIZE, currentSize);
                  }
                }
              }));
    }
  }
Example #22
0
 /**
  * Returns the preferred size of the viewport for a view component. For example the preferredSize
  * of a JList component is the size required to acommodate all of the cells in its list however
  * the value of preferredScrollableViewportSize is the size required for
  * JList.getVisibleRowCount() rows. A component without any properties that would effect the
  * viewport size should just return getPreferredSize() here.
  *
  * @return The preferredSize of a JViewport whose view is this Scrollable.
  * @see JViewport#getPreferredSize
  */
 public Dimension getPreferredScrollableViewportSize() {
   Dimension size = getPreferredSize();
   Dimension retval = new Dimension();
   retval.width = size.width > 600 ? 600 : size.width;
   retval.height = size.height > 400 ? 400 : size.height;
   return retval;
 }
  /*
   *  This method is called every time:
   *  - to make sure the viewport is returned to its default position
   *  - to remove the horizontal scrollbar when it is not wanted
   */
  private void checkHorizontalScrollBar(BasicComboPopup popup) {
    //  Reset the viewport to the left

    JViewport viewport = scrollPane.getViewport();
    Point p = viewport.getViewPosition();
    p.x = 0;
    viewport.setViewPosition(p);

    //  Remove the scrollbar so it is never painted

    if (!scrollBarRequired) {
      scrollPane.setHorizontalScrollBar(null);
      return;
    }

    //	Make sure a horizontal scrollbar exists in the scrollpane

    JScrollBar horizontal = scrollPane.getHorizontalScrollBar();

    if (horizontal == null) {
      horizontal = new JScrollBar(JScrollBar.HORIZONTAL);
      scrollPane.setHorizontalScrollBar(horizontal);
      scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    }

    //	Potentially increase height of scroll pane to display the scrollbar

    if (horizontalScrollBarWillBeVisible(popup, scrollPane)) {
      Dimension scrollPaneSize = scrollPane.getPreferredSize();
      scrollPaneSize.height += horizontal.getPreferredSize().height;
      scrollPane.setPreferredSize(scrollPaneSize);
      scrollPane.setMaximumSize(scrollPaneSize);
      scrollPane.revalidate();
    }
  }
Example #24
0
    public Dimension minimumLayoutSize(Container parent) {
      Dimension dim = new Dimension();
      Insets insets = getInsets();
      dim.width = insets.left + insets.right;
      dim.height = insets.top + insets.bottom;

      Dimension centerPref = center.getMinimumSize();
      dim.width += centerPref.width;
      dim.height += centerPref.height;
      Dimension rightPref = right.getMinimumSize();
      dim.width += rightPref.width;
      Dimension bottomPref = bottom.getMinimumSize();
      dim.height += bottomPref.height;

      return dim;
    }
  void jButtonWeights_actionPerformed(ActionEvent e) {
    NumberGeneratorDialog dlg =
        new NumberGeneratorDialog(
            (Frame) null,
            "Weights",
            "Weight of synaptic connections",
            mySynProps.getWeightsGenerator(),
            true);

    // Center the window
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = dlg.getSize();
    if (frameSize.height > screenSize.height) {
      frameSize.height = screenSize.height;
    }
    if (frameSize.width > screenSize.width) {
      frameSize.width = screenSize.width;
    }
    dlg.setLocation(
        (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    dlg.setVisible(true);

    jTextFieldWeights.setText(mySynProps.getWeightsGenerator().toShortString());

    // mySynProps.setWeightsGenerator(dlg.getFinalNumGen());
  }
Example #26
0
  /** Paint it. */
  public void paint(Graphics g) {
    Dimension d = getSize();
    if (!inited || buff == null || d.width != buffSize.width || d.height != buffSize.height) {
      buffSize.width = d.width;
      buffSize.height = d.height;
      buff = createImage(d.width + 4, d.height + 4);
      if (buff == null) return;
      buffG = buff.getGraphics();
      inited = true;
    }

    buffG.setColor(Color.lightGray);
    buffG.fillRect(0, 0, prefSize.width, prefSize.height);
    PressedRect(buffG, 0, 0, prefSize.width - 2, prefSize.height - 2);

    buffG.setColor(Color.lightGray);
    buffG.fillRect(0, 0, prefSize.width + 2, prefSize.height + 2);
    if (!gameover) if ((gameover = is_game_over())) end_game();
    for (int i = 0; i < rows; i++) {
      for (int j = 0; j < cols; j++) {
        drawBlock(buffG, i, j, status(i, j));
      }
    }
    // PressedRect(buffG,0,0,prefSize.width + 2,prefSize.height + 2);
    if (buff != null) g.drawImage(buff, 0, 0, null);
  }
Example #27
0
 /**
  * Get the preferred size at which this Widget will look best. When a WidgetContainer lays out its
  * contents, it will attempt to make this Widget as close as possible to its preferred size.
  */
 public Dimension getPreferredSize() {
   if (prefColSize == null) calculateSizes();
   Dimension prefSize = new Dimension(0, 0);
   for (int i = 0; i < prefColSize.length; i++) prefSize.width += prefColSize[i];
   for (int i = 0; i < prefRowSize.length; i++) prefSize.height += prefRowSize[i];
   return prefSize;
 }
Example #28
0
 /**
  * Get the smallest size at which this Widget can reasonably be drawn. When a WidgetContainer lays
  * out its contents, it will attempt never to make this Widget smaller than its minimum size.
  */
 public Dimension getMinimumSize() {
   if (minColSize == null) calculateSizes();
   Dimension minSize = new Dimension(0, 0);
   for (int i = 0; i < minColSize.length; i++) minSize.width += minColSize[i];
   for (int i = 0; i < minRowSize.length; i++) minSize.height += minRowSize[i];
   return minSize;
 }
  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();
  }
  public void paint(Graphics g) {
    // Only create the image at the beginning -
    if ((img == null) || (prefsize.width != size().width) || (prefsize.height != size().height)) {
      prefsize.width = size().width;
      prefsize.height = size().height;

      scale = findScale();

      //      System.out.println("New scale = " + scale);
      img = createImage(size().width, size().height);
      ig = img.getGraphics();

      redrawneeded = true;
    }

    if (redrawneeded == true) {
      drawBackground(ig, Color.black);
      drawScene(ig);
      if (drawAxes == true) {
        drawAxes(ig);
      }
      redrawneeded = false;
    } else {
      ig = img.getGraphics();
    }

    g.drawImage(img, 0, 0, this);
  }