List of usage examples for javax.swing SwingUtilities isRightMouseButton
public static boolean isRightMouseButton(MouseEvent anEvent)
From source file:ucar.unidata.idv.control.chart.ScatterPlotChartWrapper.java
/** * Handle the event/*from ww w . j av a2s .co m*/ * * @param event the event * * @return Should we pass on this event */ public boolean chartPanelMouseClicked(MouseEvent event) { if (SwingUtilities.isRightMouseButton(event) || (event.getClickCount() < 2)) { return super.chartPanelMousePressed(event); } List series = ((MyScatterPlot) plot).getSeries(); //TODO: Check if click is inside data area double minDistance = 100; int minIdx = -1; double minTime = -1; for (int seriesIdx = 0; seriesIdx < series.size(); seriesIdx++) { NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(seriesIdx); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(seriesIdx); double[][] data = (double[][]) series.get(seriesIdx); for (int i = 0; i < data[0].length; i++) { double x = domainAxis.valueToJava2D(data[0][i], getChartPanel().getScreenDataArea(), plot.getDomainAxisEdge()); double y = rangeAxis.valueToJava2D(data[1][i], getChartPanel().getScreenDataArea(), plot.getRangeAxisEdge()); double distance = Math .sqrt((x - event.getX()) * (x - event.getX()) + (y - event.getY()) * (y - event.getY())); if (distance < minDistance) { minDistance = distance; minIdx = i; } } if (minIdx >= 0) { minTime = timeValues1[minIdx]; } } if (minIdx < 0) { return EVENT_PASSON; } firePropertyChange(PROP_SELECTEDTIME, null, new Double(minTime)); return EVENT_PASSON; }
From source file:krasa.cpu.CpuUsagePanel.java
public CpuUsagePanel(Project project) { refreshColors();/*from ww w. jav a 2s . c o m*/ this.myProject = project; this.projectName = project.getName(); setOpaque(false); setFocusable(false); setToolTipText("IDE CPU usage / System CPU usage"); setBorder(StatusBarWidget.WidgetBorder.INSTANCE); updateUI(); new UiNotifyConnector(this, new Activatable() { @Override public void showNotify() { CpuUsageManager.register(CpuUsagePanel.this); } @Override public void hideNotify() { CpuUsageManager.unregister(CpuUsagePanel.this); } }); MouseAdapter mouseAdapter = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { CpuUsageManager.update(); final DataContext context = DataManager.getInstance().getDataContext(CpuUsagePanel.this); ActionManager.getInstance().getAction("TakeThreadDump").actionPerformed(new AnActionEvent(e, context, ActionPlaces.UNKNOWN, new Presentation(""), ActionManager.getInstance(), 0)); } else if (SwingUtilities.isRightMouseButton(e)) { final DataContext context = DataManager.getInstance().getDataContext(CpuUsagePanel.this); ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, getActionGroup(), context, JBPopupFactory.ActionSelectionAid.MNEMONICS, false); Dimension dimension = popup.getContent().getPreferredSize(); Point at = new Point(0, -dimension.height); popup.show(new RelativePoint(e.getComponent(), at)); } } }; addMouseListener(mouseAdapter); }
From source file:components.ScrollDemo2.java
public void mouseReleased(MouseEvent e) { final int W = 100; final int H = 100; boolean changed = false; if (SwingUtilities.isRightMouseButton(e)) { //This will clear the graphic objects. circles.removeAllElements();/*from w w w. ja v a 2 s . c o m*/ area.width = 0; area.height = 0; changed = true; } else { int x = e.getX() - W / 2; int y = e.getY() - H / 2; if (x < 0) x = 0; if (y < 0) y = 0; Rectangle rect = new Rectangle(x, y, W, H); circles.addElement(rect); drawingPane.scrollRectToVisible(rect); int this_width = (x + W + 2); if (this_width > area.width) { area.width = this_width; changed = true; } int this_height = (y + H + 2); if (this_height > area.height) { area.height = this_height; changed = true; } } if (changed) { //Update client's preferred size because //the area taken up by the graphics has //gotten larger or smaller (if cleared). drawingPane.setPreferredSize(area); //Let the scroll pane know to update itself //and its scrollbars. drawingPane.revalidate(); } drawingPane.repaint(); }
From source file:hermes.browser.components.ClasspathGroupTable.java
private void init() { final JPopupMenu popupMenu = new JPopupMenu(); final JMenuItem addItem = new JMenuItem("Add Group"); final JMenuItem removeItem = new JMenuItem("Remove Group"); final JMenuItem renameItem = new JMenuItem("Rename"); popupMenu.add(addItem);/*from w ww . j a v a2 s.co m*/ popupMenu.add(removeItem); popupMenu.add(renameItem); addItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { doAddGroup(); dialog.setDirty(); } catch (Exception ex) { log.error(ex.getMessage(), ex); } } }); removeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (getSelectedRowCount() > 0) { for (int row : getSelectedRows()) { getClasspathGroupTableModel().removeRow(row); } dialog.setDirty(); } } }); renameItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (getSelectedRow() != -1) { doRename(); } } }); mouseAdapter = new MouseAdapter() { public void mousePressed(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { removeItem.setEnabled(getClasspathGroupTableModel().getRowCount() != 0); renameItem.setEnabled(getClasspathGroupTableModel().getRowCount() != 0); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } }; addMouseListener(mouseAdapter); getTableHeader().addMouseListener(mouseAdapter); if (dialog != null) { addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { // // Think this is ok, seems 2 do the job. if (evt.getPropertyName().equals("tableCellEditor")) { dialog.setDirty(); } } }); } }
From source file:dbseer.gui.panel.DBSeerSelectableChartPanel.java
@Override public void mousePressed(MouseEvent e) { super.mousePressed(e); Rectangle2D origArea = this.getScreenDataArea(); Plot plot = chart.getPlot();//from ww w. jav a2 s . co m if (!(plot instanceof XYPlot)) { return; } XYPlot xyPlot = chart.getXYPlot(); String origDomainAxisLabel = xyPlot.getDomainAxis().getLabel(); if (SwingUtilities.isRightMouseButton(e)) { return; } for (DBSeerSelectableChartPanel panel : DBSeerPlotPresetFrame.chartPanels) { if (panel != this) { Plot otherPlot = panel.getChart().getPlot(); if (!(otherPlot instanceof XYPlot)) { continue; } Rectangle2D otherArea = panel.getScreenDataArea(); XYPlot otherXYPlot = panel.getChart().getXYPlot(); String otherDomainAxisLabel = otherXYPlot.getDomainAxis().getLabel(); if (origDomainAxisLabel.equalsIgnoreCase(otherDomainAxisLabel)) { double origRangeX = origArea.getMaxX() - origArea.getMinX(); double origRangeY = origArea.getMaxY() - origArea.getMinY(); double otherRangeX = otherArea.getMaxX() - otherArea.getMinX(); double otherRangeY = otherArea.getMaxY() - otherArea.getMinY(); double syncX = otherArea.getMinX() + (e.getX() - origArea.getMinX()) / origRangeX * otherRangeX; double syncY = otherArea.getMinY() + (e.getY() - origArea.getMinY()) / origRangeY * otherRangeY; MouseEvent syncEvent = new MouseEvent(this, 0, 0, 0, (int) syncX, (int) syncY, 1, false); panel.syncMousePressed(syncEvent); } } } }
From source file:hermes.browser.dialog.HermesAdminFactoryConfigPanel.java
public void init() { final Border border = BorderFactory.createBevelBorder(BevelBorder.RAISED); setLayout(new BorderLayout()); setBorder(BorderFactory.createTitledBorder(border, ADMIN_FACTORY)); afCombo.setModel(cfComboModel);/*from w w w.j a v a 2s. c o m*/ propertyTableSP.setViewportView(propertyTable); propertyTable.setSortable(true); add(afCombo, BorderLayout.NORTH); add(propertyTableSP, BorderLayout.CENTER); popupMenu.add(addItem); popupMenu.add(removeItem); addItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try { propertyTableModel.insertRow(); } catch (Exception ex) { cat.error(ex.getMessage(), ex); } } }); removeItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (propertyTable.getSelectedRow() != -1) { propertyTableModel.removeRow(propertyTable.getSelectedRow()); } } }); final MouseAdapter m = new MouseAdapter() { public void mousePressed(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { if (e.getComponent() == propertyTableSP) { removeItem.setEnabled(false); } else { removeItem.setEnabled(true); } if (propertySelectionComboBox.getModel().getSize() == 0) { addItem.setEnabled(false); } else { addItem.setEnabled(true); } popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } }; propertyTableSP.addMouseListener(m); propertyTable.addMouseListener(m); propertyTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); cfComboModel.addListDataListener(new ListDataListener() { public void contentsChanged(ListDataEvent arg0) { final String className = HermesBrowser.getConfigDAO() .getAdminClassForPlugIn((String) cfComboModel.getSelectedItem()); final ClassLoaderManager classLoaderManager = (ClassLoaderManager) SingletonManager .get(ClassLoaderManager.class); try { if (propertyTableModel != null) { final ClassLoader classLoader = classLoaderManager .getClassLoader(dialog.getSelectedLoader()); Thread.currentThread().setContextClassLoader(classLoader); bean = (HermesAdminFactory) classLoader.loadClass(className).newInstance(); propertyTableModel.setBean(bean); updateCellEditor(); dialog.setDirty(); } } catch (Throwable e) { HermesBrowser.getBrowser().showErrorDialog( "Unable to locate this plugin.\nSelect the loader the JMS provider classes are in before choosing the plugin."); cfComboModel.setSelectedItem(ConfigDAO.DEFAULT_PLUGIN); } } public void intervalAdded(ListDataEvent arg0) { // NOP } public void intervalRemoved(ListDataEvent arg0) { // NOP } }); }
From source file:medsavant.enrichment.app.OntologyAggregatePanel.java
public OntologyAggregatePanel(String page) { super(page);// w w w. ja va 2 s .c o m setLayout(new GridBagLayout()); chooser = new JComboBox(OntologyListItem.DEFAULT_ITEMS); chooser.setMaximumSize(new Dimension(400, chooser.getMaximumSize().height)); progress = new JProgressBar(); progress.setPreferredSize(new Dimension(600, progress.getMaximumSize().height)); progress.setStringPainted(true); JPanel banner = new JPanel(); banner.setLayout(new GridBagLayout()); banner.setBackground(new Color(245, 245, 245)); banner.setBorder(BorderFactory.createTitledBorder("Ontology")); tree = new TreeTable(); GridBagConstraints gbc = new GridBagConstraints(); gbc.weightx = 1.0; gbc.anchor = GridBagConstraints.WEST; banner.add(chooser, gbc); gbc.anchor = GridBagConstraints.EAST; banner.add(progress, gbc); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.weightx = 1.0; gbc.weighty = 0.0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.anchor = GridBagConstraints.NORTH; add(banner, gbc); gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; add(new JScrollPane(tree), gbc); chooser.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (termFetcher != null) { termFetcher.cancel(true); termFetcher = null; } recalculate(); } }); tree.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { createPopup().show(e.getComponent(), e.getX(), e.getY()); } } }); }
From source file:com.mirth.connect.client.ui.components.MirthTable.java
public void setMirthColumnControlEnabled(boolean enabled) { if (enabled) { if (tableSortAdapter == null) { tableSortAdapter = new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { getColumnMenu().show(e.getComponent(), e.getX(), e.getY()); }//from www .jav a 2 s . c o m } }; getTableHeader().addMouseListener(tableSortAdapter); } } else { if (tableSortAdapter != null) { getTableHeader().removeMouseListener(tableSortAdapter); tableSortAdapter = null; } } setColumnControlVisible(enabled); }
From source file:medsavant.enrichment.app.RegionListAggregatePanel.java
private void createSearchableTable() { tablePanel = new SearchableTablePanel(pageName, new String[] { "Name", "Chromosome", "Start", "End", "Length", "Variants", "Variants / KB", "Individuals" }, new Class[] { String.class, String.class, Integer.class, Integer.class, Integer.class, Integer.class, Double.class, Integer.class }, new int[0], true, true, Integer.MAX_VALUE, false, SearchableTablePanel.TableSelectionType.ROW, Integer.MAX_VALUE, new AggregationRetriever()); tablePanel.getTable().addMouseListener(new MouseAdapter() { @Override/*from w w w. ja v a2 s.co m*/ public void mouseReleased(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { createPopup().show(e.getComponent(), e.getX(), e.getY()); } } }); showShowCard(); }
From source file:com.diversityarrays.kdxplore.trials.SampleGroupViewer.java
private SampleGroupViewer(String title, KdxploreDatabase kdxdb, Trial trial, SampleGroup sampleGroup) { super(new BorderLayout()); this.title = title; // setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.kdxdb = kdxdb; this.trial = trial; this.sampleGroup = sampleGroup; initialise();//from w w w . jav a 2s.c om if (plotInfoByPlotId.isEmpty()) { add(new JLabel("No Plots available"), BorderLayout.CENTER); } else { tiChoiceTableModel = new TraitInstanceChoiceTableModel(); JTable tiTable = new JTable(tiChoiceTableModel); tiTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { List<Integer> modelRows = GuiUtil.getSelectedModelRows(tiTable); if (modelRows.isEmpty()) { Point pt = e.getPoint(); int vrow = tiTable.rowAtPoint(pt); if (vrow >= 0) { int mrow = tiTable.convertRowIndexToModel(vrow); if (mrow >= 0) { showPopupMenu(tiTable, pt, Arrays.asList(Integer.valueOf(mrow))); } } } else { showPopupMenu(tiTable, e.getPoint(), modelRows); } } } }); tableModel = new DataTableModel(plotInfoByPlotId); JTable table = new JTable(tableModel); DefaultTableCellRenderer r = new DefaultTableCellRenderer(); r.setHorizontalAlignment(SwingConstants.CENTER); table.setDefaultRenderer(String.class, r); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tiTable), new JScrollPane(table)); splitPane.setResizeWeight(0.2); add(splitPane, BorderLayout.CENTER); table.setTransferHandler(TableTransferHandler.initialiseForCopySelectAll(table, true)); } }