List of usage examples for java.awt Rectangle contains
public boolean contains(int x, int y)
From source file:org.domainmath.gui.FileTreePanel.java
/** * Creates new form FileTreePanel//from w w w .j ava 2s .c o m * @param frame */ public FileTreePanel(MainFrame frame) { initComponents(); this.frame = frame; fileTree.setEditable(true); addPopupMenuToFileTree(); ToolTipManager.sharedInstance().registerComponent(fileTree); // handle right click event on File Tree. fileTree.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.getClickCount() == 2) { TreePath path = fileTree.getPathForLocation(e.getX(), e.getY()); Rectangle pathBounds = fileTree.getUI().getPathBounds(fileTree, path); if (pathBounds != null && pathBounds.contains(e.getX(), e.getY())) { File file = (File) fileTree.getLastSelectedPathComponent(); selectFile(file); } } } }); keyDeleteItem = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0); keyRenameItem = KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0); keyOpenItem = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0); keyRefreshItem = KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0); }
From source file:org.domainmath.gui.FileTreePanel.java
/** * Add popup menu.//from w ww . j av a2s . com */ private void addPopupMenuToFileTree() { refreshItem = new JMenuItem(bundle.getString("fileTreeRefreshItem.text")); fileTree.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { addGlobalAction(e); if (SwingUtilities.isRightMouseButton(e)) { TreePath path = fileTree.getPathForLocation(e.getX(), e.getY()); Rectangle pathBounds = fileTree.getUI().getPathBounds(fileTree, path); if (pathBounds != null && pathBounds.contains(e.getX(), e.getY())) { JPopupMenu menu = new JPopupMenu(); File file = (File) fileTree.getLastSelectedPathComponent(); openItem = new JMenuItem(bundle.getString("fileTreeOpenItem.text")); runScriptItem = new JMenuItem(bundle.getString("fileTreeRunItem.text")); openOutsideItem = new JMenuItem(bundle.getString("fileTreeOpenOutsideItem.text")); renameItem = new JMenuItem(bundle.getString("fileTreeRenameItem.text")); deleteItem = new JMenuItem(bundle.getString("fileTreeDeleteItem.text")); openItem.setAccelerator(keyOpenItem); renameItem.setAccelerator(keyRenameItem); deleteItem.setAccelerator(keyDeleteItem); refreshItem.setAccelerator(keyRefreshItem); menu.add(openItem); menu.add(runScriptItem); menu.add(openOutsideItem); menu.addSeparator(); menu.add(renameItem); menu.add(deleteItem); menu.addSeparator(); menu.add(refreshItem); fileTreeOpenItemActionPerformed(file); fileTreeRunItemActionPerformed(file); fileTreeOpenOutsideItemActionPerformed(file); fileTreeRenameItemActionPerformed(fileTree.getSelectionPath()); fileTreeDeleteItemActionPerformed(fileTree.getSelectionModel().getSelectionPaths()); fileTreeRefreshItemActionPerformed((File) fileTree.getModel().getRoot()); if (file.isDirectory()) { runScriptItem.setEnabled(false); } else { String name = file.getName(); if (!name.endsWith(".m")) { runScriptItem.setEnabled(false); } } menu.show(fileTree, e.getX(), e.getY()); } if (pathBounds == null) { JPopupMenu menu = new JPopupMenu(); newFolderItem = new JMenuItem(bundle.getString("fileTreeNewFolderItem.text")); File file = (File) fileTree.getModel().getRoot(); menu.add(newFolderItem); menu.add(refreshItem); fileTreeNewFolderItemActionPerformed(file); fileTreeRefreshItemActionPerformed(file); menu.show(fileTree, e.getX(), e.getY()); } } } }); }
From source file:org.executequery.gui.erd.ErdTable.java
public void selected(MouseEvent e) { super.selected(e); Rectangle bounds = getBounds(); Rectangle titleBar = new Rectangle((int) bounds.getX(), (int) bounds.getY(), FINAL_WIDTH, TITLE_BAR_HEIGHT); if (titleBar.contains(xDifference, yDifference)) { dragging = true;//from www. java2 s.co m } else { dragging = false; } // need to repaint layered pane to show // selected border on tables parent.repaintLayeredPane(); }
From source file:com._17od.upm.gui.MainWindow.java
/** * Utility function for restoreWindowBounds *//* w w w .j a v a 2 s . c om*/ private GraphicsConfiguration getGraphicsConfigurationContaining(int x, int y) { ArrayList configs = new ArrayList(); GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] devices = env.getScreenDevices(); for (int i = 0; i < devices.length; i++) { GraphicsConfiguration[] gconfigs = devices[i].getConfigurations(); configs.addAll(Arrays.asList(gconfigs)); } for (int i = 0; i < configs.size(); i++) { GraphicsConfiguration config = ((GraphicsConfiguration) configs.get(i)); Rectangle bounds = config.getBounds(); if (bounds.contains(x, y)) { return config; } } return null; }
From source file:fr.inria.soctrace.framesoc.ui.histogram.view.HistogramView.java
/** * Display the chart in the UI thread, using the loaded interval. * //from w ww.j av a 2 s . com * @param chart * jfreechart chart * @param histogramInterval * displayed interval * @param first * flag indicating if it is the first refresh for a given load */ private void displayChart(final JFreeChart chart, final TimeInterval displayed, final boolean first) { // prepare the new histogram UI Display.getDefault().syncExec(new Runnable() { @Override public void run() { // Clean parent for (Control c : compositeChart.getChildren()) { c.dispose(); } // histogram chart chartFrame = new ChartComposite(compositeChart, SWT.NONE, chart, USE_BUFFER) { @Override public void mouseMove(MouseEvent e) { super.mouseMove(e); // update cursor if (!isInDataArea(e.x, e.y)) { getShell().setCursor(ARROW_CURSOR); } else { if (dragInProgress || (activeSelection && (isNear(e.x, selectedTs0)) || isNear(e.x, selectedTs1))) { getShell().setCursor(IBEAM_CURSOR); } else { getShell().setCursor(ARROW_CURSOR); } } // update marker long v = getTimestampAt(e.x); if (dragInProgress) { // when drag is in progress, the moving side is always Ts1 selectedTs1 = v; long min = Math.min(selectedTs0, selectedTs1); long max = Math.max(selectedTs0, selectedTs1); marker.setStartValue(min); marker.setEndValue(max); timeChanged = true; timeBar.setSelection(min, max); } // update status line updateStatusLine(v); } @Override public void mouseUp(MouseEvent e) { super.mouseUp(e); dragInProgress = false; selectedTs1 = getTimestampAt(e.x); if (selectedTs0 > selectedTs1) { // reorder Ts0 and Ts1 long tmp = selectedTs1; selectedTs1 = selectedTs0; selectedTs0 = tmp; } else if (selectedTs0 == selectedTs1) { marker.setStartValue(selectedTs0); marker.setEndValue(selectedTs0); activeSelection = false; timeBar.setSelection(loadedInterval); updateStatusLine(selectedTs0); } } @Override public void mouseDown(MouseEvent e) { super.mouseDown(e); if (activeSelection) { if (isNear(e.x, selectedTs0)) { // swap in order to have Ts1 as moving side long tmp = selectedTs0; selectedTs0 = selectedTs1; selectedTs1 = tmp; } else if (isNear(e.x, selectedTs1)) { // nothing to do if the moving side is already Ts1 } else { // near to no one: remove marker and add a new one removeMarker(); selectedTs0 = getTimestampAt(e.x); addNewMarker(selectedTs0, selectedTs0); } } else { removeMarker(); selectedTs0 = getTimestampAt(e.x); addNewMarker(selectedTs0, selectedTs0); } activeSelection = true; dragInProgress = true; } private boolean isNear(int pos, long value) { final int RANGE = 3; int vPos = getPosAt(value); if (Math.abs(vPos - pos) <= RANGE) { return true; } return false; } boolean isInDataArea(int x, int y) { if (chartFrame != null) { org.eclipse.swt.graphics.Rectangle swtRect = chartFrame.getScreenDataArea(); Rectangle2D screenDataArea = new Rectangle(); screenDataArea.setRect(swtRect.x, swtRect.y, swtRect.width, swtRect.height); return swtRect.contains(x, y); } return false; } }; chartFrame.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseScrolled(MouseEvent e) { if ((e.stateMask & SWT.CTRL) == SWT.CTRL) { if (e.count > 0) { // zoom in zoomChartAxis(true, e.x, e.y); } else { // zoom out zoomChartAxis(false, e.x, e.y); } } } private void zoomChartAxis(boolean increase, int x, int y) { double min = plot.getDomainAxis().getRange().getLowerBound(); double max = plot.getDomainAxis().getRange().getUpperBound(); X_FORMAT.setContext((long) min, (long) max, true); Point2D p = chartFrame.translateScreenToJava2D(new Point(x, y)); PlotRenderingInfo plotInfo = chartFrame.getChartRenderingInfo().getPlotInfo(); if (increase) { double dmin = min; double dmax = max; if (dmin <= 0) { double inc = -2 * dmin + 1; dmin += inc; dmax += inc; } double diff = (dmax - dmin) / dmin; if (diff >= 0.01) { // zoom only if the (max - min) is at least 1% of the min plot.zoomDomainAxes(0.5, plotInfo, p, true); } } else { // XXX On Fedora 17 this always dezoom all plot.zoomDomainAxes(-0.5, plotInfo, p, true); } // adjust min = plot.getDomainAxis().getRange().getLowerBound(); max = plot.getDomainAxis().getRange().getUpperBound(); Range maxRange = new Range(Math.max(loadedInterval.startTimestamp, min), Math.min(loadedInterval.endTimestamp, max)); plot.getDomainAxis().setRange(maxRange); } }); // - size chartFrame.setSize(compositeChart.getSize()); // - prevent y zooming chartFrame.setRangeZoomable(false); // - prevent x zooming (we do it manually with wheel) chartFrame.setDomainZoomable(false); // - workaround for last xaxis tick not shown (jfreechart bug) RectangleInsets insets = plot.getInsets(); plot.setInsets(new RectangleInsets(insets.getTop(), insets.getLeft(), insets.getBottom(), 25)); // - time bounds plot.getDomainAxis().setLowerBound(displayed.startTimestamp); plot.getDomainAxis().setUpperBound(displayed.endTimestamp); // producers and types if (first) { for (ConfigurationData data : configurationMap.values()) { data.tree.getViewer().setInput(data.roots); data.tree.setCheckedElements(data.checked); data.tree.getViewer().refresh(); data.tree.getViewer().expandAll(); } } // timebar timeBar.setSelection(loadedInterval); } }); }
From source file:it.cnr.icar.eric.client.ui.swing.graph.JBGraph.java
@SuppressWarnings("rawtypes") public JBGraphCell getJBGraphCellAt(DefaultGraphCell parent, int x, int y) { JBGraphCell jbCell = null;//from w w w . j a v a 2s . c o m java.util.List children = parent.getChildren(); if (children != null) { Iterator iter = children.iterator(); while (iter.hasNext()) { Object obj = iter.next(); if (obj instanceof JBGraphCell) { JBGraphCell _jbCell = (JBGraphCell) obj; Rectangle bounds = getCellBounds(_jbCell); if (bounds.contains(x, y)) { jbCell = _jbCell; break; } } } } return jbCell; }