下面列出了java.awt.event.MouseEvent#getClickCount() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() != 1) {
return;
}
JList list = (JList) e.getSource();
int index = list.locationToIndex(e.getPoint());
if (index < 0) {
return;
}
boolean selected = checkboxes[index].isSelected();
checkboxes[index].setSelected(!selected);
// The following repaint() is to get the check box state to get refreshed on the screen.
// Prior to adding this the check box did not refresh the display of its state in the
// list when selected multiple times in a row. It only seemed to repaint when focus
// was lost.
list.repaint();
}
@Override
public void mousePressed(MouseEvent e) {
maybeShowPopup(e);
// double click
if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1) {
DataItem selectedItem = this.getSelectedElementFrom(e);
if (selectedItem instanceof DataBean) {
application.visualiseWithBestMethod(FrameType.MAIN);
} else if (selectedItem instanceof DataFolder) {
// select all child beans
DataFolder folder = (DataFolder)selectedItem;
application.getSelectionManager().clearAll(false, this);
application.getSelectionManager().selectMultiple(folder.getChildren(), this);
}
}
}
public void addMouseListenerToHeaderInTable(JTable table) {
final TableSorter sorter = this;
final JTable tableView = table;
tableView.setColumnSelectionAllowed(false);
final MouseAdapter listMouseListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
final TableColumnModel columnModel = tableView.getColumnModel();
final int viewColumn = columnModel.getColumnIndexAtX(e.getX());
final int column = tableView.convertColumnIndexToModel(viewColumn);
if (e.getClickCount() == 1 && column != -1) {
//System.out.println("Sorting ...");
final int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK;
final boolean ascending = (shiftPressed == 0);
sorter.sortByColumn(column, ascending);
}
}
};
final JTableHeader th = tableView.getTableHeader();
th.addMouseListener(listMouseListener);
}
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() > 1) {
if (e.getButton() == MouseEvent.BUTTON1) {
removeSelectedFromDeck();
} else if (e.getButton() == MouseEvent.BUTTON3) {
final List<MagicCardDefinition> deckCards = deckTable.getSelectedCards();
if (deckCards.size() > 0) {
deck.addAll(deckCards);
updateDeck();
}
}
}
if (e.getButton() == MouseEvent.BUTTON3) {
final JTable table = (JTable) (e.getSource());
final int row = table.rowAtPoint(e.getPoint());
table.clearSelection();
table.addRowSelectionInterval(row, row);
}
}
public void mouseClicked(MouseEvent e) {
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = tableView.convertColumnIndexToModel(viewColumn);
if (e.getClickCount() == 1 && column != -1) {
if (tableView instanceof XTable) {
XTable attrs = (XTable) tableView;
// inform the table view that the rows are going to be sorted
// against the values in a given column. This gives the
// chance to the table view to close its editor - if needed.
//
attrs.sortRequested(column);
}
tableView.invalidate();
sortByColumn(column);
tableView.validate();
tableView.repaint();
}
}
/**
* Called when this action is selected and the user has pressed on the canvas
* Adds a new annotation and registers an undo event for its addition.
* @param event mouse event
* @param petriNetController controller for the petri net
*/
@Override
public void doAction(MouseEvent event, PetriNetController petriNetController) {
if (event.getClickCount() > 0) {
Point point = event.getPoint();
Annotation annotation = getAnnotation(point, petriNetController);
PetriNet net = petriNetController.getPetriNet();
registerUndoEvent(new AddPetriNetObject(annotation, net));
}
}
/**
* Changes the temporary arc's end point
*
* @param event mouse event that has just been fired
* @param petriNetController current petri net controller for the tab showing
*/
@Override
public void doAction(MouseEvent event, PetriNetController petriNetController) {
if (temporaryArcView != null) {
temporaryArcView.setEnd(event.getPoint());
if (event.getClickCount() > 0) {
Point point = event.getPoint();
temporaryArcView.addIntermediatePoint(new ArcPoint(point, event.isShiftDown()));
}
PetriNetTab tab = petriNetController.getPetriNetTab();
tab.validate();
tab.repaint();
}
}
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
if (!isAttached()) {
return;
}
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
pm.actionOpen.actionPerformed(UiUtils.actionEvent(table, pm.actionOpen));
return;
}
}
private void selectionProcedure(DBBrowserNode selectedNode, MouseEvent e) {
ViewProcedureColumnsInfoAction infoAction = new ViewProcedureColumnsInfoAction(selectedNode.getDBObject());
if (e.getClickCount() == 2) {
infoAction.actionPerformed(null);
} else {
JPopupMenu popupMenu = new JPopupMenu();
JMenuItem menuItem = new JMenuItem(infoAction);
popupMenu.add(menuItem);
JMenuItem menuItem2 = new JMenuItem(new ValidateProceduresAction(selectedNode.getDBObject()));
popupMenu.add(menuItem2);
popupMenu.show((Component) e.getSource(), e.getX(), e.getY());
}
}
@Override
public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 1) {
int selRow = tree.getRowForLocation(e.getX(), e.getY());
if (selRow != -1) {
TreePath selPath =
tree.getPathForLocation(e.getX(), e.getY());
DefaultMutableTreeNode node =
(DefaultMutableTreeNode) selPath.getLastPathComponent();
if (sheet.isMBeanNode(node)) {
tree.expandPath(selPath);
}
}
}
}
@Override public void mouseClicked(MouseEvent e) {
boolean isDoubleClick = e.getClickCount() >= 2;
if (isDoubleClick) {
Component src = e.getComponent();
Dimension dim = src.getSize();
rect.setBounds(getTitleBounds(src, 0, 0, dim.width, dim.height));
if (rect.contains(e.getPoint())) {
startEditing.actionPerformed(new ActionEvent(src, ActionEvent.ACTION_PERFORMED, ""));
}
}
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1) {
startBlinking();
requestFocus();
}
}
@Override
public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 1) {
int selRow = tree.getRowForLocation(e.getX(), e.getY());
if (selRow != -1) {
TreePath selPath =
tree.getPathForLocation(e.getX(), e.getY());
DefaultMutableTreeNode node =
(DefaultMutableTreeNode) selPath.getLastPathComponent();
if (sheet.isMBeanNode(node)) {
tree.expandPath(selPath);
}
}
}
}
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1) {
// Double click
int index = getCircleIndexFromPosition(e.getPoint().x);
model.setPositions(index, index);
}
}
/**
* Do mouse clicked.
* @param e the event
*/
protected void doMouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int idx = videoTable.getSelectedRow();
idx = videoTable.convertRowIndexToModel(idx);
currentVideo = videoModel.rows.get(idx);
position.setValue(0);
doPlay();
}
}
@Override
public boolean fieldElementClicked(Object clickedObject, Navigatable sourceNavigatable,
ProgramLocation location, MouseEvent mouseEvent, ServiceProvider serviceProvider) {
if (mouseEvent.getClickCount() != 2 || mouseEvent.getButton() != MouseEvent.BUTTON1) {
return false;
}
return ((AnnotatedTextFieldElement) clickedObject).handleMouseClicked(sourceNavigatable,
serviceProvider);
}
@Override
public boolean fieldElementClicked(Object clickedObject, Navigatable sourceNavigatable,
ProgramLocation location, MouseEvent mouseEvent, ServiceProvider serviceProvider) {
if (mouseEvent.getClickCount() != 2 || mouseEvent.getButton() != MouseEvent.BUTTON1) {
return false;
}
ErrorListingField errorField = (ErrorListingField) clickedObject;
String fieldName = errorField.getFieldFactory().getFieldName();
Msg.showError(this, null, "Listing Field Exception", "Exception occurred while rendering '" +
fieldName + "' field", errorField.getThrowable());
return true;
}
@Override
public void mousePressed(final MouseEvent event) {
// Update the selected element on double-click
if ((event.getButton() == 1) && (event.getClickCount() == 2)) {
setSelectedElement();
}
// Close the dialog on double-click
if (m_selectionResult != null) {
closeDialog();
}
}
/**
* Action on mouse click within the table.
* @param e the mouse event
*/
protected void doMouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() > 1) {
doPlaySelected();
}
}
/**
* Asks the editor if it can start editing using <code>anEvent</code>. <code>anEvent</code> is in the invoking
* component coordinate system. The editor can not assume the Component returned by
* <code>getCellEditorComponent</code> is installed. This method is intended for the use of client to avoid the cost
* of setting up and installing the editor component if editing is not possible. If editing can be started this method
* returns true.
*
* @param anEvent the event the editor should use to consider whether to begin editing or not
* @return true if editing can be started
* @see #shouldSelectCell
*/
public boolean isCellEditable( final EventObject anEvent ) {
if ( anEvent instanceof MouseEvent ) {
final MouseEvent mouseEvent = (MouseEvent) anEvent;
return mouseEvent.getClickCount() >= 2 && mouseEvent.getButton() == MouseEvent.BUTTON1;
}
return true;
}