java.awt.event.MouseEvent.getSource()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(167)

本文整理了Java中java.awt.event.MouseEvent.getSource()方法的一些代码示例,展示了MouseEvent.getSource()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MouseEvent.getSource()方法的具体详情如下:
包路径:java.awt.event.MouseEvent
类名称:MouseEvent
方法名:getSource

MouseEvent.getSource介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

String[] items = {"A", "B", "C", "D"};
JList list = new JList(items);

list.addMouseListener(new MouseAdapter() {
  public void mouseClicked(MouseEvent evt) {
    JList list = (JList)evt.getSource();
    if (evt.getClickCount() == 2) {

      // Double-click detected
      int index = list.locationToIndex(evt.getPoint());
    } else if (evt.getClickCount() == 3) {

      // Triple-click detected
      int index = list.locationToIndex(evt.getPoint());
    }
  }
});

代码示例来源:origin: opentripplanner/OpenTripPlanner

@Override
public void mouseClicked(MouseEvent e) {
  if( SwingUtilities.isRightMouseButton(e) ){
    @SuppressWarnings("unchecked")
    JList<PathPrinter> list = (JList<PathPrinter>)e.getSource();
    int row = list.locationToIndex(e.getPoint());
    list.setSelectedIndex(row);
    
    popup.show(list, e.getX(), e.getY());
  }
}

代码示例来源:origin: stanfordnlp/CoreNLP

@Override
public void mouseDragged(MouseEvent e) {
 if (MatchesPanel.getInstance().isEmpty()) return;
 if (firstMouseEvent1 != null) {
  e.consume();
  int dx = Math.abs(e.getX() - firstMouseEvent1.getX());
  int dy = Math.abs(e.getY() - firstMouseEvent1.getY());
  //Arbitrarily define a 5-pixel shift as the
  //official beginning of a drag.
  if (dx > 5 || dy > 5) {
   //This is a drag, not a click.
   JComponent c = (JComponent)e.getSource();
   //Tell the transfer handler to initiate the drag.
   TransferHandler handler = c.getTransferHandler();
   handler.exportAsDrag(c, firstMouseEvent1, TransferHandler.COPY);
   firstMouseEvent1 = null;
  }
 }
}

代码示例来源:origin: ron190/jsql-injection

@Override
public void mouseClicked(MouseEvent e) {
  if (SwingUtilities.isRightMouseButton(e)) {
    Component componentSource = (Component) e.getSource();
    JPopupMenu menu = new JPopupMenu();
    for (int position = 0 ; position < MediatorGui.menubar().getMenuView().getMenuComponentCount() ; position++) {
      // Fix #35348: SerializationException on clone()
      try {
        JMenuItem itemMenu = (JMenuItem) SerializationUtils.clone(MediatorGui.menubar().getMenuView().getMenuComponent(position));
        menu.add(itemMenu);
        
        final int positionFinal = position;
        itemMenu.addActionListener(actionEvent -> MediatorGui.tabManagers().setSelectedIndex(positionFinal));
      } catch (SerializationException ex) {
        LOGGER.error(ex, ex);
      }
    }
    menu.show(componentSource, e.getX(), e.getY());
    
    menu.setLocation(
      ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT
      ? e.getXOnScreen() - menu.getWidth()
      : e.getXOnScreen(),
      e.getYOnScreen()
    );
  }
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

@Override
public void mouseClicked(MouseEvent e) {
  Component source = (Component)e.getSource();
  if (source instanceof Marker) {
    ((Marker)source).mouseClicked(e);
    return;
  }
  int line = yToLine(e.getY());
  if (line>-1) {
    try {
      int offs = textArea.getLineStartOffset(line);
      textArea.setCaretPosition(offs);
    } catch (BadLocationException ble) { // Never happens
      UIManager.getLookAndFeel().provideErrorFeedback(textArea);
    }
  }
}

代码示例来源:origin: RipMeApp/ripme

@Override
  public void mouseClicked(MouseEvent e) {
    if (e.getModifiers() == InputEvent.BUTTON3_MASK) {
      if (!(e.getSource() instanceof JTable)) {
        return;
      }

      tableComponent = (JTable) e.getSource();
      tableComponent.requestFocus();

      int nx = e.getX();

      if (nx > 500) {
        nx = nx - popup.getSize().width;
      }
      popup.show(e.getComponent(), nx, e.getY() - popup.getSize().height);
    }
  }
}

代码示例来源:origin: stackoverflow.com

table.addMouseListener( new MouseAdapter()
{
  public void mouseReleased(MouseEvent e)
  {
    if (e.isPopupTrigger())
    {
      JTable source = (JTable)e.getSource();
      int row = source.rowAtPoint( e.getPoint() );
      int column = source.columnAtPoint( e.getPoint() );

      if (! source.isRowSelected(row))
        source.changeSelection(row, column, false, false);

      popup.show(e.getComponent(), e.getX(), e.getY());
    }
  }
});

代码示例来源:origin: stackoverflow.com

mytable.addMouseListener(new MouseAdapter() {
  public void mousePressed(MouseEvent me) {
    JTable table =(JTable) me.getSource();
    Point p = me.getPoint();
    int row = table.rowAtPoint(p);
    if (me.getClickCount() == 2) {
      // your valueChanged overridden method 
    }
  }
});

代码示例来源:origin: ron190/jsql-injection

public void showPopup(final MouseEvent mouseEvent) {
  if (mouseEvent.isPopupTrigger()) {
    JList<ItemList> list = (JList<ItemList>) mouseEvent.getSource();
        this.dndList.dropPasteFile(
          Arrays.asList(importFileDialog.getSelectedFiles()),
          this.dndList.locationToIndex(mouseEvent.getPoint())
        );
        list,
        ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT
        ? mouseEvent.getX() - popupMenuList.getWidth()
        : mouseEvent.getX(),
        mouseEvent.getY()
      );
    } catch (IllegalComponentStateException e) {

代码示例来源:origin: RipMeApp/ripme

@Override
  public void mouseClicked(MouseEvent e) {
    if (e.getModifiers() == InputEvent.BUTTON3_MASK) {
      if (!(e.getSource() instanceof JList)) {
        return;
      }

      queueList = (JList) e.getSource();
      queueListModel = (DefaultListModel) queueList.getModel();
      queueList.requestFocus();

      int nx = e.getX();

      if (nx > 500) {
        nx = nx - popup.getSize().width;
      }
      popup.show(e.getComponent(), nx, e.getY() - popup.getSize().height);
    }
  }
}

代码示例来源:origin: stackoverflow.com

table.addMouseListener( new MouseAdapter()
{
  public void mouseReleased(MouseEvent e)
  {
    if (e.isPopupTrigger())
    {
      JTable source = (JTable)e.getSource();
      int row = source.rowAtPoint( e.getPoint() );
      int column = source.columnAtPoint( e.getPoint() );

      if (! source.isRowSelected(row))
        source.changeSelection(row, column, false, false);

      popup.show(e.getComponent(), e.getX(), e.getY());
    }
  }
});

代码示例来源:origin: deathmarine/Luyten

public void mouseClicked(MouseEvent evt) {
  @SuppressWarnings("unchecked")
  JList<String> list = (JList<String>) evt.getSource();
  if (evt.getClickCount() == 2) {
    int index = list.locationToIndex(evt.getPoint());
    String entryName = (String) list.getModel().getElementAt(index);
    String[] array = entryName.split("/");

代码示例来源:origin: runelite/runelite

private MouseEvent translateEvent(MouseEvent e)
  {
    Dimension stretchedDimensions = client.getStretchedDimensions();
    Dimension realDimensions = client.getRealDimensions();

    int newX = (int) (e.getX() / (stretchedDimensions.width / realDimensions.getWidth()));
    int newY = (int) (e.getY() / (stretchedDimensions.height / realDimensions.getHeight()));

    return new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiersEx(),
        newX, newY, e.getClickCount(), e.isPopupTrigger(), e.getButton());
  }
}

代码示例来源:origin: magefree/mage

if (event instanceof MouseEvent && event.getSource() instanceof Component) {
  MouseEvent e = (MouseEvent) event;
  MouseEvent m = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, this);
  if (!this.contains(m.getPoint())) {
    boolean allowedEvent = false;
      popupComponent = SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY()); // show root component (popups creates at root)
      if (popupComponent != null && popupComponent.getClass().getName().contains("BasicComboPopup")) {
        popupEvent = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, popupComponent);
        allowedEvent = true;

代码示例来源:origin: stackoverflow.com

list.addMouseListener( new MouseAdapter()
{
  public void mousePressed(MouseEvent e)
  {
    if ( SwingUtilities.isRightMouseButton(e) )
    {
      JList list = (JList)e.getSource();
      int row = list.locationToIndex(e.getPoint());
      list.setSelectedIndex(row);
    }
  }

});

代码示例来源:origin: stanfordnlp/CoreNLP

@Override
 public void mouseDragged(MouseEvent e) {
  if (MatchesPanel.getInstance().isEmpty()) return;
  if (firstMouseEvent != null) {
   e.consume();
   if(dragNDrop) {
    if(textField == null)
     return;
    if(Point2D.distanceSq(e.getX(), e.getY(), firstMouseEvent.getX(), firstMouseEvent.getY()) > 25) {
     //do DnD
     textField.getTransferHandler().exportAsDrag((JComponent) e.getSource(), firstMouseEvent, TransferHandler.COPY);
    }
   } else {
    addHighlight(textField, firstMouseEvent, e);
   }
  }
 }
}

代码示例来源:origin: org.rescarta.rc-cmgr/rc-cmgr

public void mouseReleased(MouseEvent e) {
    if (e.getSource().equals(this.objectJList) && e.isPopupTrigger() && this.objectJList.getSelectedIndex() >= 0) {
      int i = this.objectJList.locationToIndex(e.getPoint());
      this.objectJList.setSelectedIndex(i);
      this.objectJPopupMenu.show(this.objectJList, e.getX(), e.getY());
    }
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override
  public void mouseClicked(MouseEvent e) {
    Point tabPt = e.getPoint();
    JTabbedPane src = (JTabbedPane) e.getSource();
    
    int i = src.indexAtLocation(tabPt.x, tabPt.y);
    
    if (-1 < i && e.getButton() == MouseEvent.BUTTON2) {
      ActionCloseTabResult.perform(i);
    }
  }
}

代码示例来源:origin: stanfordnlp/CoreNLP

@Override
public void mouseDragged(MouseEvent e) {
 if (MatchesPanel.getInstance().isEmpty()) return;
 if (firstMouseEvent != null) {
  e.consume();
  JTextField label = ((TreeFromFile) list.getSelectedValue()).getLabel();
  if(dragNDrop) {
   if(label == null)
    return;
   if(Point2D.distanceSq(e.getX(), e.getY(), firstMouseEvent.getX(), firstMouseEvent.getY()) > 25) {
    //do DnD
    list.getTransferHandler().exportAsDrag((JComponent) e.getSource(), firstMouseEvent, TransferHandler.COPY);
   }
  } else {
   addHighlight(label, firstMouseEvent, e);
  }
 }
}

代码示例来源:origin: org.rescarta.rc-cmgr/rc-cmgr

public void mouseReleased(MouseEvent e) {
  if (e.getSource().equals(this.objectJList) && e.isPopupTrigger() && this.objectJList.getSelectedIndex() >= 0) {
    int i = this.objectJList.locationToIndex(e.getPoint());
    this.objectJList.setSelectedIndex(i);
    this.objectJPopupMenu.show(this.objectJList, e.getX(), e.getY());
  }
}

相关文章