Example usage for java.awt.event MouseEvent getSource

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

Introduction

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

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:org.languagetool.gui.ConfigurationDialog.java

@NotNull
private MouseAdapter getMouseAdapter() {
    return new MouseAdapter() {
        private void handlePopupEvent(MouseEvent e) {
            JTree tree = (JTree) e.getSource();
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path == null) {
                return;
            }/*from   ww w  . j  a va 2 s.c  om*/
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            TreePath[] paths = tree.getSelectionPaths();
            boolean isSelected = false;
            if (paths != null) {
                for (TreePath selectionPath : paths) {
                    if (selectionPath.equals(path)) {
                        isSelected = true;
                    }
                }
            }
            if (!isSelected) {
                tree.setSelectionPath(path);
            }
            if (node.isLeaf()) {
                JPopupMenu popup = new JPopupMenu();
                JMenuItem aboutRuleMenuItem = new JMenuItem(messages.getString("guiAboutRuleMenu"));
                aboutRuleMenuItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        RuleNode node = (RuleNode) tree.getSelectionPath().getLastPathComponent();
                        Rule rule = node.getRule();
                        Language lang = config.getLanguage();
                        if (lang == null) {
                            lang = Languages.getLanguageForLocale(Locale.getDefault());
                        }
                        Tools.showRuleInfoDialog(tree, messages.getString("guiAboutRuleTitle"),
                                rule.getDescription(), rule, rule.getUrl(), messages,
                                lang.getShortCodeWithCountryAndVariant());
                    }
                });
                popup.add(aboutRuleMenuItem);
                popup.show(tree, e.getX(), e.getY());
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                handlePopupEvent(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                handlePopupEvent(e);
            }
        }
    };
}

From source file:org.rdv.ui.TimeSlider.java

/**
 * Gets the text for the tooltip. This will return a description of the
 * markers the mouse pointer is around./*ww  w  .ja  va 2 s.c o m*/
 * 
 * @param me  the mouse event that triggered this
 * @return    text describing the markers around the mouse pointer
 */
public String getToolTipText(MouseEvent me) {
    int x = me.getX();
    if (me.getSource() == valueButton) {
        x += valueButton.getX();
    }

    double time = getTimeFromX(x);
    double timeOffset = time - value;

    double markerOffset = 2 * getPixelTime();
    List<EventMarker> markersOver = getMarkersAroundTime(time, markerOffset);

    String text = new String("<html><font size=\"5\">");

    text += DataViewer.formatDateSmart(time);
    if (timeOffset != 0) {
        text += " (" + (timeOffset < 0 ? "-" : "+") + DataViewer.formatSeconds(Math.abs(timeOffset)) + ")";
    }

    int numberOfMarkers = markersOver.size();
    if (numberOfMarkers > 0) {
        text += "<br>Found " + numberOfMarkers + " event" + (numberOfMarkers == 1 ? "" : "s") + " (&plusmn;"
                + DataViewer.formatSeconds(markerOffset) + ")<br><br>";
    }

    for (EventMarker marker : markersOver) {
        String date = DataViewer.formatDate(Double.parseDouble(marker.getProperty("timestamp")));
        String source = marker.getProperty("source");
        String type = marker.getProperty("type");
        String label = marker.getProperty("label");
        String content = marker.getProperty("content");

        boolean showType = false;
        String dateColor;
        if (type == null) {
            dateColor = "black";
        } else if (type.compareToIgnoreCase("annotation") == 0) {
            dateColor = "blue";
        } else if (type.compareToIgnoreCase("start") == 0) {
            dateColor = "green";
        } else if (type.compareToIgnoreCase("stop") == 0) {
            dateColor = "red";
        } else {
            showType = true;
            dateColor = "#FF9900";
        }

        text += "<font color=" + dateColor + ">" + date + "</font> ";

        if (showType) {
            text += "<i>" + type + "</i> ";
        }

        if (source != null && source.length() > 0) {
            text += "by " + source + ": ";
        }

        if (label != null && label.length() > 0) {
            text += "<u>" + label + "</u> ";
        }

        if (content != null && content.length() > 0) {
            int maxLineLength = 75;
            int maxLines = 10;

            String[] words = content.split(" ");
            int lineLength = 0;
            int lines = 0;
            for (String word : words) {
                if (lineLength + word.length() < (lines == 0 ? (maxLineLength - 32) : maxLineLength)) {
                    text += " " + word;
                    lineLength += word.length() + 1;
                } else {
                    if (++lines == maxLines) {
                        text += "...";
                        break;
                    }
                    text += "<br>" + word;
                    lineLength = word.length();
                }
            }
        }
        text += "<br>";
    }
    text += "</font></html>";

    return text;
}

From source file:de.tor.tribes.ui.views.DSWorkbenchStatsFrame.java

private void fireChangeStatTimeEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireChangeStatTimeEvent
    if (evt.getSource() == jWeeklyStats) {
        //remove one week from end date
        long oneWeek = DateUtils.MILLIS_PER_DAY * 7;// 1000l * 60l * 60l * 24l * 7l;
        Date end = new Date();//jEndDate.getSelectedDate();
        jEndDate.setDate(end);//from  w ww.ja v a 2  s . c o  m
        //long start = end.getTime() - oneWeek;
        jStartDate.setDate(new Date(end.getTime() - oneWeek));
    } else {
        //remove one month from end date
        long oneMonth = DateUtils.MILLIS_PER_DAY * 31;// 1000l * 60l * 60l * 24l * 31l;
        Date end = new Date();//jEndDate.getSelectedDate();
        jEndDate.setDate(end);
        //  long start = end.getTime() - oneMonth;
        jStartDate.setDate(new Date(end.getTime() - oneMonth));
    }
}

From source file:org.rdv.ui.TimeSlider.java

/**
 * Called when the mouse is dragged. This deals dragging the time value and
 * range controls./*from   w w w. j  av  a  2s. co  m*/
 * 
 * @param me  the mosue event that triggered this 
 */
public void mouseDragged(MouseEvent me) {
    if (!isEnabled()) {
        return;
    }

    JButton button = (JButton) me.getSource();
    int x = me.getX();
    if (button == startButton) {
        x += endButton.getWidth() - clickStart;
    } else if (button == valueButton) {
        x += Math.round(valueButton.getWidth() / 2d) - clickStart;
    } else if (button == endButton) {
        x -= clickStart;
    }
    double time = getTimeFromX(button.getX() + x);

    if (button == startButton) {
        if (time < minimum) {
            time = minimum;
        } else if (time >= end) {
            time = end;
        }

        setStart(time);
    } else if (button == valueButton) {
        if (rangeChangeable) {
            if (time < start) {
                time = start;
            } else if (time > end) {
                time = end;
            }
        } else {
            if (time < minimum) {
                time = minimum;
            } else if (time > maximum) {
                time = maximum;
            }
        }

        setValue(time);
    } else if (button == endButton) {
        if (time < start) {
            time = start;
        } else if (time > maximum) {
            time = maximum;
        }

        setEnd(time);
    }
}

From source file:com.unicauca.braim.braimclient.BraimGui.java

private void add_mouse_listener_to_list() {

    MouseListener mouseListener = new MouseAdapter() {
        @Override/*from  w ww  .  ja  v a2  s  .  com*/
        public void mouseClicked(MouseEvent mouseEvent) {
            JList theList = (JList) mouseEvent.getSource();
            if (mouseEvent.getClickCount() == 2) {
                int index = theList.locationToIndex(mouseEvent.getPoint());
                if (index >= 0) {
                    actualSong = actualSongList[index];
                    lbl_song_name.setText(actualSong.getName());
                    play_song(actualSong);
                }
            }
        }
    };
    list_songs.addMouseListener(mouseListener);
}

From source file:net.sf.mzmine.modules.visualization.msms.MsMsPlot.java

@Override
public void mouseClicked(final MouseEvent event) {

    // Let the parent handle the event (selection etc.)
    super.mouseClicked(event);

    if (event.getX() < 70) { // User clicked on Y-axis
        if (event.getClickCount() == 2) { // Reset zoom on Y-axis
            XYDataset data = ((XYPlot) getChart().getPlot()).getDataset();
            Number maximum = DatasetUtils.findMaximumRangeValue(data);
            getXYPlot().getRangeAxis().setRange(0, 1.05 * maximum.floatValue());
        } else if (event.getClickCount() == 1) {
            // Auto range on Y-axis
            getXYPlot().getRangeAxis().setAutoTickUnitSelection(true);
            getXYPlot().getRangeAxis().setAutoRange(true);
        }//w w  w .j  a  v a2 s.  c  om
    } else if (event.getY() > this.getChartRenderingInfo().getPlotInfo().getPlotArea().getMaxY() - 41
            && event.getClickCount() == 2) {
        // Reset zoom on X-axis
        getXYPlot().getDomainAxis().setAutoTickUnitSelection(true);
        restoreAutoDomainBounds();
    } else if (event.getClickCount() == 2) {
        visualizer.actionPerformed(
                new ActionEvent(event.getSource(), ActionEvent.ACTION_PERFORMED, "SHOW_SPECTRUM"));
    }
}

From source file:net.sf.mzmine.modules.visualization.ida.IDAPlot.java

@Override
public void mouseClicked(final MouseEvent event) {

    // Let the parent handle the event (selection etc.)
    super.mouseClicked(event);

    if (event.getX() < 70) { // User clicked on Y-axis
        if (event.getClickCount() == 2) { // Reset zoom on Y-axis
            XYDataset data = ((XYPlot) getChart().getPlot()).getDataset();
            Number maximum = DatasetUtilities.findMaximumRangeValue(data);
            getXYPlot().getRangeAxis().setRange(0, 1.05 * maximum.floatValue());
        } else if (event.getClickCount() == 1) {
            // Auto range on Y-axis
            getXYPlot().getRangeAxis().setAutoTickUnitSelection(true);
            getXYPlot().getRangeAxis().setAutoRange(true);
        }//  w ww  . j  a va  2  s.  c o m
    } else if (event.getY() > this.getChartRenderingInfo().getPlotInfo().getPlotArea().getMaxY() - 41
            && event.getClickCount() == 2) {
        // Reset zoom on X-axis
        getXYPlot().getDomainAxis().setAutoTickUnitSelection(true);
        restoreAutoDomainBounds();
    } else if (event.getClickCount() == 2) {
        visualizer.actionPerformed(
                new ActionEvent(event.getSource(), ActionEvent.ACTION_PERFORMED, "SHOW_SPECTRUM"));
    }
}

From source file:canreg.client.gui.management.CanReg4MigrationInternalFrame.java

private void jList1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseClicked
    // TODO add your handling code here:
    list = (JList) evt.getSource();
    if (list.getModel().getSize() > 0) {
        if (list.isSelectedIndex(list.getSelectedIndex())) {
            okButton.setEnabled(true);/* www.  j  av  a2s.  c  o  m*/
        }
        regcode = registryCodes.get(list.getSelectedIndex());
        filepath = paths.get(list.getSelectedIndex());
        DBSearch dbs = new DBSearch();
        File[] dbList = dbs.getDBList(filepath);
        int dbSearch = (dbs.searchDB(dbList)) ? 1 : 0;

        switch (dbSearch) {
        case 0:
            okButton.setEnabled(false);
            JOptionPane.showConfirmDialog(CanRegClientApp.getApplication().getMainFrame().getContentPane(),
                    "'" + dlm.get(list.getSelectedIndex())
                            + "' DB Files are Missing.\nPlease Confirm Location '" + CR4Path + regcode + "'",
                    "Missing DB Files.", JOptionPane.PLAIN_MESSAGE);
            break;
        case 1:
            String dicFile = dbs.getDicDB(dbList);
            String datFile = dbs.getDatDB(dbList);

            if (dicFile == null || datFile == null) {
                okButton.setEnabled(false);
                JOptionPane.showConfirmDialog(CanRegClientApp.getApplication().getMainFrame().getContentPane(),
                        "'" + dlm.get(list.getSelectedIndex())
                                + "' DB Files are Missing.\nPlease Confirm Location '" + CR4Path + regcode
                                + "'",
                        "Missing DB Files.", JOptionPane.PLAIN_MESSAGE);
            }

            if (dicFile != null && datFile != null) {
                String dicname = "CR4-" + regcode + "D.DB";
                String dataname = "CR4-" + regcode + "M.DB";

                int dicdb = dicFile.equalsIgnoreCase(dicname) ? 1 : 0;
                int datdb = datFile.equalsIgnoreCase(dataname) ? 1 : 0;

                switch (dicdb) {
                case 0:
                    okButton.setEnabled(false);
                    JOptionPane.showConfirmDialog(
                            CanRegClientApp.getApplication().getMainFrame().getContentPane(),
                            "Incorrect Dictionary Name.\nExpected: " + dicname + ", Found " + dicFile,
                            "Incorrect Dictionary File Name.", JOptionPane.PLAIN_MESSAGE);

                    switch (datdb) {
                    case 0:
                        okButton.setEnabled(false);
                        JOptionPane.showConfirmDialog(
                                CanRegClientApp.getApplication().getMainFrame().getContentPane(),
                                "Incorrect Data Name.\nExpected: " + dataname + ", Found " + datFile,
                                "Incorrect Data File Name.", JOptionPane.PLAIN_MESSAGE);
                        break;
                    case 1:
                        okButton.setEnabled(false);
                        break;
                    }
                    break;
                case 1:
                    switch (datdb) {
                    case 0:
                        okButton.setEnabled(false);
                        JOptionPane.showConfirmDialog(
                                CanRegClientApp.getApplication().getMainFrame().getContentPane(),
                                "Incorrect Data Name.\nExpected: " + dataname + ", Found " + datFile,
                                "Incorect Data File Name.", JOptionPane.PLAIN_MESSAGE);

                        break;
                    case 1:
                        dictionary = dicFile;
                        data = datFile;
                        okButton.setEnabled(true);
                        break;
                    }
                    break;
                }
            }
            break;
        }
    }
}

From source file:game.Clue.ClueGameUI.java

public void mouseReleased(MouseEvent e) {

    System.out.println("Mouse clicked/released on chosen room" + e.getSource().toString());

    if (player == null) {
        return;//from  w  w w. j  av a  2s .c  o  m
    }

    //validate move by sending move request to Server before allowing move
    int valid = 1;

    player.setVisible(false);

    Component c = jPanel5.findComponentAt(e.getX(), e.getY());

    if (c instanceof JLabel) {
        Container parent = c.getParent();
        if (parent.getComponentCount() == 0) {
            System.out.println("------");
            //parent.remove(0);
            parent.add(player);

        } else {
            System.out.println("%%%%%");
            parent.add(player);
            parent.validate();
            //return;
        }

    } else {
        Container parent = (Container) c;
        if (parent.getComponentCount() == 1) {
            System.out.println("*****");
            return;
        } else {
            System.out.println("&&&&&");
            parent.add(player);
        }

    }
    if (valid != 0) {
        System.out.println("Player move allowed" + " x:" + e.getX() + "y: " + e.getY());
        System.out.println("Previous x:" + previous_room_x + "  Y:" + previous_room_y);
        player.setLocation(previous_room_x, previous_room_y);
        // player.setLocation(e.getX(),e.getY());
    } else {

    }
    player.setHorizontalAlignment(SwingConstants.CENTER);
    player.setVisible(true);

}

From source file:de.tor.tribes.ui.views.DSWorkbenchReTimerFrame.java

private void fireApplyTroopFiltersEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireApplyTroopFiltersEvent
    if (evt.getSource() == jApplyFiltersButton) {
        DefaultListModel filterModel = (DefaultListModel) jFilterList.getModel();
        List<Integer> rowsToRemove = new LinkedList<Integer>();
        int removeCount = 0;
        for (int i = 0; i < jResultTable.getRowCount(); i++) {
            //go through all rows in attack table and get source village
            Village v = (Village) jResultTable.getValueAt(i, 0);
            for (int j = 0; j < filterModel.size(); j++) {
                //check for all filters if villag is allowed
                if (!((TroopFilterElement) filterModel.get(j)).allowsVillage(v)) {
                    //village is not allowed, add to remove list
                    int row = jResultTable.convertRowIndexToModel(i);
                    rowsToRemove.add(row);
                    removeCount++;/*from   www.  ja va 2  s.c  o m*/
                }
            }
        }
        jResultTable.getSelectionModel().setValueIsAdjusting(true);
        for (int row : rowsToRemove) {
            jResultTable.getSelectionModel().addSelectionInterval(row, row);
        }
        jResultTable.getSelectionModel().setValueIsAdjusting(false);
    }
    jFilterDialog.setVisible(false);
}