コード例 #1
1
  protected void resizeDesktop() {
    int x = 0;
    int y = 0;
    JScrollPane scrollPane = getScrollPane();
    Insets scrollInsets = getScrollPaneInsets();

    if (scrollPane != null) {
      JInternalFrame allFrames[] = desktop.getAllFrames();
      for (int i = 0; i < allFrames.length; i++) {
        if (allFrames[i].getX() + allFrames[i].getWidth() > x) {
          x = allFrames[i].getX() + allFrames[i].getWidth();
        }
        if (allFrames[i].getY() + allFrames[i].getHeight() > y) {
          y = allFrames[i].getY() + allFrames[i].getHeight();
        }
      }
      Dimension d = scrollPane.getVisibleRect().getSize();
      if (scrollPane.getBorder() != null) {
        d.setSize(
            d.getWidth() - scrollInsets.left - scrollInsets.right,
            d.getHeight() - scrollInsets.top - scrollInsets.bottom);
      }

      if (x <= d.getWidth()) {
        x = ((int) d.getWidth()) - 20;
      }
      if (y <= d.getHeight()) {
        y = ((int) d.getHeight()) - 20;
      }
      desktop.setAllSize(x, y);
      scrollPane.invalidate();
      scrollPane.validate();
    }
  }
コード例 #2
0
 /*
  * Test method for 'java.awt.TextArea.minimumSize()'
  */
 @SuppressWarnings("deprecation")
 public void testMinimumSize() {
   Dimension minSize = new Dimension();
   assertEquals(minSize, area.minimumSize());
   minSize.setSize(130, 160);
   area.setMinimumSize(minSize);
   assertNotSame(minSize, area.minimumSize());
   assertEquals(minSize, area.minimumSize());
   area.setMinimumSize(null);
   assertEquals(new Dimension(), area.minimumSize());
   frame = new Frame();
   frame.add(area);
   frame.addNotify();
   assertEquals(
       "By default minimum size is set for 10 rows and 60 columns",
       area.minimumSize(10, 60),
       area.minimumSize());
   int rows = 15;
   area.setRows(rows);
   assertEquals(
       "By default minimum size is set for 10 rows and 60 columns",
       area.minimumSize(10, 60),
       area.minimumSize());
   int cols = 80;
   area.setColumns(cols);
   assertEquals(area.minimumSize(rows, cols), area.minimumSize());
 }
コード例 #3
0
  /*
   * Test method for 'java.awt.TextArea.getMinimumSize(int, int)'
   */
  public void testGetMinimumSizeIntInt() {
    int rows = 1;
    int cols = 1;
    Dimension minSize = new Dimension();
    assertEquals(minSize, area.getMinimumSize(rows, cols));
    minSize.setSize(12, 13);
    area.setMinimumSize(minSize);
    assertEquals(minSize, area.getMinimumSize(rows, cols));
    area.setMinimumSize(null);
    assertEquals(new Dimension(), area.getMinimumSize(rows, cols));
    frame = new Frame();
    frame.add(area);
    frame.addNotify();

    assertTrue(area.getMinimumSize(rows, cols).width > 0);
    assertTrue(area.getMinimumSize(rows, cols).height > 0);
    int dw = (area.getMinimumSize(rows, cols * 2).width - area.getMinimumSize(rows, cols).width);
    int dw1 =
        (area.getMinimumSize(rows, cols * 3).width - area.getMinimumSize(rows, cols * 2).width);
    assertEquals(dw, dw1);
    int dh = (area.getMinimumSize(rows * 2, cols).height - area.getMinimumSize(rows, cols).height);
    int dh1 =
        (area.getMinimumSize(rows * 3, cols).height - area.getMinimumSize(rows * 2, cols).height);
    assertEquals(dh1, dh);
  }
コード例 #4
0
  public FileNameRenderer(JTable table) {
    Border b = UIManager.getBorder("Table.noFocusBorder");
    if (Objects.isNull(b)) { // Nimbus???
      Insets i = focusCellHighlightBorder.getBorderInsets(textLabel);
      b = BorderFactory.createEmptyBorder(i.top, i.left, i.bottom, i.right);
    }
    noFocusBorder = b;

    p.setOpaque(false);
    panel.setOpaque(false);

    // http://www.icongalore.com/ XP Style Icons - Windows Application Icon, Software XP Icons
    nicon = new ImageIcon(getClass().getResource("wi0063-16.png"));
    sicon =
        new ImageIcon(
            p.createImage(
                new FilteredImageSource(nicon.getImage().getSource(), new SelectedImageFilter())));

    iconLabel = new JLabel(nicon);
    iconLabel.setBorder(BorderFactory.createEmptyBorder());

    p.add(iconLabel, BorderLayout.WEST);
    p.add(textLabel);
    panel.add(p, BorderLayout.WEST);

    Dimension d = iconLabel.getPreferredSize();
    dim.setSize(d);
    table.setRowHeight(d.height);
  }
コード例 #5
0
ファイル: RecentDocFrame.java プロジェクト: jjsahalf/drjava
  private void show(int _current) {
    OpenDefinitionsDocument doc = _docs.get(_current);

    String text = getTextFor(doc);

    _label.setText(_displayManager.getName(doc));
    _label.setIcon(_displayManager.getIcon(doc));

    if (text.length() > 0) {
      // as wide as the text area wants, but only 200px high
      _textpane.setText(text);
      _scroller.setPreferredSize(_textpane.getPreferredScrollableViewportSize());
      if (_scroller.getPreferredSize().getHeight() > 200)
        _scroller.setPreferredSize(
            new Dimension((int) _scroller.getPreferredSize().getWidth(), 200));

      _scroller.setVisible(_showSource);
    } else _scroller.setVisible(false);

    Dimension d = _label.getMinimumSize();
    d.setSize(d.getWidth() + _padding * 2, d.getHeight() + _padding * 2);
    _label.setPreferredSize(d);
    _label.setHorizontalAlignment(SwingConstants.CENTER);
    _label.setVerticalAlignment(SwingConstants.CENTER);
    pack();
    centerH();
  }
コード例 #6
0
ファイル: JediTerminal.java プロジェクト: patsimm/jediterm
  public Dimension resize(final Dimension pendingResize, final RequestOrigin origin) {
    final int oldHeight = myTerminalHeight;
    if (pendingResize.width <= MIN_WIDTH) {
      pendingResize.setSize(MIN_WIDTH, pendingResize.height);
    }
    final Dimension pixelSize =
        myDisplay.requestResize(
            pendingResize,
            origin,
            myCursorY,
            new ResizeHandler() {
              @Override
              public void sizeUpdated(int termWidth, int termHeight, int cursorY) {
                myTerminalWidth = termWidth;
                myTerminalHeight = termHeight;
                myCursorY = cursorY;
                myCursorX = Math.min(myCursorX, myTerminalWidth - 1);

                myTabulator.resize(myTerminalWidth);
              }
            });

    myScrollRegionBottom += myTerminalHeight - oldHeight;
    return pixelSize;
  }
コード例 #7
0
  private void initialize(Dimension dimension, int paddingSize) {
    Dimension temporaryDimension = new Dimension(dimension.width, dimension.height);
    temporaryDimension.setSize(
        dimension.width + 2 * paddingSize, dimension.height + 2 * paddingSize);
    setPreferredSize(temporaryDimension);
    setSize(temporaryDimension);

    addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseEntered(MouseEvent mouseEvent) {
            if (active) return;
            iconLabelMouseEntered();
          }

          @Override
          public void mouseExited(MouseEvent mouseEvent) {
            iconLabelMouseExited();
          }

          @Override
          public void mousePressed(MouseEvent e) {
            iconLabelMousePressed();
          }

          @Override
          public void mouseReleased(MouseEvent e) {
            iconLabelMouseReleased();
          }

          @Override
          public void mouseClicked(MouseEvent e) {}
        });
  }
コード例 #8
0
ファイル: IMDialog.java プロジェクト: tasfe/italk
 @Override
 public void setPreferredSize(Dimension preferredSize) {
   // mac下忽略背影,减去背影部分 @IMFrameWrap
   if (SystemUtils.isMac()) {
     preferredSize.setSize(preferredSize.getWidth() - 20, preferredSize.getHeight() - 10);
   }
   super.setPreferredSize(preferredSize);
 }
コード例 #9
0
ファイル: ProgressTooltipUI.java プロジェクト: dubik/tasks
  public Dimension getPreferredSize(JComponent c) {
    Dimension preferredSize = super.getPreferredSize(c);
    if (c instanceof ProgressTooltip) {
      preferredSize.setSize(preferredSize.getWidth(), preferredSize.getHeight() + 6);
    }

    return preferredSize;
  }
コード例 #10
0
  public void setNormalSize() {
    JScrollPane scrollPane = getScrollPane();
    int x = 0;
    int y = 0;
    Insets scrollInsets = getScrollPaneInsets();

    if (scrollPane != null) {
      Dimension d = scrollPane.getVisibleRect().getSize();
      if (scrollPane.getBorder() != null) {
        d.setSize(
            d.getWidth() - scrollInsets.left - scrollInsets.right,
            d.getHeight() - scrollInsets.top - scrollInsets.bottom);
      }

      d.setSize(d.getWidth() - 20, d.getHeight() - 20);
      desktop.setAllSize(x, y);
      scrollPane.invalidate();
      scrollPane.validate();
    }
  }
コード例 #11
0
ファイル: WFramePeer.java プロジェクト: netroby/jdk9-dev
 @Override
 public Dimension getMinimumSize() {
   Dimension d = new Dimension();
   if (!((Frame) target).isUndecorated()) {
     d.setSize(getSysMinWidth(), getSysMinHeight());
   }
   if (((Frame) target).getMenuBar() != null) {
     d.height += getSysMenuHeight();
   }
   return d;
 }
コード例 #12
0
ファイル: DrawbotGUI.java プロジェクト: bertbalcaen/DrawBot
  public Container CreateContentPane() {
    // Create the content-pane-to-be.
    JPanel contentPane = new JPanel(new BorderLayout());
    contentPane.setOpaque(true);

    // the log panel
    log = new JTextPane();
    log.setEditable(false);
    log.setBackground(Color.BLACK);
    logPane = new JScrollPane(log);
    kit = new HTMLEditorKit();
    doc = new HTMLDocument();
    log.setEditorKit(kit);
    log.setDocument(doc);
    DefaultCaret c = (DefaultCaret) log.getCaret();
    c.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    ClearLog();

    // the preview panel
    previewPane = new DrawPanel();
    previewPane.setPaperSize(paper_top, paper_bottom, paper_left, paper_right);

    // status bar
    statusBar = new StatusBar();
    Font f = statusBar.getFont();
    statusBar.setFont(f.deriveFont(Font.BOLD, 15));
    Dimension d = statusBar.getMinimumSize();
    d.setSize(d.getWidth(), d.getHeight() + 30);
    statusBar.setMinimumSize(d);

    // layout
    Splitter split = new Splitter(JSplitPane.VERTICAL_SPLIT);
    split.add(previewPane);
    split.add(logPane);
    split.setDividerSize(8);

    contentPane.add(statusBar, BorderLayout.SOUTH);
    contentPane.add(split, BorderLayout.CENTER);

    // open the file
    if (recentFiles[0].length() > 0) {
      OpenFileOnDemand(recentFiles[0]);
    }

    // connect to the last port
    ListSerialPorts();
    if (Arrays.asList(portsDetected).contains(recentPort)) {
      OpenPort(recentPort);
    }

    return contentPane;
  }
コード例 #13
0
ファイル: JBeanEditor.java プロジェクト: fommil/common-utils
 // Set the width/height of columns/rows by the largest rendering entry
 private void customiseMinimumDimensions(Dimension dim, int row, int column) {
   TableColumn tableColumn = getColumnModel().getColumn(column);
   // this required extra margin padding is a mystery to me...
   dim.setSize(dim.width + getColumnMargin(), dim.height + getRowMargin());
   // potential bug: refresh() is needed to reduce size of unusually large temporary entries
   if (tableColumn.getWidth() < dim.width) {
     tableColumn.setMinWidth(dim.width);
     if (column == 0) {
       tableColumn.setMaxWidth(dim.width);
     }
   }
   if (getRowHeight(row) < dim.height) {
     setRowHeight(row, dim.height);
   }
 }
コード例 #14
0
  /*
   * Test method for 'java.awt.TextArea.getPreferredSize(int, int)'
   */
  public void testGetPreferredSizeIntInt() {
    int rows = 2;
    int cols = 3;
    Dimension prefSize = new Dimension();
    assertEquals(area.getMinimumSize(rows, cols), area.getPreferredSize(rows, cols));
    prefSize.setSize(12, 13);
    area.setPreferredSize(prefSize);
    assertEquals(prefSize, area.getPreferredSize(rows, cols));
    area.setPreferredSize(null);
    assertEquals(new Dimension(), area.getPreferredSize(rows, cols));
    frame = new Frame();
    frame.add(area);
    frame.addNotify();

    assertEquals(area.getMinimumSize(rows, cols), area.getPreferredSize(rows, cols));
  }
コード例 #15
0
 /*
  * Test method for 'java.awt.TextArea.getPreferredSize()'
  */
 public void testGetPreferredSize() {
   Dimension prefSize = new Dimension();
   assertEquals(prefSize, area.getPreferredSize());
   prefSize.setSize(4, 5);
   area.setPreferredSize(prefSize);
   assertNotSame(prefSize, area.getPreferredSize());
   assertEquals(prefSize, area.getPreferredSize());
   area.setPreferredSize(null);
   assertEquals(new Dimension(), area.getPreferredSize());
   frame = new Frame();
   frame.add(area);
   frame.addNotify();
   assertEquals(
       "By default preferred size is equal to minimum size",
       area.getMinimumSize(),
       area.getPreferredSize());
 }
コード例 #16
0
 /*
  * Test method for 'java.awt.TextArea.getMinimumSize()'
  */
 public void testGetMinimumSize() {
   Dimension minSize = new Dimension();
   assertEquals(minSize, area.getMinimumSize());
   minSize.setSize(13, 16);
   area.setMinimumSize(minSize);
   assertNotSame(minSize, area.getMinimumSize());
   assertEquals(minSize, area.getMinimumSize());
   area.setMinimumSize(null);
   assertEquals(new Dimension(), area.getMinimumSize());
   frame = new Frame();
   frame.add(area);
   frame.addNotify();
   assertEquals(
       "By default minimum size is set for 10 rows and 60 columns",
       area.getMinimumSize(10, 60),
       area.getMinimumSize());
 }
コード例 #17
0
    public void setZoomFactor(double zoomFactor) {
      double oldZoomFactor = getZoomFactor();

      // Change current size
      Dimension size = imageComponent.getCanvasSize();
      BufferedImage image = imageComponent.getDocument().getValue();
      if (image != null) {
        size.setSize(
            (double) image.getWidth() * zoomFactor, (double) image.getHeight() * zoomFactor);
        imageComponent.setCanvasSize(size);
      }

      revalidate();
      repaint();
      myZoomLevelChanged = false;

      imageComponent.firePropertyChange(ZOOM_FACTOR_PROP, oldZoomFactor, zoomFactor);
    }
コード例 #18
0
 /*
  * Test method for 'java.awt.TextArea.preferredSize()'
  */
 @SuppressWarnings("deprecation")
 public void testPreferredSize() {
   Dimension prefSize = new Dimension();
   assertEquals(area.minimumSize(), area.preferredSize());
   prefSize.setSize(40, 50);
   area.setPreferredSize(prefSize);
   assertNotSame(prefSize, area.preferredSize());
   assertEquals(prefSize, area.preferredSize());
   area.setPreferredSize(null);
   assertEquals(new Dimension(), area.preferredSize());
   frame = new Frame();
   frame.add(area);
   frame.addNotify();
   assertEquals(
       "By default preferred size is equal to minimum size",
       area.minimumSize(),
       area.preferredSize());
 }
コード例 #19
0
ファイル: TextLineNumber.java プロジェクト: dejlek/jlib
  /** Calculate the width needed to display the maximum line number */
  private void setPreferredWidth() {
    Element root = component.getDocument().getDefaultRootElement();
    int lines = root.getElementCount();
    int digits = Math.max(String.valueOf(lines).length(), minimumDisplayDigits);

    //  Update sizes when number of digits in the line number changes
    if (lastDigits != digits) {
      lastDigits = digits;
      FontMetrics fontMetrics = getFontMetrics(getFont());
      int width = fontMetrics.charWidth('0') * digits;
      Insets insets = getInsets();
      int preferredWidth = insets.left + insets.right + width;

      Dimension d = getPreferredSize();
      d.setSize(preferredWidth, HEIGHT);
      setPreferredSize(d);
      setSize(d);
    }
  }
コード例 #20
0
  /**
   * Calculates the preferred size dimensions for the specified panel given the components in the
   * specified parent container.
   *
   * @see #minimumLayoutSize
   * @param target The component to be laid out.
   * @return A size deemed suitable for laying out the container.
   */
  public Dimension preferredLayoutSize(Container target) {
    int count;
    Container parent;
    Component component;
    Point point;
    Dimension dimension;
    Insets insets;
    Dimension ret;

    synchronized (target.getTreeLock()) {
      count = target.getComponentCount();
      if (0 == count) {
        // be the same size unless we have a parent
        ret = target.getSize();
        parent = target.getParent();
        if (null != parent) {
          insets = parent.getInsets();
          ret = parent.getSize();
          ret.setSize(
              ret.width - insets.left - insets.right, ret.height - insets.top - insets.bottom);
        }
      } else {
        ret = new Dimension(0, 0);
        for (int i = 0; i < count; i++) {
          component = target.getComponent(i);
          if (component.isVisible()) {
            point = component.getLocation();
            dimension = component.getPreferredSize();
            ret.width = Math.max(ret.width, point.x + dimension.width);
            ret.height = Math.max(ret.height, point.y + dimension.height);
          }
        }
        insets = target.getInsets();
        ret.width += insets.left + insets.right;
        ret.height += insets.top + insets.bottom;
      }
    }

    return (ret);
  }
コード例 #21
0
ファイル: dbfShow.java プロジェクト: akerigan/staxer
  public void setupDBFields(String dbname) throws Exception {

    viewPane.setLayout(null);
    Dimension dimView = sp.getSize();
    int height = 0, width = 50;
    viewPane.removeAll();
    db = new DBF(dbname);
    setTitle(dbname);

    gb = new GridBagLayout();
    gbc = new GridBagConstraints();
    viewPane.setLayout(gb);

    int i, j;
    fldObjects = new Vector(db.getFieldCount());
    for (i = 1; i <= db.getFieldCount(); i++) {
      j = i - 1;
      f = db.getField(i);
      if (f.isMemoField() || f.isPictureField()) {
        b = new Button(db.getField(i).getName());
        b.addActionListener(this);
        addComponent(
            viewPane, b, 1, j, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
        fldObjects.addElement(b);
      } else if (f.getType() == 'L') {
        c = new Checkbox(db.getField(i).getName(), true);
        addComponent(
            viewPane, c, 1, j, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
        fldObjects.addElement(c);
      } else {
        l = new Label(db.getField(i).getName(), Label.RIGHT);
        addComponent(
            viewPane, l, 0, j, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
        int ln = f.getLength();
        if (ln > 100) {
          ln = 100;
        }
        t = new TextField(db.getField(i).getName(), ln);
        if (width < ln * 10) {
          width = ln * 10;
        }
        addComponent(
            viewPane, t, 1, j, ln, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
        fldObjects.addElement(t);
        t.setEditable(true);
      }
      height += 10;
    }

    crl.setText("Record " + db.getCurrentRecordNumber());
    trl.setText(" of " + db.getRecordCount());
    SBrecpos.setMaximum(db.getRecordCount());
    addComponent(viewPane, crl, 0, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    addComponent(viewPane, trl, 1, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    i++;
    addComponent(
        viewPane, SBrecpos, 0, i, 2, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    addComponent(
        viewPane, delCB, 2, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    i++;
    addComponent(
        viewPane, Prev, 0, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    addComponent(
        viewPane, Next, 1, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    i++;
    addComponent(viewPane, Add, 0, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    addComponent(
        viewPane, Update, 1, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    addComponent(
        viewPane, Clear, 2, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST);
    Prev.setEnabled(false);
    prevRecord.setEnabled(false);
    if (db.getRecordCount() == 0) {
      Update.setEnabled(false);
      updateRecord.setEnabled(false);
      Next.setEnabled(false);
      nextRecord.setEnabled(false);
    }

    dimView.setSize(width + 150, height + 150);
    sp.setSize(dimView);

    goTo(1);
  }
コード例 #22
0
 @Override // from interface IRectangle
 public Dimension size(Dimension target) {
   target.setSize(width(), height());
   return target;
 }
コード例 #23
0
ファイル: Game.java プロジェクト: Genki91/collapsing-puzzle
 /*
  * Return the size of the game plus some space to take the menu bar into
  * account.
  */
 public Dimension getGameSize() {
   Dimension d = this.currentgame.getPreferredSize();
   d.setSize(d.getWidth(), d.getHeight() + 55);
   return d;
 }