List of usage examples for java.awt.event MouseEvent getX
public int getX()
From source file:JavaXWin.java
public void mouseMoved(MouseEvent e) { if (!m_dragging) { if (e.getX() < CORNER) { setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR)); } else if (e.getX() > getWidth() - CORNER) { setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR)); } else {//from w w w .ja v a2 s . c o m setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR)); } } }
From source file:JavaXWin.java
public void mouseDragged(MouseEvent e) { if (m_resizeComponent.getWidth() - (e.getX() - m_dragX) >= MIN_WIDTH) m_resizeComponent.setBounds(m_resizeComponent.getX() + (e.getX() - m_dragX), m_resizeComponent.getY(), m_resizeComponent.getWidth() - (e.getX() - m_dragX), m_resizeComponent.getHeight()); else if (m_resizeComponent.getX() + MIN_WIDTH < m_rightX) m_resizeComponent.setBounds(m_rightX - MIN_WIDTH, m_resizeComponent.getY(), MIN_WIDTH, m_resizeComponent.getHeight()); else/* w w w . j a v a 2 s . c om*/ m_resizeComponent.setBounds(m_resizeComponent.getX(), m_resizeComponent.getY(), MIN_WIDTH, m_resizeComponent.getHeight()); m_resizeComponent.validate(); }
From source file:JavaXWin.java
public void mousePressed(MouseEvent e) { m_dragging = true;// ww w .j a v a 2 s . com m_dragX = e.getX(); m_dragY = e.getY(); m_lowerY = m_resizeComponent.getY() + m_resizeComponent.getHeight(); if (e.getX() < CORNER) { m_mode = NORTHWEST; } else if (e.getX() > getWidth() - CORNER) { m_mode = NORTHEAST; } else { m_mode = NORTH; } }
From source file:com.univocity.app.swing.DataAnalysisWindow.java
private void addPopupMenuToTable(DaoTable daoTable, boolean isSourceTable) { String engineName = isSourceTable ? config.getSourceEngineName() : config.getDestinationEngineName(); if (engineName == null) { return;/*from w ww .j a v a2s .c o m*/ } final JTable table = daoTable.getDataTable(); final JPopupMenu menu = new JPopupMenu(); menu.add(newJMenuItem("Disable updates", daoTable, engineName, false, false)); menu.add(newJMenuItem("Enable updates", daoTable, engineName, true, false)); menu.add(new JSeparator()); menu.add(newJMenuItem("Disable updates on all rows", daoTable, engineName, false, true)); menu.add(newJMenuItem("Enable updates on all rows", daoTable, engineName, true, true)); table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { int rowNumber = table.rowAtPoint(e.getPoint()); if (rowNumber != -1) { table.getSelectionModel().setSelectionInterval(rowNumber, rowNumber); menu.show(table, e.getX(), e.getY()); } } }; }); }
From source file:com.ctsim.dmi.MainFrame.java
private void viewPanelMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_viewPanelMouseMoved this.x = evt.getX(); this.y = evt.getY(); }
From source file:de.codesourcery.eve.skills.ui.components.impl.ItemChooserComponent.java
@Override protected JPanel createPanelHook() { tree.setRootVisible(false);// www . j a v a2 s .c om tree.setCellRenderer(treeRenderer); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() != 2 || e.isPopupTrigger()) { return; } final TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY()); final ITreeNode node = (ITreeNode) path.getLastPathComponent(); if (node.getValue() instanceof InventoryType) { final InventoryType selectedItem = (InventoryType) node.getValue(); selectedItemsModel.addItem(selectedItem); if (selectionMode == SelectionMode.SINGLE_SELECTION) { okButtonClicked(); } else if (selectionMode == SelectionMode.MULTIPLE_SELECTION) { // ok } else { throw new RuntimeException("Unhandled mode " + selectionMode); } } } }); tree.addTreeWillExpandListener(new TreeWillExpandListener() { @Override public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { } @Override public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { handleTreeExpansion(event); } }); final JScrollPane pane = new JScrollPane(tree); pane.setPreferredSize(new Dimension(400, 400)); final JPanel result = new JPanel(); result.setLayout(new GridBagLayout()); switch (selectionMode) { case SINGLE_SELECTION: result.add(pane, constraints().useRemainingSpace().resizeBoth().end()); break; case MULTIPLE_SELECTION: result.add(pane, constraints(0, 0).useRelativeWidth().resizeBoth().end()); result.add(createListViewPanel(), constraints(1, 0).useRemainingWidth().resizeBoth().end()); break; default: throw new RuntimeException("Unhandled selection mode" + selectionMode); } return result; }
From source file:com.ctsim.dmi.MainFrame.java
private void viewPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_viewPanelMouseClicked click_x = evt.getX(); click_y = evt.getY();// w w w . j av a2 s. c om checkClickObject(); }
From source file:es.emergya.ui.gis.ControlPanel.java
public ControlPanel(final CustomMapView view) { super(new FlowLayout(FlowLayout.LEADING, 12, 0)); this.view = view; // Posicion: panel con un label de icono y un textfield JPanel posPanel = new JPanel(); posPanel.setOpaque(true);/* ww w . jav a2 s .c o m*/ posPanel.setVisible(true); JLabel mouseLocIcon = new JLabel(LogicConstants.getIcon("map_icon_coordenadas")); posPanel.add(mouseLocIcon); final JTextField posField = new JTextField(15); posField.setEditable(false); posField.setBorder(null); posField.setForeground(UIManager.getColor("Label.foreground")); posField.setFont(UIManager.getFont("Label.font")); posPanel.add(posField); view.addMouseMotionListener(new MouseMotionListener() { @Override public void mouseMoved(MouseEvent e) { LatLon ll = ((ICustomMapView) e.getSource()).getLatLon(e.getX(), e.getY()); String position = ""; String format = LogicConstants.get("FORMATO_COORDENADAS_MAPA", "UTM"); if (format.equals(LogicConstants.COORD_UTM)) { UTM u = new UTM(LogicConstants.getInt("ZONA_UTM")); EastNorth en = u.latlon2eastNorth(ll); position = String.format("x: %.1f y: %.1f", en.getX(), en.getY()); } else { position = String.format("Lat: %.4f Lon: %.4f", ll.lat(), ll.lon()); } posField.setText(position); validate(); } @Override public void mouseDragged(MouseEvent e) { } }); posPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); add(posPanel); // Panel de centrado: label, desplegable y parte cambiante JPanel centerPanel = new JPanel(); centerPanel.add(new JLabel(i18n.getString("map.centerIn"))); centerOptions = new JComboBox(new String[] { i18n.getString("map.street"), i18n.getString("map.resource"), i18n.getString("map.incidence"), i18n.getString("map.location") }); centerPanel.add(centerOptions); centerData = new JPanel(new CardLayout()); centerPanel.add(centerData); JPanel centerStreet = new JPanel(); street = new JTextField(30); street.setName(i18n.getString("map.street")); autocompleteKeyListener = new AutocompleteKeyListener(street); street.addKeyListener(autocompleteKeyListener); street.addActionListener(this); centerStreet.add(street); centerData.add(centerStreet, i18n.getString("map.street")); JPanel centerResource = new JPanel(); resources = new JComboBox(avaliableResources); resources.setName(i18n.getString("map.resource")); resources.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); resources.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { isComboResourcesShowing = true; } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { isComboResourcesShowing = false; } @Override public void popupMenuCanceled(PopupMenuEvent e) { // view.repaint(); } }); centerResource.add(resources); centerData.add(centerResource, i18n.getString("map.resource")); centerResource = new JPanel(); incidences = new JComboBox(avaliableIncidences); incidences.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); incidences.setName(i18n.getString("map.incidence")); incidences.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { isComboIncidencesShowing = true; } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { isComboIncidencesShowing = false; } @Override public void popupMenuCanceled(PopupMenuEvent e) { } }); centerResource.add(incidences); centerData.add(centerResource, i18n.getString("map.incidence")); JPanel centerLocation = new JPanel(); cx = new JTextField(10); cx.setName("x"); cx.addActionListener(this); centerLocation.add(cx); cy = new JTextField(10); cy.setName("y"); cy.addActionListener(this); centerLocation.add(cy); centerData.add(centerLocation, i18n.getString("map.location")); centerOptions.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { ((CardLayout) centerData.getLayout()).show(centerData, (String) e.getItem()); } }); JButton centerButton = new JButton(i18n.getString("map.center")); centerButton.addActionListener(this); centerPanel.add(centerButton); add(centerPanel); }
From source file:MouseTest.java
public MouseTest() { super();//from w w w.j a v a 2 s . c om final JPopupMenu pop = new JPopupMenu(); pop.add(new JMenuItem("Cut")); pop.add(new JMenuItem("Copy")); pop.add(new JMenuItem("Paste")); pop.addSeparator(); pop.add(new JMenuItem("Select All")); pop.setInvoker(this); MouseListener popup = new MouseListener() { public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { showPopup(e); } } public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { showPopup(e); } } private void showPopup(MouseEvent e) { pop.show(e.getComponent(), e.getX(), e.getY()); } }; addMouseListener(popup); MouseListener drawing1 = new MouseListener() { public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { color = Color.RED; startX = endX = e.getX(); startY = endY = e.getY(); repaint(); } public void mouseReleased(MouseEvent e) { color = Color.BLACK; repaint(); } }; addMouseListener(drawing1); MouseMotionListener drawing2 = new MouseMotionListener() { public void mouseDragged(MouseEvent e) { endX = e.getX(); endY = e.getY(); repaint(); } public void mouseMoved(MouseEvent e) { } }; addMouseMotionListener(drawing2); }
From source file:io.bibleget.BibleGetHelp.java
private void jTree1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTree1MouseClicked // TODO add your handling code here: int tp = jTree1.getRowForLocation(evt.getX(), evt.getY()); //System.out.println(tp); if (tp != -1 && tp < 4) { switch (tp) { case 0://www . j a va 2 s . c om jTextPane2.setDocument(doc); jTextPane2.setText(HTMLStr0); jTextPane2.setCaretPosition(0); break; case 1: jTextPane2.setDocument(doc); jTextPane2.setText(HTMLStr1); jTextPane2.setCaretPosition(0); break; case 2: jTextPane2.setDocument(doc); jTextPane2.setText(HTMLStr2); jTextPane2.setCaretPosition(0); break; case 3: String curLang = Locale.getDefault().getDisplayLanguage().toUpperCase(); //System.out.println(curLang); jTextPane2.setDocument(doc); jTextPane2.setText(MessageFormat.format(HTMLStr3, booksAndAbbreviations.get(curLang), curLang)); jTextPane2.setCaretPosition(0); break; default: jTextPane2.setDocument(doc); jTextPane2.setText(HTMLStr0); jTextPane2.setCaretPosition(0); } } else if (tp > 3) { TreePath treePath = jTree1.getPathForLocation(evt.getX(), evt.getY()); String curPath = treePath.getLastPathComponent().toString().toUpperCase(Locale.ENGLISH); //System.out.println(curPath); if (booksAndAbbreviations.get(curPath) != null) { jTextPane2.setDocument(doc); jTextPane2.setText(MessageFormat.format(HTMLStr3, booksAndAbbreviations.get(curPath), curPath)); jTextPane2.setCaretPosition(0); } } //jTextPane2.setText("<span>"+tp+"</span>"); //else //jtf.setText(""); }