@Override
      public void mouseDragged(MouseEvent e) {
        if (!myDragging) return;
        MouseEvent event = SwingUtilities.convertMouseEvent(e.getComponent(), e, MyDivider.this);
        final ToolWindowAnchor anchor = myInfo.getAnchor();
        final Point point = event.getPoint();
        final Container windowPane = InternalDecorator.this.getParent();
        myLastPoint = SwingUtilities.convertPoint(MyDivider.this, point, windowPane);
        myLastPoint.x = Math.min(Math.max(myLastPoint.x, 0), windowPane.getWidth());
        myLastPoint.y = Math.min(Math.max(myLastPoint.y, 0), windowPane.getHeight());

        final Rectangle bounds = InternalDecorator.this.getBounds();
        if (anchor == ToolWindowAnchor.TOP) {
          InternalDecorator.this.setBounds(0, 0, bounds.width, myLastPoint.y);
        } else if (anchor == ToolWindowAnchor.LEFT) {
          InternalDecorator.this.setBounds(0, 0, myLastPoint.x, bounds.height);
        } else if (anchor == ToolWindowAnchor.BOTTOM) {
          InternalDecorator.this.setBounds(
              0, myLastPoint.y, bounds.width, windowPane.getHeight() - myLastPoint.y);
        } else if (anchor == ToolWindowAnchor.RIGHT) {
          InternalDecorator.this.setBounds(
              myLastPoint.x, 0, windowPane.getWidth() - myLastPoint.x, bounds.height);
        }
        InternalDecorator.this.validate();
        e.consume();
      }
 public Dimension getPreferredSize() {
   Dimension d = super.getPreferredSize();
   Container parent = getParent();
   if (parent instanceof JViewport) {
     if (parent.getWidth() > d.width) {
       d = new Dimension(parent.getWidth(), d.height);
     }
   }
   return d;
 }
 @Override
 public void layoutContainer(Container parent) {
   int width = parent.getWidth();
   int height = parent.getHeight();
   Component toolbar = parent.getComponent(0);
   Dimension toolbarSize = toolbar.isVisible() ? toolbar.getPreferredSize() : new Dimension();
   toolbar.setBounds(0, 0, width, toolbarSize.height);
   parent.getComponent(1).setBounds(0, toolbarSize.height, width, height - toolbarSize.height);
 }
Example #4
0
 public int getWidth() {
   float fWidth;
   int width;
   fWidth = scale * nativeGetMaxWidth();
   width = Math.round(fWidth);
   if (parentContainer == null) {
     return width;
   } else {
     return FTAUtilities.max(width, parentContainer.getWidth());
   }
 }
Example #5
0
  public void btnChoose_actionPerformed() {
    //            java.awt.Rectangle r = dateField.getBounds();
    //            Point pOnScreen = dateField.getLocationOnScreen();
    java.awt.Rectangle r = Jtext.getBounds();
    Point pOnScreen = Jtext.getLocationOnScreen();

    Point result = new Point(pOnScreen.x, pOnScreen.y + r.height);
    Point powner = owner.getLocation();
    int offsetX = (pOnScreen.x + width) - (powner.x + owner.getWidth());
    int offsetY = (pOnScreen.y + r.height + height) - (powner.y + owner.getHeight());

    if (offsetX > 0) {
      result.x -= offsetX;
    }

    if (offsetY > 0) {
      result.y -= height + r.height;
    }

    javax.swing.JDialog dateFrame = new javax.swing.JDialog();
    dateFrame.setModal(false);
    dateFrame.setUndecorated(true);
    dateFrame.setLocation(result);
    dateFrame.setSize(width, height);

    dateFrame.addWindowListener(
        new WindowAdapter() {
          // 鍦ㄤ换鎰忕殑闈炴棩鏈熼�夋嫨鍖哄崟鍑伙紝鍒欐棩鏈熼�夋嫨缁勪欢灏嗗彉涓洪潪娲诲姩鐘舵�侊紝鑷姩閲婃斁璧勬簮銆�
          public void windowDeactivated(WindowEvent e) {
            javax.swing.JDialog f = (javax.swing.JDialog) e.getSource();
            f.dispose();
          }
        });
    DatePanel datePanel = new DatePanel(dateFrame, parten);
    dateFrame.getContentPane().setLayout(new BorderLayout());
    dateFrame.getContentPane().add(datePanel);
    dateFrame.setVisible(true);
  }
    public void layoutContainer(Container container) {
      Component[] children = container.getComponents();

      if (children != null && children.length > 0) {
        int numChildren = children.length;
        Insets insets = container.getInsets();
        int maxWidth = 0;
        int maxHeight = 0;
        int totalButtonWidth = 0;
        int x = 0;
        int xOffset = 0;
        boolean ltr = container.getComponentOrientation().isLeftToRight();
        boolean reverse = (ltr) ? reverseButtons : !reverseButtons;

        for (int counter = 0; counter < numChildren; counter++) {
          Dimension pref = children[counter].getPreferredSize();
          maxWidth = Math.max(maxWidth, pref.width);
          maxHeight = Math.max(maxHeight, pref.height);
          totalButtonWidth += pref.width;
        }
        if (getSyncAllWidths()) {
          totalButtonWidth = maxWidth * numChildren;
        }
        totalButtonWidth += (numChildren - 1) * padding;

        switch (getOrientation(container)) {
          case SwingConstants.LEFT:
            x = insets.left;
            break;
          case SwingConstants.RIGHT:
            x = container.getWidth() - insets.right - totalButtonWidth;
            break;
          case SwingConstants.CENTER:
            if (getCentersChildren() || numChildren < 2) {
              x = (container.getWidth() - totalButtonWidth) / 2;
            } else {
              x = insets.left;
              if (getSyncAllWidths()) {
                xOffset =
                    (container.getWidth() - insets.left - insets.right - totalButtonWidth)
                            / (numChildren - 1)
                        + maxWidth;
              } else {
                xOffset =
                    (container.getWidth() - insets.left - insets.right - totalButtonWidth)
                        / (numChildren - 1);
              }
            }
            break;
        }

        for (int counter = 0; counter < numChildren; counter++) {
          int index = (reverse) ? numChildren - counter - 1 : counter;
          Dimension pref = children[index].getPreferredSize();

          if (getSyncAllWidths()) {
            children[index].setBounds(x, insets.top, maxWidth, maxHeight);
          } else {
            children[index].setBounds(x, insets.top, pref.width, pref.height);
          }
          if (xOffset != 0) {
            x += xOffset;
          } else {
            x += children[index].getWidth() + padding;
          }
        }
      }
    }
  protected void handleExecute() {
    ImageView view = getSelectedView();

    if (view != null) {
      ColorBarAnnotation cbar =
          (ColorBarAnnotation) view.getAnnotation(view.getSelectedPlot(), ColorBarAnnotation.ID);

      if (cbar == null) {
        cbar = new ColorBarAnnotation(view.getModel());
        view.setAnnotation(view.getSelectedPlot(), cbar.getIdentifier(), cbar);
      }

      log.finest("retrieved color bar annotation for editing");

      ColorBarAnnotationPresenter presenter = new ColorBarAnnotationPresenter(cbar);
      Container c = JOptionPane.getFrameForComponent(view);

      final JButton okButton = new JButton("OK");
      okButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              dialog.setVisible(false);
              dialog.dispose();
            }
          });

      final JButton cancelButton = new JButton("Cancel");
      cancelButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              // view.setAnnotation(safeCopy);
              // icross.setLinePaint(safeCopy.getLinePaint());
              // icross.setLineWidth(safeCopy.getLineWidth());
              // icross.setGap(safeCopy.getGap());
              // icross.setVisible(safeCopy.isVisible());

              dialog.setVisible(false);
              dialog.dispose();
            }
          });

      final JButton applyButton = new JButton("Apply");

      dialog = new JDialog(JOptionPane.getFrameForComponent(view));
      dialog.setLayout(new BorderLayout());

      Point p = c.getLocation();

      JPanel mainPanel = new JPanel();
      mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 8, 15, 8));
      mainPanel.setLayout(new BorderLayout());
      JPanel buttonPanel =
          ButtonBarFactory.buildRightAlignedBar(okButton, cancelButton, applyButton);

      mainPanel.add(presenter.getComponent(), BorderLayout.CENTER);
      mainPanel.add(buttonPanel, BorderLayout.SOUTH);

      dialog.add(mainPanel, BorderLayout.CENTER);
      dialog.pack();
      dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
      dialog.setLocation(
          (int) (p.getX() + c.getWidth() / 2f), (int) (p.getY() + c.getHeight() / 2f));
      dialog.setVisible(true);
    }
  }
Example #8
0
  public void layoutContainer(Container parent) {
    Insets insets = parent.insets();
    int ncomponents = parent.countComponents();
    int nrows = getRows();
    int ncols = getColumns();
    int hgap = getHgap();
    int vgap = getVgap();

    if (nrows > 0) {
      ncols = (ncomponents + nrows - 1) / nrows;
    } else {
      nrows = (ncomponents + ncols - 1) / ncols;
    }

    // Set heights
    int x;
    int y;
    int nFills = 0;
    boolean[] fills = new boolean[nrows];
    int lastFillRow = -1;
    int nComps = parent.getComponentCount();

    y = insets.top;
    for (int row = 0; row < nrows; row++) {
      // Find largest minimum height for this row
      int h = 0;
      for (int col = 0; col < ncols; col++) {
        if (row * ncols + col < nComps) {
          Component c = parent.getComponent(row * ncols + col);
          h = Math.max(h, c.getMinimumSize().height);
        }
      }
      // Set heights for this row
      x = insets.left;
      for (int col = 0; col < ncols; col++) {
        if (row * ncols + col < nComps) {
          JComponent c = (JComponent) parent.getComponent(row * ncols + col);
          int w = c.getWidth();
          c.setBounds(x, y, w, h);
          x += w + hgap;
          if (col == 0 && getFillRow(c)) {
            fills[row] = true;
          }
        }
      }
      y += h + vgap;
      if (fills[row]) {
        nFills++;
        lastFillRow = row;
      }
    }

    // Fill heights
    if (nFills > 0 && y < parent.getHeight()) {
      // How much height to add
      int hAdd = (parent.getHeight() - y) / nFills;
      int hAdded = 0;
      for (int row = 0; row < nrows; row++) {
        if (fills[row]) {
          if (row == lastFillRow) {
            // Compensate for rounding error
            hAdd = parent.getHeight() - (y + hAdded);
          }
          for (int col = 0; col < ncols; col++) {
            if (row * ncols + col < nComps) {
              Component c = parent.getComponent(row * ncols + col);
              Rectangle b = c.getBounds();
              c.setBounds(b.x, b.y + hAdded, b.width, b.height + hAdd);
            }
          }
          hAdded += hAdd;
        }
      }
    }

    // Set widths
    nFills = 0;
    fills = new boolean[ncols];
    int lastFillCol = -1;

    x = insets.left;
    for (int col = 0; col < ncols; col++) {
      // Find largest minimum width for this column
      int w = 0;
      for (int row = 0; row < nrows; row++) {
        if (row * ncols + col < nComps) {
          Component c = parent.getComponent(row * ncols + col);
          w = Math.max(w, c.getMinimumSize().width);
        }
      }
      // Set widths for this column
      y = insets.top;
      for (int row = 0; row < nrows; row++) {
        if (row * ncols + col < nComps) {
          JComponent c = (JComponent) parent.getComponent(row * ncols + col);
          int h = c.getHeight();
          c.setBounds(x, y, w, h);
          y += h + vgap;
          if (row == 0 && getFillColumn(c)) {
            fills[col] = true;
          }
        }
      }
      x += w + hgap;
      if (fills[col]) {
        nFills++;
        lastFillCol = col;
      }
    }

    // Fill widths
    if (nFills > 0 && x < parent.getWidth()) {
      // How much width to add
      int wAdd = (parent.getWidth() - x) / nFills;
      int wAdded = 0;
      for (int col = 0; col < ncols; col++) {
        if (fills[col]) {
          if (col == lastFillCol) {
            wAdd = parent.getWidth() - (x + wAdded);
          }
          for (int row = 0; row < nrows; row++) {
            if (row * ncols + col < nComps) {
              Component c = parent.getComponent(row * ncols + col);
              Rectangle b = c.getBounds();
              c.setBounds(b.x + wAdded, b.y, b.width + wAdd, b.height);
            }
          }
          wAdded += wAdd;
        }
      }
    }
  }