コード例 #1
0
 public ComponentTitledBorder(Component comp, JComponent container, Border border) {
   this.comp = comp;
   this.border = border;
   if (comp instanceof JComponent) {
     ((JComponent) comp).setOpaque(true);
   }
   container.addMouseListener(this);
   container.addMouseMotionListener(this);
 }
コード例 #2
0
  public Java2DWindow(Core core, int width, int height) {
    this.core = core;
    this._frame = new JFrame();
    this._frame.setSize(width, height);
    this._frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this._rootcomp =
        new JComponent() {
          @Override
          protected void paintComponent(Graphics graphics) {
            Graphics2D gfx = (Graphics2D) graphics;
            _update(gfx, this);
          }
        };
    this._frame.add(_rootcomp);

    MasterListener ml = new MasterListener(_rootcomp, this);
    _rootcomp.addMouseListener(ml);
    _rootcomp.addMouseMotionListener(ml);
    _rootcomp.addKeyListener(ml);
  }
  protected AbstractExpandableItemsHandler(@NotNull final ComponentType component) {
    myComponent = component;
    myComponent.add(myRendererPane);
    myComponent.validate();
    myPopup = new MovablePopup(myComponent, myTipComponent);

    myTipComponent.addMouseWheelListener(
        new MouseWheelListener() {
          @Override
          public void mouseWheelMoved(MouseWheelEvent e) {
            dispatchEvent(myComponent, e);
          }
        });

    myTipComponent.addMouseListener(
        new MouseListener() {
          @Override
          public void mouseClicked(MouseEvent e) {
            dispatchEvent(myComponent, e);
          }

          @Override
          public void mousePressed(MouseEvent e) {
            dispatchEvent(myComponent, e);
          }

          @Override
          public void mouseReleased(MouseEvent e) {
            dispatchEvent(myComponent, e);
          }

          @Override
          public void mouseEntered(MouseEvent e) {}

          @Override
          public void mouseExited(MouseEvent e) {
            // don't hide the hint if mouse exited to owner component
            if (myComponent.getMousePosition() == null) {
              hideHint();
            }
          }
        });

    myTipComponent.addMouseMotionListener(
        new MouseMotionListener() {
          @Override
          public void mouseMoved(MouseEvent e) {
            dispatchEvent(myComponent, e);
          }

          @Override
          public void mouseDragged(MouseEvent e) {
            dispatchEvent(myComponent, e);
          }
        });

    myComponent.addMouseListener(
        new MouseListener() {
          @Override
          public void mouseEntered(MouseEvent e) {
            handleMouseEvent(e);
          }

          @Override
          public void mouseExited(MouseEvent e) {
            // don't hide the hint if mouse exited to it
            if (myTipComponent.getMousePosition() == null) {
              hideHint();
            }
          }

          @Override
          public void mouseClicked(MouseEvent e) {}

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

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

    myComponent.addMouseMotionListener(
        new MouseMotionListener() {
          @Override
          public void mouseDragged(MouseEvent e) {
            handleMouseEvent(e);
          }

          @Override
          public void mouseMoved(MouseEvent e) {
            handleMouseEvent(e, false);
          }
        });

    myComponent.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusLost(FocusEvent e) {
            onFocusLost();
          }

          @Override
          public void focusGained(FocusEvent e) {
            updateCurrentSelection();
          }
        });

    myComponent.addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentHidden(ComponentEvent e) {
            hideHint();
          }

          @Override
          public void componentMoved(ComponentEvent e) {
            updateCurrentSelection();
          }

          @Override
          public void componentResized(ComponentEvent e) {
            updateCurrentSelection();
          }
        });

    myComponent.addHierarchyBoundsListener(
        new HierarchyBoundsAdapter() {
          @Override
          public void ancestorMoved(HierarchyEvent e) {
            updateCurrentSelection();
          }

          @Override
          public void ancestorResized(HierarchyEvent e) {
            updateCurrentSelection();
          }
        });

    myComponent.addHierarchyListener(
        new HierarchyListener() {
          @Override
          public void hierarchyChanged(HierarchyEvent e) {
            hideHint();
          }
        });
  }
コード例 #4
0
  /** Sets up listeners */
  protected void setupListeners() {
    // Check to see if we need to close
    // the popup when a click outside of
    // it's area has been detected. Also,
    // we may need to propagte the events to
    // components below the glass pane
    glassPane.addMouseListener(
        new MouseListener() {
          /**
           * Invoked when the mouse button has been clicked (pressed and released) on a component.
           */
          public void mouseClicked(MouseEvent e) {
            propagateMouseListenerEvent(e);
          }

          /** Invoked when a mouse button has been pressed on a component. */
          public void mousePressed(MouseEvent e) {
            // Might need to hide the popup if the mouse
            // has been pressed on the glass pane
            handleHidePopup(e);

            propagateMouseListenerEvent(e);
          }

          /** Invoked when a mouse button has been released on a component. */
          public void mouseReleased(MouseEvent e) {
            propagateMouseListenerEvent(e);
          }

          /** Invoked when the mouse enters a component. */
          public void mouseEntered(MouseEvent e) {
            // Don't propagate here
            mouseOverGlassPane = true;
          }

          /** Invoked when the mouse exits a component. */
          public void mouseExited(MouseEvent e) {
            // Don't propagate
            mouseOverGlassPane = false;
          }

          /**
           * Checks to see if a mouse event on the glass pane should cause the popup to be hidden,
           * and if so, hides it.
           *
           * @param e The mouse event.
           */
          private void handleHidePopup(MouseEvent e) {
            if (HIDE_ON_CLICK == true) {
              hidePopup();
            }
          }
        });

    glassPane.addMouseMotionListener(
        new MouseMotionListener() {
          /**
           * Invoked when a mouse button is pressed on a component and then dragged. <code>
           * MOUSE_DRAGGED</code> events will continue to be delivered to the component where the
           * drag originated until the mouse button is released (regardless of whether the mouse
           * position is within the bounds of the component).
           *
           * <p>Due to platform-dependent Drag&Drop implementations, <code>MOUSE_DRAGGED</code>
           * events may not be delivered during a native Drag&Drop operation.
           */
          public void mouseDragged(MouseEvent e) {
            propagateMouseMotionListenerEvents(e);
          }

          /**
           * Invoked when the mouse cursor has been moved onto a component but no buttons have been
           * pushed.
           */
          public void mouseMoved(MouseEvent e) {
            propagateMouseMotionListenerEvents(e);
          }
        });
  }