Ejemplo n.º 1
0
  // TODO replace SwingConstant with enum other non-int
  // TODO this method places the box outside of the origin component
  // that continues the implementation approach that Amy used.  I
  // think it would be a useful poll to determine whether the box
  // should be place inside or outside of the origin (by default).
  public void showOnGlassPane(
      Container glassPane, Component origin, int offsetX, int offsetY, int positionHint) {
    Rectangle r = SwingUtilities.convertRectangle(origin, origin.getBounds(), glassPane);
    Dimension d = getPreferredSize();

    int originX = offsetX + r.x;
    int originY = offsetY + r.y;

    switch (positionHint) {
      case SwingConstants.TOP:
        originX += (r.width - d.width) / 2;
        originY -= d.height;
        break;
      case SwingConstants.BOTTOM:
        originX += (r.width - d.width) / 2;
        originY += r.height;
        break;
      case SwingConstants.LEFT:
        originX -= d.width;
        originY += (r.height - d.height) / 2;
        break;
      case SwingConstants.RIGHT:
        originX += r.width;
        originY += (r.height - d.height) / 2;
        break;
      case SwingConstants.CENTER:
        originX += (r.width - d.width) / 2;
        originY += (r.height - d.height) / 2;
        break;
      default:
        throw new IllegalArgumentException("inavlid position hint");
    }

    showOnGlassPane(glassPane, originX, originY);
  }
Ejemplo n.º 2
0
  /**
   * @param aEvent
   * @param aStartPoint
   */
  protected void handleZoomRegion(final MouseEvent aEvent, final Point aStartPoint) {
    // For now, disabled by default as it isn't 100% working yet...
    if (Boolean.FALSE.equals(Boolean.valueOf(System.getProperty("zoomregionenabled", "false")))) {
      return;
    }

    final JComponent source = (JComponent) aEvent.getComponent();
    final boolean dragging = (aEvent.getID() == MouseEvent.MOUSE_DRAGGED);

    final GhostGlassPane glassPane =
        (GhostGlassPane) SwingUtilities.getRootPane(source).getGlassPane();

    Rectangle viewRect;
    final JScrollPane scrollPane =
        SwingComponentUtils.getAncestorOfClass(JScrollPane.class, source);
    if (scrollPane != null) {
      final JViewport viewport = scrollPane.getViewport();
      viewRect = SwingUtilities.convertRectangle(viewport, viewport.getVisibleRect(), glassPane);
    } else {
      viewRect = SwingUtilities.convertRectangle(source, source.getVisibleRect(), glassPane);
    }

    final Point start = SwingUtilities.convertPoint(source, aStartPoint, glassPane);
    final Point current = SwingUtilities.convertPoint(source, aEvent.getPoint(), glassPane);

    if (dragging) {
      if (!glassPane.isVisible()) {
        glassPane.setVisible(true);
        glassPane.setRenderer(new RubberBandRenderer(), start, current, viewRect);
      } else {
        glassPane.updateRenderer(start, current, viewRect);
      }

      glassPane.repaintPartially();
    } else
    /* if ( !dragging ) */
    {
      // Fire off a signal to the zoom controller to do its job...
      this.controller.getZoomController().zoomRegion(aStartPoint, aEvent.getPoint());

      glassPane.setVisible(false);
    }
  }
 private boolean fitsInBounds(final Rectangle rect) {
   final Container container = getParent();
   if (container instanceof JViewport) {
     final Container scrollPane = container.getParent();
     if (scrollPane instanceof JScrollPane) {
       final Rectangle rectangle =
           SwingUtilities.convertRectangle(this, rect, scrollPane.getParent());
       return scrollPane.getBounds().contains(rectangle);
     }
   }
   return true;
 }
Ejemplo n.º 4
0
  public static void paintButtonGroupLines(
      RadRootContainer rootContainer, RadButtonGroup group, Graphics g) {
    List<RadComponent> components = rootContainer.getGroupContents(group);
    if (components.size() < 2) return;
    Rectangle[] allBounds = new Rectangle[components.size()];
    int lastTop = -1;
    int minLeft = Integer.MAX_VALUE;
    for (int i = 0; i < components.size(); i++) {
      final Rectangle rc =
          SwingUtilities.convertRectangle(
              components.get(i).getParent().getDelegee(),
              components.get(i).getBounds(),
              rootContainer.getDelegee());
      allBounds[i] = rc;

      minLeft = Math.min(minLeft, rc.x);
      if (i == 0) {
        lastTop = rc.y;
      } else if (lastTop != rc.y) {
        lastTop = Integer.MIN_VALUE;
      }
    }

    Graphics2D g2d = (Graphics2D) g;
    Stroke oldStroke = g2d.getStroke();
    g2d.setStroke(new BasicStroke(2.0f));
    g2d.setColor(new Color(104, 107, 130));
    if (lastTop != Integer.MIN_VALUE) {
      // all items in group have same Y
      int left = Integer.MAX_VALUE;
      int right = Integer.MIN_VALUE;
      for (Rectangle rc : allBounds) {
        final int midX = (int) rc.getCenterX();
        left = Math.min(left, midX);
        right = Math.max(right, midX);
        g2d.drawLine(midX, lastTop - 8, midX, lastTop);
      }
      g2d.drawLine(left, lastTop - 8, right, lastTop - 8);
    } else {
      int top = Integer.MAX_VALUE;
      int bottom = Integer.MIN_VALUE;
      for (Rectangle rc : allBounds) {
        final int midY = (int) rc.getCenterY();
        top = Math.min(top, midY);
        bottom = Math.max(bottom, midY);
        g2d.drawLine(minLeft - 8, midY, rc.x, midY);
      }
      g2d.drawLine(minLeft - 8, top, minLeft - 8, bottom);
    }
    g2d.setStroke(oldStroke);
  }
Ejemplo n.º 5
0
  protected void paintChildren(final Graphics g) {
    super.paintChildren(g);

    if (myOverlayedIcon == null || myLabel.getParent() == null) return;

    final Rectangle textBounds =
        SwingUtilities.convertRectangle(myLabel.getParent(), myLabel.getBounds(), this);
    if (getLayeredIcon().isLayerEnabled(1)) {

      final int top = (getSize().height - myOverlayedIcon.getIconHeight()) / 2;

      myOverlayedIcon.paintIcon(this, g, textBounds.x - myOverlayedIcon.getIconWidth() / 2, top);
    }
  }
Ejemplo n.º 6
0
    /** @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) */
    public void propertyChange(PropertyChangeEvent evt) {

      if (!isEditable()) {
        return;
      }

      Component focusedValueEntryPanel = null;
      Component newFocusOwner = (Component) evt.getNewValue();

      while (newFocusOwner != null) {

        if (newFocusOwner instanceof ValueEntryPanel) {
          focusedValueEntryPanel = newFocusOwner;
        }

        if (newFocusOwner instanceof DataConstructorEditorPanel
            && ((DataConstructorEditorPanel) newFocusOwner).getParentEditor()
                == AlgebraicValueEditor.this) {

          if (newFocusOwner == currentFocusedPanel) {

            // If there is a newly focused value entry panel, then scroll into view.
            if (focusedValueEntryPanel != null) {
              Rectangle bounds =
                  SwingUtilities.convertRectangle(
                      focusedValueEntryPanel.getParent(),
                      focusedValueEntryPanel.getBounds(),
                      currentFocusedPanel);
              currentFocusedPanel.scrollRectToVisible(bounds);
            }

            return;
          }

          if (currentFocusedPanel != null) {
            currentFocusedPanel.setFocusedLook(false);
          }

          currentFocusedPanel = (DataConstructorEditorPanel) newFocusOwner;
          currentFocusedPanel.setFocusedLook(true);

          return;
        }

        newFocusOwner = newFocusOwner.getParent();
      }
    }
Ejemplo n.º 7
0
  /**
   * Adds the value entry panel that was clicked on to the value editor hierarchy. If no value entry
   * panel was clicked on it adds the first value entry panel. If there are no value entry panels it
   * simply requests focus. This method is called by setFocusedLook and setArgumentEditorsVisible.
   */
  private void addChildEditorToHierarchy() {

    if (valueEntryPanelToFocus == null && editorPanels.length > 0) {
      valueEntryPanelToFocus = editorPanels[0].getValueEntryPanel();
    }

    if (valueEntryPanelToFocus != null) {

      parentEditor.valueEditorHierarchyManager.addEditorToHierarchy(
          valueEntryPanelToFocus, parentEditor);

      if (editorPanels.length > 0
          && valueEntryPanelToFocus == editorPanels[0].getValueEntryPanel()) {

        // If the first value entry panel is being focused, then scroll to the start of the
        // editor panel, so that the data constructor name is visible.
        scrollRectToVisible(new Rectangle(0, 0, 1, 1));

      } else {

        // Otherwise just scroll the value entry panel itself into view.
        Rectangle bounds =
            SwingUtilities.convertRectangle(
                valueEntryPanelToFocus.getParent(), valueEntryPanelToFocus.getBounds(), this);
        scrollRectToVisible(bounds);
      }

      valueEntryPanelToFocus = null;

    } else {

      // Scroll to the start of the panel so the data constructor name is visible.
      scrollRectToVisible(new Rectangle(0, 0, 1, 1));
      requestFocusInWindow();
    }
  }