List of usage examples for javax.swing SwingUtilities isLeftMouseButton
public static boolean isLeftMouseButton(MouseEvent anEvent)
From source file:org.nuclos.client.ui.collect.result.ResultController.java
/** * TODO: Make this package visible again. *//* ww w . j a v a 2 s . com*/ public void setupResultPanel() { if (NuclosEntity.isNuclosEntity(getEntity().getName())) { this.getResultPanel().setActionsEnabled(false); } this.getResultPanel().addActionsVisibleListener(actionsVisibleListener); setupActions(); // add selection listener for Result table: final JTable tblResult = this.getResultPanel().getResultTable(); tblResult.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); tblResult.getSelectionModel().addListSelectionListener(newListSelectionListener(tblResult)); this.getResultPanel().btnToggleSelectionMode.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { getResultPanel().setToggleSelection(!getResultPanel().isToggleSelection()); } }); this.getResultPanel().btnSelectAllRows.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (tblResult.getRowCount() > 0) { tblResult.getSelectionModel().setSelectionInterval(0, tblResult.getRowCount() - 1); } } }); this.getResultPanel().btnDeSelectAllRows.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tblResult.getSelectionModel().clearSelection(); } }); this.getResultPanel().addResultKeyListener(new ResultKeyListener() { @Override public boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { if (e.getKeyCode() == ESC) { if (!pressed) { tblResult.getSelectionModel().clearSelection(); return true; } } else if (e.getKeyCode() == UP || e.getKeyCode() == DOWN) { if (pressed) { /* Warum wird dies bentigt? * BasicTableUI.actionPerformed(...) sendet ein ungewolltes changeSelection mit toggle=false bei PFEIL-NACH-OBEN/-UNTEN (siehe unten). * Der Standard in der Ergebnisansicht soll aber ein umgedrehtes Verhalten fr Mausklicks sein. (siehe Implementierung * ResultPanel: super.changeSelection(rowIndex, columnIndex, alternateSelectionToggle? !toggle: toggle, extend);) * * else if (!inSelection) { * moveWithinTableRange(table, dx, dy); * table.changeSelection(leadRow, leadColumn, false, extend); * } */ getResultPanel().setAlternateSelectionToggle(false); SwingUtilities.invokeLater(new Runnable() { public void run() { getResultPanel().setAlternateSelectionToggle(true); } }); } } return false; } }); // add mouse listener for double click in table: this.mouselistenerTableDblClick = new MouseAdapter() { private long lastClick = 0l; @Override public void mouseClicked(MouseEvent ev) { if (SwingUtilities.isLeftMouseButton(ev)) { if (lastClick + MainFrameTabbedPane.DOUBLE_CLICK_SPEED > System.currentTimeMillis()) { int iRow = tblResult.rowAtPoint(ev.getPoint()); if (iRow >= 0 && iRow < tblResult.getRowCount()) { tblResult.getSelectionModel().setSelectionInterval(iRow, iRow); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (getSelectedCollectableFromTableModel() != null) { clctctl.cmdViewSelectedCollectables(); } } }); } } lastClick = System.currentTimeMillis(); } } }; getResultPanel().addDoubleClickMouseListener(this.mouselistenerTableDblClick); if (!SecurityCache.getInstance() .isActionAllowed(Actions.ACTION_WORKSPACE_CUSTOMIZE_ENTITY_AND_SUBFORM_COLUMNS) && getMainFrame().getWorkspace().isAssigned()) { getResultPanel().getResultTable().getTableHeader().setReorderingAllowed(false); } // change column ordering in table model when table columns are reordered by dragging a column with the mouse: getResultPanel().addColumnModelListener(newColumnModelListener()); PreferencesUpdateListener pul = newResultTablePreferencesUpdateListener(); getResultPanel().addColumnModelListener(pul); getResultPanel().addPopupMenuListener(); getResultPanel().getSearchFilterBar().addEnabledListener(new ResetMainFilterEnabledListener()); getResultPanel().setActionsVisible( getCollectController().getPreferences().getBoolean(RESULT_ACTIONS_VISIBLE, true)); }
From source file:org.nuclos.client.ui.collect.SubForm.java
/** * @Deprecated Never use this directly, instead use {@link #addToolbarMenuItems(List)}. *//* www. j av a2s .com*/ private MouseListener newToolbarContextMenuListener(final JComponent parent, final JTable table) { MouseListener res = new MouseAdapter() { @Override public void mouseClicked(MouseEvent mev) { if (SwingUtilities.isRightMouseButton(mev)) { List<JComponent> items = new ArrayList<JComponent>(); addToolbarMenuItems(items); if (items.isEmpty()) return; JPopupMenu popup = new JPopupMenu(); for (JComponent c : items) popup.add(c); popup.show(parent, mev.getX(), mev.getY()); } if (SwingUtilities.isLeftMouseButton(mev) && mev.getClickCount() == 2) { int row = table.rowAtPoint(mev.getPoint()); int column = table.columnAtPoint(mev.getPoint()); LOG.info(StringUtils.concat("Doubleclick on subform: column=", column, ",row=", row)); if (row == -1 || column == -1) { if (toolbarMenuItems.get(ToolbarFunction.NEW.name()).isEnabled()) { actionPerformed(ToolbarFunction.NEW.name()); } } } } }; return res; }
From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java
/** * Reacts to mouse pressed and mouse release event. * /* w w w . j a v a 2s. com*/ * @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 ww . j ava 2 s . co m*/ * @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.rdv.viz.image.ImageViz.java
private void initFilmstripPanel() { filmstripPanel = new FilmstripPanel(); filmstripPanel.setBackground(Color.black); filmstripPanel.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent pce) { String propertyName = pce.getPropertyName(); if (propertyName.equals(FilmstripPanel.MAXIMUM_IMAGES_PROPERTY)) { if (filmstripPanel.getMaximumImages() != FilmstripPanel.MAXIMUM_IMAGES_DEFAULT) { properties.setProperty(DATA_PANEL_PROPERTY_MAXIMUM_FILMSTRIP_IMAGES, pce.getNewValue().toString()); } else { properties.remove(DATA_PANEL_PROPERTY_MAXIMUM_FILMSTRIP_IMAGES); }/* w ww . j a va 2 s. co m*/ updateMaximumFilmstripImagesRadioButtons(); } } }); filmstripPanel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) { setFilmstripMode(false); } } }); }
From source file:tvbrowser.ui.filter.dlgs.EditFilterDlg.java
public EditFilterDlg(JFrame parent, FilterList filterList, UserFilter filter) { super(parent, true); UiUtilities.registerForClosing(this); mFilterList = filterList;/* ww w .ja va 2s . c om*/ mParent = parent; mFilter = filter; JPanel contentPane = (JPanel) getContentPane(); contentPane.setLayout(new BorderLayout(7, 7)); contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); if (filter == null) { setTitle(mLocalizer.msg("titleNew", "Create filter")); } else { setTitle(mLocalizer.msg("titleEdit", "Edit filter {0}", filter.toString())); mFilterName = filter.toString(); } JPanel northPanel = new JPanel(); northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.Y_AXIS)); mFilterNameTF = new JTextField(new PlainDocument() { public void insertString(int offset, String str, AttributeSet a) throws BadLocationException { str = str.replaceAll("[\\p{Punct}&&[^_]]", "_"); super.insertString(offset, str, a); } }, "", 30); mFilterNameTF.getDocument().addDocumentListener(this); JPanel panel = new JPanel(new BorderLayout(7, 7)); panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 7, 0)); panel.add(new JLabel(mLocalizer.msg("filterName", "Filter name:")), BorderLayout.WEST); JPanel panel1 = new JPanel(new BorderLayout()); panel1.add(mFilterNameTF, BorderLayout.WEST); panel.add(panel1, BorderLayout.CENTER); northPanel.add(panel); mFilterRuleTF = new JTextField(); mFilterRuleTF.getDocument().addDocumentListener(this); mFilterRuleTF.addCaretListener(this); panel = new JPanel(new BorderLayout(7, 7)); panel1 = new JPanel(new BorderLayout()); panel.add(new JLabel(mLocalizer.msg("ruleString", "Filter rule:")), BorderLayout.WEST); JLabel exampleLb = new JLabel( mLocalizer.msg("ruleExample", "example: component1 or (component2 and not component3)")); Font f = exampleLb.getFont(); exampleLb.setFont(new Font(f.getName(), Font.ITALIC | Font.PLAIN, f.getSize())); panel1.add(exampleLb, BorderLayout.WEST); panel.add(panel1, BorderLayout.CENTER); northPanel.add(panel); northPanel.add(mFilterRuleTF); mFilterRuleErrorLb = new JLabel(); mFilterRuleErrorLb.setForeground(Color.red); panel = new JPanel(new BorderLayout(7, 7)); panel.add(mFilterRuleErrorLb, BorderLayout.WEST); mColLb = new JLabel("0"); panel.add(mColLb, BorderLayout.EAST); northPanel.add(panel); JPanel filterComponentsPanel = new JPanel(new BorderLayout(7, 7)); filterComponentsPanel.add(DefaultComponentFactory.getInstance().createSeparator( mLocalizer.msg("componentsTitle", "Available filter components:")), BorderLayout.NORTH); JPanel btnPanel = new JPanel(new BorderLayout()); panel1 = new JPanel(new GridLayout(0, 1, 0, 7)); mNewBtn = new JButton(mLocalizer.msg("newButton", "new")); mEditBtn = new JButton(Localizer.getLocalization(Localizer.I18N_EDIT)); mRemoveBtn = new JButton(Localizer.getLocalization(Localizer.I18N_DELETE)); mNewBtn.addActionListener(this); mEditBtn.addActionListener(this); mRemoveBtn.addActionListener(this); panel1.add(mNewBtn); panel1.add(mEditBtn); panel1.add(mRemoveBtn); btnPanel.add(panel1, BorderLayout.NORTH); mComponentTableModel = new FilterTableModel(); mRuleTableBox = new JTable(mComponentTableModel); mRuleTableBox.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { updateBtns(); } }); mRuleTableBox.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() >= 2) { int row = mRuleTableBox.rowAtPoint(e.getPoint()); if (mRuleTableBox.getSelectedRow() == row && mEditBtn.isEnabled()) { actionPerformed(new ActionEvent(mEditBtn, ActionEvent.ACTION_PERFORMED, mEditBtn.getActionCommand())); } } } }); mRuleTableBox.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); mRuleTableBox.setShowGrid(false); mRuleTableBox.setShowVerticalLines(true); mRuleTableBox.getColumnModel().getColumn(0).setPreferredWidth(125); mRuleTableBox.getColumnModel().getColumn(1).setPreferredWidth(320); // mRuleTableBox.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // Dispatchs the KeyEvent to the RootPane for Closing the Dialog. // Needed for Java 1.4. mRuleTableBox.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { mRuleTableBox.getRootPane().dispatchEvent(e); } } }); JPanel ruleListBoxPanel = new JPanel(new BorderLayout()); ruleListBoxPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 7, 0)); ruleListBoxPanel.add(new JScrollPane(mRuleTableBox), BorderLayout.CENTER); filterComponentsPanel.add(btnPanel, BorderLayout.EAST); filterComponentsPanel.add(ruleListBoxPanel, BorderLayout.CENTER); ButtonBarBuilder2 bottomBar = Utilities.createFilterButtonBar(); mOkBtn = new JButton(Localizer.getLocalization(Localizer.I18N_OK)); mOkBtn.addActionListener(this); getRootPane().setDefaultButton(mOkBtn); mCancelBtn = new JButton(Localizer.getLocalization(Localizer.I18N_CANCEL)); mCancelBtn.addActionListener(this); bottomBar.addButton(new JButton[] { mOkBtn, mCancelBtn }); contentPane.add(northPanel, BorderLayout.NORTH); contentPane.add(filterComponentsPanel, BorderLayout.CENTER); contentPane.add(bottomBar.getPanel(), BorderLayout.SOUTH); if (mFilter != null) { mFilterNameTF.setText(mFilter.toString()); mFilterRuleTF.setText(mFilter.getRule()); } FilterComponent[] fc = FilterComponentList.getInstance().getAvailableFilterComponents(); Arrays.sort(fc, new FilterComponent.NameComparator()); for (FilterComponent element : fc) { mComponentTableModel.addElement(element); } updateBtns(); Settings.layoutWindow("editFilterDlg", this, new Dimension(600, 300)); setVisible(true); }
From source file:unikn.dbis.univis.navigation.tree.VTree.java
/** * Returns a <code>JTree</code> with a sample model. * The default model used by the tree defines a leaf node as any node * without children.// w w w. j a va2 s. c o m * * @see javax.swing.tree.DefaultTreeModel#asksAllowsChildren */ public VTree() { super(new Object[] {}); VTreeCellRenderer renderer = new VTreeCellRenderer(); setCellRenderer(renderer); setCellEditor(new VTreeCellEditor(renderer)); setEditable(true); addMouseListener(new MouseAdapter() { /** * Invoked when a mouse button has been pressed on a component. */ @Override public void mousePressed(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { setSelectionPath(getPathForLocation(e.getX(), e.getY())); } } }); }
From source file:unikn.dbis.univis.navigation.tree.VTree.java
/** * Returns a <code>JTree</code> with a sample model. * The default model used by the tree defines a leaf node as any node * without children.//from w w w. j a v a 2s .c o m * * @see javax.swing.tree.DefaultTreeModel#asksAllowsChildren */ public VTree(VDiceBox diceBox) { super(VTreeHelper.createDefaultTree(diceBox)); VTreeCellRenderer renderer = new VTreeCellRenderer(); setCellRenderer(renderer); setCellEditor(new VTreeCellEditor(renderer)); setEditable(true); addMouseListener(new MouseAdapter() { /** * Invoked when a mouse button has been pressed on a component. */ @Override public void mousePressed(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { setSelectionPath(getPathForLocation(e.getX(), e.getY())); } } }); }
From source file:view.MultipleValidationDialog.java
private void lblRevisionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblRevisionMouseClicked if (SwingUtilities.isLeftMouseButton(evt)) { DefaultMutableTreeNode dtn = (DefaultMutableTreeNode) jtValidation.getLastSelectedPathComponent(); SignatureValidation sv = null;/* w ww. ja va 2s . co m*/ if (dtn.isLeaf()) { DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) dtn.getParent(); sv = (SignatureValidation) dmtn.getUserObject(); } else { sv = (SignatureValidation) dtn.getUserObject(); } try { File f = CCInstance.getInstance().extractRevision(sv.getFilename(), sv.getName()); openPdfReaderFromFile(f); } catch (IOException | RevisionExtractionException ex) { Logger.getLogger(WorkspacePanel.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:view.MultipleValidationDialog.java
private void lblAdditionalInfoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblAdditionalInfoMouseClicked if (SwingUtilities.isLeftMouseButton(evt)) { if (msg != null) { JOptionPane.showMessageDialog(null, msg); }//from ww w. ja v a2s. c o m } }