Java Code Examples for java.awt.event.MouseEvent.getComponent()

The following are Jave code examples for showing how to use getComponent() of the java.awt.event.MouseEvent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: poi-visualizer   File: POIContextMenu.java   Source Code and License Vote up 6 votes
public void handleEntryClick(final MouseEvent mouseEvent) {
	if (!mouseEvent.isPopupTrigger() || !(mouseEvent.getComponent() instanceof JTree)) {
		return;
	}

	JTree treeDir = (JTree)mouseEvent.getComponent();
       final TreePath path = treeDir.getClosestPathForLocation(mouseEvent.getX(), mouseEvent.getY());
       if (path == null) {
       	return;
       }
   	treeDir.setSelectionPath(path);
   	
   	boolean hasStream;
   	try {
   		ByteArrayEditableData data = treeObservable.getBinarySource().getBinaryData();
   		hasStream = (data.getDataSize() > 0);
   	} catch (Exception e) {
   		hasStream = false;
   	}

   	saveStream.setEnabled(hasStream);
   	
   	show(treeDir, mouseEvent.getX(), mouseEvent.getY());
}
 
Example 2
Project: Motunautr   File: FixedMouseAdapter.java   Source Code and License Vote up 6 votes
@Override
public final void mouseReleased(final MouseEvent e) {
	FixedMouseAdapter.this.mouseReleased(e);
	final int b = e.getButton() - 1;
	if (b >= 0 && b < NUM_BUTTONS
			&& startPoints[b] != null
			&& startPoints[b].distanceSq(e.getLocationOnScreen()) <= CLICK_SENSITIVITY_SQ) {
		
		if (e.getWhen() > lastClickTime[b] + MULTI_CLICK_SENSITIVITY_MS
				|| lastClickPos[b] == null || lastClickPos[b].distanceSq(e.getLocationOnScreen()) > CLICK_SENSITIVITY_SQ)
			clickCounts[b] = 1;
		else
			clickCounts[b]++;
		
		lastClickPos[b] = e.getLocationOnScreen();
		lastClickTime[b] = e.getWhen();
		
		final MouseEvent newEvent = new MouseEvent(e.getComponent(), MouseEvent.MOUSE_CLICKED, e.getWhen(), e.getModifiers(), e.getY(), e.getY(), e.getXOnScreen(), e.getYOnScreen(), clickCounts[b], false, b + 1);
		FixedMouseAdapter.this.mouseClicked(newEvent);
		
		startPoints[b] = null;
	}
}
 
Example 3
Project: gate-core   File: LuceneDataStoreSearchGUI.java   Source Code and License Vote up 6 votes
@Override
public void mouseEntered(MouseEvent e) {
  dismissDelay = toolTipManager.getDismissDelay();
  initialDelay = toolTipManager.getInitialDelay();
  reshowDelay = toolTipManager.getReshowDelay();
  enabled = toolTipManager.isEnabled();
  Component component = e.getComponent();
  if(feature != null && !isTooltipSet && component instanceof JLabel) {
    isTooltipSet = true;
    JLabel label = (JLabel)component;
    String toolTip = label.getToolTipText();
    toolTip =
            (toolTip == null || toolTip.equals("")) ? "" : toolTip
                    .replaceAll("</?html>", "") + "<br>";
    toolTip = "<html>" + toolTip + "Right click to get statistics.</html>";
    label.setToolTipText(toolTip);
  }
  // make the tooltip indefinitely shown when the mouse is over
  toolTipManager.setDismissDelay(Integer.MAX_VALUE);
  toolTipManager.setInitialDelay(0);
  toolTipManager.setReshowDelay(0);
  toolTipManager.setEnabled(true);
}
 
Example 4
Project: rapidminer   File: PanningManager.java   Source Code and License Vote up 6 votes
@Override
public void eventDispatched(AWTEvent e) {
	if (e instanceof MouseEvent) {
		MouseEvent me = (MouseEvent) e;
		if (!SwingUtilities.isDescendingFrom(me.getComponent(), target)) {
			return;
		}
		if (me.getID() == MouseEvent.MOUSE_RELEASED) {
			// stop when mouse released
			mouseOnScreenPoint = null;
			if (timer.isRunning()) {
				timer.stop();
			}
		} else if (me.getID() == MouseEvent.MOUSE_DRAGGED && me.getComponent() == target) {
			mouseOnScreenPoint = me.getLocationOnScreen();
		} else if (me.getID() == MouseEvent.MOUSE_PRESSED && me.getComponent() == target) {
			mouseOnScreenPoint = me.getLocationOnScreen();
			timer.start();
		}
	}
}
 
Example 5
Project: Panako   File: QIFFTAudioInfoLayer.java   Source Code and License Vote up 6 votes
@Override
public void mouseMoved(MouseEvent e) {
	if(graphics !=null ){
		LinkedPanel panel = (LinkedPanel) e.getComponent();
		Graphics2D g = (Graphics2D) panel.getGraphics();
		g.setTransform(panel.getTransform());
		
		float timeOffset = LayerUtilities.pixelsToUnits(g, e.getX(), true);
		float time = cs.getMin(Axis.X) + timeOffset;
		float frequencyOffset = LayerUtilities.pixelsToUnits(g, panel.getHeight() - e.getY(), false);
		float frequency = cs.getMin(Axis.Y) + frequencyOffset;
		
		float timeDiameter = LayerUtilities.pixelsToUnits(g, 10, true) * 2f;
		float frequencyDiameter = LayerUtilities.pixelsToUnits(g, 10, false)* 2f;
		
	}
	
}
 
Example 6
Project: alevin-svn2   File: MultiAlgoScenarioWizard.java   Source Code and License Vote up 5 votes
private void showPopup(MouseEvent e) {
	if (networkTable.getSelectedRow() >= 0
			&& e.isPopupTrigger()
			&& e.getComponent() instanceof JTable) {
		this.menu.show(e.getComponent(), e.getX(), e.getY());
	}
}
 
Example 7
Project: incubator-netbeans   File: NBTabbedPaneController.java   Source Code and License Vote up 5 votes
@Override
public void mousePressed( MouseEvent e ) {

    Point p = e.getPoint();
    p = SwingUtilities.convertPoint( e.getComponent(), p, container );
    int tabIndex = container.indexAtLocation( p.x, p.y );

    SingleSelectionModel sel = container.getModel();
    //invoke possible selection change
    if( tabIndex >= 0 && e.getComponent() != container ) {
        CloseableTabComponent tab = ( CloseableTabComponent ) container.getTabComponentAt( tabIndex );
        if( tab.isInCloseButton( e ) ) {
            return;
        }
        tabIndex = container.indexOf( container.getComponentAt( tabIndex ) );
        boolean change = shouldPerformAction( TabDisplayer.COMMAND_SELECT,
                tabIndex, e );
        if( change ) {

            sel.setSelectedIndex( tabIndex );
            Component tc = container.getDataModel().getTab( tabIndex ).getComponent();
            if( null != tc && tc instanceof TopComponent && !(( TopComponent ) tc).isAncestorOf( KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner() ) ) {
                (( TopComponent ) tc).requestActive();
            }
        }
    }
    if( e.isPopupTrigger() ) {
        //Post a popup menu show request

        shouldPerformAction( TabDisplayer.COMMAND_POPUP_REQUEST, tabIndex, e );
    }
}
 
Example 8
Project: ramus   File: ButtonTabComponent.java   Source Code and License Vote up 5 votes
public void mouseEntered(MouseEvent e) {
    Component component = e.getComponent();
    if (component instanceof AbstractButton) {
        AbstractButton button = (AbstractButton) component;
        button.setBorderPainted(true);
    }
}
 
Example 9
Project: KernelHive   File: JTabPanel.java   Source Code and License Vote up 5 votes
@Override
public void mouseExited(final MouseEvent e) {
	final Component c = e.getComponent();
	if (c instanceof AbstractButton) {
		final AbstractButton ab = (AbstractButton) c;
		ab.setBorderPainted(false);
	}
}
 
Example 10
Project: Equella   File: FlatterCheckBoxUI.java   Source Code and License Vote up 5 votes
@Override
public synchronized void mouseReleased(MouseEvent e)
{
	JComponent c = (JComponent) e.getComponent();
	c.setForeground(mTextNormal);
	c.setBackground(mBackgroundNormal);
	c.repaint();
}
 
Example 11
Project: gate-core   File: LuceneDataStoreSearchGUI.java   Source Code and License Vote up 5 votes
private void addStatistics(String kind, int count, int numRow,
        final MouseEvent e) {
  JLabel label = (JLabel)e.getComponent();
  if(!label.getToolTipText().contains(kind)) {
    // add the statistics to the tooltip
    String toolTip = label.getToolTipText();
    toolTip = toolTip.replaceAll("</?html>", "");
    toolTip = kind + " = " + count + "<br>" + toolTip;
    toolTip = "<html>" + toolTip + "</html>";
    label.setToolTipText(toolTip);
  }
  if(bottomSplitPane.getDividerLocation()
          / bottomSplitPane.getSize().getWidth() < 0.90) {
    // select the row in the statistics table
    statisticsTabbedPane.setSelectedIndex(1);
    oneRowStatisticsTable.setRowSelectionInterval(numRow, numRow);
    oneRowStatisticsTable.scrollRectToVisible(oneRowStatisticsTable
            .getCellRect(numRow, 0, true));
  } else {
    // display a tooltip
    JToolTip tip = label.createToolTip();
    tip.setTipText(kind + " = " + count);
    PopupFactory popupFactory = PopupFactory.getSharedInstance();
    final Popup tipWindow =
            popupFactory.getPopup(label, tip, e.getX()
                    + e.getComponent().getLocationOnScreen().x, e.getY()
                    + e.getComponent().getLocationOnScreen().y);
    tipWindow.show();
    Date timeToRun = new Date(System.currentTimeMillis() + 2000);
    Timer timer = new Timer("Annic statistics hide tooltip timer", true);
    timer.schedule(new TimerTask() {
      @Override
      public void run() {
        // hide the tooltip after 2 seconds
        tipWindow.hide();
      }
    }, timeToRun);
  }
}
 
Example 12
Project: openjdk-jdk10   File: EventDispatcher.java   Source Code and License Vote up 5 votes
@Override
public void eventDispatched(AWTEvent event) {
    if (event instanceof MouseEvent) {
        MouseEvent e = (MouseEvent) event;
        if (e.getID() == MouseEvent.MOUSE_ENTERED) {
            mouseComponent = e.getComponent();
        } else if (e.getID() == MouseEvent.MOUSE_EXITED) {
            mouseComponent = null;
        }
    }
}
 
Example 13
Project: Mujeed-Arabic-Prolog   File: ButtonTabComponent.java   Source Code and License Vote up 5 votes
public void mouseExited(MouseEvent e) {
    Component component = e.getComponent();
    if (component instanceof AbstractButton) {
        AbstractButton button = (AbstractButton) component;
        button.setBorderPainted(false);
    }
}
 
Example 14
Project: gate-core   File: LuceneDataStoreSearchGUI.java   Source Code and License Vote up 5 votes
private void addStatistics(String kind, int count, int numRow,
        final MouseEvent e) {
  JLabel label = (JLabel)e.getComponent();
  if(!label.getToolTipText().contains(kind)) {
    // add the statistics to the tooltip
    String toolTip = label.getToolTipText();
    toolTip = toolTip.replaceAll("</?html>", "");
    toolTip = kind + " = " + count + "<br>" + toolTip;
    toolTip = "<html>" + toolTip + "</html>";
    label.setToolTipText(toolTip);
  }
  if(bottomSplitPane.getDividerLocation()
          / bottomSplitPane.getSize().getWidth() < 0.90) {
    // select the row in the statistics table
    statisticsTabbedPane.setSelectedIndex(1);
    oneRowStatisticsTable.setRowSelectionInterval(numRow, numRow);
    oneRowStatisticsTable.scrollRectToVisible(oneRowStatisticsTable
            .getCellRect(numRow, 0, true));
  } else {
    // display a tooltip
    JToolTip tip = label.createToolTip();
    tip.setTipText(kind + " = " + count);
    PopupFactory popupFactory = PopupFactory.getSharedInstance();
    final Popup tipWindow =
            popupFactory.getPopup(label, tip, e.getX()
                    + e.getComponent().getLocationOnScreen().x, e.getY()
                    + e.getComponent().getLocationOnScreen().y);
    tipWindow.show();
    Date timeToRun = new Date(System.currentTimeMillis() + 2000);
    Timer timer = new Timer("Annic statistics hide tooltip timer", true);
    timer.schedule(new TimerTask() {
      @Override
      public void run() {
        // hide the tooltip after 2 seconds
        tipWindow.hide();
      }
    }, timeToRun);
  }
}
 
Example 15
Project: featurea   File: ResizeWindowMouseAdapter.java   Source Code and License Vote up 5 votes
@Override
public void mouseDragged(MouseEvent e) {
    Component component = e.getComponent();
    Component rootComponent = SwingUtilities.getRoot(component);
    if (!rectangle.isEmpty() && component instanceof FSWindowLabel && rootComponent instanceof Window) {
        FSWindowSide FSWindowSide = ((FSWindowLabel) component).side;
        updateRectangle(FSWindowSide, e.getX(), e.getY());
        rootComponent.setBounds(rectangle);
    }
}
 
Example 16
Project: Equella   File: FlatterCheckBoxUI.java   Source Code and License Vote up 5 votes
@Override
public synchronized void mouseExited(MouseEvent e)
{
	JComponent c = (JComponent) e.getComponent();
	c.setForeground(mTextNormal);
	c.setBackground(mBackgroundNormal);
	c.repaint();
}
 
Example 17
Project: litiengine   File: Mouse.java   Source Code and License Vote up 4 votes
private MouseEvent createEvent(final MouseEvent original) {
  return new MouseEvent(original.getComponent(), original.getID(), original.getWhen(), original.getModifiers(), (int) this.getLocation().getX(), (int) this.getLocation().getY(), original.getXOnScreen(), original.getYOnScreen(), original.getClickCount(), original.isPopupTrigger(),
      original.getButton());
}
 
Example 18
Project: incubator-netbeans   File: CloseableTabComponent.java   Source Code and License Vote up 4 votes
boolean isInCloseButton( MouseEvent e ) {
    return null != closeButton && e.getComponent() == closeButton;
}
 
Example 19
Project: Tarski   File: Visualization.java   Source Code and License Vote up 4 votes
private void addMouseMotionAdaper() {
  final MouseMotionAdapter adapter = new MouseMotionAdapter() {

    @Override
    public void mouseMoved(final MouseEvent e) {
      final Object annotation =
          graph.alloyGetViewer().alloyGetAnnotationAtXY(e.getX(), e.getY());
      final JComponent cmpnt = (JComponent) e.getComponent();
      String tooltip = null;

      if (annotation instanceof AlloyAtom) {
        graphInPanel.setCursor(new Cursor(Cursor.HAND_CURSOR));

        final String id = Utility.itemIdByAlloyAtom((AlloyAtom) annotation);
        final String atomName = Utility.getAtomNameById(id);

        tooltip = atomName;
      } else if (annotation instanceof AlloyTuple) {
        final AlloyTuple tuple = (AlloyTuple) annotation;

        final AlloyAtom highLightedAtomStart = tuple.getStart();
        final AlloyAtom highLightedAtomEnd = tuple.getEnd();

        final String fromId = Utility.itemIdByAlloyAtom(highLightedAtomStart);
        final String toId = Utility.itemIdByAlloyAtom(highLightedAtomEnd);
        if (fromId == null || toId == null) {
          return;
        }
        final String fromAtomName = Utility.getAtomNameById(fromId);
        final String toAtomName = Utility.getAtomNameById(toId);

        tooltip = fromAtomName + " --> " + toAtomName;

        graphInPanel.setCursor(new Cursor(Cursor.HAND_CURSOR));
      } else {
        graphInPanel.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
      }

      cmpnt.setToolTipText(tooltip);

    }
  };
  graph.alloyGetViewer().addMouseMotionListener(adapter);
  graphInPanel.addMouseMotionListener(adapter);

}
 
Example 20
Project: scorekeeperfrontend   File: DriverTable.java   Source Code and License Vote up 4 votes
@Override
public void mouseReleased(MouseEvent e)
{
	JTableHeader header = (JTableHeader)e.getComponent();
	header.removeMouseMotionListener( this );
}