List of usage examples for java.awt.event MouseEvent isMetaDown
public boolean isMetaDown()
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Reacts to mouse pressed and mouse release event. * /*w w w. jav a 2 s . c o m*/ * @param me The event to handle. * @param released Pass <code>true</code> if the method is invoked when * the mouse is released, <code>false</code> otherwise. */ private void onClick(MouseEvent me, boolean released) { Point p = me.getPoint(); int row = treeDisplay.getRowForLocation(p.x, p.y); if (row != -1) { if (me.getClickCount() == 1) { model.setClickPoint(p); if (mousePressedTime > eventHandledTime) /* have not yet seen the tree selection event */ delayedHandlingTreeSelection = true; else handleTreeSelection(); //if (released) { if ((me.isPopupTrigger() && !released) || (me.isPopupTrigger() && released && !UIUtilities.isMacOS()) || (UIUtilities.isMacOS() && SwingUtilities.isLeftMouseButton(me) && me.isControlDown())) { if (rightClickButton && !model.isMultiSelection()) { //(!(me.isShiftDown() || ctrl)) TreePath path = treeDisplay.getPathForLocation(p.x, p.y); //treeDisplay.removeTreeSelectionListener( // selectionListener); if (path != null) treeDisplay.setSelectionPath(path); //treeDisplay.addTreeSelectionListener(selectionListener); if (path != null && path.getLastPathComponent() instanceof TreeImageDisplay) controller.onRightClick((TreeImageDisplay) path.getLastPathComponent()); } if (model.getBrowserType() == Browser.ADMIN_EXPLORER) controller.showPopupMenu(TreeViewer.ADMIN_MENU); else controller.showPopupMenu(TreeViewer.FULL_POP_UP_MENU); } } else if (me.getClickCount() == 2 && !(me.isMetaDown() || me.isControlDown() || me.isShiftDown())) { //controller.cancel(); //model.viewDataObject(); TreeImageDisplay d = model.getLastSelectedDisplay(); if (d == null) return; Object o = d.getUserObject(); if (o instanceof ImageData) { model.browse(d); } else if (o instanceof PlateData) { if (!d.hasChildrenDisplay() || d.getChildrenDisplay().size() == 1) model.browse(d); } else if (o instanceof PlateAcquisitionData) { model.browse(d); } } } }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Helper method to create the trees hosting the display. * /*from w w w. j a v a2s. c om*/ * @param exp The logged in experimenter. */ private void createTrees(ExperimenterData exp) { treeDisplay = new DnDTree(model.getUserID(), TreeViewerAgent.isAdministrator()); treeDisplay.addPropertyChangeListener(this); String key = "meta pressed A"; if (UIUtilities.isWindowsOS()) key = "ctrl pressed A"; KeyStroke ks = KeyStroke.getKeyStroke(key); treeDisplay.getInputMap().put(ks, "none"); treeDisplay.setVisible(true); treeDisplay.setRootVisible(false); ToolTipManager.sharedInstance().registerComponent(treeDisplay); treeDisplay.setCellRenderer(new TreeCellRenderer(model.getUserID())); treeDisplay.setShowsRootHandles(true); TreeImageSet root = new TreeImageSet(""); treeDisplay.setModel(new DefaultTreeModel(root)); if (model.getBrowserType() != Browser.ADMIN_EXPLORER) { TreeImageDisplay node = buildTreeNodes(exp); if (node != null) treeDisplay.collapsePath(new TreePath(node.getPath())); } //Add Listeners //treeDisplay.requestFocus(); treeDisplay.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { mousePressedTime = e.getWhen(); rightClickPad = UIUtilities.isMacOS() && SwingUtilities.isLeftMouseButton(e) && e.isControlDown(); rightClickButton = SwingUtilities.isRightMouseButton(e); ctrl = e.isControlDown(); if (UIUtilities.isMacOS()) ctrl = e.isMetaDown(); leftMouseButton = SwingUtilities.isLeftMouseButton(e); if (UIUtilities.isMacOS() || UIUtilities.isLinuxOS()) onClick(e, false); } public void mouseReleased(MouseEvent e) { leftMouseButton = SwingUtilities.isLeftMouseButton(e); if (UIUtilities.isWindowsOS()) onClick(e, true); } // public void mouseMoved(MouseEvent e) { rollOver(e); } }); treeDisplay.addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent e) { rollOver(e); } }); treeDisplay.addTreeExpansionListener(listener); selectionListener = new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { event = e; eventHandledTime = System.currentTimeMillis(); if (delayedHandlingTreeSelection) /* mouse click delayed handling until this event occurred */ handleTreeSelection(); switch (keyEvent) { case KeyEvent.VK_DOWN: case KeyEvent.VK_UP: TreePath[] paths = treeDisplay.getSelectionPaths(); if (paths != null) controller.onClick(Arrays.asList(paths)); else controller.onClick(new ArrayList<TreePath>()); break; } } }; treeDisplay.addTreeSelectionListener(selectionListener); //remove standard behaviour treeDisplay.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { ctrl = false; switch (e.getKeyCode()) { case KeyEvent.VK_ENTER: ViewCmd cmd = new ViewCmd(model.getParentModel(), true); cmd.execute(); break; case KeyEvent.VK_DELETE: switch (model.getState()) { case Browser.LOADING_DATA: case Browser.LOADING_LEAVES: //case Browser.COUNTING_ITEMS: break; default: model.delete(); } break; case KeyEvent.VK_CONTROL: if (!UIUtilities.isMacOS()) ctrl = true; break; case KeyEvent.VK_META: if (UIUtilities.isMacOS()) ctrl = true; break; case KeyEvent.VK_A: if (UIUtilities.isWindowsOS() && e.isControlDown() || !UIUtilities.isWindowsOS() && e.isMetaDown()) { handleMultiSelection(); } break; case KeyEvent.VK_DOWN: case KeyEvent.VK_UP: case KeyEvent.VK_RIGHT: keyEvent = e.getKeyCode(); break; case KeyEvent.VK_LEFT: TreePath[] paths = treeDisplay.getSelectionPaths(); TreeImageDisplay node; Object o; for (int i = 0; i < paths.length; i++) { o = paths[i].getLastPathComponent(); if (o instanceof TreeImageDisplay) { node = (TreeImageDisplay) o; if (node.isExpanded()) node.setExpanded(false); } } } } public void keyReleased(KeyEvent e) { ctrl = false; keyEvent = -1; } }); }
From source file:org.openmicroscopy.shoola.agents.util.ui.ChannelButton.java
/** * Selects the channel or displays the pop up menu. * * @param e The mouse event to handle./*w w w . java 2 s .c om*/ */ private void onClick(MouseEvent e) { boolean mask = (e.isControlDown() || e.isMetaDown()); if (e.getButton() == MouseEvent.BUTTON1 && !(mask)) setChannelSelected(); else if ((e.getButton() == MouseEvent.BUTTON2 || mask)) onReleased(e); }
From source file:paquete.HollywoodUI.java
private void label_graficoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_label_graficoMouseClicked boolean foundVertex = true; this.actoresArray = new ArrayList<>(this.HollyUniverseGraph.getVertices()); if (evt.isMetaDown()) { for (Actor temporal : actoresArray) { if (evt.getX() > temporal.getArea()[0] && evt.getX() < temporal.getArea()[1] && evt.getY() > temporal.getArea()[2] && evt.getY() < temporal.getArea()[3]) { this.temp_evt[0] = evt.getX(); this.temp_evt[1] = evt.getY(); Opc_actor.show(evt.getComponent(), evt.getX(), evt.getY()); foundVertex = false;// ww w. j ava2 s . com } } if (foundVertex) { PU_grafico.show(evt.getComponent(), evt.getX(), evt.getY()); } } }
From source file:savant.view.swing.GraphPane.java
private void setMouseModifier(MouseEvent e) { GraphPaneController gpc = GraphPaneController.getInstance(); boolean zooming = MiscUtils.MAC ? e.isMetaDown() : e.isControlDown(); boolean selecting = e.isShiftDown() && !zooming; gpc.setZooming(isDragging && zooming); gpc.setPanning(isDragging && !zooming && !selecting); gpc.setSelecting(isDragging && selecting); }
From source file:VASSAL.build.module.map.PieceMover.java
protected boolean canHandleEvent(MouseEvent e) { return !e.isShiftDown() && !e.isControlDown() && !e.isMetaDown() && e.getClickCount() < 2 && !e.isConsumed();//from w w w . java2s . c om }
From source file:VASSAL.launch.ModuleManagerWindow.java
protected void buildTree() { recentModuleConfig = new StringArrayConfigurer("RecentModules", null); Prefs.getGlobalPrefs().addOption(null, recentModuleConfig); final List<String> missingModules = new ArrayList<String>(); final List<ModuleInfo> moduleList = new ArrayList<ModuleInfo>(); for (String s : recentModuleConfig.getStringArray()) { final ModuleInfo module = new ModuleInfo(s); if (module.getFile().exists() && module.isValid()) { moduleList.add(module);/*from ww w. j av a 2 s. c o m*/ } else { missingModules.add(s); } } for (String s : missingModules) { logger.info(Resources.getString("ModuleManager.removing_module", s)); moduleList.remove(s); recentModuleConfig.removeValue(s); } Collections.sort(moduleList, new Comparator<ModuleInfo>() { public int compare(ModuleInfo f1, ModuleInfo f2) { return f1.compareTo(f2); } }); rootNode = new MyTreeNode(new RootInfo()); for (ModuleInfo moduleInfo : moduleList) { final MyTreeNode moduleNode = new MyTreeNode(moduleInfo); for (ExtensionInfo ext : moduleInfo.getExtensions()) { final MyTreeNode extensionNode = new MyTreeNode(ext); moduleNode.add(extensionNode); } final ArrayList<File> missingFolders = new ArrayList<File>(); for (File f : moduleInfo.getFolders()) { if (f.exists() && f.isDirectory()) { final GameFolderInfo folderInfo = new GameFolderInfo(f, moduleInfo); final MyTreeNode folderNode = new MyTreeNode(folderInfo); moduleNode.add(folderNode); final ArrayList<File> l = new ArrayList<File>(); final File[] files = f.listFiles(); if (files == null) continue; for (File f1 : files) { if (f1.isFile()) { l.add(f1); } } Collections.sort(l); for (File f2 : l) { final SaveFileInfo fileInfo = new SaveFileInfo(f2, folderInfo); if (fileInfo.isValid() && fileInfo.belongsToModule()) { final MyTreeNode fileNode = new MyTreeNode(fileInfo); folderNode.add(fileNode); } } } else { missingFolders.add(f); } } for (File mf : missingFolders) { logger.info(Resources.getString("ModuleManager.removing_folder", mf.getPath())); moduleInfo.removeFolder(mf); } rootNode.add(moduleNode); } updateModuleList(); treeModel = new MyTreeTableModel(rootNode); tree = new MyTree(treeModel); tree.setRootVisible(false); tree.setEditable(false); tree.setTreeCellRenderer(new MyTreeCellRenderer()); tree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { final TreePath path = tree.getPathForLocation(e.getPoint().x, e.getPoint().y); // do nothing if not on a node, or if this node was expanded // or collapsed during the past doubleClickInterval milliseconds if (path == null || (lastExpansionPath == path && e.getWhen() - lastExpansionTime <= doubleClickInterval)) return; selectedNode = (MyTreeNode) path.getLastPathComponent(); final int row = tree.getRowForPath(path); if (row < 0) return; final AbstractInfo target = (AbstractInfo) selectedNode.getUserObject(); // launch module or load save, otherwise expand or collapse node if (target instanceof ModuleInfo) { final ModuleInfo modInfo = (ModuleInfo) target; if (modInfo.isModuleTooNew()) { ErrorDialog.show("Error.module_too_new", modInfo.getFile().getPath(), modInfo.getVassalVersion(), Info.getVersion()); return; } else { ((ModuleInfo) target).play(); } } else if (target instanceof SaveFileInfo) { ((SaveFileInfo) target).play(); } else if (tree.isExpanded(row)) { tree.collapseRow(row); } else { tree.expandRow(row); } } } @Override public void mouseReleased(MouseEvent e) { final TreePath path = tree.getPathForLocation(e.getPoint().x, e.getPoint().y); if (path == null) return; selectedNode = (MyTreeNode) path.getLastPathComponent(); if (e.isMetaDown()) { final int row = tree.getRowForPath(path); if (row >= 0) { tree.clearSelection(); tree.addRowSelectionInterval(row, row); final AbstractInfo target = (AbstractInfo) selectedNode.getUserObject(); target.buildPopup(row).show(tree, e.getX(), e.getY()); } } } }); // We capture the time and location of clicks which would cause // expansion in order to distinguish these from clicks which // might launch a module or game. tree.addTreeWillExpandListener(new TreeWillExpandListener() { public void treeWillCollapse(TreeExpansionEvent e) { lastExpansionTime = System.currentTimeMillis(); lastExpansionPath = e.getPath(); } public void treeWillExpand(TreeExpansionEvent e) { lastExpansionTime = System.currentTimeMillis(); lastExpansionPath = e.getPath(); } }); // This ensures that double-clicks always start the module but // doesn't prevent single-clicks on the handles from working. tree.setToggleClickCount(3); tree.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { final MyTreeNode node = (MyTreeNode) e.getPath().getLastPathComponent(); final AbstractInfo target = node.getNodeInfo(); if (target instanceof ModuleInfo) { setSelectedModule(target.getFile()); } else { if (node.getParent() != null) { setSelectedModule(node.getParentModuleFile()); } } } }); // FIXME: Width handling needs improvement. Also save in prefs tree.getColumnModel().getColumn(KEY_COLUMN).setMinWidth(250); tree.getColumnModel().getColumn(VERSION_COLUMN).setCellRenderer(new VersionCellRenderer()); tree.getColumnModel().getColumn(VERSION_COLUMN).setMinWidth(100); tree.getColumnModel().getColumn(VASSAL_COLUMN).setCellRenderer(new VersionCellRenderer()); tree.getColumnModel().getColumn(VASSAL_COLUMN).setMinWidth(100); tree.getColumnModel().getColumn(SPARE_COLUMN).setMinWidth(10); tree.getColumnModel().getColumn(SPARE_COLUMN).setPreferredWidth(600); // FIXME: How to set alignment of individual header components? tree.getTableHeader().setAlignmentX(JComponent.CENTER_ALIGNMENT); }