List of usage examples for java.awt.event MouseEvent getButton
public int getButton()
From source file:com.joey.software.regionSelectionToolkit.controlers.ImageProfileTool.java
@Override public void mouseReleased(MouseEvent e) { processMouse(e.getPoint(), e.getButton()); }
From source file:NewGUI.Statistics.java
private void tbListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbListMouseClicked // TODO add your handling code here: if (evt.getButton() == MouseEvent.BUTTON3) { Point point = evt.getLocationOnScreen(); popupTable.setLocation(point);/*from ww w.jav a 2 s . c om*/ popupTable.setVisible(true); } }
From source file:gtu._work.ui.SvnLastestCommitInfoUI.java
private void initGUI() { try {/*from www . j av a 2 s. c o m*/ BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); this.setFocusable(false); this.setTitle("SVN lastest commit wather"); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("svn dir", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); { TableModel svnTableModel = new DefaultTableModel(); svnTable = new JTable(); jScrollPane1.setViewportView(svnTable); svnTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { try { if (evt.getButton() == 3) { final List<File> list = new ArrayList<File>(); SvnFile svnFile = null; final StringBuilder sb = new StringBuilder(); for (int row : svnTable.getSelectedRows()) { svnFile = (SvnFile) svnTable.getModel().getValueAt( svnTable.getRowSorter().convertRowIndexToModel(row), SvnTableColumn.SVN_FILE.pos); list.add(svnFile.file); sb.append(svnFile.file.getName() + ","); } if (sb.length() > 200) { sb.delete(200, sb.length() - 1); } JMenuItem copySelectedMeun = new JMenuItem(); copySelectedMeun.setText("copy selected file : " + list.size()); copySelectedMeun.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION != JOptionPaneUtil .newInstance().iconPlainMessage().confirmButtonYesNo() .showConfirmDialog( "are you sure copy files :\n" + sb + "\n???", "COPY SELECTED FILE : " + list.size())) { return; } final File copyToDir = JFileChooserUtil.newInstance() .selectDirectoryOnly().showOpenDialog() .getApproveSelectedFile(); if (copyToDir == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("dir folder is not correct!", "ERROR"); return; } new Thread(Thread.currentThread().getThreadGroup(), new Runnable() { public void run() { StringBuilder errMsg = new StringBuilder(); int errCount = 0; for (File f : list) { try { FileUtil.copyFile(f, new File(copyToDir, f.getName())); } catch (IOException e) { e.printStackTrace(); errCount++; errMsg.append(f + "\n"); } } JOptionPaneUtil.newInstance().iconPlainMessage() .showMessageDialog( "copy completed!\nerror : " + errCount + "\nerror list : \n" + errMsg, "COMPLETED"); } }, "copySelectedFiles_" + hashCode()).start(); } }); JMenuItem copySelectedOringTreeMeun = new JMenuItem(); copySelectedOringTreeMeun .setText("copy selected file (orign tree): " + list.size()); copySelectedOringTreeMeun.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION != JOptionPaneUtil .newInstance().iconPlainMessage().confirmButtonYesNo() .showConfirmDialog( "are you sure copy files :\n" + sb + "\n???", "COPY SELECTED FILE : " + list.size())) { return; } final File copyToDir = JFileChooserUtil.newInstance() .selectDirectoryOnly().showOpenDialog() .getApproveSelectedFile(); if (copyToDir == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("dir folder is not correct!", "ERROR"); return; } new Thread(Thread.currentThread().getThreadGroup(), new Runnable() { public void run() { File srcBaseDir = FileUtil .exportReceiveBaseDir(list); int cutLength = 0; if (srcBaseDir != null) { cutLength = srcBaseDir.getAbsolutePath() .length(); } StringBuilder errMsg = new StringBuilder(); int errCount = 0; File newFile = null; for (File f : list) { try { newFile = new File(copyToDir + "/" + f.getAbsolutePath() .substring(cutLength), f.getName()); newFile.getParentFile().mkdirs(); FileUtil.copyFile(f, newFile); } catch (IOException e) { e.printStackTrace(); errCount++; errMsg.append(f + "\n"); } } JOptionPaneUtil.newInstance().iconPlainMessage() .showMessageDialog( "copy completed!\nerror : " + errCount + "\nerror list : \n" + errMsg, "COMPLETED"); } }, "copySelectedFiles_orignTree_" + hashCode()).start(); } }); JPopupMenuUtil.newInstance(svnTable).applyEvent(evt) .addJMenuItem(copySelectedMeun, copySelectedOringTreeMeun) .show(); } if (!JMouseEventUtil.buttonLeftClick(2, evt)) { return; } int row = JTableUtil.newInstance(svnTable).getSelectedRow(); SvnFile svnFile = (SvnFile) svnTable.getModel().getValueAt(row, SvnTableColumn.SVN_FILE.pos); String command = String.format("cmd /c call \"%s\"", svnFile.file); System.out.println(command); try { Runtime.getRuntime().exec(command); } catch (IOException e) { e.printStackTrace(); } } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); svnTable.setModel(svnTableModel); JTableUtil.defaultSetting(svnTable); } } { jPanel3 = new JPanel(); jPanel1.add(jPanel3, BorderLayout.NORTH); jPanel3.setPreferredSize(new java.awt.Dimension(379, 35)); { filterText = new JTextField(); jPanel3.add(filterText); filterText.setPreferredSize(new java.awt.Dimension(258, 24)); filterText.getDocument() .addDocumentListener(JCommonUtil.getDocumentListener(new HandleDocumentEvent() { public void process(DocumentEvent event) { try { String scanText = JCommonUtil.getDocumentText(event); reloadSvnTable(scanText, _defaultScanProcess); } catch (Exception ex) { JCommonUtil.handleException(ex); } } })); } { choiceSvnDir = new JButton(); jPanel3.add(choiceSvnDir); choiceSvnDir.setText("choice svn dir"); choiceSvnDir.setPreferredSize(new java.awt.Dimension(154, 24)); choiceSvnDir.addActionListener(new ActionListener() { Pattern svnOutputPattern = Pattern .compile("\\s*(\\d*)\\s+(\\d+)\\s+(\\w+)\\s+([\\S]+)"); public void actionPerformed(ActionEvent evt) { try { System.out.println("choiceSvnDir.actionPerformed, event=" + evt); final File svnDir = JFileChooserUtil.newInstance().selectDirectoryOnly() .showOpenDialog().getApproveSelectedFile(); if (svnDir == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("dir is not correct!", "ERROR"); return; } Thread thread = new Thread(Thread.currentThread().getThreadGroup(), new Runnable() { public void run() { long startTime = System.currentTimeMillis(); String command = String .format("cmd /c svn status -v \"%s\"", svnDir); Matcher matcher = null; try { long projectLastestVersion = 0; SvnFile svnFile = null; Process process = Runtime.getRuntime().exec(command); BufferedReader reader = new BufferedReader( new InputStreamReader(process.getInputStream(), "BIG5")); for (String line = null; (line = reader .readLine()) != null;) { matcher = svnOutputPattern.matcher(line); if (matcher.find()) { try { if (StringUtils .isNotBlank(matcher.group(1))) { projectLastestVersion = Math.max( projectLastestVersion, Long.parseLong( matcher.group(1))); } svnFile = new SvnFile(); svnFile.lastestVersion = Long .parseLong(matcher.group(2)); svnFile.author = matcher.group(3); svnFile.filePath = matcher.group(4); svnFile.file = new File(svnFile.filePath); svnFile.fileName = svnFile.file.getName(); svnFileSet.add(svnFile); authorSet.add(svnFile.author); String extension = null; if (svnFile.file.isFile() && (extension = getExtension( svnFile.fileName)) != null) { fileExtenstionSet.add(extension); } } catch (Exception ex) { ex.printStackTrace(); } } else { System.out.println("ignore : " + line); } } reader.close(); lastestVersion = projectLastestVersion; projectName = svnDir.getName(); resetUiAndShowMessage(startTime, projectName, projectLastestVersion); } catch (IOException e) { JCommonUtil.handleException(e); } } }, "loadSvnLastest_" + this.hashCode()); thread.setDaemon(true); thread.start(); setTitle("sweeping..."); } catch (Exception ex) { JCommonUtil.handleException(ex); } } String getExtension(String name) { int pos = -1; if ((pos = name.lastIndexOf(".")) != -1) { return name.substring(pos).toLowerCase(); } return null; } }); } { jLabel1 = new JLabel(); jPanel3.add(jLabel1); jLabel1.setText("match :"); jLabel1.setPreferredSize(new java.awt.Dimension(56, 22)); } { matchCount = new JLabel(); jPanel3.add(matchCount); matchCount.setPreferredSize(new java.awt.Dimension(82, 22)); } } } { jPanel2 = new JPanel(); FlowLayout jPanel2Layout = new FlowLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("config", null, jPanel2, null); { DefaultComboBoxModel authorComboBoxModel = new DefaultComboBoxModel(); authorComboBox = new JComboBox(); jPanel2.add(authorComboBox); authorComboBox.setModel(authorComboBoxModel); authorComboBox.setPreferredSize(new java.awt.Dimension(260, 24)); authorComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { Object author = authorComboBox.getSelectedItem(); if (author instanceof Map.Entry) { Map.Entry<?, ?> entry = (Map.Entry<?, ?>) author; reloadSvnTable((String) entry.getKey(), _authorScanProcess); } else { reloadSvnTable((String) author, _authorScanProcess); } } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); } { ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(); fileExtensionComboBox = new JComboBox(); jPanel2.add(fileExtensionComboBox); fileExtensionComboBox.setModel(jComboBox1Model); fileExtensionComboBox.setPreferredSize(new java.awt.Dimension(186, 24)); fileExtensionComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { String extension = (String) fileExtensionComboBox.getSelectedItem(); reloadSvnTable(extension, _fileExtensionScanProcess); } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); } { jScrollPane2 = new JScrollPane(); jScrollPane2.setPreferredSize(new java.awt.Dimension(130, 200)); jPanel2.add(jScrollPane2); { DefaultListModel model = new DefaultListModel(); fileExtensionFilter = new JList(); jScrollPane2.setViewportView(fileExtensionFilter); fileExtensionFilter.setModel(model); fileExtensionFilter.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { try { System.out .println(Arrays.toString(fileExtensionFilter.getSelectedValues())); String extensionStr = ""; StringBuilder sb = new StringBuilder(); for (Object val : fileExtensionFilter.getSelectedValues()) { sb.append(val + ","); } extensionStr = (sb.length() > 0 ? sb.deleteCharAt(sb.length() - 1) : sb) .toString(); System.out.format("extensionStr = [%s]\n", extensionStr); multiExtendsionFilter.setName(extensionStr); } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); } } { multiExtendsionFilter = new JButton(); jPanel2.add(multiExtendsionFilter); multiExtendsionFilter.setText("multi extension filter"); multiExtendsionFilter.setPreferredSize(new java.awt.Dimension(166, 34)); multiExtendsionFilter.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { reloadSvnTable(multiExtendsionFilter.getName(), _fileExtensionMultiScanProcess); } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); } { loadAuthorReference = new JButton(); jPanel2.add(loadAuthorReference); loadAuthorReference.setText("load author reference"); loadAuthorReference.setPreferredSize(new java.awt.Dimension(188, 35)); loadAuthorReference.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { File file = JFileChooserUtil.newInstance().selectFileOnly().showOpenDialog() .getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("file is not correct!", "ERROR"); return; } authorProps.load(new FileInputStream(file)); reloadAuthorComboBox(); } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); } { saveCurrentData = new JButton(); jPanel2.add(saveCurrentData); saveCurrentData.setText("save current data"); saveCurrentData.setPreferredSize(new java.awt.Dimension(166, 34)); saveCurrentData.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { File saveDataConfig = new File(jarExistLocation, getSaveCurrentDataFileName()); ObjectOutputStream writer = new ObjectOutputStream( new FileOutputStream(saveDataConfig)); writer.writeObject(projectName); writer.writeObject(authorSet); writer.writeObject(fileExtenstionSet); writer.writeObject(svnFileSet); writer.writeObject(authorProps); writer.writeObject(lastestVersion); writer.flush(); writer.close(); JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("current project : " + projectName + " save completed! \n" + saveDataConfig, "SUCCESS"); } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); } { loadDataFromFile = new JButton(); jPanel2.add(loadDataFromFile); loadDataFromFile.setText("load data cfg"); loadDataFromFile.setPreferredSize(new java.awt.Dimension(165, 35)); loadDataFromFile.addActionListener(new ActionListener() { @SuppressWarnings("unchecked") public void actionPerformed(ActionEvent evt) { try { File file = JFileChooserUtil.newInstance().selectFileOnly() .addAcceptFile(".cfg", ".cfg").showOpenDialog() .getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("file is not correct!", "ERROR"); return; } long startTime = System.currentTimeMillis(); ObjectInputStream input = new ObjectInputStream(new FileInputStream(file)); projectName = (String) input.readObject(); authorSet = (Set<String>) input.readObject(); fileExtenstionSet = (Set<String>) input.readObject(); svnFileSet = (Set<SvnFile>) input.readObject(); authorProps = (Properties) input.readObject(); lastestVersion = (Long) input.readObject(); input.close(); resetUiAndShowMessage(startTime, projectName, lastestVersion); } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); } } } pack(); this.setSize(726, 459); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ctsim.simemua_instructor.ACarControlPanelFrame.java
private void viewPanelMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_viewPanelMousePressed Device dev;//from w ww .ja va 2s .c o m try { Iterator<Device> devs = DEVS.values().iterator(); //save data devices to iterator. while (devs.hasNext()) { //loop next to device dev = (Device) (devs.next()); //save key //x >= current position x and x <= (current position x + width) become area x if ((x >= dev.getX() & x <= (dev.getX() + dev.getWidth())) & (y >= dev.getY() & y <= (dev.getY() + dev.getHeight()))) { mousePressed = true; //Check device type event on clicked. If type equal Switch Rotary Black. if (dev.getType().equalsIgnoreCase("Switch Rotary Black")) { doRotarySwitchPress(evt.getButton(), dev, switchYesNoBlackOnImg, switchYesNoBlackOffImg); } else if (dev.getType().equalsIgnoreCase("Switch Rotary Yellow")) { doRotarySwitchPress(evt.getButton(), dev, switchRotaryYellowOnImg, switchRotaryYellowOffImg); } else if (dev.getType().equalsIgnoreCase("Switch PB Permit")) { doPBSwitchPress(dev, switchPBPermitOnImg); } else if (dev.getType().equalsIgnoreCase("Switch PB Square Black")) { doPBSwitchPress(dev, switchPBSquareBlackOnImg); } } } } catch (Exception ex) { Logger.getLogger(DriverDeskFrame.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.openconcerto.erp.core.finance.accounting.element.AnalytiqueSQLElement.java
public SQLComponent createComponent() { return new BaseSQLComponent(this) { public void addViews() { this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); c.anchor = GridBagConstraints.NORTHWEST; c.gridwidth = 4;//from w w w . j a v a 2 s . co m c.gridheight = 8; vecteurTabAxe = new Vector(); repartitionsAxe = new Vector(); repartitionElemsAxe = new Vector(); postesAxe = new Vector(); tabAxes = new JTabbedPane(); /*********************************************************************************** * * CREATION DES ONGLETS **********************************************************************************/ // on recupere les axes existant // SELECT ID, NOM FROM AXE SQLBase base = getTable().getBase(); SQLSelect sel = new SQLSelect(base); sel.addSelect(getTable().getKey()); sel.addSelect(getTable().getField("NOM")); sel.addRawOrder("AXE_ANALYTIQUE.NOM"); String req = sel.asString(); Object ob = getTable().getBase().getDataSource().execute(req, new ArrayListHandler()); List myList = (List) ob; if (myList.size() != 0) { // on cre les onglets et on stocke les axes for (int i = 0; i < myList.size(); i++) { // ID, nom Object[] objTmp = (Object[]) myList.get(i); axes.add(new Axe(Integer.parseInt(objTmp[0].toString()), objTmp[1].toString())); // on recupere les repartitions et les lements associs l'axe RepartitionAxeAnalytiquePanel repAxeComp = new RepartitionAxeAnalytiquePanel( ((Axe) axes.get(i)).getId()); repartitionsAxe.add(repAxeComp.getRepartitions()); repartitionElemsAxe.add(repAxeComp.getRepartitionElems()); postesAxe.add(repAxeComp.getPostes()); tabAxes.addTab(((Axe) axes.get(i)).getNom(), repAxeComp); vecteurTabAxe.add(i, new String(String.valueOf(i))); } System.out.println("Size ----> " + axes.size()); } else { ajouterAxe("Nouvel Axe"); } c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; this.add(tabAxes, c); tabAxes.addMouseListener(new MouseAdapter() { public void mousePressed(final MouseEvent e) { final int index = tabAxes.indexAtLocation(e.getX(), e.getY()); validAxeText(); if (e.getClickCount() == 2) { actionModifierAxe(e, index); } if (e.getButton() == MouseEvent.BUTTON3) { actionDroitOnglet(index, e); } } }); tabAxes.addAncestorListener(new AncestorListener() { public void ancestorAdded(AncestorEvent event) { validAxeText(); } public void ancestorRemoved(AncestorEvent event) { validAxeText(); } public void ancestorMoved(AncestorEvent event) { validAxeText(); } }); /*********************************************************************************** * * AJOUT D'UN AXE **********************************************************************************/ JButton boutonAddAxe = new JButton("Ajouter un axe"); boutonAddAxe.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (ajoutAxeFrame == null) { ajoutAxeFrame = new AjouterAxeAnalytiqueFrame(a); } ajoutAxeFrame.pack(); ajoutAxeFrame.setVisible(true); } }); c.gridx += 4; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; this.add(boutonAddAxe, c); /*********************************************************************************** * * SUPPRESSION D'UN AXE **********************************************************************************/ JButton boutonDelAxe = new JButton("Supprimer un axe"); boutonDelAxe.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { supprimerAxe(Integer.parseInt(vecteurTabAxe.get(tabAxes.getSelectedIndex()).toString())); } }); c.gridy++; this.add(boutonDelAxe, c); JButton boutonSet = new JButton("SetVal"); boutonSet.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { setVal(); } }); c.gridy++; this.add(boutonSet, c); JButton boutonCheck = new JButton("Check"); boutonCheck.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { checkID(); } }); c.gridy++; this.add(boutonCheck, c); } }; }
From source file:net.sf.firemox.Magic.java
public void mouseClicked(MouseEvent e) { Object obj = e.getSource();/*from ww w . j a v a2s.c o m*/ if (obj == skipButton) { /** * invoked by a click directly on the "skip/cancel" of the label". * * @param evt * mouse event * @see MEventManager#raiseEvent(int,boolean) * @see MEventManager#getNextStop() * @see MPhase#breakpoint * @see MPhase#skipAll * @see Magic#manuaSkip() */ // only if enabled and left mouse button pressed StackManager.noReplayToken.take(); try { if (ConnectionManager.isConnected() && skipButton.isEnabled() && e.getButton() == MouseEvent.BUTTON1) { manualSkip(); } } catch (Throwable t) { t.printStackTrace(); } finally { StackManager.noReplayToken.release(); } } }
From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java
/** * System Tray Icon setup//w w w.j a va 2s. com * @param frame owner JFrame */ private void setupTrayIcon(final JFrame frame) { // Idle Icon idleIcon = Toolkit.getDefaultToolkit() .getImage(ClassLoader.getSystemResource("META-INF/resources/cluster_inactive.png")); // Active Icon activeIcon = Toolkit.getDefaultToolkit() .getImage(ClassLoader.getSystemResource("META-INF/resources/cluster_active.png")); frame.setIconImage(idleIcon); // If system tray is supported by OS if (SystemTray.isSupported()) { // Set Icon trayIcon = new TrayIcon(idleIcon, "Nebula Grid Cluster", createTrayPopup()); trayIcon.setImageAutoSize(true); trayIcon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { if (!frame.isVisible()) { frame.setVisible(true); } frame.setExtendedState(JFrame.NORMAL); frame.requestFocus(); frame.toFront(); } } }); try { SystemTray.getSystemTray().add(trayIcon); } catch (AWTException ae) { log.debug("[UI] Unable to Initialize Tray Icon"); return; } frame.addWindowListener(new WindowAdapter() { @Override public void windowIconified(WindowEvent e) { // Hide (can be shown using tray icon) frame.setVisible(false); } }); } }
From source file:org.openconcerto.erp.core.finance.accounting.ui.PlanComptableGPanel.java
public JTable creerJTable(ClasseCompte ccTmp) { // NO_UCD final PlanComptableGModel model; if (this.radioCompteDeveloppe.isSelected()) { model = new PlanComptableGModel(ccTmp, 3); } else if (this.radioCompteAbrege.isSelected()) { model = new PlanComptableGModel(ccTmp, 2); } else {//ww w . ja va 2 s. c om model = new PlanComptableGModel(ccTmp, 1); } final JTable table = new JTable(model) { public JToolTip createToolTip() { JMultiLineToolTip t = new JMultiLineToolTip(); t.setFixedWidth(500); return t; } }; table.getColumnModel().getColumn(0).setCellRenderer(new PlanComptableCellRenderer(0)); table.getColumnModel().getColumn(1).setCellRenderer(new PlanComptableCellRenderer(0)); // TODO calcul de la taille de la colone numero de compte table.getColumnModel().getColumn(0).setMaxWidth(90); table.getTableHeader().setReorderingAllowed(false); table.addMouseMotionListener(new MouseMotionAdapter() { int lastRow = -1; public void mouseMoved(final MouseEvent e) { final Point p = new Point(e.getX(), e.getY()); SwingUtilities.invokeLater(new Runnable() { public void run() { final int row = table.rowAtPoint(p); if (lastRow != row) { lastRow = row; String strTmp = ((Compte) (model.getComptes().get(lastRow))).getInfos(); if (strTmp.length() != 0) { table.setToolTipText(strTmp); } else { table.setToolTipText(null); } } } }); } }); if (this.actionClickDroit != null) { // System.out.println("Ajout menu droit"); table.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { actionDroitTable(e, table); } } }); } // Enable row selection (default) /** * table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true); * * table.setSelectionMode(table.getSelectionModel().MULTIPLE_INTERVAL_SELECTION); */ table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { int selectedRow = table.getSelectedRow(); if (selectedRow < 0) { // Pas de selection textInfos.setText("Pas de compte slctionn"); } else { textInfos.setText(((Compte) (model.getComptes().get(selectedRow))).getInfos()); } } }); return table; }
From source file:org.jas.gui.MainWindow.java
public JTable getDescriptionTable() { if (descriptionTable == null) { descriptionTable = new DescriptionTable(); descriptionTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { MetadataDialog metadataDialog = new MetadataDialog(MainWindow.this, controlEngineConfigurator, "Alter ALL rows"); metadataDialog.setVisible(true); }// w w w. ja v a2s. c o m } }); descriptionTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (tableLoaded) { selectedRow = descriptionTable.getSelectedRow(); log.info("SETTING SELECTED ROW to : " + selectedRow); updateImage(selectedRow); } } }); descriptionTable.getModel().addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { if (e.getType() == TableModelEvent.UPDATE && tableLoaded && e.getColumn() != ApplicationState.STATUS_COLUMN) { int column = e.getColumn(); int row = e.getFirstRow(); String value = getDescriptionTable().getModel().getValueAt(row, column).toString(); log.info("value changed: " + value); List<Metadata> metadataList = viewEngineConfigurator.getViewEngine().get(Model.METADATA); Metadata metadata = metadataList.get(row); metadataAdapter.update(metadata, column, value); metadataWithAlbum.add(metadata); getDescriptionTable().getModel().setValueAt(ActionResult.New, row, ApplicationState.STATUS_COLUMN); controlEngineConfigurator.getControlEngine().set(Model.METADATA_ARTIST, metadataWithAlbum, null); getApplyButton().setEnabled(!working); log.info("setting applyButton to : " + !working); } } }); } return descriptionTable; }
From source file:de.tor.tribes.ui.panels.MinimapPanel.java
/** * Creates new form MinimapPanel/* www.j av a 2 s. c o m*/ */ MinimapPanel() { initComponents(); setSize(300, 300); mMinimapListeners = new LinkedList<>(); mToolChangeListeners = new LinkedList<>(); setCursor(ImageManager.getCursor(iCurrentCursor)); mScreenshotPanel = new ScreenshotPanel(); minimapButtons.put(ID_MINIMAP, new Rectangle(2, 2, 26, 26)); minimapButtons.put(ID_ALLY_CHART, new Rectangle(30, 2, 26, 26)); minimapButtons.put(ID_TRIBE_CHART, new Rectangle(60, 2, 26, 26)); try { minimapIcons.put(ID_MINIMAP, ImageIO.read(new File("./graphics/icons/minimap.png"))); minimapIcons.put(ID_ALLY_CHART, ImageIO.read(new File("./graphics/icons/ally_chart.png"))); minimapIcons.put(ID_TRIBE_CHART, ImageIO.read(new File("./graphics/icons/tribe_chart.png"))); } catch (Exception ignored) { } jPanel1.add(mScreenshotPanel); rVisiblePart = new Rectangle(ServerSettings.getSingleton().getMapDimension()); zoomed = false; MarkerManager.getSingleton().addManagerListener(this); TagManager.getSingleton().addManagerListener(this); MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart); if (!GlobalOptions.isMinimal()) { MinimapRepaintThread.getSingleton().start(); } addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (!showControls && e.getButton() != MouseEvent.BUTTON1) { //show controls Point p = e.getPoint(); p.translate(-5, -5); showControls(p); return; } if (!showControls && iCurrentView == ID_MINIMAP) { Point p = mousePosToMapPosition(e.getX(), e.getY()); DSWorkbenchMainFrame.getSingleton().centerPosition(p.getX(), p.getY()); MapPanel.getSingleton().getMapRenderer().initiateRedraw(MapRenderer.ALL_LAYERS); if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().toFront(); } } else { if (minimapButtons.get(ID_MINIMAP).contains(e.getPoint())) { iCurrentView = ID_MINIMAP; mBuffer = null; showControls = false; MinimapRepaintThread.getSingleton().update(); } else if (minimapButtons.get(ID_ALLY_CHART).contains(e.getPoint())) { iCurrentView = ID_ALLY_CHART; lastHash = 0; showControls = false; updateComplete(); } else if (minimapButtons.get(ID_TRIBE_CHART).contains(e.getPoint())) { iCurrentView = ID_TRIBE_CHART; lastHash = 0; showControls = false; updateComplete(); } } } @Override public void mousePressed(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } if (iCurrentCursor == ImageManager.CURSOR_SHOT || iCurrentCursor == ImageManager.CURSOR_ZOOM) { iXDown = e.getX(); iYDown = e.getY(); } } @Override public void mouseReleased(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } if (rDrag == null) { return; } if (iCurrentCursor == ImageManager.CURSOR_SHOT) { try { BufferedImage i = MinimapRepaintThread.getSingleton().getImage(); double widthFactor = ((double) ServerSettings.getSingleton().getMapDimension().width) / getWidth(); double heightFactor = ((double) ServerSettings.getSingleton().getMapDimension().height) / getHeight(); int x = (int) Math.rint(widthFactor * rDrag.getX()); int y = (int) Math.rint(heightFactor * rDrag.getY()); int w = (int) Math.rint(widthFactor * (rDrag.getWidth() - rDrag.getX())); int h = (int) Math.rint(heightFactor * (rDrag.getHeight() - rDrag.getY())); BufferedImage sub = i.getSubimage(x, y, w, h); mScreenshotPanel.setBuffer(sub); jPanel1.setSize(mScreenshotPanel.getSize()); jPanel1.setPreferredSize(mScreenshotPanel.getSize()); jPanel1.setMinimumSize(mScreenshotPanel.getSize()); jPanel1.setMaximumSize(mScreenshotPanel.getSize()); jScreenshotPreview.pack(); jScreenshotControl.pack(); jScreenshotPreview.setVisible(true); jScreenshotControl.setVisible(true); } catch (Exception ie) { logger.error("Failed to initialize mapshot", ie); } } else if (iCurrentCursor == ImageManager.CURSOR_ZOOM) { if (!zoomed) { Rectangle mapDim = ServerSettings.getSingleton().getMapDimension(); double widthFactor = ((double) mapDim.width) / getWidth(); double heightFactor = ((double) mapDim.height) / getHeight(); int x = (int) Math.rint(widthFactor * rDrag.getX() + mapDim.getMinX()); int y = (int) Math.rint(heightFactor * rDrag.getY() + mapDim.getMinY()); int w = (int) Math.rint(widthFactor * (rDrag.getWidth() - rDrag.getX())); if (w >= 10) { rVisiblePart = new Rectangle(x, y, w, w); MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart); redraw(); zoomed = true; } } else { rVisiblePart = new Rectangle(ServerSettings.getSingleton().getMapDimension()); MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart); redraw(); zoomed = false; } MinimapZoomFrame.getSingleton().setVisible(false); } iXDown = 0; iYDown = 0; rDrag = null; } @Override public void mouseEntered(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } switch (iCurrentCursor) { case ImageManager.CURSOR_ZOOM: { MinimapZoomFrame.getSingleton().setVisible(true); } } } @Override public void mouseExited(MouseEvent e) { if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(false); } iXDown = 0; iYDown = 0; rDrag = null; } }); addMouseMotionListener(new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } switch (iCurrentCursor) { case ImageManager.CURSOR_MOVE: { Point p = mousePosToMapPosition(e.getX(), e.getY()); DSWorkbenchMainFrame.getSingleton().centerPosition(p.x, p.y); rDrag = null; break; } case ImageManager.CURSOR_SHOT: { rDrag = new Rectangle2D.Double(iXDown, iYDown, e.getX(), e.getY()); break; } case ImageManager.CURSOR_ZOOM: { rDrag = new Rectangle2D.Double(iXDown, iYDown, e.getX(), e.getY()); break; } } } @Override public void mouseMoved(MouseEvent e) { if (iCurrentView == ID_MINIMAP) { switch (iCurrentCursor) { case ImageManager.CURSOR_ZOOM: { if (!MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(true); } int mapWidth = (int) ServerSettings.getSingleton().getMapDimension().getWidth(); int mapHeight = (int) ServerSettings.getSingleton().getMapDimension().getHeight(); int x = (int) Math.rint((double) mapWidth / (double) getWidth() * (double) e.getX()); int y = (int) Math.rint((double) mapHeight / (double) getHeight() * (double) e.getY()); MinimapZoomFrame.getSingleton().updatePosition(x, y); break; } default: { if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(false); } } } } Point location = minimapButtons.get(ID_MINIMAP).getLocation(); location.translate(-2, -2); if (!new Rectangle(location.x, location.y, 88, 30).contains(e.getPoint())) { //hide controls showControls = false; repaint(); } } }); addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { if (iCurrentView != ID_MINIMAP) { return; } iCurrentCursor += e.getWheelRotation(); if (iCurrentCursor == ImageManager.CURSOR_DEFAULT + e.getWheelRotation()) { if (e.getWheelRotation() < 0) { iCurrentCursor = ImageManager.CURSOR_SHOT; } else { iCurrentCursor = ImageManager.CURSOR_MOVE; } } else if (iCurrentCursor < ImageManager.CURSOR_MOVE) { iCurrentCursor = ImageManager.CURSOR_DEFAULT; } else if (iCurrentCursor > ImageManager.CURSOR_SHOT) { iCurrentCursor = ImageManager.CURSOR_DEFAULT; } if (iCurrentCursor != ImageManager.CURSOR_ZOOM) { if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(false); } } else { MinimapZoomFrame.getSingleton().setVisible(true); } setCurrentCursor(iCurrentCursor); } }); }