Example usage for java.awt.event MouseEvent getX

List of usage examples for java.awt.event MouseEvent getX

Introduction

In this page you can find the example usage for java.awt.event MouseEvent getX.

Prototype

public int getX() 

Source Link

Document

Returns the horizontal x position of the event relative to the source component.

Usage

From source file:com.hexidec.ekit.component.RelativeImageView.java

/** Select or grow image when clicked.
  *//*from  w w w.  j  av a2  s . c o  m*/
public void mousePressed(MouseEvent e) {
    Dimension size = fComponent.getSize();
    if ((e.getX() >= (size.width - 7)) && (e.getY() >= (size.height - 7)) && (getSelectionState() == 2)) {
        // Click in selected grow-box:
        Point loc = fComponent.getLocationOnScreen();
        fGrowBase = new Point(loc.x + e.getX() - fWidth, loc.y + e.getY() - fHeight);
        fGrowProportionally = e.isShiftDown();
    } else {
        // Else select image:
        fGrowBase = null;
        JTextComponent comp = (JTextComponent) fContainer;
        int start = fElement.getStartOffset();
        int end = fElement.getEndOffset();
        int mark = comp.getCaret().getMark();
        int dot = comp.getCaret().getDot();
        if (e.isShiftDown()) {
            // extend selection if shift key down:
            if (mark <= start) {
                comp.moveCaretPosition(end);
            } else {
                comp.moveCaretPosition(start);
            }
        } else {
            // just select image, without shift:
            if (mark != start) {
                comp.setCaretPosition(start);
            }
            if (dot != end) {
                comp.moveCaretPosition(end);
            }
        }
    }
}

From source file:com.ivli.roim.controls.ChartControl.java

@Override
public void mouseDragged(MouseEvent e) {
    final XYPlot plot = getChart().getXYPlot();

    if (null != iEntity) {
        moveTo(plot.getRangeAxis().java2DToValue(e.getY(), getChartRenderingInfo().getPlotInfo().getDataArea(),
                plot.getRangeAxisEdge()));
    }/*from www  .  j  av  a 2 s  .c o  m*/
    if (null != iMarker) {
        double domainX = plot.getDomainAxis().java2DToValue(e.getX(), getScreenDataArea(),
                plot.getDomainAxisEdge());
        iMarker.setValue(domainX);
    } else
        super.mouseDragged(e);
}

From source file:net.sf.jabref.gui.maintable.MainTableSelectionListener.java

/**
 * Process general right-click events on the table. Show the table context menu at
 * the position where the user right-clicked.
 * @param e The mouse event defining the popup trigger.
 * @param row The row where the event occurred.
 *///from   ww  w.  j  a va 2s  .c om
private void processPopupTrigger(MouseEvent e, int row) {
    int selRow = table.getSelectedRow();
    if ((selRow == -1) || !table.isRowSelected(table.rowAtPoint(e.getPoint()))) {
        table.setRowSelectionInterval(row, row);
    }
    RightClickMenu rightClickMenu = new RightClickMenu(JabRefGUI.getMainFrame(), panel);
    rightClickMenu.show(table, e.getX(), e.getY());
}

From source file:be.nbb.demetra.dfm.output.simulation.RealTimePerspGraphView.java

/**
 * Creates new form FixedHorizonsGraphView
 *///w w  w  .j  ava  2s.  co m
public RealTimePerspGraphView(DfmDocument doc) {
    initComponents();

    demetraUI = DemetraUI.getDefault();
    formatter = demetraUI.getDataFormat().numberFormatter();
    defaultColorSchemeSupport = new SwingColorSchemeSupport() {
        @Override
        public ColorScheme getColorScheme() {
            return demetraUI.getColorScheme();
        }
    };

    this.graphs_ = new LinkedHashMap<>();

    trueDataRenderer = new XYLineAndShapeRenderer(true, false);
    trueDataRenderer.setAutoPopulateSeriesPaint(false);
    trueDataRenderer.setBasePaint(defaultColorSchemeSupport.getLineColor(KnownColor.RED));

    forecastsRenderer = new XYLineAndShapeRenderer(true, false);
    forecastsRenderer.setAutoPopulateSeriesPaint(false);
    forecastsRenderer.setAutoPopulateSeriesShape(false);
    forecastsRenderer.setBaseShape(new Ellipse2D.Double(-2, -2, 4, 4));
    forecastsRenderer.setBasePaint(defaultColorSchemeSupport.getLineColor(KnownColor.BLUE));
    forecastsRenderer.setBaseShapesFilled(false);

    arimaRenderer = new XYLineAndShapeRenderer(true, false);
    arimaRenderer.setAutoPopulateSeriesPaint(false);
    arimaRenderer.setAutoPopulateSeriesShape(false);
    arimaRenderer.setBaseShape(new Ellipse2D.Double(-2, -2, 4, 4));
    arimaRenderer.setBasePaint(defaultColorSchemeSupport.getLineColor(KnownColor.GREEN));
    arimaRenderer.setBaseShapesFilled(false);

    mainChart = createChart();
    detailChart = createChart();

    this.dfmSimulation = Optional.absent();

    chartPanel = new JChartPanel(null);
    chartPanel.setPopupMenu(buildMenu().getPopupMenu());

    chartPanel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            indexSelected = -1;
            if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
                double x = chartPanel.getChartX(e.getX());
                Graphs g = null;
                for (Bornes b : graphs_.keySet()) {
                    indexSelected++;
                    if (x >= b.min_ && x <= b.max_) {
                        g = graphs_.get(b);
                        break;
                    }
                }
                if (g == null) {
                    return;
                }

                showDetail(g);
            }
        }
    });

    comboBox.setRenderer(new ComboBoxRenderer());
    comboBox.addItemListener((ItemEvent e) -> {
        filterPanel = null;
        updateChart();
    });

    addPropertyChangeListener((PropertyChangeEvent evt) -> {
        switch (evt.getPropertyName()) {
        case DFM_SIMULATION_PROPERTY:
            updateComboBox();
            updateChart();
            break;
        }
    });

    updateComboBox();
    updateChart();

    demetraUI.addPropertyChangeListener((PropertyChangeEvent evt) -> {
        switch (evt.getPropertyName()) {
        case DemetraUI.DATA_FORMAT_PROPERTY:
            onDataFormatChanged();
            break;
        case DemetraUI.COLOR_SCHEME_NAME_PROPERTY:
            onColorSchemeChanged();
            break;
        }
    });

    add(chartPanel, BorderLayout.CENTER);
}

From source file:forge.screens.match.CMatchUI.java

@Override
public SpellAbility getAbilityToPlay(List<SpellAbility> abilities, ITriggerEvent triggerEvent) {
    if (triggerEvent == null) {
        if (abilities.isEmpty()) {
            return null;
        }//www  .  j a v a 2s .co m
        if (abilities.size() == 1) {
            return abilities.get(0);
        }
        return GuiChoose.oneOrNone("Choose ability to play", abilities);
    }

    if (abilities.isEmpty()) {
        return null;
    }
    if (abilities.size() == 1 && !abilities.get(0).promptIfOnlyPossibleAbility()) {
        if (abilities.get(0).canPlay()) {
            return abilities.get(0); //only return ability if it's playable, otherwise return null
        }
        return null;
    }

    //show menu if mouse was trigger for ability
    final JPopupMenu menu = new JPopupMenu("Abilities");

    boolean enabled;
    boolean hasEnabled = false;
    int shortcut = KeyEvent.VK_1; //use number keys as shortcuts for abilities 1-9
    for (final SpellAbility ab : abilities) {
        enabled = ab.canPlay();
        if (enabled) {
            hasEnabled = true;
        }
        GuiUtils.addMenuItem(menu, FSkin.encodeSymbols(ab.toString(), true),
                shortcut > 0 ? KeyStroke.getKeyStroke(shortcut, 0) : null, new Runnable() {
                    @Override
                    public void run() {
                        CPrompt.SINGLETON_INSTANCE.selectAbility(ab);
                    }
                }, enabled);
        if (shortcut > 0) {
            shortcut++;
            if (shortcut > KeyEvent.VK_9) {
                shortcut = 0; //stop adding shortcuts after 9
            }
        }
    }
    if (hasEnabled) { //only show menu if at least one ability can be played
        SwingUtilities.invokeLater(new Runnable() { //use invoke later to ensure first ability selected by default
            public void run() {
                MenuSelectionManager.defaultManager()
                        .setSelectedPath(new MenuElement[] { menu, menu.getSubElements()[0] });
            }
        });
        MouseEvent mouseEvent = ((MouseTriggerEvent) triggerEvent).getMouseEvent();
        menu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
    }

    return null; //delay ability until choice made
}

From source file:net.fenyo.gnetwatch.GUI.BasicComponent.java

public void mouseDragged(final MouseEvent e) {
    if (manual_mode) {
        manual_now = drag_now_start/*w  w  w  .  j av  a2s  .  c o  m*/
                + manual_delay_per_interval * (drag_x_start - e.getX()) / pixels_per_interval;
    }
    repaint();
}

From source file:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java

/**
 * {@inheritDoc}/*from w  w  w  .  j  a va 2s  .co  m*/
 */

@Override
public void mouseDragged(MouseEvent e) {
    if (checkModifiers(e)) {
        @SuppressWarnings("unchecked")
        final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource();
        final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout();
        final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport();
        if (startVertex != null) {
            transformEdgeShape(down, e.getPoint());
            if (edgeIsDirected == EdgeType.DIRECTED) {
                transformArrowShape(down, e.getPoint());
                final CNode pointedVertex = pickSupport.getVertex(layout, e.getX(), e.getY());
                if (pointedVertex != null && pointedVertex != startVertex) {
                    if (!pointedVertices.containsKey(pointedVertex)) {
                        pointedVertices.put(pointedVertex, pointedVertex.getColor()); //save original color
                    }
                    Color prevColor = pointedVertex.getColor();
                    if (pointedVertex.getColor().equals(pointedVertices.get(pointedVertex))) {

                        if (pointedVertex != this.lastDragVertex && this.lastDragVertex != null) {
                            lastDragVertex.setColor(pointedVertices.get(lastDragVertex));
                        }
                        //Don't change color if there is an existing edge
                        if (layout.getGraph().findEdge(startVertex, pointedVertex) == null) {
                            if (GraphUtil.isDarkNode(pointedVertex)) {
                                if (prevColor.darker().equals(prevColor)) {
                                    pointedVertex.setColor(Color.GRAY);
                                } else {
                                    if (prevColor.brighter().equals(prevColor)) {
                                        pointedVertex.setColor(Color.GRAY);
                                    } else {
                                        pointedVertex.setColor(pointedVertices.get(pointedVertex).brighter());
                                    }
                                }
                            } else {
                                pointedVertex.setColor(pointedVertices.get(pointedVertex).darker());
                            }
                        }
                    }
                    this.lastDragVertex = this.dragVertex;
                    this.dragVertex = pointedVertex;
                } else if (dragVertex != null) {
                    dragVertex.setColor(pointedVertices.get(dragVertex));
                }
            }
        }
        vv.repaint();
    }
}

From source file:hermes.browser.dialog.HermesAdminFactoryConfigPanel.java

public void init() {
    final Border border = BorderFactory.createBevelBorder(BevelBorder.RAISED);
    setLayout(new BorderLayout());
    setBorder(BorderFactory.createTitledBorder(border, ADMIN_FACTORY));

    afCombo.setModel(cfComboModel);/*  w  w w .j ava2s . co m*/

    propertyTableSP.setViewportView(propertyTable);
    propertyTable.setSortable(true);
    add(afCombo, BorderLayout.NORTH);
    add(propertyTableSP, BorderLayout.CENTER);

    popupMenu.add(addItem);
    popupMenu.add(removeItem);

    addItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            try {
                propertyTableModel.insertRow();
            } catch (Exception ex) {
                cat.error(ex.getMessage(), ex);
            }
        }
    });

    removeItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (propertyTable.getSelectedRow() != -1) {
                propertyTableModel.removeRow(propertyTable.getSelectedRow());
            }
        }
    });

    final MouseAdapter m = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                if (e.getComponent() == propertyTableSP) {
                    removeItem.setEnabled(false);
                } else {
                    removeItem.setEnabled(true);
                }

                if (propertySelectionComboBox.getModel().getSize() == 0) {
                    addItem.setEnabled(false);
                } else {
                    addItem.setEnabled(true);
                }

                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    };

    propertyTableSP.addMouseListener(m);
    propertyTable.addMouseListener(m);
    propertyTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

    cfComboModel.addListDataListener(new ListDataListener() {
        public void contentsChanged(ListDataEvent arg0) {
            final String className = HermesBrowser.getConfigDAO()
                    .getAdminClassForPlugIn((String) cfComboModel.getSelectedItem());
            final ClassLoaderManager classLoaderManager = (ClassLoaderManager) SingletonManager
                    .get(ClassLoaderManager.class);

            try {
                if (propertyTableModel != null) {
                    final ClassLoader classLoader = classLoaderManager
                            .getClassLoader(dialog.getSelectedLoader());
                    Thread.currentThread().setContextClassLoader(classLoader);

                    bean = (HermesAdminFactory) classLoader.loadClass(className).newInstance();
                    propertyTableModel.setBean(bean);
                    updateCellEditor();
                    dialog.setDirty();
                }
            } catch (Throwable e) {
                HermesBrowser.getBrowser().showErrorDialog(
                        "Unable to locate this plugin.\nSelect the loader the JMS provider classes are in before choosing the plugin.");
                cfComboModel.setSelectedItem(ConfigDAO.DEFAULT_PLUGIN);
            }
        }

        public void intervalAdded(ListDataEvent arg0) {
            // NOP
        }

        public void intervalRemoved(ListDataEvent arg0) {
            // NOP
        }
    });

}

From source file:es.emergya.ui.gis.FleetControlMapViewer.java

@Override
public void actionPerformed(final ActionEvent e) {

    final CustomMapView mapViewLocal = this.mapView;

    SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {
        @Override/*from   w  ww . j a  va  2  s .  c  o  m*/
        protected Object doInBackground() throws Exception {

            try {
                final MouseEvent mouseEvent = FleetControlMapViewer.this.eventOriginal;
                if (e.getActionCommand().equals(// Centrar aqui
                        i18n.getString(Locale.ROOT, "map.menu.centerHere"))) {
                    mapViewLocal.zoomToFactor(mapViewLocal.getEastNorth(mouseEvent.getX(), mouseEvent.getY()),
                            mapViewLocal.zoomFactor);

                } else if (e.getActionCommand().equals(// nueva incidencia
                        i18n.getString("map.menu.newIncidence"))) {
                    Incidencia f = new Incidencia();
                    f.setCreador(Authentication.getUsuario());
                    LatLon from = mapViewLocal.getLatLon(mouseEvent.getX(), mouseEvent.getY());
                    GeometryFactory gf = new GeometryFactory();
                    f.setGeometria(gf.createPoint(new Coordinate(from.lon(), from.lat())));
                    IncidenceDialog id = new IncidenceDialog(f, i18n.getString("Incidences.summary.title") + " "
                            + i18n.getString("Incidences.nuevaIncidencia"), "tittleficha_icon_recurso");
                    id.setVisible(true);

                } else if (e.getActionCommand().equals(// ruta desde
                        i18n.getString("map.menu.route.from"))) {
                    routeDialog.showRouteDialog(mapViewLocal.getLatLon(mouseEvent.getX(), mouseEvent.getY()),
                            null, mapViewLocal);

                } else if (e.getActionCommand().equals(// ruta hasta
                        i18n.getString("map.menu.route.to"))) {
                    routeDialog.showRouteDialog(null,
                            mapViewLocal.getLatLon(mouseEvent.getX(), mouseEvent.getY()), mapViewLocal);

                } else if (e.getActionCommand().equals(// Actualizar gps
                        i18n.getString("map.menu.gps"))) {
                    if (!(menuObjective instanceof Recurso)) {
                        return null;
                    }

                    GPSDialog sdsDialog = null;
                    for (Frame f : Frame.getFrames()) {
                        if (f instanceof GPSDialog)
                            if (((GPSDialog) f).getRecurso().equals(menuObjective))
                                sdsDialog = (GPSDialog) f;
                    }
                    if (sdsDialog == null)
                        sdsDialog = new GPSDialog((Recurso) menuObjective);
                    sdsDialog.setVisible(true);
                    sdsDialog.setExtendedState(JFrame.NORMAL);

                } else if (e.getActionCommand().equals(// Ficha
                        i18n.getString("map.menu.summary"))) {
                    if (log.isTraceEnabled()) {
                        log.trace("Mostramos la ficha del objetivo del menu");
                    }
                    if (menuObjective instanceof Recurso) {
                        log.trace(">recurso");
                        SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {

                            @Override
                            protected Object doInBackground() throws Exception {
                                for (Frame f : JFrame.getFrames()) {
                                    if (f.getName().equals(((Recurso) menuObjective).getIdentificador())
                                            && f instanceof SummaryDialog) {
                                        if (f.isShowing()) {
                                            f.toFront();
                                            f.setExtendedState(JFrame.NORMAL);
                                            return null;
                                        }
                                    }
                                }
                                new SummaryDialog((Recurso) menuObjective).setVisible(true);
                                return null;
                            }
                        };

                        sw.execute();
                    } else if (menuObjective instanceof Incidencia) {
                        if (log.isTraceEnabled()) {
                            log.trace(">incidencia");
                        }
                        SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {

                            @Override
                            protected Object doInBackground() throws Exception {
                                for (Frame f : JFrame.getFrames()) {
                                    if (f.getName().equals(((Incidencia) menuObjective).getTitulo())
                                            && f instanceof IncidenceDialog) {
                                        if (log.isTraceEnabled()) {
                                            log.trace("Ya lo tenemos abierto");
                                        }
                                        if (f.isShowing()) {
                                            f.toFront();
                                            f.setExtendedState(JFrame.NORMAL);
                                        } else {
                                            f.setVisible(true);
                                            f.setExtendedState(JFrame.NORMAL);
                                        }
                                        return null;
                                    }
                                }
                                if (log.isTraceEnabled()) {
                                    log.trace("Abrimos uno nuevo");
                                }
                                new IncidenceDialog((Incidencia) menuObjective,
                                        i18n.getString("Incidences.summary.title") + " "
                                                + ((Incidencia) menuObjective).getTitulo(),
                                        "tittleficha_icon_recurso").setVisible(true);
                                return null;
                            }
                        };

                        sw.execute();
                    } else {
                        return null;
                    }

                } else if (e.getActionCommand().equals( // Mas cercanos
                        i18n.getString("map.menu.showNearest"))) {
                    if (log.isTraceEnabled()) {
                        log.trace("showNearest");
                    }

                    if (menuObjective != null) {
                        for (Frame f : JFrame.getFrames()) {
                            String identificador = menuObjective.toString();
                            if (menuObjective instanceof Recurso) {
                                identificador = ((Recurso) menuObjective).getIdentificador();
                            }
                            if (menuObjective != null && f.getName().equals(identificador)
                                    && f instanceof NearestResourcesDialog && f.isDisplayable()) {
                                if (log.isTraceEnabled()) {
                                    log.trace("Encontrado " + f);
                                }
                                if (f.isShowing()) {
                                    f.toFront();
                                    f.setExtendedState(JFrame.NORMAL);
                                } else {
                                    f.setVisible(true);
                                    f.setExtendedState(JFrame.NORMAL);
                                }
                                return null;
                            }
                        }
                    }
                    NearestResourcesDialog d;
                    if (menuObjective instanceof Recurso) {
                        d = new NearestResourcesDialog((Recurso) menuObjective, mapViewLocal);
                    } else if (menuObjective instanceof Incidencia) {
                        d = new NearestResourcesDialog((Incidencia) menuObjective,
                                mapViewLocal.getLatLon(mouseEvent.getX(), mouseEvent.getY()), mapViewLocal);
                    } else {
                        d = new NearestResourcesDialog(
                                mapViewLocal.getLatLon(mouseEvent.getX(), mouseEvent.getY()), mapViewLocal);
                    }
                    d.setVisible(true);

                } else {
                    log.error("ActionCommand desconocido: " + e.getActionCommand());
                }
            } catch (Throwable t) {
                log.error("Error al ejecutar la accion del menu contextual", t);
            }
            return null;
        }
    };

    sw.execute();
}

From source file:com.hexidec.ekit.component.RelativeImageView.java

/** Resize image if initial click was in grow-box: */
public void mouseDragged(MouseEvent e) {
    if (fGrowBase != null) {
        Point loc = fComponent.getLocationOnScreen();
        int width = Math.max(2, loc.x + e.getX() - fGrowBase.x);
        int height = Math.max(2, loc.y + e.getY() - fGrowBase.y);
        if (e.isShiftDown() && fImage != null) {
            // Make sure size is proportional to actual image size
            float imgWidth = fImage.getWidth(this);
            float imgHeight = fImage.getHeight(this);
            if ((imgWidth > 0) && (imgHeight > 0)) {
                float prop = imgHeight / imgWidth;
                float pwidth = height / prop;
                float pheight = width * prop;
                if (pwidth > width) {
                    width = (int) pwidth;
                } else {
                    height = (int) pheight;
                }//  ww  w . j a v  a 2s  .c om
            }
        }
        resize(width, height);
    }
}