List of usage examples for java.awt.event MouseEvent getX
public int getX()
From source file:com.quinsoft.zeidon.objectbrowser.EntitySquare.java
private void doPop(MouseEvent e) { EntityPopupMenu menu = new EntityPopupMenu(); menu.show(e.getComponent(), e.getX(), e.getY()); }
From source file:JavaXWin.java
public void mousePressed(MouseEvent e) { //toFront();//from w w w . jav a 2s . c om m_dragging = true; m_dragX = e.getX(); m_dragY = e.getY(); if (e.getX() < CORNER) { m_mode = SOUTHWEST; } else if (e.getX() > getWidth() - CORNER) { m_mode = SOUTHEAST; } else { m_mode = SOUTH; } }
From source file:com.wwidesigner.gui.StudyView.java
@Override protected void initializeComponents() { // create file tree tree = new JTree() { @Override/*www.j a v a2 s.c o m*/ public String getToolTipText(MouseEvent e) { String tip = null; TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path != null) { if (path.getPathCount() == 3) // it is a leaf { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); if (node instanceof TreeNodeWithToolTips) { tip = ((TreeNodeWithToolTips) node).getToolTip(); } } } return tip == null ? getToolTipText() : tip; } }; // Show tooltips for the Study view, and let them persist for 8 seconds. ToolTipManager.sharedInstance().registerComponent(tree); ToolTipManager.sharedInstance().setDismissDelay(8000); // If a Study view node doesn't fit in the pane, expand it when hovering // over it. ExpandedTipUtils.install(tree); tree.setRootVisible(false); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); tree.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path != null) { if (path.getPathCount() == 3) // it is a leaf { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent(); String category = (String) parentNode.getUserObject(); study.setCategorySelection(category, (String) node.getUserObject()); if (StudyModel.INSTRUMENT_CATEGORY_ID.equals(category) || StudyModel.TUNING_CATEGORY_ID.equals(category)) { try { study.validHoleCount(); } catch (Exception ex) { showException(ex); } } } updateView(); } } }); JScrollPane scrollPane = new JScrollPane(tree); scrollPane.setPreferredSize(new Dimension(225, 100)); add(scrollPane); Preferences myPreferences = getApplication().getPreferences(); String modelName = myPreferences.get(OptimizationPreferences.STUDY_MODEL_OPT, OptimizationPreferences.NAF_STUDY_NAME); setStudyModel(modelName); study.setPreferences(myPreferences); getApplication().getEventManager().subscribe(WIDesigner.FILE_OPENED_EVENT_ID, this); getApplication().getEventManager().subscribe(WIDesigner.FILE_CLOSED_EVENT_ID, this); getApplication().getEventManager().subscribe(WIDesigner.FILE_SAVED_EVENT_ID, this); getApplication().getEventManager().subscribe(WIDesigner.WINDOW_RENAMED_EVENT_ID, this); }
From source file:biz.wolschon.finance.jgnucash.accountProperties.AccountProperties.java
/** * {@inheritDoc}/*from w w w . j a v a2s . c om*/ */ @Override public void actionPerformed(final ActionEvent aE) { JPanel newPanel = new JPanel(new GridLayout(2, 2)); newPanel.add(new JLabel("GUID:")); final JTextField disabledIDInput = new JTextField(myAccount.getId()); final JPopupMenu accountIDPopupMenu = createAccountIDPopupMenu(); disabledIDInput.setEditable(false); disabledIDInput.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(final MouseEvent arg0) { if (arg0.isPopupTrigger()) { accountIDPopupMenu.show(disabledIDInput, arg0.getX(), arg0.getY()); } } @Override public void mousePressed(final MouseEvent arg0) { if (arg0.isPopupTrigger()) { accountIDPopupMenu.show(disabledIDInput, arg0.getX(), arg0.getY()); } } }); newPanel.add(disabledIDInput); newPanel.add(new JLabel("name:")); final JTextField nameInput = new JTextField(myAccount.getName()); nameInput.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent aE) { myAccount.setName(nameInput.getText()); } }); newPanel.add(nameInput); myFrame = new JFrame(myAccount.getName()); myFrame.getContentPane().setLayout(new BorderLayout()); myFrame.getContentPane().add(newPanel, BorderLayout.NORTH); myFrame.getContentPane().add(getButtonsPanel(), BorderLayout.SOUTH); myFrame.getContentPane().add(getMySettingsPanel(), BorderLayout.CENTER); myFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); myFrame.pack(); myFrame.setVisible(true); }
From source file:au.org.ala.delta.editor.ui.CharacterTree.java
public CharacterTree() { setToggleClickCount(0);/*from w ww .ja v a2s. c om*/ _characterListBehaviour = new CharacterListBehaviour(); _stateListBehaviour = new StateListBehaviour(); ToolTipManager.sharedInstance().registerComponent(this); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (_doubleProcessingMouseEvent) { return; } if (!isEditing()) { int selectedRow = getClosestRowForLocation(e.getX(), e.getY()); if ((selectedRow >= 0) && (e.getClickCount() == 2) && SwingUtilities.isLeftMouseButton(e)) { Action action = getActionMap().get(SELECTION_ACTION_KEY); if (action != null) { action.actionPerformed(new ActionEvent(this, -1, "")); } } } } }); addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { TreePath selection = e.getNewLeadSelectionPath(); if (selection != null) { Object lastComponent = selection.getLastPathComponent(); if (lastComponent instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent; if (node.isLeaf()) { CharacterTree.super.setTransferHandler(_stateTransferHandler); } else { CharacterTree.super.setTransferHandler(_characterTransferHandler); } } } } }); ActionMap actionMap = Application.getInstance().getContext().getActionMap(this); javax.swing.Action find = actionMap.get("find"); if (find != null) { getActionMap().put("find", find); } javax.swing.Action findNext = actionMap.get("findNext"); if (findNext != null) { getActionMap().put("findNext", findNext); } getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_MASK), SELECTION_ACTION_KEY); }
From source file:com.mirth.connect.client.ui.SettingsPanelDatabaseTasks.java
private void initComponents() { JPanel containerPanel = new JPanel(new MigLayout("insets 0, novisualpadding, hidemode 3, fill")); containerPanel.setBackground(getBackground()); containerPanel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(204, 204, 204)), "Database Tasks", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Tahoma", 1, 11))); containerPanel.add(new JLabel( "Cleanup or optimization tasks for the internal database. If no tasks are present, no action is necessary."), "top, wrap"); taskTable = new MirthTable(); taskTable/*from w ww . j a v a2s. co m*/ .setModel(new RefreshTableModel(new Object[] { "Status", "Name", "Description", "Start Time" }, 0)); taskTable.setDragEnabled(false); taskTable.setRowSelectionAllowed(true); taskTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); taskTable.setRowHeight(UIConstants.ROW_HEIGHT); taskTable.setFocusable(false); taskTable.setOpaque(true); taskTable.getTableHeader().setReorderingAllowed(false); taskTable.setEditable(false); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { taskTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } taskTable.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent evt) { checkSelection(evt); } @Override public void mouseReleased(MouseEvent evt) { checkSelection(evt); } private void checkSelection(MouseEvent evt) { if (taskTable.rowAtPoint(new Point(evt.getX(), evt.getY())) < 0) { taskTable.clearSelection(); setVisibleTasks(2, 3, false); } } }); taskTable.getColumnModel().getColumn(0).setMinWidth(75); taskTable.getColumnModel().getColumn(0).setMaxWidth(75); taskTable.getColumnModel().getColumn(0).setCellRenderer(new ImageCellRenderer()); taskTable.getColumnModel().getColumn(1).setMinWidth(45); taskTable.getColumnModel().getColumn(1).setPreferredWidth(250); taskTable.getColumnModel().getColumn(2).setMinWidth(75); taskTable.getColumnModel().getColumn(2).setPreferredWidth(475); taskTable.getColumnModel().getColumn(3).setMinWidth(95); taskTable.getColumnModel().getColumn(3).setMaxWidth(95); taskTable.getColumnModel().getColumn(3).setCellRenderer(new DateCellRenderer()); taskTable.getSelectionModel().addListSelectionListener(this); JScrollPane taskTableScrollPane = new JScrollPane(taskTable); containerPanel.add(taskTableScrollPane, "grow, push"); add(containerPanel, "grow, h 60%"); JPanel channelsPanel = new JPanel(new MigLayout("insets 0, novisualpadding, hidemode 3, fill")); channelsPanel.setBackground(getBackground()); channelsPanel.setBorder(BorderFactory.createTitledBorder( BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(204, 204, 204)), "Affected Channels", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Tahoma", 1, 11))); channelsTable = new MirthTable(); channelsTable.setModel(new RefreshTableModel(new Object[] { "Name", "Id" }, 0)); channelsTable.setDragEnabled(false); channelsTable.setRowSelectionAllowed(false); channelsTable.setRowHeight(UIConstants.ROW_HEIGHT); channelsTable.setFocusable(false); channelsTable.setOpaque(true); channelsTable.getTableHeader().setReorderingAllowed(false); channelsTable.setEditable(false); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { channelsTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } channelsPanel.add(new JScrollPane(channelsTable), "grow"); add(channelsPanel, "newline, grow, h 40%"); }
From source file:com.openbravo.pos.admin.RolesViewTree.java
private void createTree() { //Create the jtree root = new DefaultMutableTreeNode(); uTree = new CheckboxTree(root); root.setUserObject("All Permissions"); uTree.getCheckingModel().setCheckingMode(TreeCheckingModel.CheckingMode.PROPAGATE_PRESERVING_CHECK); uTree.clearSelection();/*from w w w . ja va 2s . c o m*/ DefaultCheckboxTreeCellRenderer renderer = (DefaultCheckboxTreeCellRenderer) uTree.getCellRenderer(); renderer.setLeafIcon(null); renderer.setClosedIcon(null); renderer.setOpenIcon(null); // set up listeners MouseListener ml = new MouseAdapter() { public void mousePressed(MouseEvent e) { int selRow = uTree.getRowForLocation(e.getX(), e.getY()); TreePath selPath = uTree.getPathForLocation(e.getX(), e.getY()); if (selPath != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath.getLastPathComponent(); // If using Right to left Language change the way the check tree works if (!uTree.getComponentOrientation().isLeftToRight()) { if (uTree.isPathChecked(new TreePath(node.getPath()))) { uTree.removeCheckingPath(new TreePath(node.getPath())); } else { uTree.addCheckingPath(new TreePath(node.getPath())); } } jPermissionDesc.setText(descriptionMap.get(node)); } } }; uTree.addMouseListener(ml); // when this listener is fired changes state to dirty uTree.addTreeCheckingListener(new TreeCheckingListener() { public void valueChanged(TreeCheckingEvent e) { passedDirty.setDirty(true); } }); try { // Get list of all the permisions in the database // and the list of sections dbPermissions = (List) m_dlAdmin.getAlldbPermissions(); branches = m_dlAdmin.getSectionsList(); } catch (BasicException ex) { Logger.getLogger(RolesViewTree.class.getName()).log(Level.SEVERE, null, ex); } // Create the main branches in the tree for (Object branch : branches) { section = ((StringUtils.substring(branch.toString(), 0, 2)).equals("##")) ? AppLocal.getIntString(StringUtils.right(branch.toString(), branch.toString().length() - 2)) : branch.toString(); root.add(new DefaultMutableTreeNode(section)); } classMap = new HashMap(); descriptionMap = new HashMap(); nodePaths = new HashMap(); // Replace displayname, Section and Description // from the database with the correct details from the permissions locale for (DBPermissionsInfo Perm : dbPermissions) { Perm.setDisplayName(((StringUtils.substring(Perm.getDisplayName(), 0, 2)).equals("##")) ? AppLocal.getIntString( StringUtils.right(Perm.getDisplayName(), Perm.getDisplayName().length() - 2)) : Perm.getDisplayName()); Perm.setSection(((StringUtils.substring(Perm.getSection(), 0, 2)).equals("##")) ? AppLocal.getIntString(StringUtils.right(Perm.getSection(), Perm.getSection().length() - 2)) : Perm.getSection()); Perm.setDescription(((StringUtils.substring(Perm.getDescription(), 0, 2)).equals("##")) ? AppLocal.getIntString( StringUtils.right(Perm.getDescription(), Perm.getDescription().length() - 2)) : Perm.getDescription()); } //put the list into order by display name sort(); // Create the leaf nodes & fill in hashmap's for (DBPermissionsInfo Perm : dbPermissions) { DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(Perm.getDisplayName(), false); if (searchNode(Perm.getSection(), root) != null) { searchNode(Perm.getSection(), root).add(newNode); classMap.put("[All Permissions, " + Perm.getSection() + ", " + newNode + "]", Perm.getClassName()); descriptionMap.put(newNode, Perm.getDescription()); nodePaths.put(Perm.getClassName(), newNode); } } root = sortTree(root); jScrollPane1.setViewportView(uTree); uTree.expandAll(); }
From source file:JavaXWin.java
public WindowWatcher(JDesktopPane desktop) { m_desktop = desktop;/*from w w w . j av a2 s .com*/ setOpaque(true); m_northResizer = new NorthResizeEdge(this); m_southResizer = new SouthResizeEdge(this); m_eastResizer = new EastResizeEdge(this); m_westResizer = new WestResizeEdge(this); setLayout(new BorderLayout()); add(m_northResizer, BorderLayout.NORTH); add(m_southResizer, BorderLayout.SOUTH); add(m_eastResizer, BorderLayout.EAST); add(m_westResizer, BorderLayout.WEST); MouseInputAdapter ma = new MouseInputAdapter() { public void mousePressed(MouseEvent e) { m_XDifference = e.getX(); m_YDifference = e.getY(); } public void mouseDragged(MouseEvent e) { int vx = 0; int vy = 0; if (m_desktop.getParent() instanceof JViewport) { vx = ((JViewport) m_desktop.getParent()).getViewPosition().x; vy = ((JViewport) m_desktop.getParent()).getViewPosition().y; } int w = m_desktop.getParent().getWidth(); int h = m_desktop.getParent().getHeight(); int x = getX(); int y = getY(); int ex = e.getX(); int ey = e.getY(); if ((ey + y > vy && ey + y < h + vy) && (ex + x > vx && ex + x < w + vx)) { setLocation(ex - m_XDifference + x, ey - m_YDifference + y); } else if (!(ey + y > vy && ey + y < h + vy) && (ex + x > vx && ex + x < w + vx)) { if (!(ey + y > vy) && ey + y < h + vy) setLocation(ex - m_XDifference + x, vy - m_YDifference); else if (ey + y > vy && !(ey + y < h + vy)) setLocation(ex - m_XDifference + x, (h + vy) - m_YDifference); } else if ((ey + y > vy && ey + y < h + vy) && !(ex + x > vx && ex + x < w + vx)) { if (!(ex + x > vx) && ex + x < w + vx) setLocation(vx - m_XDifference, ey - m_YDifference + y); else if (ex + x > vx && !(ex + x < w)) setLocation((w + vx) - m_XDifference, ey - m_YDifference + y); } else if (!(ey + y > vy) && ey + y < h + vy && !(ex + x > vx) && ex + x < w + vx) setLocation(vx - m_XDifference, vy - m_YDifference); else if (!(ey + y > vy) && ey + y < h + vy && ex + x > vx && !(ex + x < w + vx)) setLocation((w + vx) - m_XDifference, vy - m_YDifference); else if (ey + y > vy && !(ey + y < h + vy) && !(ex + x > vx) && ex + x < w + vx) setLocation(vx - m_XDifference, (h + vy) - m_YDifference); else if (ey + y > vy && !(ey + y < h + vy) && ex + x > vx && !(ex + x < w + vx)) setLocation((w + vx) - m_XDifference, (h + vy) - m_YDifference); } public void mouseEntered(MouseEvent e) { setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); } public void mouseExited(MouseEvent e) { setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }; addMouseListener(ma); addMouseMotionListener(ma); }
From source file:ScribbleDragAndDrop.java
/** * This method and mouseMoved() below are from the MouseMotionListener * interface. If we're in drawing mode, this method adds a new point to the * current scribble and requests a redraw *///from w ww.j a v a2s. c o m public void mouseDragged(MouseEvent e) { if (dragMode) return; currentScribble.lineto(e.getX(), e.getY()); repaint(); }
From source file:com.mirth.connect.connectors.jdbc.DatabaseMetadataDialog.java
private void checkTableNameSelected(java.awt.event.MouseEvent evt) { if (!evt.isPopupTrigger()) { int row = includedMetaDataTable.rowAtPoint(new Point(evt.getX(), evt.getY())); int column = includedMetaDataTable.columnAtPoint(new Point(evt.getX(), evt.getY())); if (row != -1 && column == 0) { String type = (String) includedMetaDataTable.getModel().getValueAt(row, 2); Boolean selected = (Boolean) includedMetaDataTable.getModel().getValueAt(row, 0); if (type.equals(TABLE_TYPE_COLUMN)) { RefreshTableModel model = (RefreshTableModel) includedMetaDataTable.getModel(); boolean nextTableFound = false; int tableLength = model.getRowCount(); int endRow = -1; for (int i = row + 1; !nextTableFound && i != tableLength; i++) { String nextType = (String) includedMetaDataTable.getModel().getValueAt(i, 2); if (nextType.equals(TABLE_TYPE_COLUMN)) { endRow = i;/*ww w .j av a 2 s . c o m*/ nextTableFound = true; } else if (i + 1 == tableLength) { endRow = i + 1; } } if (endRow == -1) { return; } for (int i = row + 1; i < endRow; i++) { model.setValueAt(selected, i, 0); } } } } }