Example usage for java.awt.event MouseEvent getButton

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

Introduction

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

Prototype

public int getButton() 

Source Link

Document

Returns which, if any, of the mouse buttons has changed state.

Usage

From source file:org.nebulaframework.ui.swing.node.NodeMainUI.java

/**
 * Setup System Tray Icon.//w ww  .  j  a  v  a  2 s . com
 * 
 * @param frame owner frame
 */
private void setupTrayIcon(final JFrame frame) {

    idleIcon = Toolkit.getDefaultToolkit()
            .getImage(ClassLoader.getSystemResource("META-INF/resources/node_inactive.png"));

    activeIcon = Toolkit.getDefaultToolkit()
            .getImage(ClassLoader.getSystemResource("META-INF/resources/node_active.png"));

    frame.setIconImage(idleIcon);

    // If system tray is supported by OS
    if (SystemTray.isSupported()) {
        trayIcon = new TrayIcon(idleIcon, "Nebula Grid Node", createTrayPopup());
        trayIcon.setImageAutoSize(true);
        trayIcon.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1) {
                    if (!frame.isVisible()) {
                        frame.setVisible(true);
                    }

                    frame.setExtendedState(JFrame.NORMAL);
                    frame.requestFocus();
                    frame.toFront();
                }
            }

        });

        try {
            SystemTray.getSystemTray().add(trayIcon);
        } catch (AWTException ae) {
            log.debug("[UI] Unable to Initialize Tray Icon");
            return;
        }

        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowIconified(WindowEvent e) {
                // Hide (can be shown using tray icon)
                frame.setVisible(false);
            }

        });
    }

}

From source file:nosqltools.MainForm.java

public void connect() {
    String user;/*w  ww  .ja  v  a  2  s . c o m*/
    String pass;
    String dbname;
    String serveradd;
    int port;

    LoginDialog dlg_login = new LoginDialog(null);
    dlg_login.setVisible(true);

    //If user chose login and not cancel option on dialog box
    if (dlg_login.isToLogin()) {
        Text_MessageBar.setText(Initializations.DBATTEMPTING);
        Text_MessageBar.setForeground(Color.ORANGE);
        user = dlg_login.getUsername();
        pass = dlg_login.getPassword();
        dbname = dlg_login.getDatabase();
        serveradd = dlg_login.getServerAddr();
        port = dlg_login.getPort();

        if (dbcon.connect(user, pass, dbname, serveradd, port)) {
            DefaultTreeModel defTableMod = dbcon.buildDBTree();
            if (defTableMod != null && dbcon.isConnectionSuccess()) {
                jTree1.setModel(defTableMod);
                Text_MessageBar.setText(Initializations.DBCONNSUCCESS);
                Text_MessageBar.setForeground(Color.GREEN);
                Menu_Collections.setEnabled(true);

                //load the data of collection in panel_text on double click
                jTree1.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent me) {
                        if (me.getButton() == MouseEvent.BUTTON1) {
                            if (me.getClickCount() == 2) {
                                //get the path of the mouse click ex:[localhost,test,testData] 
                                Op_Refresh.setEnabled(true);
                                tp = jTree1.getPathForLocation(me.getX(), me.getY());
                                if (tp != null) {
                                    List<String> coll_db = dbcon.getAllCollections();
                                    int cnt = tp.getPathCount();
                                    for (int i = 0; i < cnt; i++) {
                                        //if one of the collection matches the coll that was clicked by the user load data
                                        if (coll_db.contains(tp.getPathComponent(i).toString())) {
                                            indexOfCurrentCollection = i;
                                            sb = dbcon.getCollectionData(tp.getPathComponent(i).toString());

                                            if (sb != null) {
                                                Panel_Text.setVisible(true);

                                                JsonNode jNode1;
                                                try {
                                                    jNode1 = mapper.readTree(sb.toString());
                                                    textArea.setText(mapper.writerWithDefaultPrettyPrinter()
                                                            .writeValueAsString(jNode1));
                                                } catch (IOException ex) {
                                                    Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE,
                                                            null, ex);
                                                }

                                                Text_MessageBar.setText(Initializations.INITSTRING);
                                                // textArea.setText(sb.toString());
                                                validateDataPanel_text(sb);
                                                /*
                                                if (json_util.isValid(sb.toString())) 
                                                {
                                                    json_util.isDataParsed(textArea.getText());
                                                    Text_MessageBar.setText(Initializations.JSONFILESUCCESS);
                                                } 
                                                else 
                                                {
                                                    sb.setLength(0);
                                                    //JOptionPane.showMessageDialog(this, Initializations.JSONINCORRECTFORMAT , Initializations.VALIDATIONERROR , JOptionPane.ERROR_MESSAGE);
                                                        
                                                    try
                                                    {
                                                Object obj = parser.parse(sb.toString());
                                                    }
                                                    catch(org.json.simple.parser.ParseException pe)
                                                    {
                                                       Text_MessageBar.setText(Initializations.ERRORLINE + json_util.getLineNumber(pe.getPosition(), textArea.getText()) + " - " + pe);
                                                    }
                                                } */
                                            } else {
                                                Panel_Text.setVisible(false);
                                                Text_MessageBar.setText(Initializations.SYSTEMCOLL);
                                                Text_MessageBar.setForeground(Color.RED);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                });
            } else {
                jTree1.setModel(null);
                Text_MessageBar.setText(Initializations.DBCONNFAIL);
                Text_MessageBar.setForeground(Color.RED);
            }
        } else {
            jTree1.setModel(null);
            Text_MessageBar.setText(Initializations.DBCONNFAIL);
            Text_MessageBar.setForeground(Color.RED);
        }
    } else {
        jTree1.setModel(null);
        Text_MessageBar.setText(Initializations.DBCONNFAIL);
        Text_MessageBar.setForeground(Color.RED);
    }

}

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

/**
 * Called when the mouse is clicked. Used to set the time value when there is
 * a click on the time slider.//  w  w w . j a v a 2 s  .  com
 * 
 * @param me  the mouse event that triggered this
 */
public void mouseClicked(MouseEvent me) {
    double time;
    if (me.getSource() == this) {
        time = getTimeFromX(me.getX());
    } else if (me.getSource() == valueButton) {
        time = getTimeFromX(valueButton.getX() + me.getX());
    } else {
        return;
    }

    if (me.getButton() == MouseEvent.BUTTON1) {
        setValue(time);
    } else if (me.getButton() == MouseEvent.BUTTON3) {
        EventMarker eventMarker = getMarkerClosestToTime(time);
        if (eventMarker != null) {
            double markerTime = Double.parseDouble(eventMarker.getProperty("timestamp"));
            setValue(markerTime);
        }
    }
}

From source file:org.rdv.viz.image.ImageViz.java

private void initRoboticMouseClickListener() {
    roboticMouseClickListener = new MouseInputAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
                Point imagePoint = imagePanel.panelToScaledImagePoint(e.getPoint());
                if (imagePoint != null) {
                    center(imagePoint);//  w  ww .ja  va 2 s. c  om
                }
            }
        }
    };
}

From source file:com.puzzle.gui.MainFrame.java

public void trayIconMouseClick(MouseEvent e) {
    if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1)//?  
    {//from  w w  w  .j a v a 2s  .  c om
        this.setExtendedState(JFrame.NORMAL);//?  
        this.setVisible(true);//  
    }
}

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

@Override
public void mouseClicked(MouseEvent e) {

    // First find the column on which the user has clicked.
    final int row = table.rowAtPoint(e.getPoint());

    // A double click on an entry should open the entry's editor.
    if (e.getClickCount() == 2) {
        BibEntry toShow = tableRows.get(row);
        editSignalled(toShow);/*  w w  w  . java2 s .  c  om*/
        return;
    }

    final int col = table.columnAtPoint(e.getPoint());
    // get the MainTableColumn which is currently visible at col
    int modelIndex = table.getColumnModel().getColumn(col).getModelIndex();
    MainTableColumn modelColumn = table.getMainTableColumn(modelIndex);

    // Workaround for Windows. Right-click is not popup trigger on mousePressed, but
    // on mouseReleased. Therefore we need to avoid taking action at this point, because
    // action will be taken when the button is released:
    if (OS.WINDOWS && (modelColumn.isIconColumn()) && (e.getButton() != MouseEvent.BUTTON1)) {
        return;
    }

    // Check if the clicked colum is a specialfield column
    if (modelColumn.isIconColumn() && (SpecialFieldsUtils.isSpecialField(modelColumn.getColumnName()))) {
        // handle specialfield
        handleSpecialFieldLeftClick(e, modelColumn.getColumnName());
    } else if (modelColumn.isIconColumn()) { // left click on icon field

        Object value = table.getValueAt(row, col);
        if (value == null) {
            return; // No icon here, so we do nothing.
        }

        final BibEntry entry = tableRows.get(row);

        final List<String> fieldNames = modelColumn.getBibtexFields();

        // Open it now. We do this in a thread, so the program won't freeze during the wait.
        JabRefExecutorService.INSTANCE.execute(() -> {
            panel.output(Localization.lang("External viewer called") + '.');
            // check for all field names whether a link is present
            // (is relevant for combinations such as "url/doi")
            for (String fieldName : fieldNames) {
                // Check if field is present, if not skip this field
                if (entry.hasField(fieldName)) {
                    String link = entry.getFieldOptional(fieldName).get();

                    // See if this is a simple file link field, or if it is a file-list
                    // field that can specify a list of links:
                    if (fieldName.equals(FieldName.FILE)) {

                        // We use a FileListTableModel to parse the field content:
                        FileListTableModel fileList = new FileListTableModel();
                        fileList.setContent(link);

                        FileListEntry flEntry = null;
                        // If there are one or more links of the correct type, open the first one:
                        if (modelColumn.isFileFilter()) {
                            for (int i = 0; i < fileList.getRowCount(); i++) {
                                if (fileList.getEntry(i).type.toString().equals(modelColumn.getColumnName())) {
                                    flEntry = fileList.getEntry(i);
                                    break;
                                }
                            }
                        } else if (fileList.getRowCount() > 0) {
                            //If there are no file types specified open the first file
                            flEntry = fileList.getEntry(0);
                        }
                        if (flEntry != null) {
                            ExternalFileMenuItem item = new ExternalFileMenuItem(panel.frame(), entry, "",
                                    flEntry.link, flEntry.type.get().getIcon(), panel.getBibDatabaseContext(),
                                    flEntry.type);
                            boolean success = item.openLink();
                            if (!success) {
                                panel.output(Localization.lang("Unable to open link."));
                            }
                        }
                    } else {
                        try {
                            JabRefDesktop.openExternalViewer(panel.getBibDatabaseContext(), link, fieldName);
                        } catch (IOException ex) {
                            panel.output(Localization.lang("Unable to open link."));
                            LOGGER.info("Unable to open link", ex);
                        }
                    }
                    break; // only open the first link
                }
            }
        });
    } else if (modelColumn.getBibtexFields().contains(FieldName.CROSSREF)) { // Clicking on crossref column
        tableRows.get(row).getFieldOptional(FieldName.CROSSREF).ifPresent(crossref -> panel.getDatabase()
                .getEntryByKey(crossref).ifPresent(entry -> panel.highlightEntry(entry)));
    }
}

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

@Override
public void mouseClicked(MouseEvent e) {

    // First find the column on which the user has clicked.
    final int col = table.columnAtPoint(e.getPoint());
    final int row = table.rowAtPoint(e.getPoint());

    // A double click on an entry should open the entry's editor.
    if (e.getClickCount() == 2) {

        BibtexEntry toShow = tableRows.get(row);
        editSignalled(toShow);//from w  w  w  .  jav a 2 s. com
    }

    // Check if the user has clicked on an icon cell to open url or pdf.
    final String[] iconType = table.getIconTypeForColumn(col);

    // Workaround for Windows. Right-click is not popup trigger on mousePressed, but
    // on mouseReleased. Therefore we need to avoid taking action at this point, because
    // action will be taken when the button is released:
    if (OS.WINDOWS && (iconType != null) && (e.getButton() != MouseEvent.BUTTON1)) {
        return;
    }

    if (iconType != null) {
        // left click on icon field
        SpecialField field = SpecialFieldsUtils.getSpecialFieldInstanceFromFieldName(iconType[0]);
        if ((e.getClickCount() == 1) && (field != null)) {
            // special field found
            if (field.isSingleValueField()) {
                // directly execute toggle action instead of showing a menu with one action
                field.getValues().get(0).getAction(panel.frame()).action();
            } else {
                JPopupMenu menu = new JPopupMenu();
                for (SpecialFieldValue val : field.getValues()) {
                    menu.add(val.getMenuAction(panel.frame()));
                }
                menu.show(table, e.getX(), e.getY());
            }
            return;
        }

        Object value = table.getValueAt(row, col);
        if (value == null) {
            return; // No icon here, so we do nothing.
        }

        final BibtexEntry entry = tableRows.get(row);

        // Get the icon type. Corresponds to the field name.
        int hasField = -1;
        for (int i = iconType.length - 1; i >= 0; i--) {
            if (entry.getField(iconType[i]) != null) {
                hasField = i;
            }
        }
        if (hasField == -1) {
            return;
        }
        final String fieldName = iconType[hasField];

        //If this is a file link field with specified file types,
        //we should also pass the types.
        String[] fileTypes = {};
        if ((hasField == 0) && iconType[hasField].equals(Globals.FILE_FIELD) && (iconType.length > 1)) {
            fileTypes = iconType;
        }
        final List<String> listOfFileTypes = Collections.unmodifiableList(Arrays.asList(fileTypes));

        // Open it now. We do this in a thread, so the program won't freeze during the wait.
        JabRefExecutorService.INSTANCE.execute(new Runnable() {

            @Override
            public void run() {
                panel.output(Localization.lang("External viewer called") + '.');

                Object link = entry.getField(fieldName);
                if (link == null) {
                    LOGGER.info("Error: no link to " + fieldName + '.');
                    return; // There is an icon, but the field is not set.
                }

                // See if this is a simple file link field, or if it is a file-list
                // field that can specify a list of links:
                if (fieldName.equals(Globals.FILE_FIELD)) {

                    // We use a FileListTableModel to parse the field content:
                    FileListTableModel fileList = new FileListTableModel();
                    fileList.setContent((String) link);

                    FileListEntry flEntry = null;
                    // If there are one or more links of the correct type,
                    // open the first one:
                    if (!listOfFileTypes.isEmpty()) {
                        for (int i = 0; i < fileList.getRowCount(); i++) {
                            flEntry = fileList.getEntry(i);
                            boolean correctType = false;
                            for (String listOfFileType : listOfFileTypes) {
                                if (flEntry.getType().toString().equals(listOfFileType)) {
                                    correctType = true;
                                }
                            }
                            if (correctType) {
                                break;
                            }
                            flEntry = null;
                        }
                    }
                    //If there are no file types specified, consider all files.
                    else if (fileList.getRowCount() > 0) {
                        flEntry = fileList.getEntry(0);
                    }
                    if (flEntry != null) {
                        //                            if (fileList.getRowCount() > 0) {
                        //                                FileListEntry flEntry = fileList.getEntry(0);

                        ExternalFileMenuItem item = new ExternalFileMenuItem(panel.frame(), entry, "",
                                flEntry.getLink(), flEntry.getType().getIcon(), panel.metaData(),
                                flEntry.getType());
                        boolean success = item.openLink();
                        if (!success) {
                            panel.output(Localization.lang("Unable to open link."));
                        }
                    }
                } else {
                    try {
                        JabRefDesktop.openExternalViewer(panel.metaData(), (String) link, fieldName);
                    } catch (IOException ex) {
                        panel.output(Localization.lang("Unable to open link."));
                    }

                    /*ExternalFileType type = Globals.prefs.getExternalFileTypeByMimeType("text/html");
                    ExternalFileMenuItem item = new ExternalFileMenuItem
                        (panel.frame(), entry, "",
                        (String)link, type.getIcon(),
                        panel.metaData(), type);
                    boolean success = item.openLink();
                    if (!success) {
                    panel.output(Localization.lang("Unable to open link."));
                    } */
                    //Util.openExternalViewer(panel.metaData(), (String)link, fieldName);
                }

                //catch (IOException ex) {
                //    panel.output(Globals.lang("Error") + ": " + ex.getMessage());
                //}
            }

        });
    }
}

From source file:com.puzzle.gui.MainFrame.java

private void jDialog1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jDialog1MouseClicked
    // TODO add your handling code here:
    if (evt.getClickCount() == 2 && evt.getButton() == MouseEvent.BUTTON1) {
        if (jDialog1.getSize().width < 900) {
            jDialog1.setSize(Toolkit.getDefaultToolkit().getScreenSize().width,
                    Toolkit.getDefaultToolkit().getScreenSize().height);
            jDialog1.setLocationRelativeTo(null);
        } else {/*www  .  j a  va  2s  .co m*/
            jDialog1.setSize(800, 540);
            jDialog1.setLocationRelativeTo(null);
        }

    }

}

From source file:com.puzzle.gui.MainFrame.java

private void jTable3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable3MouseClicked
    // TODO add your handling code here:
    if (evt.getClickCount() == 2 && evt.getButton() == MouseEvent.BUTTON1) {
        int rowNumber = this.jTable3.getSelectedRow();
        String fileName = (String) this.jTable3.getValueAt(rowNumber, 1);

        String content = null;/*w  w  w .  ja v a2 s.  co m*/
        try {
            content = org.apache.commons.io.FileUtils.readFileToString(new File(fileName), "UTF-8");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        //              String ll=this.readXML(workpath,ff);
        this.jDialog1.setTitle(fileName);
        //??

        textArea.setText(content);
        textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
        textArea.setCodeFoldingEnabled(true);
        textArea.setAutoscrolls(true);
        //            textArea.setBackground(Color.black);
        textArea.setEditable(false);
        //             textArea.setVisible(true);
        this.jPanel6.add(sp);

        this.jDialog1.setLocationRelativeTo(this);
        this.jDialog1.setVisible(true);
    } //GEN-LAST:event_jTable3MouseClicked
}

From source file:com.puzzle.gui.MainFrame.java

private void jTable4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable4MouseClicked
    // TODO add your handling code here:
    if (evt.getClickCount() == 2 && evt.getButton() == MouseEvent.BUTTON1) {
        int rowNumber = this.jTable4.getSelectedRow();
        String fileName = (String) this.jTable4.getValueAt(rowNumber, 1);

        String content = null;/*from  www .  j  a va  2s  .co m*/
        try {
            content = org.apache.commons.io.FileUtils.readFileToString(new File(fileName), "UTF-8");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        //              String ll=this.readXML(workpath,ff);
        this.jDialog1.setTitle(fileName);
        //??

        textArea.setText(content);
        textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML);
        textArea.setCodeFoldingEnabled(true);
        textArea.setAutoscrolls(true);
        //            textArea.setBackground(Color.black);
        textArea.setEditable(false);
        //             textArea.setVisible(true);
        this.jPanel6.add(sp);

        this.jDialog1.setLocationRelativeTo(this);
        this.jDialog1.setVisible(true);
    }
}