List of usage examples for javax.swing JTable addMouseListener
public synchronized void addMouseListener(MouseListener l)
From source file:org.nuclos.client.main.MainController.java
private Map<String, Map<String, Action>> getCommandMap() { HashMap<String, Map<String, Action>> res = new HashMap<String, Map<String, Action>>(); HashMap<String, Action> mainController = new HashMap<String, Action>(); /* that's too cumbersome: mainController.put(/*from w w w . j a v a 2 s . co m*/ "cmdChangePassword", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { cmdChangePassword(); } }); */ mainController.put("cmdDirectHelp", cmdDirectHelp); mainController.put("cmdShowPersonalTasks", cmdShowPersonalTasks); mainController.put("cmdShowTimelimitTasks", cmdShowTimelimitTasks); mainController.put("cmdShowPersonalSearchFilters", cmdShowPersonalSearchFilters); mainController.put("cmdChangePassword", cmdChangePassword); mainController.put("cmdOpenSettings", cmdOpenSettings); mainController.put("cmdOpenManagementConsole", cmdOpenManagementConsole); //mainController.put("cmdOpenEntityWizard", cmdOpenEntityWizard); mainController.put("cmdOpenRelationEditor", cmdOpenRelationEditor); mainController.put("cmdOpenCustomComponentWizard", cmdOpenCustomComponentWizard); //mainController.put("cmdRefreshClientCaches", cmdRefreshClientCaches); mainController.put("cmdSelectAll", cmdSelectAll); mainController.put("cmdHelpContents", cmdHelpContents); mainController.put("cmdShowAboutDialog", cmdShowAboutDialog); mainController.put("cmdShowProjectReleaseNotes", cmdShowProjectReleaseNotes); mainController.put("cmdShowNuclosReleaseNotes", cmdShowNuclosReleaseNotes); mainController.put("cmdLogoutExit", cmdLogoutExit); mainController.put("cmdWindowClosing", cmdWindowClosing); mainController.put("cmdExecuteRport", cmdExecuteRport); for (Method m : getClass().getDeclaredMethods()) { if (m.getName().startsWith("cmd")) { Class<?>[] pt = m.getParameterTypes(); if (pt.length == 0 || (pt.length == 1 && pt[0].isAssignableFrom(ActionEvent.class))) { final Method fm = m; Action a = new AbstractAction(m.getName()) { @Override public void actionPerformed(ActionEvent e) { miDelegator(e, fm); } }; mainController.put(m.getName(), a); } } } res.put("MainController", mainController); HashMap<String, Action> clipboardUtils = new HashMap<String, Action>(); clipboardUtils.put("cutAction", new ClipboardUtils.CutAction()); clipboardUtils.put("copyAction", new ClipboardUtils.CopyAction()); clipboardUtils.put("pasteAction", new ClipboardUtils.PasteAction()); res.put("ClipboardUtils", clipboardUtils); HashMap<String, Action> dev = new HashMap<String, Action>(); dev.put("jmsNotification", new AbstractAction("Test JMS notification") { @Override public void actionPerformed(ActionEvent e) { String s = JOptionPane.showInputDialog(getMainFrame(), "Topic: Message"); if (s == null) return; String[] a = s.split(": *"); if (a.length == 2) { // testFacadeRemote.testClientNotification(a[0], a[1]); throw new UnsupportedOperationException("TestFacade removed"); } else { JOptionPane.showMessageDialog(getMainFrame(), "Wrong input format"); } } }); dev.put("webPrefs", new AbstractAction("Test Web Prefs-Access") { @Override public void actionPerformed(ActionEvent e) { String s = JOptionPane.showInputDialog(getMainFrame(), "Access-Path"); if (s == null) return; try { Map<String, String> m = getWebAccessPrefs().getPrefsMap(s); StringBuilder sb = new StringBuilder(); for (String k : m.keySet()) sb.append(k).append(": ").append(m.get(k)).append("\n"); JOptionPane.showMessageDialog(getMainFrame(), sb.toString()); } catch (CommonBusinessException e1) { Errors.getInstance().showExceptionDialog(getMainFrame(), e1); } } }); dev.put("uiDefaults", new AbstractAction("UIDefaults") { @Override public void actionPerformed(ActionEvent e) { JFrame out = new JFrame("UIDefaults"); out.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); out.getContentPane().setLayout(new BorderLayout()); final UIDefTableModel mdl = new UIDefTableModel(); final JTable contentTable = new JTable(mdl); JScrollPane sp = new JScrollPane(contentTable); out.getContentPane().add(sp, BorderLayout.CENTER); UIDefaults defs = UIManager.getDefaults(); for (Object key : CollectionUtils.iterableEnum((defs.keys()))) mdl.add(key.toString(), defs.get(key)); mdl.sort(); contentTable.getColumnModel().getColumn(1).setCellRenderer(new UIDefaultsRenderer()); contentTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int row = contentTable.rowAtPoint(e.getPoint()); mdl.forceValue(contentTable.convertRowIndexToModel(row)); } }); out.pack(); out.setVisible(true); } }); dev.put("checkJawin", new AbstractAction("Check Jawin") { @Override public void actionPerformed(ActionEvent e) { try { SystemUtils.checkJawin(); JOptionPane.showMessageDialog(Main.getInstance().getMainFrame(), "Jawin ok"); } catch (Exception ex) { Errors.getInstance().showDetailedExceptionDialog(Main.getInstance().getMainFrame(), ex); } } }); res.put("Dev", dev); return res; }
From source file:org.nuclos.client.ui.collect.CollectController.java
/** * alternative entry point: view search result (in Results tab) * @precondition this.isSearchPanelAvailable() * * @deprecated Move to ResultController. *//*from w ww .j a v a2s .c o m*/ public final void runViewResults(final ICollectableListOfValues clctlovSource) throws CommonBusinessException { // remove mouse listener for double click in table: final JTable tbl = this.getResultTable(); tbl.removeMouseListener(this.getMouseListenerForTableDoubleClick()); // add alternative mouse listener for foreign key lookup: foreignKeyMouseListenerForTableDoubleClick = new MouseAdapter() { @Override public void mouseClicked(MouseEvent ev) { if (SwingUtilities.isLeftMouseButton(ev) && ev.getClickCount() == 2) { try { final Collectable clctSelected = CollectController.this.getCompleteSelectedCollectable(); // TODO assert clctSelected != null ? if (clctSelected != null) { clctlovSource.acceptLookedUpCollectable(clctSelected); // remove the mouse listener after it has done its job: // tbl.removeMouseListener(this); // TODO may whatever mouselistener was installed should be removed from the table in "close()" // Note that Controller.close() is called implicitly here: getTab().dispose(); } } catch (Exception ex) { Errors.getInstance().showExceptionDialog(getTab(), ex); } } } }; tbl.addMouseListener(foreignKeyMouseListenerForTableDoubleClick); if (!this.isSearchPanelAvailable()) { throw new IllegalStateException("this.isSearchPanelAvailable()"); } this.setCollectableSearchConditionInSearchPanel(clctlovSource.getCollectableSearchCondition()); this.selectTab(); getResultController().getSearchResultStrategy().cmdSearch(); this.getCollectPanel().setTabbedPaneEnabledAt(CollectState.OUTERSTATE_DETAILS, false); this.getCollectPanel().setTabbedPaneEnabledAt(CollectState.OUTERSTATE_SEARCH, false); }
From source file:org.openconcerto.erp.core.finance.accounting.ui.GrandLivrePanel.java
/** * Cree un JTable contenant les ecritures du compte pass en argument * /*from w ww . j a v a2 s . c o m*/ * @param compte * @return null si aucune ecriture */ private JTable createJTableCompte(Compte compte) { // on cree la JTable final JTable tableTmp = creerJTable(compte); if (tableTmp != null) { // On met en place le renderer EcritureGrandLivreRenderer ecritureRenderer = new EcritureGrandLivreRenderer( ((TableSorter) tableTmp.getModel())); for (int j = 0; j < tableTmp.getColumnCount(); j++) { tableTmp.getColumnModel().getColumn(j).setCellRenderer(ecritureRenderer); } // Gestion de la souris sur la JTable tableTmp.addMouseListener(new MouseAdapter() { public void mousePressed(final MouseEvent mE) { if (mE.getButton() == MouseEvent.BUTTON3) { JPopupMenu menuDroit = new JPopupMenu(); menuDroit.add(new AbstractAction("Voir la source") { public void actionPerformed(ActionEvent e) { int row = tableTmp.rowAtPoint(mE.getPoint()); TableSorter s = (TableSorter) tableTmp.getModel(); int modelIndex = s.modelIndex(row); ConsultCompteModel consultCompteModel = ((ConsultCompteModel) s.getTableModel()); Ecriture ecriture = consultCompteModel.getEcritures().get(modelIndex); MouvementSQLElement.showSource(ecriture.getIdMvt()); } }); menuDroit.show(mE.getComponent(), mE.getX(), mE.getY()); } } }); } return tableTmp; }
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 {//from w w w.j av a2 s . c o m 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.revager.tools.GUITools.java
/** * Creates a new standard table./*from w w w . jav a 2s . co m*/ * * @param model * the table model * @param showHeader * true if the header of the table should be visible * * @return the newly created table */ @SuppressWarnings("serial") public static JTable newStandardTable(TableModel model, boolean showHeader) { /* * Prep. for rollover */ if (lastRolloverKey == Integer.MAX_VALUE) { lastRolloverKey = 0; } else { lastRolloverKey++; } final int keyIdx = lastRolloverKey; rollOverRowIndex.put(keyIdx, -1); final JTable table = new JTable(model) { @Override public boolean editCellAt(int row, int column, java.util.EventObject e) { boolean result = super.editCellAt(row, column, e); final Component editor = getEditorComponent(); TableCellRenderer renderer = this.getColumnModel().getColumn(column).getCellRenderer(); Font cellFont = null; if (renderer instanceof DefaultTableCellRenderer) { cellFont = ((DefaultTableCellRenderer) renderer).getFont(); } if (editor != null && editor instanceof JTextComponent) { JTextComponent jTextComponent = (JTextComponent) editor; if (e == null) { jTextComponent.selectAll(); } else { SwingUtilities.invokeLater(jTextComponent::selectAll); } jTextComponent.setBorder(UI.MARKED_BORDER_INLINE); if (cellFont != null) { jTextComponent.setFont(cellFont); } editor.requestFocusInWindow(); } return result; } @Override public TableCellRenderer getCellRenderer(int row, int column) { TableCellRenderer renderer = super.getCellRenderer(row, column); if (renderer instanceof DefaultTableCellRenderer) { ((DefaultTableCellRenderer) renderer).setBorder(new EmptyBorder(3, 3, 3, 3)); } return renderer; } @Override public Component prepareRenderer(TableCellRenderer renderer, int row, int col) { Component comp = super.prepareRenderer(renderer, row, col); // Rollover comp.setBackground(getBackground()); comp = super.prepareRenderer(renderer, row, col); if (!isRowSelected(row) && row == rollOverRowIndex.get(keyIdx)) { comp.setForeground(getForeground()); comp.setBackground(UI.BLUE_BACKGROUND_COLOR); } // Tooltips JComponent jcomp = (JComponent) comp; if (renderer instanceof DefaultTableCellRenderer) { String toolTip = ((DefaultTableCellRenderer) renderer).getToolTipText(); if (!StringUtils.isEmpty(toolTip)) { jcomp.setToolTipText(toolTip); } } return comp; } }; // Table properties table.setRowHeight(UI.TABLE_ROW_HEIGHT); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setShowGrid(false); table.setShowHorizontalLines(true); table.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); // Rollover MouseInputAdapter rolloverListener = new MouseInputAdapter() { @Override public void mouseExited(MouseEvent e) { rollOverRowIndex.put(keyIdx, -1); table.repaint(); } @Override public void mouseMoved(MouseEvent e) { int row = table.rowAtPoint(e.getPoint()); if (row != rollOverRowIndex.get(keyIdx)) { rollOverRowIndex.put(keyIdx, row); table.repaint(); } } }; table.addMouseMotionListener(rolloverListener); table.addMouseListener(rolloverListener); // Header if (!showHeader) { table.setTableHeader(null); } return table; }
From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewer.java
private void setupTable() { tableModel = new ElementListTableModel(); table = new JXTable(tableModel); tableSorter = new ElementListTableSorter(tableModel, table); table.getTableHeader().addMouseListener(tableSorter); // add sorter & header renderer table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true);/*from ww w . j av a 2 s .c o m*/ // set our column widths ElementListTableModel.setupColumnWidths(table); table.setDefaultRenderer(Object.class, new ElementListCellRenderer(this, false)); table.setDefaultRenderer(Boolean.class, new BooleanCellRenderer(this, false)); // hide irrelevent columns TableColumnModelExt colmodel = (TableColumnModelExt) table.getColumnModel(); table.setColumnControlVisible(true); colmodel.getColumnExt(I18n.getText("hidden.MostRecentVersion")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.n")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.rec")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.hash")).setVisible(false); // popup menu table.addMouseListener(new PopupListener() { @Override public void showPopup(MouseEvent e) { // only clicks on tables if (!(e.getSource() instanceof JTable)) return; JTable table = (JTable) e.getSource(); ElementListTableModel model = (ElementListTableModel) table.getModel(); // get the row and sanity check int row = table.rowAtPoint(e.getPoint()); if (row < 0 || row >= model.getRowCount()) return; // select it? table.setRowSelectionInterval(row, row); // get the element Element element = model.getElementAt(row); // create and show the menu JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewer.this); popup.show(table, e.getX(), e.getY()); } }); }
From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewerOld.java
private void setupTable() { tableModel = new ElementListTableModel(); table = new JXTable(tableModel); tableSorter = new ElementListTableSorter(tableModel, table); table.getTableHeader().addMouseListener(tableSorter); // add sorter & header renderer table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true);/*from w ww . j a v a 2 s. c o m*/ // set our column widths ElementListTableModel.setupColumnWidths(table); table.setDefaultRenderer(Object.class, new ElementListCellRenderer(this, false)); table.setDefaultRenderer(Boolean.class, new BooleanCellRenderer(this, false)); // hide irrelevent columns TableColumnModelExt colmodel = (TableColumnModelExt) table.getColumnModel(); table.setColumnControlVisible(true); colmodel.getColumnExt(I18n.getText("hidden.MostRecentVersion")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.n")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.rec")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.hash")).setVisible(false); // popup menu table.addMouseListener(new PopupListener() { @Override public void showPopup(MouseEvent e) { // only clicks on tables if (!(e.getSource() instanceof JTable)) return; JTable table = (JTable) e.getSource(); ElementListTableModel model = (ElementListTableModel) table.getModel(); // get the row and sanity check int row = table.rowAtPoint(e.getPoint()); if (row < 0 || row >= model.getRowCount()) return; // select it? table.setRowSelectionInterval(row, row); // get the element Element element = model.getElementAt(row); // create and show the menu JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewerOld.this); popup.show(table, e.getX(), e.getY()); } }); }