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:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java

protected void initComponent() {
    layout = new MigLayout("flowy, fill, insets 0", "", "[min!][fill]");
    panel = new JPanel(layout);

    topPanel = new JPanel(new BorderLayout());
    topPanel.setVisible(false);//from  w  w w.  j  a  v  a2s. co m
    panel.add(topPanel, "growx");

    scrollPane = new JScrollPane(impl);
    impl.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    impl.setFillsViewportHeight(true);
    panel.add(scrollPane, "grow");

    impl.setShowGrid(true);
    impl.setGridColor(Color.lightGray);

    impl.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
                handleClickAction();
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            showPopup(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            showPopup(e);
        }

        protected void showPopup(MouseEvent e) {
            if (e.isPopupTrigger() && contextMenuEnabled) {
                // select row
                Point p = e.getPoint();
                int viewRowIndex = impl.rowAtPoint(p);

                int rowNumber;
                if (viewRowIndex >= 0) {
                    rowNumber = impl.convertRowIndexToModel(viewRowIndex);
                } else {
                    rowNumber = -1;
                }
                ListSelectionModel model = impl.getSelectionModel();

                if (!model.isSelectedIndex(rowNumber)) {
                    model.setSelectionInterval(rowNumber, rowNumber);
                }

                // show popup menu
                JPopupMenu popupMenu = createPopupMenu();
                if (popupMenu.getComponentCount() > 0) {
                    popupMenu.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }
    });

    ColumnControlButton columnControlButton = new ColumnControlButton(impl) {
        @Override
        protected ColumnVisibilityAction createColumnVisibilityAction(TableColumn column) {
            ColumnVisibilityAction columnVisibilityAction = super.createColumnVisibilityAction(column);

            columnVisibilityAction.addPropertyChangeListener(evt -> {
                if ("SwingSelectedKey".equals(evt.getPropertyName()) && evt.getNewValue() instanceof Boolean) {
                    ColumnVisibilityAction action = (ColumnVisibilityAction) evt.getSource();

                    String columnName = action.getActionCommand();
                    boolean collapsed = !((boolean) evt.getNewValue());

                    Column col = getColumn(columnName);
                    if (col != null) {
                        col.setCollapsed(collapsed);
                    }
                }
            });

            return columnVisibilityAction;
        }
    };
    impl.setColumnControl(columnControlButton);

    impl.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");
    impl.getActionMap().put("enter", new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (enterPressAction != null) {
                enterPressAction.actionPerform(DesktopAbstractTable.this);
            } else {
                handleClickAction();
            }
        }
    });

    Messages messages = AppBeans.get(Messages.NAME);
    // localize default column control actions
    for (Object actionKey : impl.getActionMap().allKeys()) {
        if ("column.packAll".equals(actionKey)) {
            BoundAction action = (BoundAction) impl.getActionMap().get(actionKey);
            action.setName(messages.getMessage(DesktopTable.class, "DesktopTable.packAll"));
        } else if ("column.packSelected".equals(actionKey)) {
            BoundAction action = (BoundAction) impl.getActionMap().get(actionKey);
            action.setName(messages.getMessage(DesktopTable.class, "DesktopTable.packSelected"));
        } else if ("column.horizontalScroll".equals(actionKey)) {
            BoundAction action = (BoundAction) impl.getActionMap().get(actionKey);
            action.setName(messages.getMessage(DesktopTable.class, "DesktopTable.horizontalScroll"));
        }
    }

    // Ability to configure fonts in table
    // Add action to column control
    String configureFontsLabel = messages.getMessage(DesktopTable.class, "DesktopTable.configureFontsLabel");
    impl.getActionMap().put(ColumnControlButton.COLUMN_CONTROL_MARKER + "fonts",
            new AbstractAction(configureFontsLabel) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    Component rootComponent = SwingUtilities.getRoot(impl);
                    final FontDialog fontDialog = FontDialog.show(rootComponent, impl.getFont());
                    fontDialog.addWindowListener(new WindowAdapter() {
                        @Override
                        public void windowClosed(WindowEvent e) {
                            Font result = fontDialog.getResult();
                            if (result != null) {
                                impl.setFont(result);
                                packRows();
                            }
                        }
                    });
                    fontDialog.open();
                }
            });

    // Ability to reset settings
    String resetSettingsLabel = messages.getMessage(DesktopTable.class, "DesktopTable.resetSettings");
    impl.getActionMap().put(ColumnControlButton.COLUMN_CONTROL_MARKER + "resetSettings",
            new AbstractAction(resetSettingsLabel) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    resetPresentation();
                }
            });

    scrollPane.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            if (!columnsInitialized) {
                adjustColumnHeaders();
            }
            columnsInitialized = true;
        }
    });

    // init default row height
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            if (!fontInitialized) {
                applyFont(impl, impl.getFont());
            }
        }
    });
}

From source file:playground.sergioo.networkBusLaneAdder2012.gui.BusLaneAdderPanel.java

@Override
public void mouseClicked(MouseEvent e) {
    double[] p = getWorld(e.getX(), e.getY());
    if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON3)
        camera.centerCamera(p);/*from w ww .  j  av a  2 s  .  c  o m*/
    else {
        if (busLaneAdderWindow.getOption().equals(Options.SELECT_NODES)
                && e.getButton() == MouseEvent.BUTTON1) {
            ((NetworkTwoNodesPainterManager) ((NetworkPainter) getActiveLayer().getPainter())
                    .getNetworkPainterManager()).selectNearestNode(p[0], p[1]);
            busLaneAdderWindow.refreshLabel(Labels.NODES);
        } else if (busLaneAdderWindow.getOption().equals(Options.SELECT_NODES)
                && e.getButton() == MouseEvent.BUTTON3) {
            ((NetworkTwoNodesPainterManager) ((NetworkPainter) getActiveLayer().getPainter())
                    .getNetworkPainterManager()).unselectNearestNode(p[0], p[1]);
            busLaneAdderWindow.refreshLabel(Labels.NODES);
        } else if (busLaneAdderWindow.getOption().equals(Options.ZOOM) && e.getButton() == MouseEvent.BUTTON1) {
            camera.zoomIn(p[0], p[1]);
        } else if (busLaneAdderWindow.getOption().equals(Options.ZOOM) && e.getButton() == MouseEvent.BUTTON3) {
            camera.zoomOut(p[0], p[1]);
        }
    }
    repaint();
}

From source file:org.jopenray.server.thinclient.DisplayReaderThread.java

private void processMouseEvent(int buttons, int mouseX, int mouseY) {
    buttons = buttons - 64;/*w  w  w  .  j  a  v  a  2 s. c om*/
    if (this.lastMouseState == Integer.MIN_VALUE) {
        this.lastMouseState = buttons;
        this.lastMouseX = mouseX;
        this.lastMouseY = mouseY;
        return;
    }

    // Mouse move
    if (lastMouseX != mouseX || lastMouseY != mouseY) {
        sendMouseMoved(mouseX, mouseY);
    }

    // Mouse pressed/released

    int change = buttons ^ this.lastMouseState;

    if ((change & 1) > 0) {
        if ((buttons & 1) > 0) {
            System.out.println("DisplayReaderThread.processMouseEvent() BUTTON1 pressed");
            sendMousePressed(MouseEvent.BUTTON1, mouseX, mouseY);
        } else {
            System.out.println("DisplayReaderThread.processMouseEvent() BUTTON1 released");
            sendMouseReleased(MouseEvent.BUTTON1, mouseX, mouseY);
        }
    }
    if ((change & 2) > 0) {
        if ((buttons & 2) > 0) {
            System.out.println("DisplayReaderThread.processMouseEvent() BUTTON2 pressed");
            sendMousePressed(MouseEvent.BUTTON2, mouseX, mouseY);
        } else {
            sendMouseReleased(MouseEvent.BUTTON2, mouseX, mouseY);
        }
    }
    if ((change & 4) > 0) {
        if ((buttons & 4) > 0) {
            System.out.println("DisplayReaderThread.processMouseEvent() BUTTON3 pressed");
            sendMousePressed(MouseEvent.BUTTON3, mouseX, mouseY);
        } else {
            sendMouseReleased(MouseEvent.BUTTON3, mouseX, mouseY);
        }
    }
    if ((change & 8) > 0) {
        if ((buttons & 8) > 0) {
            System.out.println("DisplayReaderThread.processMouseEvent() mouse wheel up");
            sendMouseWheelUp(mouseX, mouseY);
        } else {
            // sendMouseReleased(MouseEvent.BUTTON3, mouseX, mouseY);
        }
    }
    if ((change & 16) > 0) {
        if ((buttons & 16) > 0) {
            System.out.println("DisplayReaderThread.processMouseEvent() mouse wheel down");
            sendMouseWheelDown(mouseX, mouseY);
        } else {
            // sendMouseReleased(MouseEvent.BUTTON3, mouseX, mouseY);
        }
    }

    this.lastMouseState = buttons;
    this.lastMouseX = mouseX;
    this.lastMouseY = mouseY;

}

From source file:org.pentaho.reporting.libraries.designtime.swing.date.DateCellEditor.java

/**
 * Asks the editor if it can start editing using <code>anEvent</code>. <code>anEvent</code> is in the invoking
 * component coordinate system. The editor can not assume the Component returned by
 * <code>getCellEditorComponent</code> is installed.  This method is intended for the use of client to avoid the cost
 * of setting up and installing the editor component if editing is not possible. If editing can be started this method
 * returns true.//from w w  w  . j a  v a2s .  c o m
 *
 * @param anEvent the event the editor should use to consider whether to begin editing or not
 * @return true if editing can be started
 * @see #shouldSelectCell
 */
public boolean isCellEditable(final EventObject anEvent) {
    if (anEvent instanceof MouseEvent) {
        final MouseEvent mouseEvent = (MouseEvent) anEvent;
        return mouseEvent.getClickCount() >= 2 && mouseEvent.getButton() == MouseEvent.BUTTON1;
    }
    return true;
}

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  .  ja  va 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:org.openuat.apps.BedaApp.java

/**
 * Creates a new instance of this class and launches the
 * actual application./*  w  w w  . j a v a 2 s  . c  om*/
 */
public BedaApp() {
    random = new SecureRandom();
    devices = new RemoteDevice[0];
    currentPeerUrl = null;
    currentChannel = null;
    isInitiator = false;

    // Initialize the logger. Use a wrapper around the log4j framework.
    /*LogFactory.init(new Log4jFactory());
    logger = LogFactory.getLogger(BedaApp.class.getName());
    logger.finer("Logger initiated!");*/

    mainWindow = new JFrame("Beda App");
    mainWindow.setSize(new Dimension(FRAME_WIDTH, FRAME_HIGHT));
    mainWindow.setPreferredSize(new Dimension(FRAME_WIDTH, FRAME_HIGHT));
    mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainWindow.getContentPane().setLayout(new FlowLayout());
    URL imgURL = getClass().getResource("/resources/Button_Icon_Blue_beda.png");
    ImageIcon icon = imgURL != null ? new ImageIcon(imgURL)
            : new ImageIcon("resources/Button_Icon_Blue_beda.png");
    mainWindow.setIconImage(icon.getImage());

    // prepare the button channels
    ActionListener abortHandler = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (e.getID() == ActionEvent.ACTION_PERFORMED) {
                logger.warning("Protocol run aborted by user");
                BluetoothRFCOMMChannel.shutdownAllChannels();
                alertError("Protocol run aborted.");
            }
        }
    };
    buttonChannels = new HashMap<String, OOBChannel>();
    ButtonChannelImpl impl = new AWTButtonChannelImpl(mainWindow.getContentPane(), abortHandler);
    OOBChannel c = new ButtonToButtonChannel(impl);
    buttonChannels.put(c.toString(), c);
    c = new FlashDisplayToButtonChannel(impl, false);
    buttonChannels.put(c.toString(), c);
    c = new TrafficLightToButtonChannel(impl);
    buttonChannels.put(c.toString(), c);
    c = new ProgressBarToButtonChannel(impl);
    buttonChannels.put(c.toString(), c);
    c = new PowerBarToButtonChannel(impl);
    buttonChannels.put(c.toString(), c);
    c = new ShortVibrationToButtonChannel(impl);
    buttonChannels.put(c.toString(), c);
    c = new LongVibrationToButtonChannel(impl);
    buttonChannels.put(c.toString(), c);

    // set up the menu bar
    menuBar = new JMenuBar();
    JMenu menu = new JMenu("Menu");
    final JMenuItem homeEntry = new JMenuItem("Home");
    final JMenuItem testEntry = new JMenuItem("Test channels");

    ActionListener menuListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JMenuItem menuItem = (JMenuItem) event.getSource();
            if (menuItem == homeEntry) {
                showHomeScreen();
            } else if (menuItem == testEntry) {
                showTestScreen();
            }
        }
    };
    homeEntry.addActionListener(menuListener);
    testEntry.addActionListener(menuListener);

    menu.add(homeEntry);
    menu.add(testEntry);
    menuBar.add(menu);
    mainWindow.setJMenuBar(menuBar);

    // set up channel list
    OOBChannel[] channels = { new ButtonToButtonChannel(impl), new FlashDisplayToButtonChannel(impl, false),
            new TrafficLightToButtonChannel(impl), new ProgressBarToButtonChannel(impl),
            new PowerBarToButtonChannel(impl), new ShortVibrationToButtonChannel(impl),
            new LongVibrationToButtonChannel(impl) };
    channelList = new JList(channels);
    channelList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    channelList.setVisibleRowCount(15);
    channelList.setPreferredSize(new Dimension(LIST_WIDTH, LIST_HIGHT));

    // set up device list
    deviceList = new JList();
    deviceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    deviceList.setVisibleRowCount(15);
    deviceList.setPreferredSize(new Dimension(LIST_WIDTH, LIST_HIGHT));

    // enable double clicks on the two lists
    doubleClickListener = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent event) {
            // react on double clicks
            if (event.getButton() == MouseEvent.BUTTON1 && event.getClickCount() == 2) {
                JList source = (JList) event.getSource();
                if (source == channelList && channelList.isEnabled()) {
                    currentChannel = (OOBChannel) channelList.getSelectedValue();
                    startAuthentication();
                } else if (source == deviceList) {
                    int index = deviceList.getSelectedIndex();
                    if (index > -1) {
                        String peerAddress = devices[index].getBluetoothAddress();
                        searchForService(peerAddress);
                    }
                }
            }
            event.consume();
        }
    };
    deviceList.addMouseListener(doubleClickListener);
    // note: this listener will be set on the channelList in the showHomeScreen method

    ListSelectionListener selectionListener = new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent event) {
            channelList.setEnabled(false);
        }
    };
    deviceList.addListSelectionListener(selectionListener);

    // create refresh button
    refreshButton = new JButton("Refresh list");
    ActionListener buttonListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if ((JButton) event.getSource() == refreshButton) {
                refreshButton.setEnabled(false);
                statusLabel.setText("Please wait... scanning for devices...");
                peerManager.startInquiry(false);
            }
        }
    };
    refreshButton.addActionListener(buttonListener);

    // set up the bluetooth peer manager
    BluetoothPeerManager.PeerEventsListener listener = new BluetoothPeerManager.PeerEventsListener() {
        public void inquiryCompleted(Vector newDevices) {
            refreshButton.setEnabled(true);
            statusLabel.setText("");
            updateDeviceList();
        }

        public void serviceSearchCompleted(RemoteDevice remoteDevice, Vector services, int errorReason) {
            // ignore
        }
    };

    try {
        peerManager = new BluetoothPeerManager();
        peerManager.addListener(listener);
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Could not initiate BluetoothPeerManager.", e);
    }

    // set up the bluetooth rfcomm server
    try {
        btServer = new BluetoothRFCOMMServer(null, SERVICE_UUID, SERVICE_NAME, 30000, true, false);
        btServer.addAuthenticationProgressHandler(this);
        btServer.start();
        if (logger.isLoggable(Level.INFO)) {
            logger.info("Finished starting SDP service at " + btServer.getRegisteredServiceURL());
        }
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Could not create bluetooth server.", e);
    }
    ProtocolCommandHandler inputProtocolHandler = new ProtocolCommandHandler() {
        @Override
        public boolean handleProtocol(String firstLine, RemoteConnection remote) {
            if (logger.isLoggable(Level.FINER)) {
                logger.finer("Handle protocol command: " + firstLine);
            }
            if (firstLine.equals(UACAPProtocolConstants.PRE_AUTH)) {
                inputProtocol(false, remote, null);
                return true;
            }
            return false;
        }
    };
    btServer.addProtocolCommandHandler(UACAPProtocolConstants.PRE_AUTH, inputProtocolHandler);

    // build staus bar
    statusLabel = new JLabel("");
    statusLabel.setPreferredSize(new Dimension(FRAME_WIDTH - 40, LABEL_HIGHT));

    // build initial screen (the home screen)
    showHomeScreen();

    // launch window
    mainWindow.pack();
    mainWindow.setVisible(true);
}

From source file:org.tinymediamanager.ui.tvshows.dialogs.TvShowEpisodeChooserDialog.java

public TvShowEpisodeChooserDialog(TvShowEpisode ep, MediaScraper mediaScraper) {
    super(BUNDLE.getString("tvshowepisode.choose"), "episodeChooser"); //$NON-NLS-1$
    setBounds(5, 5, 600, 400);/*from w w  w  .  jav a 2  s.co m*/

    this.episode = ep;
    this.mediaScraper = mediaScraper;
    this.metadata = new MediaEpisode(mediaScraper.getId());
    episodeEventList = new ObservableElementList<>(
            GlazedLists.threadSafeList(new BasicEventList<TvShowEpisodeChooserModel>()),
            GlazedLists.beanConnector(TvShowEpisodeChooserModel.class));
    sortedEpisodes = new SortedList<>(GlazedListsSwing.swingThreadProxyList(episodeEventList),
            new EpisodeComparator());

    getContentPane().setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("590px:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("200dlu:grow"),
                    FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("fill:37px"),
                    FormSpecs.RELATED_GAP_ROWSPEC, }));
    {
        JSplitPane splitPane = new JSplitPane();
        getContentPane().add(splitPane, "2, 2, fill, fill");

        JPanel panelLeft = new JPanel();
        panelLeft.setLayout(new FormLayout(
                new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("150dlu:grow"),
                        FormSpecs.RELATED_GAP_COLSPEC, },
                new RowSpec[] { FormSpecs.LINE_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                        FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"),
                        FormSpecs.RELATED_GAP_ROWSPEC, }));

        textField = EnhancedTextField.createSearchTextField();
        panelLeft.add(textField, "2, 2, fill, default");
        textField.setColumns(10);

        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setMinimumSize(new Dimension(200, 23));
        panelLeft.add(scrollPane, "2, 4, fill, fill");
        splitPane.setLeftComponent(panelLeft);

        MatcherEditor<TvShowEpisodeChooserModel> textMatcherEditor = new TextComponentMatcherEditor<>(textField,
                new TvShowEpisodeChooserModelFilterator());
        FilterList<TvShowEpisodeChooserModel> textFilteredEpisodes = new FilterList<>(sortedEpisodes,
                textMatcherEditor);
        AdvancedTableModel<TvShowEpisodeChooserModel> episodeTableModel = GlazedListsSwing
                .eventTableModelWithThreadProxyList(textFilteredEpisodes, new EpisodeTableFormat());
        DefaultEventSelectionModel<TvShowEpisodeChooserModel> selectionModel = new DefaultEventSelectionModel<>(
                textFilteredEpisodes);
        selectedEpisodes = selectionModel.getSelected();

        selectionModel.addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) {
                    return;
                }
                // display first selected episode
                if (!selectedEpisodes.isEmpty()) {
                    TvShowEpisodeChooserModel episode = selectedEpisodes.get(0);
                    taPlot.setText(episode.getOverview());
                } else {
                    taPlot.setText("");
                }
                taPlot.setCaretPosition(0);
            }
        });

        table = new JTable(episodeTableModel);
        table.setSelectionModel(selectionModel);
        scrollPane.setViewportView(table);

        JPanel panelRight = new JPanel();
        panelRight.setLayout(new FormLayout(
                new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("150dlu:grow"),
                        FormSpecs.RELATED_GAP_COLSPEC, },
                new RowSpec[] { FormSpecs.LINE_GAP_ROWSPEC, RowSpec.decode("default:grow"),
                        FormSpecs.RELATED_GAP_ROWSPEC, }));
        JScrollPane scrollPane_1 = new JScrollPane();
        panelRight.add(scrollPane_1, "2, 2, fill, fill");
        splitPane.setRightComponent(panelRight);

        taPlot = new JTextArea();
        taPlot.setEditable(false);
        taPlot.setWrapStyleWord(true);
        taPlot.setLineWrap(true);
        scrollPane_1.setViewportView(taPlot);
        splitPane.setDividerLocation(300);

    }
    JPanel bottomPanel = new JPanel();
    getContentPane().add(bottomPanel, "2, 4, fill, top");

    bottomPanel.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.LABEL_COMPONENT_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                    FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, RowSpec.decode("25px"),
                    FormFactory.RELATED_GAP_ROWSPEC, }));

    JPanel buttonPane = new JPanel();
    bottomPanel.add(buttonPane, "5, 2, fill, fill");
    EqualsLayout layout = new EqualsLayout(5);
    layout.setMinWidth(100);
    buttonPane.setLayout(layout);
    final JButton okButton = new JButton(BUNDLE.getString("Button.ok")); //$NON-NLS-1$
    okButton.setToolTipText(BUNDLE.getString("tvshow.change"));
    okButton.setIcon(IconManager.APPLY);
    buttonPane.add(okButton);
    okButton.setActionCommand("OK");
    okButton.addActionListener(this);

    JButton cancelButton = new JButton(BUNDLE.getString("Button.cancel")); //$NON-NLS-1$
    cancelButton.setToolTipText(BUNDLE.getString("edit.discard"));
    cancelButton.setIcon(IconManager.CANCEL);
    buttonPane.add(cancelButton);
    cancelButton.setActionCommand("Cancel");
    cancelButton.addActionListener(this);

    // column widths
    table.getColumnModel().getColumn(0).setMaxWidth(50);
    table.getColumnModel().getColumn(1).setMaxWidth(50);

    SearchTask task = new SearchTask();
    task.execute();

    MouseListener mouseListener = new MouseListener() {

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2 && !e.isConsumed() && e.getButton() == MouseEvent.BUTTON1) {
                actionPerformed(new ActionEvent(okButton, ActionEvent.ACTION_PERFORMED, "OK"));
            }
        }

    };
    table.addMouseListener(mouseListener);
}

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);//from www  . jav a 2 s. c o m
        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:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java

private void jTree1MouseClicked1(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTree1MouseClicked1

    if (evt.getClickCount() == 2 && evt.getButton() == MouseEvent.BUTTON1) {
        DefaultMutableTreeNode tn = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();

        if (tn.getChildCount() > 0)
            return;

        /*if (!jTree1.isCollapsed( jTree1.getSelectionPath() ))
        {//w  ww.  j a v a  2 s  .c  om
        jTree1.collapsePath( jTree1.getSelectionPath() );
        return;
        }
         *
         */
        if (tn.getUserObject() instanceof TreeJRField) {
            TreeJRField jrf = (TreeJRField) tn.getUserObject();
            if (!jrf.getObj().isPrimitive() && !jrf.getObj().getName().startsWith("java.lang.")) {
                exploreBean(tn, jrf.getObj().getName(),
                        isPathOnDescription() ? Misc.nvl(jrf.getField().getDescription(), "")
                                : Misc.nvl(jrf.getField().getName(), ""));
            }
        }
    }

}

From source file:edu.harvard.mcz.imagecapture.ImageZoomPanel.java

@Override
public void mouseClicked(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON1) {
        Point clickAt = e.getPoint();
        Dimension size = jLabel.getSize();
        jLabel.zoomIn();// ww  w .jav a 2s . c o m
        jLabel.repaint();
        jLabel.doLayout();
        jLabel.centerOn(clickAt);
        jLabel.invalidate();
        jScrollPane.revalidate();
        jScrollPane.getParent().validate();
        jScrollPane.setVisible(false);
        jScrollPane.setVisible(true);
        jScrollPane.validate();
        jScrollPane.doLayout();
        zoomIn();
        zoomOut();
    } else if (e.getButton() == MouseEvent.BUTTON3) {
        Point clickAt = e.getPoint();
        zoomOut();
        jLabel.centerOn(clickAt);
    }
}