List of usage examples for java.awt.event MouseEvent getPoint
public Point getPoint()
From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java
@Override public void setSortable(boolean enable) { super.setSortable(enable); JTableHeader header = getTableHeader(); if (enable) { if (treeTableSortAdapter == null) { treeTableSortAdapter = new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { JTableHeader h = (JTableHeader) e.getSource(); TableColumnModel columnModel = getColumnModel(); int viewColumn = h.columnAtPoint(e.getPoint()); int column = columnModel.getColumn(viewColumn).getModelIndex(); if (column != -1) { beforeSort(); // Toggle sort order (ascending <-> descending) SortableTreeTableModel model = (SortableTreeTableModel) getTreeTableModel(); model.setColumnAndToggleSortOrder(column); // Set sorting icon and current column index ((SortableHeaderCellRenderer) getTableHeader().getDefaultRenderer()) .setSortingIcon(model.getSortOrder()); ((SortableHeaderCellRenderer) getTableHeader().getDefaultRenderer()) .setColumnIndex(column); saveSortPreferences(column); afterSort(); }//w w w . j av a2s . c o m } } }; header.addMouseListener(treeTableSortAdapter); } } else { if (treeTableSortAdapter != null) { header.removeMouseListener(treeTableSortAdapter); treeTableSortAdapter = null; } } }
From source file:HelloUniverse.java
public void mouseDragged(MouseEvent e) { Point pos = e.getPoint(); int diffX = pos.x - oldMousePos.x; int diffY = pos.y - oldMousePos.y; switch (mode) { case NONE://ww w . java2s.c o m break; case SLIDE_Y: // Overwrite the old pip drawYPip((Graphics2D) ((Canvas) e.getSource()).getGraphics(), yAngle); if (diffX < 0) yAngle -= angleStep; else if (diffX > 0) yAngle += angleStep; yAngle = constrainAngle(yAngle); // Draw the new Pip drawYPip((Graphics2D) ((Canvas) e.getSource()).getGraphics(), yAngle); oldMousePos = pos; break; case SLIDE_X: // Overwrite the old pip drawXPip((Graphics2D) ((Canvas) e.getSource()).getGraphics(), xAngle); if (diffY < 0) xAngle -= angleStep; else if (diffY > 0) xAngle += angleStep; xAngle = constrainAngle(xAngle); // Draw the new Pip drawXPip((Graphics2D) ((Canvas) e.getSource()).getGraphics(), xAngle); oldMousePos = pos; break; case SLIDE_Z: drawZPip((Graphics2D) ((Canvas) e.getSource()).getGraphics(), zAngle); if (diffX < 0) zAngle -= angleStep; else if (diffX > 0) zAngle += angleStep; zAngle = constrainAngle(zAngle); drawZPip((Graphics2D) ((Canvas) e.getSource()).getGraphics(), zAngle); oldMousePos = pos; break; default: throw (new RuntimeException("Internal Error")); } }
From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java
private void makeCustomTableHeader(TableColumnModel columnModel) { JTableHeader h = new JTableHeader(columnModel) { public String getToolTipText(MouseEvent e) { if (isHasColumnHeaderPopup()) { int col = columnAtPoint(e.getPoint()); Field f = ((SpreadSheetModel) getModel()).getFieldInNonTranslatedColumn(col + 1); if (f != null) return "<html>" + f.getName() + "<br>" + Messages.getString("Text.rightClickToInsertRemoveColumns") + "</html>"; }/* w ww . j av a2s . c o m*/ return super.getToolTipText(e); } }; setTableHeader(h); }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.ToolBar.java
/** Initializes the components. */ private void initComponents() { setBackground(UIUtilities.BACKGROUND_COLOR); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); IconManager icons = IconManager.getInstance(); saveButton = new JButton(icons.getIcon(IconManager.SAVE)); saveButton.setToolTipText("Save changes back to the server."); saveButton.addActionListener(controller); saveButton.setActionCommand("" + EditorControl.SAVE); saveButton.setEnabled(false);/*from www . j a v a 2s .c o m*/ saveButton.setBackground(UIUtilities.BACKGROUND_COLOR); downloadButton = new JButton(icons.getIcon(IconManager.DOWNLOAD)); downloadButton.setToolTipText("Download the Archived File(s)."); downloadButton.addActionListener(controller); downloadButton.setActionCommand("" + EditorControl.DOWNLOAD); //downloadButton.setEnabled(false); downloadButton.setBackground(UIUtilities.BACKGROUND_COLOR); rndButton = new JButton(icons.getIcon(IconManager.RENDERER)); rndButton.setToolTipText("Rendering control for the first selected " + "image."); rndButton.addActionListener(controller); rndButton.setActionCommand("" + EditorControl.RENDERER); rndButton.setEnabled(false); rndButton.setBackground(UIUtilities.BACKGROUND_COLOR); refreshButton = new JButton(icons.getIcon(IconManager.REFRESH)); refreshButton.setToolTipText("Refresh."); refreshButton.addActionListener(controller); refreshButton.setActionCommand("" + EditorControl.REFRESH); refreshButton.setBackground(UIUtilities.BACKGROUND_COLOR); publishingButton = new JButton(icons.getIcon(IconManager.PUBLISHING)); publishingButton.setToolTipText("Display the publishing options."); publishingButton.setEnabled(false); publishingButton.setBackground(UIUtilities.BACKGROUND_COLOR); publishingButton.addMouseListener(new MouseAdapter() { /** * Launches the dialog when the user releases the mouse. * MouseAdapter#mouseReleased(MouseEvent) */ public void mouseReleased(MouseEvent e) { launchOptions((Component) e.getSource(), e.getPoint(), MetadataViewer.PUBLISHING_OPTION); } }); analysisButton = new JButton(icons.getIcon(IconManager.ANALYSIS)); analysisButton.setToolTipText("Display the analysis options."); analysisButton.setEnabled(false); analysisButton.setBackground(UIUtilities.BACKGROUND_COLOR); analysisButton.addMouseListener(new MouseAdapter() { /** * Launches the dialog when the user releases the mouse. * MouseAdapter#mouseReleased(MouseEvent) */ public void mouseReleased(MouseEvent e) { launchOptions((Component) e.getSource(), e.getPoint(), MetadataViewer.ANALYSIS_OPTION); } }); scriptsButton = new JButton(icons.getIcon(IconManager.ANALYSIS_RUN)); scriptsButton.setToolTipText("Display the available scripts."); scriptsButton.setEnabled(false); scriptsButton.setBackground(UIUtilities.BACKGROUND_COLOR); scriptsButton.addMouseListener(new MouseAdapter() { /** * Loads the scripts of displays them if already loaded. * MouseAdapter#mousePressed(MouseEvent) */ public void mouseReleased(MouseEvent e) { if (model.getScripts() == null) { location = e.getPoint(); scriptsButton.setEnabled(false); model.loadScripts(); setStatus(true); } else { launchOptions((Component) e.getSource(), e.getPoint(), MetadataViewer.SCRIPTS_OPTION); } } }); exportAsOmeTiffButton = new JButton(icons.getIcon(IconManager.EXPORT_AS_OMETIFF)); exportAsOmeTiffButton.setEnabled(false); exportAsOmeTiffButton.setToolTipText(EXPORT_AS_OME_TIFF_TOOLTIP); exportAsOmeTiffButton.addActionListener(controller); exportAsOmeTiffButton.setActionCommand("" + EditorControl.EXPORT_AS_OMETIFF); exportAsOmeTiffButton.setBackground(UIUtilities.BACKGROUND_COLOR); uploadScriptButton = new JButton(icons.getIcon(IconManager.UPLOAD_SCRIPT)); uploadScriptButton.setToolTipText("Upload a script to the server."); uploadScriptButton.addActionListener(controller); uploadScriptButton.setActionCommand("" + EditorControl.UPLOAD_SCRIPT); uploadScriptButton.setBackground(UIUtilities.BACKGROUND_COLOR); saveAsButton = new JButton(icons.getIcon(IconManager.EXPORT_AS_OMETIFF)); saveAsButton.setToolTipText("Display the saving options."); saveAsButton.addMouseListener(new MouseAdapter() { /** * Displays the saving options. * MouseAdapter#mousePressed(MouseEvent) */ public void mouseReleased(MouseEvent e) { launchOptions((Component) e.getSource(), e.getPoint(), MetadataViewer.SAVE_OPTION); } }); saveAsButton.setBackground(UIUtilities.BACKGROUND_COLOR); viewButton = new JButton(icons.getIcon(IconManager.VIEW)); viewButton.setToolTipText("Open the Image Viewer"); if (MetadataViewerAgent.runAsPlugin() == MetadataViewer.IMAGE_J) { viewButton.addMouseListener(new MouseAdapter() { /** * Displays the <code>view</code> menu. * @see MouseListener#mouseReleased(MouseEvent) */ public void mouseReleased(MouseEvent e) { showViewMenu((Component) e.getSource(), e.getPoint()); } }); } else { viewButton.setActionCommand("" + EditorControl.VIEW_IMAGE); viewButton.addActionListener(controller); } linkButton = new JButton(icons.getIcon(IconManager.LINK)); linkButton.addMouseListener(new MouseAdapter() { /** * Launches the dialog when the user releases the mouse. * MouseAdapter#mouseReleased(MouseEvent) */ public void mouseReleased(MouseEvent e) { location = e.getPoint(); component = (Component) e.getSource(); createLinkMenu().show(component, location.x, location.y); } }); UIUtilities.unifiedButtonLookAndFeel(linkButton); UIUtilities.unifiedButtonLookAndFeel(viewButton); UIUtilities.unifiedButtonLookAndFeel(saveAsButton); UIUtilities.unifiedButtonLookAndFeel(saveButton); UIUtilities.unifiedButtonLookAndFeel(downloadButton); UIUtilities.unifiedButtonLookAndFeel(rndButton); UIUtilities.unifiedButtonLookAndFeel(refreshButton); UIUtilities.unifiedButtonLookAndFeel(exportAsOmeTiffButton); UIUtilities.unifiedButtonLookAndFeel(publishingButton); UIUtilities.unifiedButtonLookAndFeel(uploadScriptButton); UIUtilities.unifiedButtonLookAndFeel(analysisButton); UIUtilities.unifiedButtonLookAndFeel(scriptsButton); Dimension d = new Dimension(UIUtilities.DEFAULT_ICON_WIDTH, UIUtilities.DEFAULT_ICON_HEIGHT); busyLabel = new JXBusyLabel(d); busyLabel.setEnabled(true); busyLabel.setVisible(false); }
From source file:de.dakror.villagedefense.game.entity.struct.Struct.java
@Override public boolean mousePressed(MouseEvent e) { if (guiPoint != null && guiSize != null) e.translatePoint(-(guiPoint.x - guiSize.width / 2), -(guiPoint.y - guiSize.height / 2)); for (Component c : components) c.mousePressed(e);/* w ww .j av a 2 s .c o m*/ if (guiPoint != null && guiSize != null) e.translatePoint(guiPoint.x - guiSize.width / 2, guiPoint.y - guiSize.height / 2); boolean pressed = super.mousePressed(e); if (pressed && guiPoint == null && guiSize != null) { guiPoint = e.getPoint(); guiPoint.translate(Game.world.x, Game.world.y); if (guiPoint.x - guiSize.width / 2 < 0) guiPoint.x = guiSize.width / 2; if (guiPoint.y - guiSize.height / 2 < 0) guiPoint.y = guiSize.height / 2; if (guiPoint.x + guiSize.width / 2 > Game.getWidth()) guiPoint.x = Game.getWidth() - guiSize.width / 2; if (guiPoint.y + guiSize.height / 2 > Game.getHeight()) guiPoint.y = Game.getHeight() - guiSize.height / 2; } else { if (guiPoint != null && guiSize != null && !new Rectangle(guiPoint.x - guiSize.width / 2, guiPoint.y - guiSize.height / 2, guiSize.width, guiSize.height).contains(e.getPoint())) { destroyGUI(); } } return pressed; }
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 www . j a v a 2 s. c o m*/ 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)); } }
From source file:forge.itemmanager.views.ItemListView.java
/** * ItemTable Constructor.// ww w .j av a 2 s. c om * * @param itemManager0 * @param model0 */ public ItemListView(final ItemManager<T> itemManager0, final ItemManagerModel<T> model0) { super(itemManager0, model0); this.tableModel = new ItemTableModel(model0); this.setAllowMultipleSelections(false); this.getPnlOptions().setVisible(false); //hide options panel by default // use different selection highlight colors for focused vs. unfocused tables this.table.addMouseListener(new FMouseAdapter() { @Override public void onLeftDoubleClick(final MouseEvent e) { if (e.isConsumed()) { return; } //don't activate if inline button double clicked final int clickedIndex = table.rowAtPoint(e.getPoint()); itemManager.activateSelectedItems(); if (clickedIndex >= table.getRowCount()) { FMouseAdapter.forceMouseUp(); //prevent mouse getting stuck if final row removed from double click handling } } @Override public void onRightClick(final MouseEvent e) { itemManager.showContextMenu(e); } }); // prevent tables from intercepting tab focus traversals this.table.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null); this.table.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null); }
From source file:maltcms.ui.fileHandles.csv.CSVTableView.java
/** * * @param tm/* w w w .j av a2s. c om*/ */ public void setTableModel(TableModel tm) { if (tm == null) { Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Received table model was null!"); return; } this.jTable1.setModel(tm); //default column model for (int i = 0; i < tm.getColumnCount(); i++) { this.jTable1.getColumnModel().getColumn(i).setCellRenderer( new ColorColumnRenderer(new Color(255, 255, 255, 255), jTable1.getSelectedRows())); } JTableCustomizer.changeComparators(this.jTable1); JTableCustomizer.fitAllColumnWidth(this.jTable1); this.jTable1.getTableHeader().addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (e.getButton() == 3) { activeColumn = jTable1.getTableHeader().columnAtPoint(e.getPoint()); int[] selectedRows = jTable1.getSelectedRows(); int minRow = 0;// int maxRow = jTable1.getRowCount() - 1;// int[] selectedColumns = jTable1.getSelectedColumns(); int minCol = 0; int maxCol = jTable1.getColumnCount() - 1; if (cellSelection) { jTable1.setRowSelectionAllowed(true); minRow = MathTools.min(selectedRows); maxRow = MathTools.max(selectedRows); minCol = MathTools.min(selectedColumns); maxCol = MathTools.min(selectedColumns); } else { } jTable1.setColumnSelectionInterval(activeColumn, activeColumn); jTable1.setRowSelectionInterval(minRow, maxRow); createAndShowPopupMenu(e); } } }); }
From source file:org.kontalk.view.UserListView.java
UserListView(final View view, UserList userList) { super();/* w w w . jav a 2 s. c o m*/ mView = view; mUserList = userList; this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //this.setDragEnabled(true); // right click popup menu mPopupMenu = new UserPopupMenu(); // actions triggered by mouse events this.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { mView.selectThreadByUser(UserListView.this.getSelectedValue()); } } @Override public void mousePressed(MouseEvent e) { check(e); } @Override public void mouseReleased(MouseEvent e) { check(e); } private void check(MouseEvent e) { if (e.isPopupTrigger()) { int row = UserListView.this.rowAtPoint(e.getPoint()); UserListView.this.setSelectedItem(row); UserListView.this.showPopupMenu(e); } } }); this.updateOnEDT(null); }
From source file:org.colombbus.tangara.CommandSelection.java
/** * This method initializes commandList/* ww w. j a v a 2s . c o m*/ * * @return javax.swing.JList */ private JList getCommandList() { if (commandList == null) { commandList = new JList(); } commandList.setSelectionBackground(selectedBackgroundColor); commandList.setSelectionForeground(selectedForegroundColor); commandList.setBackground(Color.white); commandList.setForeground(Color.gray); MouseListener[] mouseListeners = commandList.getMouseListeners(); for (MouseListener m : mouseListeners) { commandList.removeMouseListener(m); } MouseMotionListener[] motionListeners = commandList.getMouseMotionListeners(); for (MouseMotionListener m : motionListeners) { commandList.removeMouseMotionListener(m); } commandList.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { int index = commandList.locationToIndex(e.getPoint()); if (commandList.isSelectedIndex(index)) { commandList.removeSelectionInterval(index, index); selecting = false; } else { commandList.addSelectionInterval(index, index); selecting = true; } previousIndex = index; } @Override public void mouseReleased(MouseEvent e) { previousIndex = -1; } }); commandList.addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { int index = commandList.locationToIndex(e.getPoint()); if (index != previousIndex) { if (previousIndex > -1) { if (index > previousIndex) { if (selecting) { commandList.addSelectionInterval(previousIndex + 1, index); } else { commandList.removeSelectionInterval(previousIndex + 1, index); } } else { if (selecting) { commandList.addSelectionInterval(index, previousIndex - 1); } else { commandList.removeSelectionInterval(index, previousIndex - 1); } } } else { if (selecting) { commandList.addSelectionInterval(index, index); } else { commandList.removeSelectionInterval(index, index); } } commandList.ensureIndexIsVisible(index); previousIndex = index; } } }); return commandList; }