Example usage for java.awt.event MouseAdapter MouseAdapter

List of usage examples for java.awt.event MouseAdapter MouseAdapter

Introduction

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

Prototype

MouseAdapter

Source Link

Usage

From source file:ucar.unidata.idv.flythrough.Flythrough.java

/**
 * _more_//w w w  .ja v  a2s. c o  m
 *
 * @return _more_
 */
public JComponent doMakePointsPanel() {

    pointTableModel = new FlythroughTableModel(this);
    pointTable = new JTable(pointTableModel);
    pointTable.setToolTipText("Double click: view; Control-P: Show point properties; Delete: delete point");

    pointTable.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if ((e.getKeyCode() == KeyEvent.VK_P) && e.isControlDown()) {
                List<FlythroughPoint> newPoints = new ArrayList<FlythroughPoint>();
                int[] rows = pointTable.getSelectedRows();
                List<FlythroughPoint> oldPoints = pointsToUse;
                for (int j = 0; j < rows.length; j++) {
                    FlythroughPoint pt = oldPoints.get(rows[j]);
                    if (!showProperties(pt)) {
                        break;
                    }
                    pointTable.repaint();
                }
            }

            if (GuiUtils.isDeleteEvent(e)) {
                List<FlythroughPoint> newPoints = new ArrayList<FlythroughPoint>();
                int[] rows = pointTable.getSelectedRows();
                List<FlythroughPoint> oldPoints = pointsToUse;
                for (int i = 0; i < oldPoints.size(); i++) {
                    boolean good = true;
                    for (int j = 0; j < rows.length; j++) {
                        if (i == rows[j]) {
                            good = false;
                            break;
                        }
                    }
                    if (good) {
                        newPoints.add(oldPoints.get(i));
                    }
                }
                flythrough(newPoints);
            }
        }
    });

    pointTable.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            final int row = pointTable.rowAtPoint(e.getPoint());
            if ((row < 0) || (row >= pointsToUse.size())) {
                return;
            }
            if (e.getClickCount() > 1) {
                animation.setCurrent(row);
            }
        }
    });

    JScrollPane scrollPane = new JScrollPane(pointTable);
    scrollPane.setPreferredSize(new Dimension(400, 300));
    return scrollPane;

}

From source file:com.intellij.lang.jsgraphql.ide.project.JSGraphQLLanguageUIProjectService.java

private void createToolWindowResultEditor(ToolWindow toolWindow) {

    final LightVirtualFile virtualFile = new LightVirtualFile("GraphQL.result.json", JsonFileType.INSTANCE, "");
    fileEditor = PsiAwareTextEditorProvider.getInstance().createEditor(myProject, virtualFile);

    if (fileEditor instanceof TextEditor) {
        final Editor editor = ((TextEditor) fileEditor).getEditor();
        final EditorEx editorEx = (EditorEx) editor;

        // set read-only mode
        editorEx.setViewer(true);/* w  w  w  .  j  a v a 2  s .  c o  m*/
        editorEx.getSettings().setShowIntentionBulb(false);
        editor.getSettings().setAdditionalLinesCount(0);
        editor.getSettings().setCaretRowShown(false);
        editor.getSettings().setBlinkCaret(false);

        // query result header
        final JSGraphQLEditorHeaderComponent header = new JSGraphQLEditorHeaderComponent();

        querySuccessLabel = new JBLabel();
        querySuccessLabel.setVisible(false);
        querySuccessLabel.setIconTextGap(0);
        header.add(querySuccessLabel, BorderLayout.WEST);

        queryResultLabel = new JBLabel("", null, SwingConstants.LEFT);
        queryResultLabel.setBorder(new EmptyBorder(4, 6, 4, 6));
        queryResultLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        queryResultLabel.setVisible(false);
        queryResultLabel.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                final String fileUrl = (String) queryResultLabel.getClientProperty(FILE_URL_PROPERTY);
                if (fileUrl != null) {
                    final VirtualFile queryFile = VirtualFileManager.getInstance().findFileByUrl(fileUrl);
                    if (queryFile != null) {
                        final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
                        fileEditorManager.openFile(queryFile, true, true);
                    }
                }
            }
        });
        header.add(queryResultLabel, BorderLayout.CENTER);

        // finally set the header as permanent such that it's restored after searches
        editor.setHeaderComponent(header);
        editorEx.setPermanentHeaderComponent(header);
    }

    Disposer.register(this, fileEditor);

    final ContentImpl content = new ContentImpl(fileEditor.getComponent(), "Query result", true);
    content.setCloseable(false);
    toolWindow.getContentManager().addContent(content);

}

From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java

protected void showInfo() {
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(// w  w  w . j  a v a  2 s.  c  o  m
            new JLabel(
                    "<html>Kevin Krummenauer 2015<br><br>Icons by http://jonasraskdesign.com<br><br></html>"),
            BorderLayout.NORTH);
    JLabel link = new JLabel("Kontakt: " + EMAIL);
    link.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            openEMail();
        }

    });
    link.setCursor(new Cursor(Cursor.HAND_CURSOR));
    link.setForeground(Color.BLUE);
    panel.add(link, BorderLayout.CENTER);

    JPanel panel2 = new JPanel(new GridLayout(0, 1, 4, 4));
    {
        panel2.add(new JLabel("<html><b>Libraries and its licenses</b> (click to open)</html>"),
                BorderLayout.NORTH);

        val list = Arrays.asList(
                new TwoObjectsX<String, String>("ILIAS Downloader 2",
                        ServiceFunctions.ILIASDOWNLOADER_WEBSITE_LICENSE),
                new TwoObjectsX<String, String>("Java JDK 8",
                        "http://www.oracle.com/technetwork/java/javase/terms/license/index.html"),
                new TwoObjectsX<String, String>("Apache Commons IO und Apache Commons Codec",
                        "apache_license.txt"),
                new TwoObjectsX<String, String>("Project Lombok", "lombok_license.txt"),
                new TwoObjectsX<String, String>("KSOAP2", "ksoap2_android.txt"),
                new TwoObjectsX<String, String>("Simple XML Serialization", "apache_license.txt"));
        for (val lib : list) {
            link = new JLabel(lib.getObjectA());

            if (lib.getObjectB() != null) {
                link.addMouseListener(new MouseAdapter() {

                    @Override
                    public void mouseClicked(MouseEvent e) {
                        String s = lib.getObjectB();
                        try {
                            if (s.toLowerCase().startsWith("http")) {
                                Desktop.getDesktop().browse(new URI(s));
                            } else {
                                showLicense(s);
                            }
                        } catch (Exception e1) {
                            showError("Lizenz nicht gefunden: " + s, e1);
                        }
                    }

                });
                link.setCursor(new Cursor(Cursor.HAND_CURSOR));
                link.setForeground(Color.BLUE);
            }
            panel2.add(link);
        }
    }
    panel.add(panel2, BorderLayout.SOUTH);

    JOptionPane.showMessageDialog(mainFrame, panel, "Info " + APP_NAME, JOptionPane.INFORMATION_MESSAGE);

}

From source file:edu.ku.brc.specify.tasks.ExpressSearchTask.java

@Override
public List<ToolBarItemDesc> getToolBarItems() {
    toolbarItems = new Vector<ToolBarItemDesc>();

    ActionListener doQuery = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doQuery();/*www  . jav  a 2  s . co  m*/
        }
    };

    searchBoxComp = new SearchBoxComponent(new SearchBoxMenuCreator(), doQuery, false,
            PickListDBAdapterFactory.getInstance().create("ExpressSearch", true));
    searchBoxComp.createUI();
    searchBox = searchBoxComp.getSearchBox();
    searchText = searchBoxComp.getSearchText();
    searchBtn = searchBoxComp.getSearchBtn();
    textBGColor = searchBoxComp.getTextBGColor();
    badSearchColor = searchBoxComp.getBadSearchColor();

    searchBtn.setToolTipText(getResourceString("ExpressSearchTT"));
    HelpMgr.setHelpID(searchBtn, "Express_Search");
    HelpMgr.registerComponent(searchText, "Express_Search");

    AppPreferences localPrefs = AppPreferences.getLocalPrefs();
    searchText.setText(localPrefs.get(getLastSearchKey(), ""));
    textBGColor = searchText.getBackground();

    searchText.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            showContextMenu(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            showContextMenu(e);

        }
    });

    toolbarItems.add(new ToolBarItemDesc(searchBoxComp, ToolBarItemDesc.Position.AdjustRightLastComp));

    return toolbarItems;
}

From source file:com.pianobakery.complsa.MainGui.java

public MainGui() {

    $$$setupUI$$$();//  w ww .  ja v  a2  s .  c o  m
    runtimeParameters();
    trainCorp = new HashMap<String, File>();
    trainSentModels = new HashMap<String, File>();
    indexFilesModel = new HashMap<String, File>();
    searchCorpusModel = new HashMap<String, File>();
    selDocdirContent = new ArrayList<File>();
    langModelsText.setText("None");
    posIndRadiusTextField.setEnabled(false);
    //Disable all Components as long as wDir is not set.
    enableUIElements(false);

    ButtonGroup selSearchGroup = new ButtonGroup();
    selSearchGroup.add(searchSearchCorpRadioButton);
    selSearchGroup.add(searchTopCorpRadioButton);

    ButtonGroup searchSelGroup = new ButtonGroup();
    searchSelGroup.add(selTextRadioButton);
    searchSelGroup.add(selDocRadioButton);

    //licenseKeyGUI = new LicenseKeyGUI(frame, true);

    //Added to get the docSearchTable the focus when opening the Reader without selecting something so up down button will work
    frame.addWindowFocusListener(new WindowAdapter() {
        public void windowGainedFocus(WindowEvent e) {
            docSearchResTable.requestFocusInWindow();
        }
    });

    frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
            .put(KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "CTRL + S");
    frame.getRootPane().getActionMap().put("CTRL + S", runSearch());

    frame.addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent evt) {
            formWindowOpened(evt);
        }
    });

    //Needs to get a white background in the termtableview (only in windows)
    termTablePane.getViewport().setBackground(Color.WHITE);

    //Project Page
    //Project Folder
    newFolderButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            newFolderMethod();

        }
    });

    selectFolderButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            selectFolderMethod();

        }
    });

    //Download Language Models
    downloadModelButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            downloadModelMethod();

        }
    });

    //Add-Remove Topic Corpus
    addTopicCorpusButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            addTopicCorpusMethod();

        }
    });

    selectTrainCorp.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            frame.setTitle("Selected Training Corpus: " + selectTrainCorp.getSelectedItem() + " and "
                    + "Sel. Search Corpus: " + searchCorpComboBox.getSelectedItem());
            algTextField.setText("Knowledge Corpus: " + selectTrainCorp.getSelectedItem());

            try {
                updateIndexFileFolder();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    });

    removeTopicCorpusButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) throws ArrayIndexOutOfBoundsException {
            removeTopicCorpusMethod();

        }

    });

    //Update and remove Index
    updateIndexButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            updateIndexMethod();

        }
    });

    removeIndexButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            removeIndexMethod();

        }
    });

    //Train Semantic
    trainCorpButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            trainCorpMethod();

        }
    });

    indexTypeComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            if (indexTypeComboBox.getSelectedIndex() == 2) {
                logger.debug("Enable indexType Combo with Index: " + indexTypeComboBox.getSelectedIndex());

                posIndRadiusTextField.setEnabled(true);
                return;
            }
            logger.debug("Disable indexType Combo with Index: " + indexTypeComboBox.getSelectedIndex());
            posIndRadiusTextField.setEnabled(false);

        }
    });

    //Import and remove Search Corpora
    impSearchCorpButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            impSearchCorpMethod();

        }
    });

    searchCorpComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            frame.setTitle("Selected Training Corpus: " + selectTrainCorp.getSelectedItem() + " and "
                    + "Sel. Search Corpus: " + searchCorpComboBox.getSelectedItem());
        }
    });

    removeSearchCorpButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) throws ArrayIndexOutOfBoundsException {
            removeSearchCorpMethod();

        }

    });

    //Search Page
    //Choose Index Type
    selectIndexTypeComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            if (searchModelList.isEmpty()) {
                return;
            }

            if (searchModelList.get(selectIndexTypeComboBox.getSelectedItem()) == null) {
                return;
            }

            List<String> theList = searchModelList.get(selectIndexTypeComboBox.getSelectedItem().toString());
            selectTermweightComboBox.removeAllItems();
            for (String aTFItem : theList) {
                selectTermweightComboBox.addItem(aTFItem);
            }

            getSelectedSearchModelFiles();

        }
    });

    selectTermweightComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            if (searchModelList.isEmpty()) {
                return;
            }

            if (searchModelList.get(selectIndexTypeComboBox.getSelectedItem()) == null) {
                return;
            }
            getSelectedSearchModelFiles();
        }
    });

    //Select Search Type
    selTextRadioButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            selectDocumentButton.setEnabled(false);
            searchTextArea.setEnabled(true);
            //searchDocValue.setText("nothing selected");

        }
    });

    selDocRadioButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            selectDocumentButton.setEnabled(true);
            searchTextArea.setText(null);
            searchTextArea.setEnabled(false);

        }
    });

    selectDocumentButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            importSearchFile();
            openSearchDocumentButton.setEnabled(true);

        }
    });

    openSearchDocumentButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (searchDocReader == null) {
                searchDocReader = getReaderLater(null, maingui);
                searchDocReader.setSearchTerms(getSelectedTermTableWords());
            } else if (!searchDocReader.getFrameVisible()) {
                searchDocReader.setFrameVisible(true);
                searchDocReader.setSearchTerms(getSelectedTermTableWords());
            }
            searchDocReader.setDocumentText(searchFileString);
            searchDocReader.setSelFullDocLabel(searchDocValue.toString());
            searchDocReader.setViewPane(2);
            searchDocReader.disableComponents();
            searchDocReader.setSearchTerms(getSelectedTermTableWords());

        }
    });

    //Search Button
    searchButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            searchMethod();

        }

    });

    //Table Listeners
    docSearchResTable.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent me) {
            JTable table = (JTable) me.getSource();
            Point p = me.getPoint();
            int row = docSearchResTable.rowAtPoint(p);
            if (docSearchResModel == null || docSearchResModel.getRowCount() == 0
                    || docSearchResModel.getDocFile(0).getFileName().equals(emptyTable)) {
                return;
            }

            switch (me.getClickCount()) {
            case 1:
                if (row == -1) {
                    break;
                }
                if (docSearchResTable.getRowCount() > 0) {
                    logger.debug("Single click Doc: " + ((DocSearchModel) docSearchResTable.getModel())
                            .getDocSearchFile(row).getFile().toString());
                    fillMetaDataField(
                            ((DocSearchModel) docSearchResTable.getModel()).getDocSearchFile(row).getFile());
                    if (reader != null) {
                        reader.setSearchTerms(getSelectedTermTableWords());
                    }
                    if (searchDocReader != null) {
                        searchDocReader.setSearchTerms(getSelectedTermTableWords());
                    }
                    setSelReaderContent();
                    setDocReaderContent(0);
                    if (reader != null) {
                        reader.setSearchTerms(getSelectedTermTableWords());
                    }
                    if (searchDocReader != null) {
                        searchDocReader.setSearchTerms(getSelectedTermTableWords());
                    }

                }
                break;
            case 2:
                if (row == -1) {
                    break;
                }
                if (docSearchResTable.getRowCount() > 0) {
                    logger.debug("Double click Doc: " + ((DocSearchModel) docSearchResTable.getModel())
                            .getDocSearchFile(row).getFile().toString());
                    fillMetaDataField(
                            ((DocSearchModel) docSearchResTable.getModel()).getDocSearchFile(row).getFile());

                    if (reader == null) {
                        reader = getReaderLater((DocSearchModel) docSearchResTable.getModel(), maingui);
                        reader.setSearchTerms(getSelectedTermTableWords());
                    } else if (!reader.getFrameVisible()) {
                        reader.setFrameVisible(true);
                        reader.setSearchTerms(getSelectedTermTableWords());
                    }
                    setSelReaderContent();
                    setDocReaderContent(0);
                    if (reader != null) {
                        reader.setSearchTerms(getSelectedTermTableWords());
                    }
                    if (searchDocReader != null) {
                        searchDocReader.setSearchTerms(getSelectedTermTableWords());
                    }
                }
                break;
            }

        }
    });

    termSearchResTable.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent me) {
            JTable table = (JTable) me.getSource();
            Point p = me.getPoint();
            int row = docSearchResTable.rowAtPoint(p);
            if (termSearchResTable.getModel() == null || termSearchResTable.getRowCount() == 0
                    || termSearchResTable.getModel().getValueAt(row, 1).equals(emptyTable)) {
                return;
            }
            switch (me.getClickCount()) {
            case 1:
                logger.debug("Single click Term: " + termSearchResTable.getModel().getValueAt(row, 1));
                logger.debug("Selected Terms: " + Arrays.toString(getSelectedTermTableWords()));
                if (reader != null) {
                    reader.setSearchTerms(getSelectedTermTableWords());

                }
                if (searchDocReader != null) {
                    searchDocReader.setSearchTerms(getSelectedTermTableWords());
                }
                break;
            case 2:
                logger.debug("Double click Term: " + termSearchResTable.getModel().getValueAt(row, 1));
                if (reader != null) {
                    reader.setSearchTerms(getSelectedTermTableWords());
                }
                if (searchDocReader != null) {
                    searchDocReader.setSearchTerms(getSelectedTermTableWords());
                }
                break;

            }

        }
    });

    docSearchResTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent event) {
            if (docSearchResModel == null || docSearchResModel.getRowCount() == 0
                    || docSearchResModel.getDocFile(0).getFileName().equals(emptyTable)) {
                return;
            }
            if (docSearchResTable.getSelectedRow() > -1) {
                // print first column value from selected row
                logger.debug("KeyboardSelection: " + ((DocSearchModel) docSearchResTable.getModel())
                        .getDocSearchFile(
                                docSearchResTable.convertRowIndexToModel(docSearchResTable.getSelectedRow()))
                        .getFile().toString());
                fillMetaDataField(((DocSearchModel) docSearchResTable.getModel())
                        .getDocSearchFile(
                                docSearchResTable.convertRowIndexToModel(docSearchResTable.getSelectedRow()))
                        .getFile());
                setSelReaderContent();
                setDocReaderContent(0);
                if (reader != null) {
                    reader.setSearchTerms(getSelectedTermTableWords());
                }
                if (searchDocReader != null) {
                    searchDocReader.setSearchTerms(getSelectedTermTableWords());
                }

            }
        }
    });

    termSearchResTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (termSearchResTable.getModel() == null || termSearchResTable.getRowCount() == 0
                    || termSearchResTable.getModel().getValueAt(0, 1).equals(emptyTable)) {
                return;
            }
            if (termSearchResTable.getSelectedRow() > -1) {
                // print first column value from selected row
                if (reader != null) {
                    reader.setSearchTerms(getSelectedTermTableWords());
                }
                if (searchDocReader != null) {
                    searchDocReader.setSearchTerms(getSelectedTermTableWords());
                }

            }

        }
    });

}

From source file:gda.gui.BatonPanel.java

private JTextField getTxtMessage() {
    if (txtMessage == null) {
        txtMessage = new JTextField();
        txtMessage.setText("Type your messages here");
        // txtMessage.setPreferredSize(new java.awt.Dimension(258, 22));
        txtMessage.addMouseListener(new MouseAdapter() {
            @Override/*w  w w .  j a  va2s .  c  o  m*/
            public void mouseClicked(MouseEvent evt) {
                if (firstUse) {
                    getTxtMessage().setText("");
                    firstUse = false;
                }
            }
        });
        txtMessage.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                if (!firstUse && !getTxtMessage().getText().trim().equals("")) {
                    InterfaceProvider.getBatonStateProvider().sendMessage(getTxtMessage().getText());
                    getTxtMessage().setText("");
                }
            }
        });
    }
    return txtMessage;
}

From source file:com.t3.client.ui.T3Frame.java

private JComponent createTokenTreePanel() {
    final JTree tree = new JTree();
    tokenPanelTreeModel = new TokenPanelTreeModel(tree);
    tree.setModel(tokenPanelTreeModel);//from  w w  w. j  av a  2  s .  co m
    tree.setCellRenderer(new TokenPanelTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.addMouseListener(new MouseAdapter() {
        // TODO: Make this a handler class, not an aic
        @Override
        public void mousePressed(MouseEvent e) {
            // tree.setSelectionPath(tree.getPathForLocation(e.getX(), e.getY()));
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path == null) {
                return;
            }
            Object row = path.getLastPathComponent();
            int rowIndex = tree.getRowForLocation(e.getX(), e.getY());
            if (SwingUtilities.isLeftMouseButton(e)) {
                if (!SwingUtil.isShiftDown(e)) {
                    tree.clearSelection();
                }
                tree.addSelectionInterval(rowIndex, rowIndex);

                if (row instanceof Token) {
                    if (e.getClickCount() == 2) {
                        Token token = (Token) row;
                        getCurrentZoneRenderer().clearSelectedTokens();
                        getCurrentZoneRenderer().centerOn(new ZonePoint(token.getX(), token.getY()));

                        // Pick an appropriate tool
                        getToolbox().setSelectedTool(token.isToken() ? PointerTool.class : StampTool.class);
                        getCurrentZoneRenderer().setActiveLayer(token.getLayer());
                        getCurrentZoneRenderer().selectToken(token.getId());
                        getCurrentZoneRenderer().requestFocusInWindow();
                    }
                }
            }
            if (SwingUtilities.isRightMouseButton(e)) {
                if (!isRowSelected(tree.getSelectionRows(), rowIndex) && !SwingUtil.isShiftDown(e)) {
                    tree.clearSelection();
                    tree.addSelectionInterval(rowIndex, rowIndex);
                }
                final int x = e.getX();
                final int y = e.getY();
                EventQueue.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        Token firstToken = null;
                        Set<GUID> selectedTokenSet = new HashSet<GUID>();
                        for (TreePath path : tree.getSelectionPaths()) {
                            if (path.getLastPathComponent() instanceof Token) {
                                Token token = (Token) path.getLastPathComponent();
                                if (firstToken == null) {
                                    firstToken = token;
                                }
                                if (AppUtil.playerOwns(token)) {
                                    selectedTokenSet.add(token.getId());
                                }
                            }
                        }
                        if (!selectedTokenSet.isEmpty()) {
                            try {
                                if (firstToken.isStamp()) {
                                    new StampPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(),
                                            firstToken).showPopup(tree);
                                } else {
                                    new TokenPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(),
                                            firstToken).showPopup(tree);
                                }
                            } catch (IllegalComponentStateException icse) {
                                log.info(tree.toString(), icse);
                            }
                        }
                    }
                });
            }
        }
    });
    TabletopTool.getEventDispatcher().addListener(new AppEventListener() {
        @Override
        public void handleAppEvent(AppEvent event) {
            tokenPanelTreeModel.setZone((Zone) event.getNewValue());
        }
    }, TabletopTool.ZoneEvent.Activated);
    return tree;
}

From source file:cz.muni.fi.pv168.MainForm.java

public MainForm() {
    initComponents();//from w w  w. ja v a2  s . com
    carManager.setDataSource(dataSource);
    customerManager.setDataSource(dataSource);
    rentManager.setDataSource(dataSource);
    FileOutputStream fs = null;
    try {
        fs = new FileOutputStream("main.log", true);
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
    }

    carManager.setLogger(fs);
    customerManager.setLogger(fs);
    rentManager.setLogger(fs);

    final SortFilterModel sorter = new SortFilterModel(rentTable.getModel());
    rentTable.getTableHeader().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent event) {
            // check for double click
            if (event.getClickCount() < 2) {
                return;
            }
            // find column of click and
            int tableColumn = rentTable.columnAtPoint(event.getPoint());
            // translate to table model index and sort
            int modelColumn = rentTable.convertColumnIndexToModel(tableColumn);
            sorter.sort(modelColumn);
        }
    });

    jTabbedPane1.setTitleAt(0, localization.getString("cars"));
    jTabbedPane1.setTitleAt(1, localization.getString("customers"));
    jTabbedPane1.setTitleAt(2, localization.getString("rents"));

    carTable.setModel(new CarsTableModel(localization));
    customerTable.setModel(new CustomersTableModel(localization));
    rentTable.setModel(new RentsTableModel(localization));

    jMenu1.setText(localization.getString("file"));
    jMenu2.setText(localization.getString("data"));
    jMenu3.setText(localization.getString("new"));
    jMenu4.setText(localization.getString("help"));

    jMenuItem1.setText(localization.getString("db_connect"));
    jMenuItem2.setText(localization.getString("db_disconnect"));
    jMenuItem9.setText(localization.getString("help"));
    jMenuItem10.setText(localization.getString("credits"));

    jMenuItem3.setAction(new ExitAction(localization.getString("exit")));
    jMenuItem7.setAction(new AddRentAction(localization.getString("rent")));
    jMenuItem8.setAction(new AddCarAction(localization.getString("car")));
    jMenuItem11.setAction(new CommitAction(localization.getString("commit")));
    jMenuItem18.setAction(new AddCustomerAction(localization.getString("customer")));

    jButton1.setAction(new CommitAction(localization.getString("commit")));
    jButton2.setAction(new AddCarAction(localization.getString("new_car")));
    jButton3.setAction(new AddCustomerAction(localization.getString("new_customer")));
    jButton4.setAction(new AddRentAction(localization.getString("new_rent")));

    jMenuItem5.setText(localization.getString("find"));

    jButton9.setText(localization.getString("search"));

    jMenu6.setText(localization.getString("remove"));
    jMenuItem19.setText(localization.getString("car"));
    jMenuItem20.setText(localization.getString("customer"));
    jMenuItem21.setText(localization.getString("rent"));

    jMenuItem23.setAction(new CopyAction(localization.getString("copy")));
    jMenuItem24.setAction(new CutAction(localization.getString("cut")));
    jMenuItem25.setAction(new PasteAction(localization.getString("paste")));
}

From source file:edu.pdi2.visual.PDI.java

private JCheckBoxMenuItem getJCheckBoxMIThumbs() {
    if (jCheckBoxMIThumbs == null) {
        jCheckBoxMIThumbs = new JCheckBoxMenuItem();
        jCheckBoxMIThumbs.setText("Bands Thumbnails");
        jCheckBoxMIThumbs.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent evt) {
                showThumbnails(evt);/* ww w .  ja  v  a  2 s .  c  o m*/
            }
        });
    }
    return jCheckBoxMIThumbs;
}

From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java

protected void initTabContextMenu(JComponent tabComponent) {
    tabComponent.addMouseListener(new MouseAdapter() {
        @Override//from  w  w  w  .jav a2 s.c om
        public void mousePressed(MouseEvent e) {
            dispatchToParent(e);
            if (e.isPopupTrigger()) {
                showTabPopup(e);
            }
        }

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

        @Override
        public void mouseEntered(MouseEvent e) {
            dispatchToParent(e);
        }

        @Override
        public void mouseMoved(MouseEvent e) {
            dispatchToParent(e);
        }

        @Override
        public void mouseDragged(MouseEvent e) {
            dispatchToParent(e);
        }

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            dispatchToParent(e);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            dispatchToParent(e);
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            dispatchToParent(e);
        }

        public void dispatchToParent(MouseEvent e) {
            tabsPane.dispatchEvent(SwingUtilities.convertMouseEvent(e.getComponent(), e, tabsPane));
        }
    });
}