List of usage examples for java.awt.event MouseEvent getPoint
public Point getPoint()
From source file:savant.agp.HTTPBrowser.java
public HTTPBrowser(URL rootURL) throws IOException { host = rootURL.getHost();//from w w w . j ava 2s .co m int p = rootURL.getPort(); port = p != -1 ? p : rootURL.getDefaultPort(); rootDir = new File(rootURL.getPath()); curDir = rootDir; setLayout(new BorderLayout()); addressLabel = new JLabel(); add(addressLabel, BorderLayout.NORTH); add(getToolBar(), BorderLayout.SOUTH); table = new JTable(); updateDirectory(); table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { String f = ((HTTPTableModel) table.getModel()).getEntry(table.rowAtPoint(evt.getPoint())); if (f.equals("..")) { // Going up a directory. curDir = curDir.getParentFile(); updateDirectory(); } else if (!f.contains(".")) { if (f.startsWith("/")) { curDir = new File(f); } else { curDir = new File(curDir, f); } updateDirectory(); } else { openIndexAs(table.rowAtPoint(evt.getPoint()), OpenAsOption.TRACK); } } } }); JScrollPane scrollPane = new JScrollPane(table); scrollPane.getViewport().setBackground(Color.WHITE); scrollPane.setPreferredSize(new Dimension(800, 500)); add(scrollPane, BorderLayout.CENTER); this.setPreferredSize(new Dimension(800, 500)); }
From source file:io.github.jeremgamer.editor.panels.Buttons.java
public Buttons(final JFrame frame, final ButtonPanel be, final PanelSave ps) { this.setBorder(BorderFactory.createTitledBorder("")); this.frame = frame; JButton add = null;//w ww. j a v a2 s .co m try { add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png")))); } catch (IOException e) { e.printStackTrace(); } add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") String name = jop.showInputDialog(null, "Nommez le bouton :", "Crer un bouton", JOptionPane.QUESTION_MESSAGE); if (name != null) { for (int i = 0; i < data.getSize(); i++) { if (data.get(i).equals(name)) { name += "1"; } } data.addElement(name); new ButtonSave(name); ActionPanel.updateLists(); OtherPanel.updateLists(); PanelsPanel.updateLists(); } } catch (IOException e) { e.printStackTrace(); } } }); JButton remove = null; try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (buttonList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/buttons/" + buttonList.getSelectedValue() + "/" + buttonList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog(null, "tes-vous sr de vouloir supprimer ce bouton?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { File dir = new File("projects/" + Editor.getProjectName() + "/panels"); for (File f : FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { if (!f.isDirectory()) { try { ps.load(f); } catch (IOException e) { e.printStackTrace(); } for (String section : ps .getSectionsContaining(buttonList.getSelectedValue() + " (Bouton)")) { ps.removeSection(section); try { ps.save(f); } catch (IOException e) { e.printStackTrace(); } } } } if (buttonList.getSelectedValue().equals(be.getFileName())) { be.setFileName(""); } be.hide(); file.delete(); File parent = new File(file.getParent()); for (File img : FileUtils.listFiles(parent, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { img.delete(); } parent.delete(); data.remove(buttonList.getSelectedIndex()); ActionPanel.updateLists(); OtherPanel.updateLists(); PanelsPanel.updateLists(); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS)); buttons.add(add); buttons.add(remove); updateList(); buttonList.addMouseListener(new MouseAdapter() { @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent evt) { JList<String> list = (JList<String>) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { be.load(new File("projects/" + Editor.getProjectName() + "/buttons/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); be.show(); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { be.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { be.hideThenShow(); previousSelection = list.getSelectedValue(); be.load(new File("projects/" + Editor.getProjectName() + "/buttons/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { be.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { be.load(new File("projects/" + Editor.getProjectName() + "/buttons/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); be.show(); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { be.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { be.hideThenShow(); previousSelection = list.getSelectedValue(); be.load(new File("projects/" + Editor.getProjectName() + "/buttons/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { be.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(buttonList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); }
From source file:picocash.Picocash.java
private JPanel initMainFrame() { this.accountPanel = new StandardAccountPanel(); mainPanel = new JXPanel(new MigLayout("fill, insets 0 0 0 0", "[grow]", "[40!] 0 [31!] 0 [grow] 0 [20!]")); headerPanel = new HeaderPanel(); modePanel = new ModePanel(); accountContainer = new JXPanel(new MigLayout("fill, insets 0 0 0 0")); statisticPanel = new StatisticPanel(); footerPanel = new FooterPanel(); headerPanel.addMouseListener(new MouseAdapter() { @Override/* w w w . j a v a 2 s. c om*/ public void mousePressed(MouseEvent arg0) { Point clickPoint = new Point(arg0.getPoint()); SwingUtilities.convertPointToScreen(clickPoint, getMainFrame()); dX = clickPoint.x - getMainFrame().getX(); dY = clickPoint.y - getMainFrame().getY(); } @Override public void mouseClicked(MouseEvent arg0) { if (System.currentTimeMillis() - lastClickOn < DOUBLE_CLICK_TIME) { maximize(); } lastClickOn = System.currentTimeMillis(); } }); headerPanel.addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent arg0) { Point dragPoint = new Point(arg0.getPoint()); SwingUtilities.convertPointToScreen(dragPoint, getMainFrame()); getMainFrame().setLocation(dragPoint.x - dX, dragPoint.y - dY); } }); modePanel.addModePanelSelectionListener(this); mainPanel.add(headerPanel, "aligny top, growx, h 40!, wrap"); mainPanel.add(modePanel, "aligny top, growx, h 31!, wrap"); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, accountContainer, statisticPanel); splitPane.setDividerLocation(0.7d); JXPanel tmp = new JXPanel(new MigLayout("fill, insets 0 0 0 0")); tmp.add(splitPane, "grow"); mainPanel.add(tmp, "growx, growy, wrap"); mainPanel.add(footerPanel, "aligny bottom, growx, h 20!"); return mainPanel; }
From source file:figs.treeVisualization.gui.TimeAxisTree2DPanel.java
/** * Handle mouse clicked events.//from w w w . j a va2s .c om * <P> * Overrides the parent method because we have two seperate areas. */ @Override public void mouseClicked(MouseEvent evt) { Point2D point = evt.getPoint(); boolean rightButton = SwingUtilities.isRightMouseButton(evt) || evt.isControlDown(); if (this.fLeftTreeArea.contains(point)) { /** In tree area. */ Element elem = this.fTreePainter.java2DToClade(point, this.fLeftTreeArea, this.getMouseClickDistance()); if (elem == null) { /** Unselect every thing. */ if (rightButton && this.fSelectedCladeList != null) { this.fSelectedCladeList = null; this.notifyTree2DPanelChangeListeners( new Tree2DPanelChangeEvent(this, Tree2DPanelChangeEvent.ITEM_SELECTED)); } return; } if (rightButton) { this.fSelectedCladeList = new LinkedList<Element>(); this.fSelectedCladeList.add(elem); this.notifyTree2DPanelChangeListeners( new Tree2DPanelChangeEvent(this, Tree2DPanelChangeEvent.ITEM_SELECTED)); } else { /** Unselect every thing and add only this one. */ this.fSelectedCladeList.clear(); this.fSelectedCladeList.add(elem); /** Now show a CladeEditorDialog */ CladeEditorDialog.showDialog(this, elem); } } else { /** In time axis area */ } }
From source file:org.eclipse.birt.chart.device.swing.SwingEventHandler.java
public void mouseMoved(MouseEvent e) { final Point p = e.getPoint(); // 1. CHECK FOR MOUSE-CLICK TRIGGERS ShapedAction sa = getShapedActionForConditionPoint( new TriggerCondition[] { TriggerCondition.MOUSE_CLICK_LITERAL, TriggerCondition.ONCLICK_LITERAL, TriggerCondition.ONMOUSEDOWN_LITERAL, TriggerCondition.ONMOUSEOVER_LITERAL, TriggerCondition.ONMOUSEMOVE_LITERAL }, p);//from www . j a v a2 s .c om if (sa != null) { setCursor((JComponent) iun.peerInstance(), sa.getCursor(), Cursor.getDefaultCursor()); } else { setCursor((JComponent) iun.peerInstance(), null, Cursor.getDefaultCursor()); } // 2. CHECK FOR MOUSE-HOVER CONDITION handleAction(new TriggerCondition[] { TriggerCondition.MOUSE_HOVER_LITERAL, TriggerCondition.ONMOUSEMOVE_LITERAL, TriggerCondition.ONMOUSEOVER_LITERAL }, e, false); }
From source file:com.diversityarrays.kdxplore.trials.TrialDetailsPanel.java
TrialDetailsPanel(WindowOpener<JFrame> windowOpener, MessagePrinter mp, BackgroundRunner backgroundRunner, OfflineData offlineData, Action editTrialAction, Action seedPrepAction, Action harvestAction, Action uploadTrialAction, Action refreshTrialInfoAction, ImageIcon barcodeIcon, Transformer<Trial, Boolean> checkIfEditorActive, Consumer<Trial> onTraitInstancesRemoved) { super(new BorderLayout()); this.editTrialAction = editTrialAction; this.uploadTrialAction = uploadTrialAction; this.refreshTrialInfoAction = refreshTrialInfoAction; this.onTraitInstancesRemoved = onTraitInstancesRemoved; this.messagePrinter = mp; this.backgroundRunner = backgroundRunner; this.offlineData = offlineData; if (barcodeIcon == null) { barcodesMenuButton = new JLabel("Barcodes"); //$NON-NLS-1$ } else {//w w w. j a v a 2 s .c o m barcodesMenuButton = new JLabel(barcodeIcon); } barcodesMenuButton.setBorder(BorderFactory.createRaisedSoftBevelBorder()); barcodesMenuButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (trial != null) { barcodesMenuHandler.handleMouseClick(e.getPoint()); } } }); trialViewPanel = new TrialViewPanel(windowOpener, offlineData, checkIfEditorActive, onTraitInstancesRemoved, mp); Box buttons = Box.createHorizontalBox(); buttons.add(new JButton(refreshTrialInfoAction)); buttons.add(new JButton(seedPrepAction)); buttons.add(new JButton(editTrialAction)); buttons.add(new JButton(uploadTrialAction)); buttons.add(new JButton(harvestAction)); buttons.add(barcodesMenuButton); buttons.add(Box.createHorizontalGlue()); // JPanel trialPanel = new JPanel(new BorderLayout()); // trialPanel.add(buttons, BorderLayout.NORTH); // trialPanel.add(fieldViewPanel, BorderLayout.CENTER); cardPanel.add(new JLabel(Msg.LABEL_NO_TRIAL_SELECTED()), CARD_NO_TRIAL); cardPanel.add(trialViewPanel, CARD_HAVE_TRIAL); setSelectedTrial(null); add(buttons, BorderLayout.NORTH); add(cardPanel, BorderLayout.CENTER); }
From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphPanel.java
/** * Handle mouse released event/*from ww w .j ava 2s. co m*/ * * @param e the mouse event */ public void mouseReleased(MouseEvent e) { checkPopup(e); if (connectingSourceFromHead) { final GraphNode n = findNode(e.getPoint()); if (n != null && selectedNode != n) { connectSourceTargetNode.connectOperatorSource(n.getID()); } } else if (connectingSourceFromTail) { final GraphNode n = findNode(e.getPoint()); if (n != null && selectedNode != n) { n.connectOperatorSource(connectSourceTargetNode.getID()); } } connectingSourceFromHead = false; connectingSourceFromTail = false; connectSourceTargetNode = null; repaint(); }
From source file:io.github.jeremgamer.editor.panels.Panels.java
public Panels(final JFrame frame, final PanelsPanel pp) { this.setBorder(BorderFactory.createTitledBorder("")); JButton add = null;/*from ww w .j av a2 s . c o m*/ try { add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png")))); } catch (IOException e) { e.printStackTrace(); } add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") String name = jop.showInputDialog((JFrame) SwingUtilities.windowForComponent(panelList), "Nommez le panneau :", "Crer un panneau", JOptionPane.QUESTION_MESSAGE); if (name != null) { for (int i = 0; i < data.getSize(); i++) { if (data.get(i).equals(name)) { name += "1"; } } data.addElement(name); new PanelSave(name); PanelsPanel.updateLists(); mainPanel.addItem(name); } } catch (IOException e) { e.printStackTrace(); } } }); JButton remove = null; try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (panelList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/panels/" + panelList.getSelectedValue() + "/" + panelList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog((JFrame) SwingUtilities.windowForComponent(panelList), "tes-vous sr de vouloir supprimer ce panneau?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { if (panelList.getSelectedValue().equals(pp.getFileName())) { pp.setFileName(""); } pp.hide(); file.delete(); File parent = new File(file.getParent()); for (File img : FileUtils.listFiles(parent, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { img.delete(); } parent.delete(); mainPanel.removeItem(panelList.getSelectedValue()); data.remove(panelList.getSelectedIndex()); ActionPanel.updateLists(); PanelsPanel.updateLists(); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS)); buttons.add(add); buttons.add(remove); mainPanel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); GeneralSave gs = new GeneralSave(); try { gs.load(new File("projects/" + Editor.getProjectName() + "/general.rbd")); gs.set("mainPanel", combo.getSelectedItem()); } catch (IOException e) { e.printStackTrace(); } } }); updateList(); panelList.addMouseListener(new MouseAdapter() { @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent evt) { JList<String> list = (JList<String>) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); pp.show(); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { pp.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { pp.hideThenShow(); previousSelection = list.getSelectedValue(); pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); } } catch (NullPointerException npe) { pp.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); pp.show(); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { pp.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { pp.hideThenShow(); previousSelection = list.getSelectedValue(); pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); } } catch (NullPointerException npe) { pp.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(panelList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); JPanel mainPanelInput = new JPanel(); mainPanelInput.setPreferredSize(new Dimension(280, 35)); mainPanelInput.setMaximumSize(new Dimension(280, 35)); mainPanelInput.add(new JLabel("Panneau principal:")); mainPanel.setPreferredSize(new Dimension(150, 27)); mainPanelInput.add(mainPanel); this.add(mainPanelInput); }
From source file:it.unibas.spicygui.vista.listener.MyMouseEventListener.java
public void mousePressed(MouseEvent e) { e.consume();// w w w . j a va 2 s . c o m Component comS = SwingUtilities.getDeepestComponentAt(pannelloPrincipale, e.getX(), e.getY()); if ((comS instanceof JScrollBar || !((comS instanceof JPanel) || (comS instanceof JTree))) && comS != null) { if (tmp12 == null) { tmp12 = comS; } } if (!(Costanti.INTERMEDIE.equals(comS.getName()))) { dispacciaEvento(null, e, e.getPoint(), false); } jLayeredPane.moveToFront(component); component.updateUI(); }
From source file:com.diversityarrays.kdxplore.curate.TraitsAndInstancesPanel2.java
private void showTraitInstanceInfo(MouseEvent me) { Point point = me.getPoint(); int vrow = traitInstanceStatsTable.rowAtPoint(point); if (vrow >= 0) { int mrow = traitInstanceStatsTable.convertRowIndexToModel(vrow); if (mrow >= 0) { SimpleStatistics<?> stats = tiStatsModel.getStatsAt(mrow); TraitInstance ti = tiStatsModel.getTraitInstanceAt(mrow); String tiName = curationContext.getTrial().getTraitNameStyle().makeTraitInstanceName(ti); StringBuilder html = new StringBuilder("<HTML>"); html.append("<dl>"); html.append("<dt><b>Description:</b></dt>").append("<dd>") .append(StringUtil.htmlEscape(ti.trait.getTraitDescription())).append("</dd>"); html.append("<dt><b>Unit:</b></dt>").append("<dd>") .append(StringUtil.htmlEscape(ti.trait.getTraitUnit())).append("</dd>"); try { ValidationRule rule = ValidationRule.create(ti.trait.getTraitValRule()); html.append("<dt><b>Validation Rule:</b></dt>").append("<dd>") .append(StringUtil.htmlEscape(rule.getDescription())).append("</dd>"); } catch (InvalidRuleException e) { }// w ww .java 2 s.c o m html.append("</dl>"); html.append("<hr>"); if (stats == null) { html.append("No Outliers"); } else { html.append("<b>Outliers</b><br>"); describeStats(stats, html, ti); } JOptionPane.showMessageDialog(TraitsAndInstancesPanel2.this, html.toString(), "Information for " + tiName, JOptionPane.INFORMATION_MESSAGE); } } }