List of usage examples for java.awt.event MouseEvent getSource
public Object getSource()
From source file:corelyzer.ui.CorelyzerApp.java
public void mouseReleased(final MouseEvent e) { // From JDK Doc // Note: Popup menus are triggered differently on different systems. // Therefore, isPopupTrigger should be checked in both mousePressed and // mouseReleased for proper cross-platform functionality. Point p = e.getPoint();/*from w w w . j a va 2 s. c o m*/ Object actionSource = e.getSource(); if (actionSource instanceof JList) { // find the index of the clicked item in the JList int index = ((JList) e.getSource()).locationToIndex(e.getPoint()); if (index < 0) { return; } // show our popup menu if it was a right/ctrl-click if (e.isPopupTrigger()) { if (actionSource.equals(sessionList)) { Session s = (Session) sessionList.getSelectedValue(); JMenuItem t; // Show label switching if (s == null) { return; } String l = s.isShow() ? "Hide" : "Show"; t = (JMenuItem) sessionPopupMenu.getComponent(0); t.setText(l); sessionPopupMenu.show(e.getComponent(), p.x, p.y); } else if (actionSource.equals(trackList)) { ((JList) e.getSource()).setSelectedIndex(index); // Update context-aware show/hide TrackSceneNode t = (TrackSceneNode) trackList.getSelectedValue(); if ((t != null) && (t.getId() >= 0)) { boolean isShown = SceneGraph.getTrackShow(t.getId()); String label = isShown ? "Hide" : "Show"; ((JMenuItem) trackPopupMenu.getComponent(0)).setText(label); } trackPopupMenu.show(e.getComponent(), p.x, p.y); } else if (actionSource.equals(sectionList)) { int[] rows = getSectionList().getSelectedIndices(); JPopupMenu menu = sectionListPopupMenu(rows); menu.show(e.getComponent(), p.x, p.y); } else if (actionSource.equals(dataFileList)) { ((JList) e.getSource()).setSelectedIndex(index); dataPopupMenu.show(e.getComponent(), p.x, p.y); } } } }
From source file:org.openconcerto.erp.core.humanresources.payroll.element.VariablePayeSQLElement.java
public SQLComponent createComponent() { return new BaseSQLComponent(this) { private ValidState validVarName; private JRadioButton radioVal = new JRadioButton("Valeur"); private JRadioButton radioFormule = new JRadioButton("Formule"); private final JTextField textValeur = new JTextField(); // private final ITextArea textFormule = new ITextArea(); private final VariableTree treeVariable = new VariableTree(); private final JTextField textNom = new JTextField(); private final JLabel labelWarningBadVar = new JLabelWarning(); private ElementComboBox comboSelSal; private EditFrame edit = null; private final SQLJavaEditor textFormule = new SQLJavaEditor(getMapTree()); public void addViews() { this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); this.validVarName = null; this.textFormule.setEditable(false); // Arbre des variables JScrollPane sc = new JScrollPane(this.treeVariable); sc.setPreferredSize(new Dimension(150, sc.getPreferredSize().height)); this.treeVariable.addMouseListener(new MouseAdapter() { public void mousePressed(final MouseEvent mE) { if (mE.getButton() == MouseEvent.BUTTON3) { JPopupMenu menuDroit = new JPopupMenu(); TreePath path = treeVariable.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y); final Object obj = path.getLastPathComponent(); if ((obj == null) || !(obj instanceof VariableRowTreeNode)) { return; }// ww w .j a v a2s.c om menuDroit.add(new AbstractAction("Editer") { public void actionPerformed(ActionEvent e) { if (edit == null) { edit = new EditFrame(getElement(), EditFrame.MODIFICATION); } System.err.println("Action performed"); if (obj != null) { System.err.println("Object not null --> " + obj.toString()); if (obj instanceof VariableRowTreeNode) { System.err.println("Object VariableRowTreeNode"); VariableRowTreeNode varNode = (VariableRowTreeNode) obj; edit.selectionId(varNode.getID(), 1); edit.setVisible(true); } } } }); menuDroit.show((Component) mE.getSource(), mE.getPoint().x, mE.getPoint().y); } else { if (mE.getClickCount() == 2) { TreePath path = treeVariable.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y); Object obj = path.getLastPathComponent(); if (obj != null) { if (obj instanceof FormuleTreeNode) { final FormuleTreeNode n = (FormuleTreeNode) obj; int start = textFormule.getSelectionStart(); String tmp = textFormule.getText(); textFormule.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length())); } } } } } }); JPanel panelDroite = new JPanel(); panelDroite.setLayout(new GridBagLayout()); // Categorie JTextField textCategorie = new JTextField(); c.fill = GridBagConstraints.HORIZONTAL; c.gridheight = 1; c.gridx = 1; c.gridy = 0; JLabel labelCategorie = new JLabel("Catgorie"); panelDroite.add(labelCategorie, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; panelDroite.add(textCategorie, c); c.gridwidth = 1; // Nom c.fill = GridBagConstraints.HORIZONTAL; c.gridheight = 1; c.gridx = 1; c.gridy++; JLabel labelNom = new JLabel("Nom"); panelDroite.add(labelNom, c); c.gridx++; c.weightx = 1; panelDroite.add(this.textNom, c); this.textNom.getDocument().addDocumentListener(new SimpleDocumentListener() { @Override public void update(DocumentEvent e) { updateValidVarName(); } }); c.gridx++; c.weightx = 0; panelDroite.add(this.labelWarningBadVar, c); // Description JLabel labelInfos = new JLabel(getLabelFor("INFOS")); ITextArea textInfos = new ITextArea(); c.gridy++; c.gridx = 1; c.gridwidth = 1; c.weightx = 0; panelDroite.add(labelInfos, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1; c.weighty = 0; panelDroite.add(textInfos, c); // Valeur c.gridx = 1; c.gridy++; c.gridwidth = 1; c.weightx = 0; panelDroite.add(this.radioVal, c); c.gridx++; c.weightx = 1; c.gridwidth = GridBagConstraints.REMAINDER; panelDroite.add(this.textValeur, c); c.gridwidth = 1; c.gridx = 1; c.gridy++; panelDroite.add(this.radioFormule, c); c.gridx++; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; panelDroite.add(this.textFormule, c); c.gridwidth = 1; ButtonGroup group = new ButtonGroup(); group.add(this.radioVal); group.add(this.radioFormule); this.radioVal.setSelected(true); setFormuleEnabled(false); this.radioVal.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setFormuleEnabled(false); } }); this.radioFormule.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setFormuleEnabled(true); } }); c.gridy++; c.gridx = 1; c.weighty = 0; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; this.comboSelSal = new ElementComboBox(false); this.comboSelSal.init(getDirectory().getElement(SalarieSQLElement.class)); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 0; panelDroite.add(this.comboSelSal, c); c.gridwidth = 1; JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sc, panelDroite); c.fill = GridBagConstraints.BOTH; c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1; this.add(split, c); this.addRequiredSQLObject(this.textNom, "NOM"); this.addSQLObject(this.textValeur, "VALEUR"); this.addSQLObject(this.textFormule, "FORMULE"); this.addSQLObject(textCategorie, "CATEGORIE"); this.addSQLObject(textInfos, "INFOS"); this.comboSelSal.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { // TODO Auto-generated method stub textFormule.setSalarieID(comboSelSal.getSelectedId()); } }); } @Override public synchronized ValidState getValidState() { return super.getValidState().and(this.validVarName); } private void setFormuleEnabled(boolean b) { if (b) { this.textValeur.setText(""); } else { this.textFormule.setText(""); } this.textValeur.setEditable(!b); this.textValeur.setEnabled(!b); this.textFormule.setEditable(b); this.textFormule.setEnabled(b); this.treeVariable.setEnabled(b); this.treeVariable.setEditable(b); } private void setValidVarName(ValidState s) { if (!s.equals(this.validVarName)) { this.validVarName = s; final boolean warningVisible = !s.isValid(); if (warningVisible) this.labelWarningBadVar.setText(s.getValidationText()); this.labelWarningBadVar.setVisible(warningVisible); this.fireValidChange(); } } private void updateValidVarName() { this.setValidVarName(this.computeValidVarName()); } private ValidState computeValidVarName() { // on vrifie si la syntaxe de la variable est correct (chiffre lettre et _) final String varName = this.textNom.getText().trim(); System.err.println("Verification de la validit du nom de la variable."); if (varName.length() == 0) { return VAR_NO_NAME; } // ne contient que des chiffre lettre et _ et ne commence pas par un chiffre if (!isJavaVar(varName)) { return VAR_NAME_NOT_CORRECT; } // on vrifie que la variable n'existe pas dja SQLSelect selAllVarName = new SQLSelect(getTable().getBase()); selAllVarName.addSelect(VariablePayeSQLElement.this.getTable().getField("ID")); Where w = new Where(VariablePayeSQLElement.this.getTable().getField("NOM"), "=", varName); w = w.and(new Where(VariablePayeSQLElement.this.getTable().getKey(), "!=", getSelectedID())); selAllVarName.setWhere(w); String reqAllVarName = selAllVarName.asString();// + " AND '" + varName.trim() + "' // REGEXP VARIABLE_PAYE.NOM"; Object[] objKeysRowName = ((List) getTable().getBase().getDataSource().execute(reqAllVarName, new ArrayListHandler())).toArray(); if (objKeysRowName.length > 0) { return VAR_ALREADY_EXIST; } else { // Impossible de crer une variable du meme nom qu'un champ du salarie if (isForbidden(varName)) return VAR_ALREADY_EXIST; this.textFormule.setVarAssign(varName); return ValidState.getTrueInstance(); } } private boolean isJavaVar(String s) { if ((s.charAt(0) >= '0') && ((s.charAt(0) <= '9'))) { System.err.println("Erreur la variable commence par un chiffre!!"); return false; } else { for (int i = 0; i < s.length(); i++) { if (!(((s.charAt(i) >= '0') && (s.charAt(i) <= '9')) || (s.charAt(i) >= 'a') && (s.charAt(i) <= 'z') || (s.charAt(i) >= 'A') && (s.charAt(i) <= 'Z') || (s.charAt(i) == '_'))) { System.err.println("Erreur la variable contient un caractere incorrect!!"); return false; } } return (!CTokenMarker.getKeywords().isExisting(s)); } } @Override public void select(SQLRowAccessor r) { super.select(r); // System.err.println("Select RowAccess -------> " + r.getID() + " For Object " + // this.hashCode()); if (r != null) { if (r.getString("FORMULE").trim().length() == 0) { this.radioVal.setSelected(true); setFormuleEnabled(false); } else { this.radioFormule.setSelected(true); setFormuleEnabled(true); } this.textFormule.setVarAssign(r.getString("NOM")); } this.updateValidVarName(); } }; }
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
private void selectionChartGroup(DBBrowserNode selectedNode, MouseEvent e) { if (e.getClickCount() == 2) { return;//from w w w . j a v a2s . c o m } JPopupMenu popupMenu = new JPopupMenu(); ImportChartAction importAction = new ImportChartAction(); JMenuItem menuItem = new JMenuItem(importAction); popupMenu.add(menuItem); JMenuItem menuItem2 = new JMenuItem(new AddFolderAction(this, selectedNode, DBObject.FOLDER_CHART)); popupMenu.add(menuItem2); JMenuItem menuItem3 = new JMenuItem(new ValidateSqlsAction(selectedNode.getDBObject())); popupMenu.add(menuItem3); JMenuItem menuItem4 = new JMenuItem(new PublishBulkChartAction()); popupMenu.add(menuItem4); JMenuItem menuItem5 = new JMenuItem( new DownloadBulkChartAction(FileReportPersistence.getChartsAbsolutePath())); popupMenu.add(menuItem5); popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); }
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
private void selectionReportGroup(DBBrowserNode selectedNode, MouseEvent e) { if (e.getClickCount() == 2) { return;/*from w w w . j a v a2s.c om*/ } ImportReportAction importAction = new ImportReportAction(); JPopupMenu popupMenu = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(importAction); popupMenu.add(menuItem); JMenuItem menuItem2 = new JMenuItem(new AddFolderAction(this, selectedNode, DBObject.FOLDER_REPORT)); popupMenu.add(menuItem2); JMenuItem menuItem3 = new JMenuItem(new ValidateSqlsAction(selectedNode.getDBObject())); popupMenu.add(menuItem3); JMenuItem menuItem4 = new JMenuItem(new PublishBulkReportAction()); popupMenu.add(menuItem4); JMenuItem menuItem5 = new JMenuItem( new DownloadBulkReportAction(FileReportPersistence.getReportsAbsolutePath())); popupMenu.add(menuItem5); popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); }
From source file:de.main.sessioncreator.DesktopApplication1View.java
public void getAreasBacgroundW(File f) { fileHelper.getAreas(f);/*from w w w. jav a 2s . c om*/ Iterator<Map.Entry<String, List>> it = fileHelper.areaMap.entrySet().iterator(); while (it.hasNext()) { DefaultListModel dlm = new DefaultListModel(); JList list = new JList(dlm); list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); JScrollPane scrollPane = new JScrollPane(list); scrollPane.getViewport().setView(list); Map.Entry en = it.next(); wizardtabpAreas.addTab(en.getKey().toString().substring(3), scrollPane); for (Object o : fileHelper.areaMap.get(en.getKey().toString())) { dlm.addElement(o); } MouseListener mouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent mouseEvent) { JList tabList = (JList) mouseEvent.getSource(); if (mouseEvent.getClickCount() == 2) { int index = tabList.locationToIndex(mouseEvent.getPoint()); if (index >= 0) { Object o = tabList.getModel().getElementAt(index); wizardtaChoosenAreas.append(o.toString() + "\n"); } } } }; list.addMouseListener(mouseListener); ListSelectionListener listListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { JList list = (JList) e.getSource(); if (e.getValueIsAdjusting() == false) { if (list.getSelectedIndex() == -1) { //No selection, disable add button. wizardbtnAddAreas.setEnabled(false); } else { //Selection, enable the add button. wizardbtnAddAreas.setEnabled(true); } } } }; list.addListSelectionListener(listListener); } }
From source file:de.tor.tribes.ui.windows.DSWorkbenchMainFrame.java
/** * Zoom main map//from w w w . ja v a2 s. co m */ private void fireZoomEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireZoomEvent if (evt.getSource() == jZoomInButton) { zoomIn(); } else { zoomOut(); } }
From source file:de.tor.tribes.ui.windows.DSWorkbenchMainFrame.java
private void fireChangeROIEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireChangeROIEvent if (evt.getSource() == jAddROIButton) { int x = UIHelper.parseIntFromField(jCenterX, (int) dCenterX); int y = UIHelper.parseIntFromField(jCenterY, (int) dCenterY); jROIRegion.setText("(" + x + "|" + y + ")"); jROIPosition.setSelectedIndex(jROIPosition.getItemCount() - 1); jAddROIDialog.setLocationRelativeTo(this); jAddROIDialog.setVisible(true);/*from w ww.j av a 2 s . c o m*/ } else { try { String item = (String) jROIBox.getSelectedItem(); logger.debug("Removing ROI '" + item + "'"); ROIManager.getSingleton().removeROI(item); jROIBox.removeItem(item); } catch (Exception ignored) { } } }
From source file:de.tor.tribes.ui.windows.DSWorkbenchMainFrame.java
private void fireAddROIDoneEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireAddROIDoneEvent if (evt.getSource() == jAddNewROIButton) { try {//from www . java2 s.co m int x = UIHelper.parseIntFromField(jCenterX, (int) dCenterX); int y = UIHelper.parseIntFromField(jCenterY, (int) dCenterY); String value = jROITextField.getText() + " (" + x + "|" + y + ")"; int pos = Integer.MAX_VALUE; try { pos = Integer.parseInt((String) jROIPosition.getSelectedItem()); pos -= 1; } catch (Exception ee) { //end pos selected pos = Integer.MAX_VALUE; } if (ROIManager.getSingleton().containsROI(value)) { JOptionPaneHelper.showWarningBox(this, "ROI '" + value + "' existiert bereits.", "ROI vorhanden"); return; } ROIManager.getSingleton().addROI(pos, value); jROIBox.setModel(new DefaultComboBoxModel(ROIManager.getSingleton().getROIs())); } catch (Exception e) { logger.error("Failed to add ROI", e); } } jAddROIDialog.setVisible(false); }
From source file:jp.massbank.spectrumsearch.SearchPage.java
/** * ?//from ww w . j av a 2 s .c o m * @param e */ private void recListPopup(MouseEvent e) { JTable tbl = null; JScrollPane pane = null; try { tbl = (JTable) e.getSource(); } catch (ClassCastException cce) { pane = (JScrollPane) e.getSource(); if (pane.equals(queryDbPane)) { tbl = queryDbTable; } else if (pane.equals(resultPane)) { tbl = resultTable; } if (pane.equals(queryFilePane)) { tbl = queryFileTable; } } int rowCnt = tbl.getSelectedRows().length; JMenuItem item1 = new JMenuItem("Show Record"); item1.addActionListener(new PopupShowRecordListener(tbl)); JMenuItem item2 = new JMenuItem("Multiple Display"); item2.addActionListener(new PopupMultipleDisplayListener(tbl)); // ? if (tbl.equals(queryFileTable)) { item1.setEnabled(false); item2.setEnabled(false); } else if (rowCnt == 0) { item1.setEnabled(false); item2.setEnabled(false); } else if (rowCnt == 1) { item1.setEnabled(true); item2.setEnabled(false); } else if (rowCnt > 1) { item1.setEnabled(false); item2.setEnabled(true); } // ? JPopupMenu popup = new JPopupMenu(); popup.add(item1); if (tbl.equals(resultTable)) { popup.add(item2); } popup.show(e.getComponent(), e.getX(), e.getY()); }
From source file:de.tor.tribes.ui.windows.DSWorkbenchMainFrame.java
/** * Update map movement/* www . j a va2 s . c o m*/ */ private void fireMoveMapEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireMoveMapEvent double cx = UIHelper.parseIntFromField(jCenterX, (int) dCenterX); double cy = UIHelper.parseIntFromField(jCenterY, (int) dCenterY); double mapFieldsH = MapPanel.getSingleton().getHeight() / (GlobalOptions.getSkin().getBasicFieldHeight() * dZoomFactor); double mapFieldsW = MapPanel.getSingleton().getWidth() / (GlobalOptions.getSkin().getBasicFieldWidth() * dZoomFactor); if (evt.getSource() == jMoveN) { cy -= mapFieldsH; } else if (evt.getSource() == jMoveNE) { cx += mapFieldsW; cy -= mapFieldsH; } else if (evt.getSource() == jMoveE) { cx += mapFieldsW; } else if (evt.getSource() == jMoveSE) { cx += mapFieldsW; cy += mapFieldsH; } else if (evt.getSource() == jMoveS) { cy += mapFieldsH; } else if (evt.getSource() == jMoveSW) { cx -= mapFieldsW; cy += mapFieldsH; } else if (evt.getSource() == jMoveW) { cx -= mapFieldsH; } else if (evt.getSource() == jMoveNW) { cx -= mapFieldsW; cy -= mapFieldsH; } centerPosition(cx, cy); }