Example usage for java.awt.event MouseEvent BUTTON1

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

Introduction

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

Prototype

int BUTTON1

To view the source code for java.awt.event MouseEvent BUTTON1.

Click Source Link

Document

Indicates mouse button #1; used by #getButton .

Usage

From source file:ec.ui.view.StabilityView.java

public StabilityView() {
    super();/* w  w w  .j a v  a 2 s . com*/
    setLayout(new BorderLayout());

    this.graphs_ = new LinkedHashMap<>();

    meanRenderer = new XYLineAndShapeRenderer(true, false);
    meanRenderer.setAutoPopulateSeriesPaint(false);
    meanRenderer.setBasePaint(themeSupport.getLineColor(KnownColor.RED));

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

    smoothRenderer = new XYLineAndShapeRenderer(true, false);
    smoothRenderer.setAutoPopulateSeriesPaint(false);
    smoothRenderer.setBasePaint(themeSupport.getLineColor(KnownColor.GREEN));

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

    panel = new JChartPanel(null);

    errorPanel = new JPanel(new BorderLayout());
    errorLabel = new JLabel();
    errorLabel.setHorizontalAlignment(SwingConstants.CENTER);
    errorLabel.setFont(errorLabel.getFont().deriveFont(errorLabel.getFont().getSize2D() * 3 / 2));
    errorPanel.add(errorLabel, BorderLayout.CENTER);

    panel.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            indexSelected = -1;
            if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
                double x = panel.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);
            } else if (e.getButton() == MouseEvent.BUTTON3) {
                showMain();
                indexSelected = -1;
            }
        }
    });

    StandardXYToolTipGenerator generator = new StandardXYToolTipGenerator() {
        final DecimalFormat format = new DecimalFormat("0.0000");

        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            try {
                StabilityViewItem i = items.get(indexSelected == -1 ? series : indexSelected);
                int cpt = 0;
                for (Map.Entry<TsDomain, Double> e : i.data.entrySet()) {
                    if (cpt == item) {
                        TsDomain dom = e.getKey();
                        return "(" + dom.getStart().toString() + ", " + dom.getEnd().toString() + ") : "
                                + format.format(e.getValue());
                    }
                    cpt++;
                }
            } catch (IndexOutOfBoundsException e) {
            }
            return null;
        }
    };
    pointsRenderer.setBaseToolTipGenerator(generator);
    cards = new JPanel(new CardLayout());

    cards.add(MAIN_PANEL, panel);

    cards.add(ERROR_PANEL, errorPanel);

    add(cards, BorderLayout.CENTER);

    onColorSchemeChange();
}

From source file:at.ac.tuwien.ibk.biqini.pep.gui.PEPGUI.java

public PEPGUI(String arg0, Vector<IBandwidthTracer> qosRules) {
    super(arg0);/*from w w  w .j av a  2  s.  c o m*/

    // initiate all collections
    tsc = new TimeSeriesCollection[MAXCHARTS];
    charts = new JFreeChart[MAXCHARTS];
    positions = new Vector<Integer>();
    chartPosition = new Hashtable<String, Integer>();
    for (int i = 0; i < MAXCHARTS; i++)
        positions.add(i);
    allSessions = new Hashtable<String, IBandwidthTracer>();

    // fill the BandwidthGenerator with the ongoing QoSRules
    bandwidthGenerator = new BandwidthGenerator();
    Enumeration<IBandwidthTracer> enbandwidth = qosRules.elements();
    while (enbandwidth.hasMoreElements()) {
        IBandwidthTracer b = enbandwidth.nextElement();
        allSessions.put(b.getName(), b);
        bandwidthGenerator.add(b);
    }

    gridBagLayout = new GridBagLayout();

    //insert the list with all QoS rules
    GridBagConstraints c = new GridBagConstraints();
    c.weighty = 9;
    c.weightx = 2.0;
    c.gridheight = MAXCHARTS;
    c.fill = GridBagConstraints.BOTH;
    content = new JPanel(gridBagLayout);
    qoSRuleList = new JList(allSessions.keySet().toArray());
    qoSRuleList.setPreferredSize(new java.awt.Dimension(200, 600));
    qoSRuleList.setBorder(BorderFactory.createRaisedBevelBorder());

    // set a MouseListner on the List
    MouseListener mouseListener = new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {

            if (e.getButton() == MouseEvent.BUTTON1) {
                int index = qoSRuleList.locationToIndex(e.getPoint());
                addStream(allSessions.get(allSessions.keySet().toArray()[index]));
            }
            if (e.getButton() == MouseEvent.BUTTON3) {
                int index = qoSRuleList.locationToIndex(e.getPoint());
                removeStream(allSessions.get(allSessions.keySet().toArray()[index]));
            }
        }
    };
    qoSRuleList.addMouseListener(mouseListener);

    // place all parts at the content pane
    gridBagLayout.setConstraints(qoSRuleList, c);
    content.add(qoSRuleList);
    setContentPane(content);
    content.setSize(1000, 800);

    //create all GUI aspects for our Charts
    insertAllCharts();

    //Start the thread that fills up our time series
    periodicBandwidthReader = new Thread(bandwidthGenerator);
    periodicBandwidthReader.setName("data-collector");
    periodicBandwidthReader.start();
}

From source file:org.kalypso.model.wspm.ui.action.selection.AbstractProfilePointSelectionWidget.java

@Override
public void mousePressed(final MouseEvent e) {
    if (m_viewMode)
        return;//w w  w.  jav a2  s.  c  o m

    if (MouseEvent.BUTTON1 != e.getButton())
        return;

    final boolean shiftDown = e.isShiftDown();
    if (!shiftDown)
        m_p0 = getSnapPoint();

    updateSelection(shiftDown);
}

From source file:net.sf.maltcms.chromaui.charts.events.ChartPanelMouseListener.java

/**
 *
 * @param arg0/*from w w  w.ja v  a2 s .  c  o m*/
 */

@Override
public void chartMouseClicked(final ChartMouseEvent arg0) {
    final ChartPanelMouseListener cpml = this;
    if (arg0.getEntity() != null) {
        if (arg0.getEntity() instanceof XYItemEntity) {
            XYItemEntity xyie = (XYItemEntity) arg0.getEntity();

            if (arg0.getTrigger().getButton() == MouseEvent.BUTTON1) {
                //                
                if (arg0.getTrigger().isAltDown() && arg0.getTrigger().isShiftDown()) {
                    //                        System.out.println("Item removed");
                    fireEvent(new XYItemEntityRemovedEvent((XYItemEntity) arg0.getEntity(), cpml));
                } else if (arg0.getTrigger().isAltDown()) {
                    //                        System.out.println("Item added");
                    fireEvent(new XYItemEntityAddedEvent((XYItemEntity) arg0.getEntity(), cpml));
                } else {
                    setTarget(arg0);
                    //                        System.out.println("Item clicked");
                    fireEvent(new XYItemEntityClickedEvent((XYItemEntity) arg0.getEntity(), cpml));
                }
            }
        } else if (arg0.getEntity() instanceof LegendItemEntity) {
            JPopupMenu jpm = new JPopupMenu();
            final LegendItemEntity lie = (LegendItemEntity) arg0.getEntity();
            Dataset ds = lie.getDataset();
            Comparable skey = lie.getSeriesKey();
            Plot plot = arg0.getChart().getPlot();
            if (plot instanceof XYPlot) {
                XYPlot xyplot = arg0.getChart().getXYPlot();
                if (xyplot.getSeriesCount() > 1) {
                    XYDataset xyds = (XYDataset) ds;
                    XYItemRenderer xyir = xyplot.getRendererForDataset(xyds);

                    xyir.setSeriesVisible(xyds.indexOf(skey), !xyir.isSeriesVisible(xyds.indexOf(skey)));
                    xyir.setSeriesVisibleInLegend(xyds.indexOf(skey), Boolean.TRUE);
                }
            } else if (plot instanceof CategoryPlot) {
                CategoryPlot cplot = arg0.getChart().getCategoryPlot();
                if (cplot.getDatasetCount() > 1) {
                    CategoryDataset cds = (CategoryDataset) ds;
                    CategoryItemRenderer xyir = cplot.getRendererForDataset(cds);
                    int seriesIndex = cds.getColumnIndex(skey);
                    if (seriesIndex == -1) {
                        seriesIndex = cds.getRowIndex(skey);
                    }
                    xyir.setSeriesVisible(seriesIndex, !xyir.isSeriesVisible(seriesIndex));
                    xyir.setSeriesVisibleInLegend(seriesIndex, Boolean.TRUE);
                }
            }
            //                AbstractAction hse = new AbstractAction("Hide") {
            //
            //                    @Override
            //                    public void actionPerformed(ActionEvent ae) {
            //                        
            //                    }
            //                };
            //                AbstractAction hse = new AbstractAction("Show") {
            //
            //                    @Override
            //                    public void actionPerformed(ActionEvent ae) {
            //                        
            //                    }
            //                };
            //                AbstractAction hse = new AbstractAction("Remove") {
            //
            //                    @Override
            //                    public void actionPerformed(ActionEvent ae) {
            //                        
            //                    }
            //                };
        }
    }
}

From source file:org.kalypso.kalypsomodel1d2d.ui.map.channeledit.DrawBanklineWidget.java

@Override
public void mouseReleased(final MouseEvent event) {
    if (event.getButton() != MouseEvent.BUTTON1)
        return;//from   ww w .ja v  a2  s.  co  m
    event.consume();

    if (m_edit && m_lineEditor != null) {
        final GM_Curve curve = m_lineEditor.finish();
        if (curve != null)
            finishLine(curve);
    }
}

From source file:iqq.app.ui.manager.MainManager.java

public void enableTray() {
    if (SystemTray.isSupported() && tray == null) {
        menu = new PopupMenu();
        MenuItem restore = new MenuItem("  ?  ");
        restore.addActionListener(new ActionListener() {
            @Override//  w  ww .  j  av a 2 s. com
            public void actionPerformed(ActionEvent e) {
                show();
            }
        });
        MenuItem exit = new MenuItem("  ?  ");
        exit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        menu.add(restore);
        menu.addSeparator();
        menu.add(exit);

        if (SystemUtils.isMac()) {
            defaultImage = skinService.getIconByKey("window/titleWIconBlack").getImage();
        } else {
            defaultImage = mainFrame.getIconImage();
        }
        blankImage = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
        tray = SystemTray.getSystemTray();
        icon = new TrayIcon(defaultImage, "IQQ");
        icon.setImageAutoSize(true);
        if (!SystemUtils.isMac()) {
            icon.setPopupMenu(menu);
        }
        try {
            tray.add(icon);
            icon.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    logger.debug("MouseEvent " + e.getButton() + " " + e.getClickCount());
                    //??
                    if (e.getButton() == MouseEvent.BUTTON1) {
                        if (flashOwner != null) {
                            Map<String, Object> data = (Map<String, Object>) flashOwner.getAttachment();
                            if (data != null && data.containsKey("action")
                                    && data.get("action").equals("ADD_BUDDY_REQUEST")) {
                                IMContext.getBean(FrameManager.class).showGetFriendRequest((IMBuddy) flashOwner,
                                        data.get("buddy_request_id").toString());
                                eventService.broadcast(new UIEvent(UIEventType.FLASH_USER_STOP, flashOwner));
                                return;
                            } else {
                                // ?
                                chatManager.addChat(flashOwner);
                            }
                        } else {
                            show();
                        }
                    }
                }
            });
        } catch (AWTException e) {
            logger.error("SystemTray add icon.", e);
        }
    }

}

From source file:org.openestate.tool.helloworld.HelloWorldFrameSidebarExtension.java

@Override
public JComponent createComponent() {
    // create the component, that is shown in the sidebar
    final HelloWorldList list = new HelloWorldList();
    list.setModel(ObjectUtils.defaultIfNull(createListModel(), new DefaultListModel<>()));
    list.setCellRenderer(new HelloWorldListRenderer());

    // register keyboard events
    list.addKeyListener(new KeyAdapter() {
        @Override//from ww w .ja  v a  2 s .  co m
        public void keyPressed(KeyEvent e) {
            if (!list.isEnabled())
                return;

            // ENTER was pressed
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                DbHelloWorldObject object = list.getSelectedValue();
                if (object != null)
                    new HelloWorldPlugin.ObjectFormAction(object.id).actionPerformed(null);
            }
        }
    });

    // register mouse events
    list.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (!list.isEnabled())
                return;

            // single click with the right mouse button
            if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) {
                // fetch the clicked element
                int index = list.locationToIndex(e.getPoint());
                if (index >= 0)
                    list.setSelectedIndex(index);

                // show popup menu with further actions
                DbHelloWorldObject object = list.getSelectedValue();
                JPopupMenu popup = createActionMenu(object);
                if (popup != null)
                    popup.show(list, e.getPoint().x, e.getPoint().y);
            }

            // double click with the left mouse button
            else if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
                DbHelloWorldObject object = list.getSelectedValue();
                if (object != null)
                    new HelloWorldPlugin.ObjectFormAction(object.id).actionPerformed(null);
            }
        }
    });

    return list;
}

From source file:org.kalypso.kalypsomodel1d2d.ui.map.channeledit.DrawBanklineWidget.java

@Override
public void mouseClicked(final MouseEvent event) {
    if (event.getButton() != MouseEvent.BUTTON1)
        return;/*from  w  w  w. ja va2 s. c o  m*/
    if (event.getClickCount() < 2)
        return;
    event.consume();

    if (m_edit && event.isShiftDown()) {
        // TODO: insert points into current line
    }

    if (m_lineBuilder != null) {
        try {
            final GM_Curve curve = (GM_Curve) m_lineBuilder.finish();
            finishLine(curve);
        } catch (final Exception e) {
            e.printStackTrace();
            reinit();
        }
    }
}

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

/**
 * Creates new form FixedHorizonsGraphView
 *///ww w  .  ja  va  2s  .  c  o  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:TransferableScribblePane.java

/**
 * This method is called on mouse button events. It begins a new line or tries
 * to select an existing line./*from  w w w  . j av  a2 s.  c om*/
 */
public void processMouseEvent(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON1) { // Left mouse button
        if (e.getID() == MouseEvent.MOUSE_PRESSED) { // Pressed down
            if (e.isShiftDown()) { // with Shift key
                // If the shift key is down, try to select a line
                int x = e.getX();
                int y = e.getY();

                // Loop through the lines checking to see if we hit one
                PolyLine selection = null;
                int numlines = lines.size();
                for (int i = 0; i < numlines; i++) {
                    PolyLine line = (PolyLine) lines.get(i);
                    if (line.intersects(x - 2, y - 2, 4, 4)) {
                        selection = line;
                        e.consume();
                        break;
                    }
                }
                // If we found an intersecting line, save it and repaint
                if (selection != selectedLine) { // If selection changed
                    selectedLine = selection; // remember which is selected
                    repaint(); // will make selection dashed
                }
            } else if (!e.isControlDown()) { // no shift key or ctrl key
                // Start a new line on mouse down without shift or ctrl
                currentLine = new PolyLine(e.getX(), e.getY());
                lines.add(currentLine);
                e.consume();
            }
        } else if (e.getID() == MouseEvent.MOUSE_RELEASED) {// Left Button Up
            // End the line on mouse up
            if (currentLine != null) {
                currentLine = null;
                e.consume();
            }
        }
    }

    // The superclass method dispatches to registered event listeners
    super.processMouseEvent(e);
}