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);
  }
예제 #2
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;
  }
예제 #3
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);
 }
  /**
   * Randomly picks the location of a new window, such that it fits completely on the screen.
   *
   * @param desktopPane the desktop pane that the frame is being added to.
   * @param frame the JInternalFrame which is being added.
   * @param desiredSize the desired dimensions of the frame.
   */
  private static void setGoodBounds(
      JInternalFrame frame, JDesktopPane desktopPane, Dimension desiredSize) {
    RandomUtil randomUtil = RandomUtil.getInstance();
    Dimension desktopSize = desktopPane.getSize();

    Dimension d = new Dimension(desiredSize);
    int tx = desktopSize.width - d.width;
    int ty = desktopSize.height - d.height;

    if (tx < 0) {
      tx = 0;
      d.width = desktopSize.width;
    } else {
      tx = (int) (randomUtil.nextDouble() * tx);
    }

    if (ty < 0) {
      ty = 0;
      d.height = desktopSize.height;
    } else {
      ty = (int) (randomUtil.nextDouble() * ty);
    }

    frame.setBounds(tx, ty, d.width, d.height);
  }
예제 #5
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);
                  }
                }
              }));
    }
  }
  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);
  }
예제 #7
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);
  }
예제 #8
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;
 }
  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());
  }
예제 #10
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;
 }
예제 #11
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;
 }
  /**
   * Returns the preferred size of this component.
   *
   * @return the preferred size of this component
   */
  public Dimension getPreferredSize() {
    Dimension preferredSize = new Dimension();
    int preferredHeight;

    if (treeNode instanceof ContactNode) {
      UIContact contact = ((ContactNode) treeNode).getContactDescriptor();

      preferredHeight = contact.getPreferredHeight();

      if (preferredHeight > 0) preferredSize.height = preferredHeight;
      else if (contact instanceof ShowMoreContact) preferredSize.height = 20;
      else if (isSelected && treeContactList.isContactButtonsVisible()) preferredSize.height = 70;
      else preferredSize.height = 35;
    } else if (treeNode instanceof GroupNode) {
      UIGroup group = ((GroupNode) treeNode).getGroupDescriptor();

      preferredHeight = group.getPreferredHeight();

      if (isSelected && customActionButtonsUIGroup != null && !customActionButtonsUIGroup.isEmpty())
        preferredSize.height = 70;
      else if (preferredHeight > 0) preferredSize.height = preferredHeight;
      else preferredSize.height = 20;
    }

    return preferredSize;
  }
예제 #13
0
  protected void checkMinimumSize() {
    Dimension d = getDrawingSize();

    if (fViewSize.height < d.height || fViewSize.width < d.width) {
      fViewSize.height = d.height + SCROLL_OFFSET;
      fViewSize.width = d.width + SCROLL_OFFSET;
      setSize(fViewSize);
    }
  }
예제 #14
0
    public Dimension preferredLayoutSize(Container parent) {
      Dimension dim = new Dimension();

      Dimension captionSize = caption.getPreferredSize();
      dim.width = captionSize.width;

      for (int i = 0; i < pages.length; i++) {
        Dimension _dim = pages[i].getPreferredSize();
        dim.width = Math.max(_dim.width, dim.width);
        dim.height = Math.max(_dim.height, dim.height);
      }

      dim.width += PADDING * 2;
      dim.height += PADDING * 2;
      dim.height += nextButton.getPreferredSize().height;
      dim.height += captionSize.height;
      return dim;
    }
예제 #15
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;
   if (!inEditMode) {
     if ((h != nHeight) || (h < rHeight)) {
       adjustFont(w, h);
     }
   }
   super.reshape(x, y, w, h);
 }
예제 #16
0
 /**
  * Return the size of the area occupied by the contained figures inside the drawing. This method
  * is called by checkMinimumSize().
  */
 protected Dimension getDrawingSize() {
   FigureEnumeration fe = drawing().figures();
   Dimension d = new Dimension(0, 0);
   while (fe.hasNextFigure()) {
     Rectangle r = fe.nextFigure().displayBox();
     d.width = Math.max(d.width, r.x + r.width);
     d.height = Math.max(d.height, r.y + r.height);
   }
   return d;
 }
예제 #17
0
 @Override
 public Dimension preferredLayoutSize(final Container parent) {
   Dimension result = new Dimension();
   for (int i = 0; i < parent.getComponentCount(); i++) {
     final Dimension prefSize = parent.getComponent(i).getPreferredSize();
     result.width += prefSize.width;
     result.height = Math.max(prefSize.height, result.height);
   }
   return result;
 }
예제 #18
0
 public void setSizeRatio(double x, double y) {
   xRatio = x;
   yRatio = y;
   if (x > 1.0) xRatio = x - 1.0;
   if (y > 1.0) yRatio = y - 1.0;
   if (defDim.width <= 0) defDim = getPreferredSize();
   curLoc.x = (int) ((double) defLoc.x * xRatio);
   curLoc.y = (int) ((double) defLoc.y * yRatio);
   curDim.width = (int) ((double) defDim.width * xRatio);
   curDim.height = (int) ((double) defDim.height * yRatio);
   if (!inEditMode) setBounds(curLoc.x, curLoc.y, curDim.width, curDim.height);
 }
예제 #19
0
 public void setEditMode(boolean s) {
   twin.setEditMode(s);
   setOpaque(s);
   if (s) {
     addMouseListener(ml);
     curLoc.x = defLoc.x;
     curLoc.y = defLoc.y;
     defDim = getPreferredSize();
     curDim.width = defDim.width;
     curDim.height = defDim.height;
   } else removeMouseListener(ml);
   inEditMode = s;
 }
예제 #20
0
 public void setSizeRatio(double x, double y) {
   double rx = x;
   double ry = y;
   if (rx > 1.0) rx = x - 1.0;
   if (ry > 1.0) ry = y - 1.0;
   if (defDim.width <= 0) defDim = getPreferredSize();
   curLoc.x = (int) ((double) defLoc.x * rx);
   curLoc.y = (int) ((double) defLoc.y * ry);
   curDim.width = (int) ((double) defDim.width * rx);
   curDim.height = (int) ((double) defDim.height * ry);
   if (!inEditMode) setBounds(curLoc.x, curLoc.y, curDim.width, curDim.height);
   twin.setSizeRatio(x, y);
 }
예제 #21
0
  /** Construct an applet viewer and start the applet. */
  public void init() {
    try {
      // Get the width (if any)
      defaultAppletSize.width = getWidth();
      currentAppletSize.width = defaultAppletSize.width;

      // Get the height (if any)
      defaultAppletSize.height = getHeight();
      currentAppletSize.height = defaultAppletSize.height;

    } catch (NumberFormatException e) {
      // Turn on the error flag and let TagAppletPanel
      // do the right thing.
      status = APPLET_ERROR;
      showAppletStatus("badattribute.exception");
      showAppletLog("badattribute.exception");
      showAppletException(e);
    }

    setLayout(new BorderLayout());

    createAppletThread();
  }
예제 #22
0
    TextPanel(String file) {
      super(new BorderLayout());

      JEditorPane text = new JEditorPane();

      try {
        text.setPage(TextPanel.this.getClass().getResource(file));
      } catch (Exception e) {
        text.setText("Error loading '" + file + "'");
        e.printStackTrace();
      }

      text.setEditable(false);

      JScrollPane scrollPane = new JScrollPane(text);
      Dimension dim = new Dimension();
      dim.width = 450;
      dim.height = 200;
      scrollPane.setPreferredSize(dim);
      TextPanel.this.add(BorderLayout.CENTER, scrollPane);
    }
예제 #23
0
 public static void openFrame(Object frame) {
   boolean packFrame = false;
   if (packFrame) {
     ((JFrame) frame).pack();
   } else {
     ((JFrame) frame).validate();
   }
   // Center the window
   Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
   Dimension frameSize = ((JFrame) frame).getSize();
   if (frameSize.height > screenSize.height) {
     frameSize.height = screenSize.height;
   }
   if (frameSize.width > screenSize.width) {
     frameSize.width = screenSize.width;
   }
   ((JFrame) frame)
       .setLocation(
           (screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
   ((JFrame) frame).setVisible(true);
 }
예제 #24
0
 public void setEditMode(boolean s) {
   if (s) {
     addMouseListener(ml);
     setOpaque(s);
     if (font != null) {
       setFont(font);
       fontH = font.getSize();
       rHeight = fontH;
     }
     defDim = getPreferredSize();
     curLoc.x = defLoc.x;
     curLoc.y = defLoc.y;
     curDim.width = defDim.width;
     curDim.height = defDim.height;
     xRatio = 1.0;
     yRatio = 1.0;
   } else {
     removeMouseListener(ml);
     if ((bg != null) || (isActive < 1)) setOpaque(true);
     else setOpaque(false);
   }
   inEditMode = s;
 }
예제 #25
0
 @Override
 public void setBounds(int x, int y, int width, int height) {
   super.setBounds(x, y, width, height);
   currentAppletSize.width = width;
   currentAppletSize.height = height;
 }