List of usage examples for java.awt.event MouseEvent getPoint
public Point getPoint()
From source file:gui.InboxPanel.java
public void generate() { Message[] arrMsg = GmailAPI.Inbox.toArray(new Message[GmailAPI.Inbox.size()]); InboxList = new JList(arrMsg); InboxList.setCellRenderer(new DefaultListCellRenderer() { // Setting the DefaultListCellRenderer public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Message message = (Message) value; // Using value we are getting the object in JList Map<String, String> map = null; try { map = GmailAPI.getMessageDetails(message.getId()); } catch (MessagingException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); }/* w w w. j av a 2s . co m*/ String sub = map.get("subject"); if (map.get("subject").length() > 22) { sub = map.get("subject").substring(0, 20) + "..."; } setText(sub); // Setting the text //setIcon( shape.getImage() ); // Setting the Image Icon return this; } }); InboxList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); InboxList.setLayoutOrientation(JList.VERTICAL); InboxList.setVisibleRowCount(-1); jScrollPane1.setViewportView(InboxList); InboxList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { try { JList list = (JList) evt.getSource(); int index = list.locationToIndex(evt.getPoint()); String id = arrMsg[index].getId(); curId = id; Map<String, String> map = GmailAPI.getMessageDetails(id); jTextField1.setText(map.get("from")); jTextField2.setText(map.get("subject")); dateTextField.setText(map.get("senddate")); BodyTextPane.setText(map.get("body")); //BodyTextPane.setContentType("text/html"); //BodyTextArea.setCo } catch (IOException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); } catch (MessagingException ex) { Logger.getLogger(InboxPanel.class.getName()).log(Level.SEVERE, null, ex); } } }); }
From source file:edu.ku.brc.ui.dnd.SimpleGlassPane.java
@Override protected void processMouseEvent(MouseEvent e) { if (hideOnClick && e.getClickCount() == 1) { hideOnClick = false;/*from w w w .j a v a 2 s .c o m*/ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { SimpleGlassPane.this.setVisible(false); } }); } else if (!dblClickProgBar || !getProgressBarRect().contains(e.getPoint())) { e.consume(); } super.processMouseEvent(e); }
From source file:pt.lsts.neptus.plugins.sunfish.IridiumComms.java
@Override public void mouseClicked(MouseEvent event, StateRenderer2D source) { if (event.getButton() != MouseEvent.BUTTON3) { super.mouseClicked(event, source); return;/* w w w . j av a2 s. c om*/ } final LocationType loc = source.getRealWorldLocation(event.getPoint()); loc.convertToAbsoluteLatLonDepth(); JPopupMenu popup = new JPopupMenu(); if (IridiumManager.getManager().isActive()) { popup.add(I18n.text("Deactivate Polling")).addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { IridiumManager.getManager().stop(); } }); } else { popup.add(I18n.text("Activate Polling")).addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { IridiumManager.getManager().start(); } }); } popup.add(I18n.text("Select Iridium gateway")).addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { IridiumManager.getManager().selectMessenger(getConsole()); } }); popup.addSeparator(); popup.add(I18n.textf("Send %vehicle a command via Iridium", getMainVehicleId())) .addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { sendIridiumCommand(); } }); popup.add(I18n.textf("Command %vehicle a plan via Iridium", getMainVehicleId())) .addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { commandPlanExecution(); } }); popup.add(I18n.textf("Subscribe to iridium device updates", getMainVehicleId())) .addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ActivateSubscription activate = new ActivateSubscription(); activate.setDestination(0xFF); activate.setSource(ImcMsgManager.getManager().getLocalId().intValue()); try { IridiumManager.getManager().send(activate); getConsole().post(Notification.success("Iridium message sent", "1 Iridium messages were sent using " + IridiumManager.getManager().getCurrentMessenger().getName())); } catch (Exception ex) { GuiUtils.errorMessage(getConsole(), ex); } } }); popup.add(I18n.textf("Unsubscribe to iridium device updates", getMainVehicleId())) .addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DeactivateSubscription deactivate = new DeactivateSubscription(); deactivate.setDestination(0xFF); deactivate.setSource(ImcMsgManager.getManager().getLocalId().intValue()); try { IridiumManager.getManager().send(deactivate); } catch (Exception ex) { GuiUtils.errorMessage(getConsole(), ex); } } }); popup.add("Set this as actual wave glider target").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setWaveGliderTargetPosition(loc); } }); popup.add("Set this as desired wave glider target").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setWaveGliderDesiredPosition(loc); } }); popup.addSeparator(); popup.add(I18n.text("Send a text note")).addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { sendTextNote(); } }); popup.add("Add virtual drifter").addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { VirtualDrifter d = new VirtualDrifter(loc, 0, 0.1); PropertiesEditor.editProperties(d, true); drifters.add(d); update(); } }); popup.show(source, event.getX(), event.getY()); }
From source file:net.sf.jabref.gui.MainTableSelectionListener.java
@Override public void mouseClicked(MouseEvent e) { // First find the column on which the user has clicked. final int col = table.columnAtPoint(e.getPoint()); final int row = table.rowAtPoint(e.getPoint()); // A double click on an entry should open the entry's editor. if (e.getClickCount() == 2) { BibtexEntry toShow = tableRows.get(row); editSignalled(toShow);/*from w w w .j a v a 2s . c om*/ } // Check if the user has clicked on an icon cell to open url or pdf. final String[] iconType = table.getIconTypeForColumn(col); // Workaround for Windows. Right-click is not popup trigger on mousePressed, but // on mouseReleased. Therefore we need to avoid taking action at this point, because // action will be taken when the button is released: if (OS.WINDOWS && (iconType != null) && (e.getButton() != MouseEvent.BUTTON1)) { return; } if (iconType != null) { // left click on icon field SpecialField field = SpecialFieldsUtils.getSpecialFieldInstanceFromFieldName(iconType[0]); if ((e.getClickCount() == 1) && (field != null)) { // special field found if (field.isSingleValueField()) { // directly execute toggle action instead of showing a menu with one action field.getValues().get(0).getAction(panel.frame()).action(); } else { JPopupMenu menu = new JPopupMenu(); for (SpecialFieldValue val : field.getValues()) { menu.add(val.getMenuAction(panel.frame())); } menu.show(table, e.getX(), e.getY()); } return; } Object value = table.getValueAt(row, col); if (value == null) { return; // No icon here, so we do nothing. } final BibtexEntry entry = tableRows.get(row); // Get the icon type. Corresponds to the field name. int hasField = -1; for (int i = iconType.length - 1; i >= 0; i--) { if (entry.getField(iconType[i]) != null) { hasField = i; } } if (hasField == -1) { return; } final String fieldName = iconType[hasField]; //If this is a file link field with specified file types, //we should also pass the types. String[] fileTypes = {}; if ((hasField == 0) && iconType[hasField].equals(Globals.FILE_FIELD) && (iconType.length > 1)) { fileTypes = iconType; } final List<String> listOfFileTypes = Collections.unmodifiableList(Arrays.asList(fileTypes)); // Open it now. We do this in a thread, so the program won't freeze during the wait. JabRefExecutorService.INSTANCE.execute(new Runnable() { @Override public void run() { panel.output(Localization.lang("External viewer called") + '.'); Object link = entry.getField(fieldName); if (link == null) { LOGGER.info("Error: no link to " + fieldName + '.'); return; // There is an icon, but the field is not set. } // See if this is a simple file link field, or if it is a file-list // field that can specify a list of links: if (fieldName.equals(Globals.FILE_FIELD)) { // We use a FileListTableModel to parse the field content: FileListTableModel fileList = new FileListTableModel(); fileList.setContent((String) link); FileListEntry flEntry = null; // If there are one or more links of the correct type, // open the first one: if (!listOfFileTypes.isEmpty()) { for (int i = 0; i < fileList.getRowCount(); i++) { flEntry = fileList.getEntry(i); boolean correctType = false; for (String listOfFileType : listOfFileTypes) { if (flEntry.getType().toString().equals(listOfFileType)) { correctType = true; } } if (correctType) { break; } flEntry = null; } } //If there are no file types specified, consider all files. else if (fileList.getRowCount() > 0) { flEntry = fileList.getEntry(0); } if (flEntry != null) { // if (fileList.getRowCount() > 0) { // FileListEntry flEntry = fileList.getEntry(0); ExternalFileMenuItem item = new ExternalFileMenuItem(panel.frame(), entry, "", flEntry.getLink(), flEntry.getType().getIcon(), panel.metaData(), flEntry.getType()); boolean success = item.openLink(); if (!success) { panel.output(Localization.lang("Unable to open link.")); } } } else { try { JabRefDesktop.openExternalViewer(panel.metaData(), (String) link, fieldName); } catch (IOException ex) { panel.output(Localization.lang("Unable to open link.")); } /*ExternalFileType type = Globals.prefs.getExternalFileTypeByMimeType("text/html"); ExternalFileMenuItem item = new ExternalFileMenuItem (panel.frame(), entry, "", (String)link, type.getIcon(), panel.metaData(), type); boolean success = item.openLink(); if (!success) { panel.output(Localization.lang("Unable to open link.")); } */ //Util.openExternalViewer(panel.metaData(), (String)link, fieldName); } //catch (IOException ex) { // panel.output(Globals.lang("Error") + ": " + ex.getMessage()); //} } }); } }
From source file:com.vgi.mafscaling.MafChartPanel.java
public void mousePressed(MouseEvent e) { Insets insets = chartPanel.getInsets(); int x = (int) ((e.getX() - insets.left) / chartPanel.getScaleX()); int y = (int) ((e.getY() - insets.top) / chartPanel.getScaleY()); ChartEntity entity = chartPanel.getChartRenderingInfo().getEntityCollection().getEntity(x, y); if (entity == null || !(entity instanceof XYItemEntity)) return;/*from w ww .j a v a 2 s.co m*/ IsMovable = true; chartPanel.setCursor(new Cursor(Cursor.HAND_CURSOR)); xyItemEntity = (XYItemEntity) entity; XYPlot plot = chartPanel.getChart().getXYPlot(); Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); Point2D p = chartPanel.translateScreenToJava2D(e.getPoint()); initialMovePointY = plot.getRangeAxis().java2DToValue(p.getY(), dataArea, plot.getRangeAxisEdge()); }
From source file:op.care.nursingprocess.DlgNursingProcess.java
private void tblPlanungMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblPlanungMousePressed if (!SwingUtilities.isRightMouseButton(evt)) { return;//from w w w . j a v a 2 s . co m } Point p = evt.getPoint(); ListSelectionModel lsm = tblPlanung.getSelectionModel(); int row = tblPlanung.rowAtPoint(p); if (lsm.isSelectionEmpty() || (lsm.getMinSelectionIndex() == lsm.getMaxSelectionIndex())) { lsm.setSelectionInterval(row, row); } menu = new JPopupMenu(); /*** * _ _ ____ ____ _ _ * (_) |_ ___ _ __ ___ | _ \ ___ _ __ _ _ _ __ | _ \ ___| | ___| |_ ___ * | | __/ _ \ '_ ` _ \| |_) / _ \| '_ \| | | | '_ \| | | |/ _ \ |/ _ \ __/ _ \ * | | || __/ | | | | | __/ (_) | |_) | |_| | |_) | |_| | __/ | __/ || __/ * |_|\__\___|_| |_| |_|_| \___/| .__/ \__,_| .__/|____/ \___|_|\___|\__\___| * |_| |_| */ JMenuItem itemPopupDelete = new JMenuItem(SYSTools.xx("misc.commands.delete"), SYSConst.icon22delete); itemPopupDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { for (int row : tblPlanung.getSelectedRows()) { listInterventionSchedule2Remove .add(((TMPlan) tblPlanung.getModel()).getInterventionSchedule(row)); nursingProcess.getInterventionSchedule() .remove(((TMPlan) tblPlanung.getModel()).getInterventionSchedule(row)); } ((TMPlan) tblPlanung.getModel()).fireTableDataChanged(); } }); menu.add(itemPopupDelete); /*** * _ _ ____ ____ _ _ _ * (_) |_ ___ _ __ ___ | _ \ ___ _ __ _ _ _ __/ ___| ___| |__ ___ __| |_ _| | ___ * | | __/ _ \ '_ ` _ \| |_) / _ \| '_ \| | | | '_ \___ \ / __| '_ \ / _ \/ _` | | | | |/ _ \ * | | || __/ | | | | | __/ (_) | |_) | |_| | |_) |__) | (__| | | | __/ (_| | |_| | | __/ * |_|\__\___|_| |_| |_|_| \___/| .__/ \__,_| .__/____/ \___|_| |_|\___|\__,_|\__,_|_|\___| * |_| |_| */ final JMenuItem itemPopupSchedule = new JMenuItem(SYSTools.xx("misc.commands.editsheduling"), SYSConst.icon22clock); itemPopupSchedule.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { final JidePopup popup = new JidePopup(); /** * This routine uses the <b>first</b> element of the selection as the template for editing * the schedule. After the edit it clones this "template", removes the original * InterventionSchedules (copying the apropriate Intervention of every single * Schedule first) and finally creates new schedules and adds them to * the CareProcess in question. */ int row = tblPlanung.getSelectedRows()[0]; InterventionSchedule firstInterventionScheduleWillBeTemplate = ((TMPlan) tblPlanung.getModel()) .getInterventionSchedule(row); JPanel dlg = new PnlSchedule(firstInterventionScheduleWillBeTemplate, new Closure() { @Override public void execute(Object o) { if (o != null) { InterventionSchedule template = (InterventionSchedule) o; ArrayList<InterventionSchedule> listInterventionSchedule2Add = new ArrayList(); for (int row : tblPlanung.getSelectedRows()) { InterventionSchedule oldTermin = ((TMPlan) tblPlanung.getModel()) .getInterventionSchedule(row); InterventionSchedule newTermin = template.clone(); newTermin.setIntervention(oldTermin.getIntervention()); listInterventionSchedule2Remove.add(oldTermin); listInterventionSchedule2Add.add(newTermin); } nursingProcess.getInterventionSchedule().removeAll(listInterventionSchedule2Remove); nursingProcess.getInterventionSchedule().addAll(listInterventionSchedule2Add); popup.hidePopup(); Collections.sort(nursingProcess.getInterventionSchedule()); ((TMPlan) tblPlanung.getModel()).fireTableDataChanged(); } } }); popup.setMovable(false); popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.getContentPane().add(dlg); popup.setOwner(jspPlanung); popup.removeExcludedComponent(jspPlanung); popup.setDefaultFocusComponent(dlg); GUITools.showPopup(popup, SwingConstants.SOUTH_WEST); } }); menu.add(itemPopupSchedule); menu.show(evt.getComponent(), (int) p.getX(), (int) p.getY()); }
From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java
public boolean isOnIcon(MouseEvent e) { Point p = e.getPoint(); int row = rowAtPoint(p); int col = columnAtPoint(p); Rectangle bounds = getCellRect(row, col, false); SpreadSheetModel model = (SpreadSheetModel) getModel(); GraphicNode node = model.getNode(row); return NameCellComponent.isOnIcon( new Point((int) (p.getX() - bounds.getX()), (int) (p.getY() - bounds.getY())), bounds.getSize(), model.getCache().getLevel(node)); }
From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java
public boolean isOnText(MouseEvent e) { Point p = e.getPoint(); int row = rowAtPoint(p); int col = columnAtPoint(p); Rectangle bounds = getCellRect(row, col, false); SpreadSheetModel model = (SpreadSheetModel) getModel(); GraphicNode node = model.getNode(row); return NameCellComponent.isOnText( new Point((int) (p.getX() - bounds.getX()), (int) (p.getY() - bounds.getY())), bounds.getSize(), model.getCache().getLevel(node)); }
From source file:net.sf.firemox.clickable.target.card.VirtualCard.java
public void mousePressed(MouseEvent e) { if (card.getParent() instanceof MZone) { card.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); ((MZone) card.getParent()).startDragAndDrop(card, e.getPoint()); }/* w ww.j a v a 2s. c o m*/ }
From source file:net.sf.xmm.moviemanager.gui.DialogIMDB.java
JPanel createMoviehitsList() { /* Movies List panel...*/ JPanel panelMoviesList = new JPanel(); panelMoviesList.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), Localizer.get("DialogIMDB.panel-movie-list.title")), //$NON-NLS-1$ BorderFactory.createEmptyBorder(5, 5, 5, 5))); listMovies = new JList() { public String getToolTipText(MouseEvent e) { if (getCellBounds(0, 0) == null) return null; String retVal = null; int row = (int) e.getPoint().getY() / (int) getCellBounds(0, 0).getHeight(); if (row >= 0 && row < getModel().getSize() && getMoviesList().getModel().getElementAt(row) instanceof ModelIMDbSearchHit) { retVal = ((ModelIMDbSearchHit) getMoviesList().getModel().getElementAt(row)).getAka(); if (retVal != null && retVal.trim().equals("")) //$NON-NLS-1$ retVal = null;/* w ww. j a v a 2 s. com*/ } return retVal; } public JToolTip createToolTip() { JMultiLineToolTip tooltip = new JMultiLineToolTip(); tooltip.setComponent(this); return tooltip; } }; // Unfortunately setting tooltip timeout affects ALL tooltips ToolTipManager ttm = ToolTipManager.sharedInstance(); ttm.registerComponent(listMovies); ttm.setInitialDelay(0); ttm.setReshowDelay(0); listMovies.setFixedCellHeight(18); listMovies.setFont(new Font(listMovies.getFont().getName(), Font.PLAIN, listMovies.getFont().getSize())); listMovies.setLayoutOrientation(JList.VERTICAL); listMovies.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listMovies.setCellRenderer(new MovieHitListCellRenderer()); listMovies.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent event) { // Open we page if (SwingUtilities.isRightMouseButton(event)) { int index = listMovies.locationToIndex(event.getPoint()); if (index >= 0) { ModelIMDbSearchHit hit = (ModelIMDbSearchHit) listMovies.getModel().getElementAt(index); if (hit.getUrlID() != null && !hit.getUrlID().equals("")) { BrowserOpener opener = new BrowserOpener(hit.getCompleteUrl()); opener.executeOpenBrowser(MovieManager.getConfig().getSystemWebBrowser(), MovieManager.getConfig().getBrowserPath()); } } } else if (SwingUtilities.isLeftMouseButton(event) && event.getClickCount() >= 2) { buttonSelect.doClick(); } } }); KeyStroke enterKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true); ActionListener listKeyBoardActionListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { log.debug("ActionPerformed: " + "Movielist - ENTER pressed."); //$NON-NLS-1$ buttonSelect.doClick(); } }; listMovies.registerKeyboardAction(listKeyBoardActionListener, enterKeyStroke, JComponent.WHEN_FOCUSED); JScrollPane scrollPaneMovies = new JScrollPane(listMovies); scrollPaneMovies.setAutoscrolls(true); //scrollPaneMovies.registerKeyboardAction(listKeyBoardActionListener,enterKeyStroke, JComponent.WHEN_FOCUSED); panelMoviesList.setLayout(new BorderLayout()); panelMoviesList.add(scrollPaneMovies, BorderLayout.CENTER); return panelMoviesList; }