Example usage for javax.swing SwingUtilities isRightMouseButton

List of usage examples for javax.swing SwingUtilities isRightMouseButton

Introduction

In this page you can find the example usage for javax.swing SwingUtilities isRightMouseButton.

Prototype

public static boolean isRightMouseButton(MouseEvent anEvent) 

Source Link

Document

Returns true if the mouse event specifies the right mouse button.

Usage

From source file:org.ut.biolab.medsavant.client.cohort.CohortDetailedView.java

public synchronized void setPatientList(List<SimplePatient> patients) {

    members.removeAll();//  www . j  a  v a  2  s .c o m

    final Object[][] data = new Object[patients.size()][1];

    for (int i = 0; i < patients.size(); i++) {
        data[i][0] = patients.get(i);
    }

    list = new StripyTable(data, new String[] { "Member Hospital IDs" });
    list.setFont(FontFactory.getGeneralFont().deriveFont(16));
    list.setBorder(null);
    list.setShowGrid(false);
    list.setRowHeight(21);

    list.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {

                int[] selection = list.getSelectedRows();

                String[] hosIds = new String[selection.length];

                for (int i = 0; i < selection.length; i++) {
                    int j = list.convertRowIndexToModel(selection[i]);
                    hosIds[i] = ((SimplePatient) data[j][0]).getHospitalId();
                }

                createHospitalPopup(hosIds).show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

    final JButton removeButton = removeIndividualsButton();
    removeButton.setEnabled(false);
    list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            int count = list.getSelectedRowCount();
            removeButton.setEnabled(count > 0);
            if (count == 0) {
                removeButton.setText("Remove selected member");
            } else {
                if (count == 1) {
                    removeButton.setText("Remove selected member");
                } else {
                    removeButton.setText(String.format("Remove %d selected members", count));
                }
            }
        }

    });

    members.setLayout(new MigLayout("fillx, insets 0, wrap"));
    members.add(new JLabel(ViewUtil.numToString(list.getRowCount()) + " "
            + MiscUtils.pluralize(list.getRowCount(), "member", "members")), "split, growx 1.0");
    members.add(removeButton, "right,wrap");
    members.add(list, "width 100%");

    members.updateUI();
}

From source file:org.ut.biolab.medsavant.client.view.genetics.charts.SummaryChart.java

private synchronized Chart drawChart(ChartFrequencyMap[] chartMaps) {

    ChartFrequencyMap filteredChartMap = chartMaps[0];
    ChartFrequencyMap unfilteredChartMap = null;

    DefaultChartModel filteredChartModel = new DefaultChartModel();
    DefaultChartModel unfilteredChartModel = null;

    if (this.showComparedToOriginal) {
        unfilteredChartMap = ChartFrequencyMap.subtract(chartMaps[1], filteredChartMap, isLogScaleY());
        unfilteredChartModel = new DefaultChartModel();
    }//w w  w  .  j a v a 2  s .c om

    final Chart chart = new Chart();

    JPanel panel = new JPanel();
    Legend legend = new Legend(chart, 0);
    panel.add(legend);
    legend.addChart(chart);

    boolean multiColor = !mapGenerator.isNumeric() || isPie;

    chart.setRolloverEnabled(true);
    chart.setSelectionEnabled(true);
    chart.setSelectionShowsOutline(true);
    chart.setSelectionShowsExplodedSegments(true);
    chart.setAntiAliasing(true);
    chart.setBarGap(5);
    chart.setBorder(ViewUtil.getBigBorder());
    chart.setLabellingTraces(true);

    chart.setAnimateOnShow(false);

    chart.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                JPopupMenu popup = createPopup(chart);
                popup.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

    AbstractPieSegmentRenderer rpie = new DefaultPieSegmentRenderer();
    chart.setPieSegmentRenderer(rpie);

    //Makes a box with fill color 255,255,255,0 and put a label with a black
    //font in that box.  The box is positioned directly over the corresponding pie slice.
    /*
    SimplePieLabelRenderer plr = new SimplePieLabelRenderer();
    plr.setLabelColor(Color.BLACK);
    plr.setBackground(new Color(0,0,0,0));
    rpie.setPieLabelRenderer(plr);
    */

    //....alternatively, the below draws a line from the pie wedge to the label.
    //see http://www.jidesoft.com/javadoc/com/jidesoft/chart/render/LinePieLabelRenderer.html
    LinePieLabelRenderer plr = new LinePieLabelRenderer();
    plr.setLabelColor(Color.black);
    plr.setLineColor(Color.black); //see also plr.setLineStroke        
    rpie.setPieLabelRenderer(plr);

    DefaultBarRenderer rbar = new DefaultBarRenderer();
    chart.setBarRenderer(rbar);

    rpie.setSelectionColor(Color.gray);
    rbar.setSelectionColor(Color.gray);

    if (isSortedKaryotypically()) {
        filteredChartMap.sortKaryotypically();
        if (this.showComparedToOriginal) {
            unfilteredChartMap.sortKaryotypically();
        }
    }

    if (isSorted() && !mapGenerator.isNumeric() && !isSortedKaryotypically()) {
        filteredChartMap.sortNumerically();
        if (this.showComparedToOriginal) {
            chartMaps[1].sortNumerically();
        }
    } else {
        filteredChartMap.undoSortNumerically();
        if (this.showComparedToOriginal) {
            chartMaps[1].undoSortNumerically();
        }
    }

    long max = filteredChartMap.getMax();
    List<ChartCategory> chartCategories;
    if (this.showComparedToOriginal) {
        chartCategories = chartMaps[1].getCategories();
        max = chartMaps[1].getMax();
    } else {
        chartCategories = filteredChartMap.getCategories();
    }

    CategoryRange<String> range = new CategoryRange<String>();
    List<Highlight> highlights = new ArrayList<Highlight>();

    Color color = new Color(72, 181, 249);
    Highlight h;
    int catNum = 0;
    int totalCats = filteredChartMap.getEntries().size();

    for (ChartCategory category : chartCategories) {
        range.add(category);
        if (multiColor) {
            color = ViewUtil.getColor(catNum++, totalCats);
        }
        h = new Highlight(category.getName());
        highlights.add(h);
        chart.setHighlightStyle(h, barStyle(color));
    }

    final CategoryAxis xaxis = new CategoryAxis(range, "Category");
    chart.setXAxis(xaxis);
    if (this.isLogScaleY()) {
        chart.setYAxis(new Axis(new NumericRange(0, Math.log10(max) * 1.1), "log(Frequency)"));
    } else {
        chart.setYAxis(new Axis(new NumericRange(0, max * 1.1), "Frequency"));
    }

    addEntriesToChart(filteredChartModel, filteredChartMap, chartCategories, highlights);
    if (this.showComparedToOriginal) {
        addEntriesToChart(unfilteredChartModel, unfilteredChartMap, chartCategories, null);
    }

    chart.getXAxis().getLabel().setFont(ViewUtil.getMediumTitleFont());
    chart.getYAxis().getLabel().setFont(ViewUtil.getMediumTitleFont());

    // rotate 90 degrees (using radians)
    chart.getXAxis().setTickLabelRotation(1.57079633);

    if (isPie) {
        System.out.println("Setting chart type to pie");
        chart.setChartType(ChartType.PIE);
        chart.getXAxis().getLabel().setColor(Color.BLUE);
    }

    // This adds zooming cababilities to bar charts, not great though
    /*else {
     RubberBandZoomer rubberBand = new RubberBandZoomer(chart);
     chart.addDrawable(rubberBand);
     chart.addMouseListener(rubberBand);
     chart.addMouseMotionListener(rubberBand);
            
     rubberBand.addZoomListener(new ZoomListener() {
     public void zoomChanged(ChartSelectionEvent event) {
     if (event instanceof RectangleSelectionEvent) {
     Range<?> currentXRange = chart.getXAxis().getOutputRange();
     Range<?> currentYRange = chart.getYAxis().getOutputRange();
     ZoomFrame frame = new ZoomFrame(currentXRange, currentYRange);
     zoomStack.push(frame);
     Rectangle selection = (Rectangle) event.getLocation();
     Point topLeft = selection.getLocation();
     topLeft.x = (int) Math.floor(frame.getXRange().minimum());
     Point bottomRight = new Point(topLeft.x + selection.width, topLeft.y + selection.height);
     bottomRight.x = (int) Math.ceil(frame.getXRange().maximum());
     assert bottomRight.x >= topLeft.x;
     Point2D rp1 = chart.calculateUserPoint(topLeft);
     Point2D rp2 = chart.calculateUserPoint(bottomRight);
     if (rp1 != null && rp2 != null) {
     assert rp2.getX() >= rp1.getX();
     Range<?> xRange = new NumericRange(rp1.getX(), rp2.getX());
     assert rp1.getY() >= rp2.getY();
     Range<?> yRange = new NumericRange(rp2.getY(), rp1.getY());
     //chart.getXAxis().setRange(xRange);
     chart.getYAxis().setRange(yRange);
     }
     } else if (event instanceof PointSelectionEvent) {
     if (zoomStack.size() > 0) {
     ZoomFrame frame = zoomStack.pop();
     Range<?> xRange = frame.getXRange();
     Range<?> yRange = frame.getYRange();
     //chart.getXAxis().setRange(xRange);
     chart.getYAxis().setRange(yRange);
     }
     }
     }
     });
     }
     *
     */

    for (int i = 1; i < this.getComponentCount(); i++) {
        this.remove(i);
    }

    chart.addModel(filteredChartModel, new ChartStyle().withBars());
    if (this.showComparedToOriginal) {
        chart.addModel(unfilteredChartModel, new ChartStyle(new Color(10, 10, 10, 100)).withBars());
    }

    return chart;
}

From source file:org.ut.biolab.medsavant.client.view.list.ListView.java

private void updateShowCard() {
    showCard.removeAll();/*from w w  w.j  a v a2s  . c  om*/

    showCard.setLayout(new BorderLayout());

    String[] columnNames = detailedModel.getColumnNames();
    Class[] columnClasses = detailedModel.getColumnClasses();
    int[] columnVisibility = detailedModel.getHiddenColumns();

    int firstVisibleColumn = 0;
    while (columnVisibility.length > 0 && firstVisibleColumn == columnVisibility[firstVisibleColumn]) {
        firstVisibleColumn++;
    }

    Set<NiceListItem> selectedItems;
    if (list != null) {
        selectedItems = new HashSet<NiceListItem>(list.getSelectedItems());
    } else {
        selectedItems = new HashSet<NiceListItem>(); // empty set, for simplicity of not having to null check later on
    }

    list = new NiceList();
    if (listColorScheme != null) {
        list.setColorScheme(listColorScheme);
    }
    list.startTransaction();

    List<Integer> selectedIndicies = new ArrayList<Integer>();

    int counter = 0;
    for (Object[] row : data) {
        NiceListItem nli = new NiceListItem(row[firstVisibleColumn].toString(), row);
        list.addItem(nli);

        if (selectedItems.contains(nli)) {
            selectedIndicies.add(counter);
        }
        counter++;
    }

    /*
     int[] selectedIndiciesArray = new int[selectedIndicies.size()];
            
     System.out.println("Reselecting "  + selectedIndicies.size() + " items");
     for (int i = 0; i < selectedIndicies.size();i++) {
     System.out.println("Reselecting "  + list.getItem(selectedIndicies.get(i)).toString() + " at index " + selectedIndicies.get(i));
     selectedIndiciesArray[i] = selectedIndicies.get(i);
     }*/
    list.endTransaction();

    wp.setBackground(list.getColorScheme().getBackgroundColor());

    if (detailedView != null) {
        list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {

                if (!e.getValueIsAdjusting()) {
                    List<Object[]> selectedItems = getSelectedRows();
                    if (selectedItems.size() == 1) {
                        detailedView.setSelectedItem(selectedItems.get(0));
                    } else {
                        detailedView.setMultipleSelections(selectedItems);
                    }
                }
            }
        });

        list.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                if (SwingUtilities.isRightMouseButton(e)) {
                    JPopupMenu popup = detailedView.createPopup();
                    if (popup != null) {
                        popup.show(e.getComponent(), e.getX(), e.getY());
                    }
                }
            }
        });
    }

    if (selectedIndicies.isEmpty()) {
        list.selectItemAtIndex(0);
    } else {
        list.selectItemsAtIndicies(selectedIndicies);
    }

    JScrollPane jsp = ViewUtil.getClearBorderlessScrollPane(list);
    jsp.setHorizontalScrollBar(null);

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new MigLayout("wrap, fillx"));

    topPanel.add(ViewUtil.getEmphasizedLabel(pageName.toUpperCase()));
    topPanel.setBackground(list.getColorScheme().getBackgroundColor());

    if (searchBarEnabled) {
        topPanel.add(list.getSearchBar(), "growx 1.0");
    }
    showCard.add(topPanel, BorderLayout.NORTH);

    showCard.add(jsp, BorderLayout.CENTER);

    showCard.add(controlBar.getComponent(), BorderLayout.SOUTH);

}

From source file:org.ut.biolab.medsavant.client.view.list.MasterView.java

private void updateShowCard() {
    showCard.removeAll();//from  w ww .ja v a2s .com

    showCard.setLayout(new BorderLayout());
    showCard.setBackground(ViewUtil.getTertiaryMenuColor());
    showCard.setBorder(ViewUtil.getBigBorder());

    String[] columnNames = detailedModel.getColumnNames();
    Class[] columnClasses = detailedModel.getColumnClasses();
    int[] columnVisibility = detailedModel.getHiddenColumns();

    stp = new ListViewTablePanel(data, columnNames, columnClasses, columnVisibility) {
        @Override
        public void forceRefreshData() {
            refreshList();
        }
    };

    selectionGrabber = new RowSelectionGrabber(stp.getTable(), data);

    if (detailedView != null) {
        stp.getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {

                if (!e.getValueIsAdjusting()) {
                    List<Object[]> selectedItems = selectionGrabber.getSelectedItems();
                    if (selectedItems.size() == 1) {
                        detailedView.setSelectedItem(selectedItems.get(0));
                    } else {
                        detailedView.setMultipleSelections(selectedItems);
                    }
                }
            }
        });

        stp.getTable().addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                if (SwingUtilities.isRightMouseButton(e)) {
                    JPopupMenu popup = detailedView.createPopup();
                    if (popup != null) {
                        popup.show(e.getComponent(), e.getX(), e.getY());
                    }
                }
            }
        });
    }

    stp.getTable().getSelectionModel().setSelectionInterval(0, 0);

    showCard.add(stp, BorderLayout.CENTER);

    showCard.add(buttonPanel, BorderLayout.SOUTH);

}

From source file:org.zaproxy.zap.extension.encoder2.EncodeDecodeDialog.java

private ZapTextArea newField(boolean editable) {
    final ZapTextArea field = new ZapTextArea();
    field.setLineWrap(true);//from   ww w. j a va2 s.co  m
    field.setBorder(BorderFactory.createEtchedBorder());
    field.setEditable(editable);
    field.setName(ENCODE_DECODE_RESULTFIELD);

    field.addMouseListener(new java.awt.event.MouseAdapter() {
        @Override
        public void mousePressed(java.awt.event.MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

    return field;
}

From source file:org.zaproxy.zap.extension.encoder2.EncodeDecodeDialog.java

private ZapTextArea getInputField() {
    if (inputField == null) {
        inputField = newField(true);//from ww w  .  j  a  v a 2 s .  c om
        inputField.setName(ENCODE_DECODE_FIELD);

        inputField.getDocument().addDocumentListener(new DocumentListener() {
            @Override
            public void insertUpdate(DocumentEvent documentEvent) {
                updateEncodeDecodeFields();
            }

            @Override
            public void removeUpdate(DocumentEvent documentEvent) {
                updateEncodeDecodeFields();
            }

            @Override
            public void changedUpdate(DocumentEvent documentEvent) {
            }
        });

        inputField.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mousePressed(java.awt.event.MouseEvent e) {
                if (SwingUtilities.isRightMouseButton(e)) {
                    View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY());
                }
            }
        });
    }
    return inputField;
}

From source file:org.zaproxy.zap.extension.multiFuzz.impl.http.HttpFuzzerContentPanel.java

public JXTreeTable getFuzzResultTable() {
    if (fuzzResultTable == null) {
        resetFuzzResultTable();/*from  ww w .j  av a  2 s.  com*/
        fuzzResultTable = new JXTreeTable(getResultsModel());
        fuzzResultTable.setName("HttpFuzzResultTable");
        fuzzResultTable.setDoubleBuffered(true);
        fuzzResultTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        fuzzResultTable.setFont(new java.awt.Font("Default", java.awt.Font.PLAIN, 12));
        fuzzResultTable.setDefaultRenderer(Pair.class, new IconTableCellRenderer());

        int[] widths = { 10, 25, 550, 30, 85, 55, 40, 70 };
        for (int i = 0, count = widths.length; i < count; i++) {
            TableColumn column = fuzzResultTable.getColumnModel().getColumn(i);
            column.setPreferredWidth(widths[i]);
        }
        fuzzResultTable.addMouseListener(new java.awt.event.MouseAdapter() {
            @Override
            public void mousePressed(java.awt.event.MouseEvent e) {
                showPopupMenuIfTriggered(e);
            }

            @Override
            public void mouseReleased(java.awt.event.MouseEvent e) {
                showPopupMenuIfTriggered(e);
            }

            private void showPopupMenuIfTriggered(java.awt.event.MouseEvent e) {
                if (e.isPopupTrigger() && SwingUtilities.isRightMouseButton(e)) {
                    // Select list item on right click
                    JTable table = (JTable) e.getSource();
                    int row = table.rowAtPoint(e.getPoint());

                    if (!table.isRowSelected(row)) {
                        table.changeSelection(row, 0, false, false);
                    }
                    View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY());
                }
            }

        });

        fuzzResultTable.getSelectionModel()
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {

                    @Override
                    public void valueChanged(javax.swing.event.ListSelectionEvent e) {
                        if (!e.getValueIsAdjusting()) {
                            if (fuzzResultTable.getSelectedRowCount() == 0) {
                                return;
                            }
                            final int row = fuzzResultTable.getSelectedRow();
                            if (getEntry(row) instanceof HttpFuzzRequestRecord) {
                                final HistoryReference historyReference = ((HttpFuzzRequestRecord) getEntry(
                                        row)).getHistory();
                                try {
                                    displayMessage(historyReference.getHttpMessage());
                                } catch (HttpMalformedHeaderException | SQLException ex) {
                                    logger.error(ex.getMessage(), ex);
                                }
                            }
                        }
                    }
                });
        fuzzResultTable.getTableHeader().addMouseListener(new MouseListener() {
            int sortedOn = -1;

            @Override
            public void mouseReleased(MouseEvent arg0) {
            }

            @Override
            public void mousePressed(MouseEvent arg0) {
            }

            @Override
            public void mouseExited(MouseEvent arg0) {
            }

            @Override
            public void mouseEntered(MouseEvent arg0) {
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                int index = fuzzResultTable.columnAtPoint(e.getPoint());
                List<HttpFuzzRecord> list = getResultsModel().getEntries();
                if (list.size() == 0) {
                    return;
                }
                HttpFuzzRecordComparator comp = new HttpFuzzRecordComparator();
                comp.setFeature(index);
                if (index == sortedOn) {
                    Collections.sort(list, comp);
                    Collections.reverse(list);
                    sortedOn = -1;
                } else {
                    Collections.sort(list, comp);
                    sortedOn = index;
                }
                fuzzResultTable.updateUI();
            }
        });
        fuzzResultTable.setRootVisible(false);
        fuzzResultTable.setVisible(true);
    }
    return fuzzResultTable;
}

From source file:pl.kotcrab.arget.gui.ContactsPanel.java

public ContactsPanel(final Profile profile, MainWindowCallback callback) {
    this.profile = profile;

    setLayout(new BorderLayout());

    table = new JTable(new ContactsTableModel(profile.contacts));

    table.setDefaultRenderer(ContactInfo.class, new ContactsTableEditor(table, callback));
    table.setDefaultEditor(ContactInfo.class, new ContactsTableEditor(table, callback));
    table.setShowGrid(false);/*from  w  ww .  ja  v a2 s  .co m*/
    table.setTableHeader(null);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setRowHeight(40);

    final JPopupMenu popupMenu = new JPopupMenu();

    {
        JMenuItem menuModify = new JMenuItem("Modify");
        JMenuItem menuDelete = new JMenuItem("Delete");

        popupMenu.add(menuModify);
        popupMenu.add(menuDelete);

        menuModify.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String key = Base64.encodeBase64String(profile.rsa.getPublicKey().getEncoded());
                new CreateContactDialog(MainWindow.instance, key,
                        (ContactInfo) table.getValueAt(table.getSelectedRow(), 0));
                ProfileIO.saveProfile(profile);
                updateContactsTable();
            }
        });

        menuDelete.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                ContactInfo contact = (ContactInfo) table.getValueAt(table.getSelectedRow(), 0);

                if (contact.status == ContactStatus.CONNECTED_SESSION) {
                    JOptionPane.showMessageDialog(MainWindow.instance,
                            "This contact cannot be deleted because session is open.", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }

                int result = JOptionPane.showConfirmDialog(MainWindow.instance,
                        "Are you sure you want to delete '" + contact.name + "'?", "Warning",
                        JOptionPane.YES_NO_OPTION);

                if (result == JOptionPane.NO_OPTION || result == JOptionPane.CLOSED_OPTION)
                    return;

                profile.contacts.remove(contact);
                ProfileIO.saveProfile(profile);
                updateContactsTable();
            }
        });
    }

    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                Point p = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), table);

                int rowNumber = table.rowAtPoint(p);
                table.editCellAt(rowNumber, 0);
                table.getSelectionModel().setSelectionInterval(rowNumber, rowNumber);

                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });

    JScrollPane tableScrollPane = new JScrollPane(table);
    tableScrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));

    add(tableScrollPane, BorderLayout.CENTER);
}

From source file:tvbrowser.ui.mainframe.searchfield.SearchTextField.java

/**
 * Create the Search-Field//  w  ww  . j av  a  2 s . c  om
 * @param len Specified amount of Columns
 */
public SearchTextField(int len) {
    super(len);

    addFocusListener(this);
    addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                requestFocus();
            }
        }
    });

    int r = (getForeground().getRed() + getBackground().getRed()) >> 1;
    int g = (getForeground().getGreen() + getBackground().getGreen()) >> 1;
    int b = (getForeground().getBlue() + getBackground().getBlue()) >> 1;

    mNoTextColor = new Color(r, g, b);
    mTextColor = getForeground();

    setText(mLocalizer.ellipsisMsg("search", "Search"));
    setForeground(mNoTextColor);
}

From source file:view.MainWindow.java

private void setupTreePopups() {
    jtOpenedDocuments.addMouseListener(new MouseAdapter() {
        @Override//w w  w .  j a  v  a 2  s .  c  o m
        public void mouseClicked(MouseEvent e) {

            if (SwingUtilities.isRightMouseButton(e)) {
                JPopupMenu popup = new JPopupMenu();
                if (null != jtOpenedDocuments.getSelectionRows()) {
                    if (1 >= jtOpenedDocuments.getSelectionRows().length) {
                        int row = jtOpenedDocuments.getClosestRowForLocation(e.getX(), e.getY());
                        jtOpenedDocuments.setSelectionRow(row);
                    } else {
                        int row = jtOpenedDocuments.getClosestRowForLocation(e.getX(), e.getY());
                        boolean selected = false;
                        for (int i : jtOpenedDocuments.getSelectionRows()) {
                            if (i == row) {
                                selected = true;
                                break;
                            }
                        }
                        if (!selected) {
                            jtOpenedDocuments.setSelectionRow(row);
                        }
                    }

                    JMenuItem m = null;
                    ActionListener open = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            loadPdf(getSelectedFile(jtOpenedDocuments), true);
                        }
                    };

                    ActionListener remove = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            closeDocument(true);
                        }
                    };

                    ActionListener removeOthers = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            final ArrayList<File> alFilesToClose = new ArrayList<>();
                            boolean showDialog = false;
                            for (File file : getOpenedFiles()) {
                                if (!getSelectedOpenedFiles().contains(file)) {
                                    alFilesToClose.add(file);
                                    if (file.equals(openedFile)) {
                                        showDialog = true;
                                    }
                                }
                            }
                            closeDocuments(alFilesToClose, showDialog);
                        }
                    };

                    ActionListener removeAll = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            closeDocuments(getOpenedFiles(), true);
                        }
                    };

                    ActionListener show = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            try {
                                Desktop.getDesktop().open(getSelectedFile(jtOpenedDocuments).getParentFile());
                            } catch (IOException ex) {
                                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    };

                    if (!openedFile.equals(getSelectedFile(jtOpenedDocuments))) {
                        m = new JMenuItem(Bundle.getBundle().getString("menuItem.open"));
                        m.addActionListener(open);
                        popup.add(m);
                    }
                    m = new JMenuItem(getSelectedOpenedFiles().size() > 1
                            ? Bundle.getBundle().getString("menuItem.removeTheseLoadedDocuments")
                            : Bundle.getBundle().getString("menuItem.removeThisLoadedDocument"));
                    m.addActionListener(remove);
                    popup.add(m);
                    if (getOpenedFiles().size() > 1) {
                        m = new JMenuItem(Bundle.getBundle().getString("menuItem.removeOtherLoadedDocuments"));
                        m.addActionListener(removeOthers);
                        popup.add(m);
                        m = new JMenuItem(Bundle.getBundle().getString("menuItem.removeAllLoadedDocuments"));
                        m.addActionListener(removeAll);
                        popup.add(m);
                    }
                    if (getSelectedOpenedFiles().size() == 1) {
                        m = new JMenuItem(Bundle.getBundle().getString("menuItem.showInExplorer"));
                        m.addActionListener(show);
                        popup.add(m);
                    }

                    popup.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }
    });

    jtExplorer.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {

            if (SwingUtilities.isRightMouseButton(e)) {
                JPopupMenu popup = new JPopupMenu();
                if (null != jtExplorer.getSelectionRows()) {
                    if (1 >= jtExplorer.getSelectionRows().length) {
                        int row = jtExplorer.getClosestRowForLocation(e.getX(), e.getY());
                        jtExplorer.setSelectionRow(row);
                    } else {
                        int row = jtExplorer.getClosestRowForLocation(e.getX(), e.getY());
                        boolean selected = false;
                        for (int i : jtExplorer.getSelectionRows()) {
                            if (i == row) {
                                selected = true;
                                break;
                            }
                        }
                        if (!selected) {
                            jtExplorer.setSelectionRow(row);
                        }
                    }

                    JMenuItem m = null;
                    ActionListener loadFile = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            if (jtExplorer.getSelectionRows().length == 1) {
                                loadPdf(getSelectedFile(jtExplorer), true);
                            } else {
                                ArrayList<File> sl = getMultipleSelectedFiles(jtExplorer);
                                for (File f : sl) {
                                    loadPdf(f, false);
                                }
                            }
                        }
                    };
                    ActionListener loadFolder = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            if (jtExplorer.getSelectionRows().length == 1) {
                                File f = getSelectedFile(jtExplorer);
                                loadFolder(f, false);
                            } else {
                                ArrayList<File> sl = getMultipleSelectedFiles(jtExplorer);
                                for (File f : sl) {
                                    loadFolder(f, false);
                                }
                            }
                        }
                    };
                    ActionListener loadFolderRecursively = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            if (jtExplorer.getSelectionRows().length == 1) {
                                File f = getSelectedFile(jtExplorer);
                                loadFolder(f, true);
                            } else {
                                ArrayList<File> sl = getMultipleSelectedFiles(jtExplorer);
                                for (File s : sl) {
                                    loadFolder(s, true);
                                }
                            }
                        }
                    };
                    ActionListener remove = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            ArrayList<File> listaF = getMultipleSelectedFiles(jtExplorer);
                            closeDocuments(listaF, true);
                        }
                    };

                    ActionListener show = new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            try {
                                Desktop.getDesktop()
                                        .open(getSelectedFile(jtExplorer).isFile()
                                                ? getSelectedFile(jtExplorer).getParentFile()
                                                : getSelectedFile(jtExplorer));
                            } catch (IOException ex) {
                                Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    };

                    if (files.isEmpty()) {
                        if (jtExplorer.getSelectionRows().length <= 1) {
                            File f = getSelectedFile(jtExplorer);
                            if (f.isDirectory()) {
                                m = new JMenuItem(
                                        Bundle.getBundle().getString("menuItem.openDocumentsInThisFolder"));
                                m.addActionListener(loadFolder);
                                popup.add(m);
                                m = new JMenuItem(Bundle.getBundle()
                                        .getString("menuItem.openDocumentsThisFolderRecursive"));
                                m.addActionListener(loadFolderRecursively);
                                popup.add(m);
                                m = new JMenuItem(Bundle.getBundle().getString("menuItem.showInExplorer"));
                                m.addActionListener(show);
                                popup.add(m);
                            } else {
                                m = new JMenuItem(Bundle.getBundle().getString("menuItem.openDocument"));
                                m.addActionListener(loadFile);
                                popup.add(m);
                                m = new JMenuItem(Bundle.getBundle().getString("menuItem.showInExplorer"));
                                m.addActionListener(show);
                                popup.add(m);
                            }

                        } else {
                            ArrayList<File> l = getMultipleSelectedFiles(jtExplorer);
                            boolean file = l.get(0).isFile();
                            boolean allSame = true;
                            for (File f : l) {
                                if (file != f.isFile()) {
                                    allSame = false;
                                    break;
                                }
                            }
                            if (allSame) {
                                if (file) {
                                    m = new JMenuItem(Bundle.getBundle().getString("menuItem.openDocuments"));
                                    m.addActionListener(loadFile);
                                    popup.add(m);
                                } else {
                                    m = new JMenuItem(Bundle.getBundle()
                                            .getString("menuItem.openDocumentsInTheseFolders"));
                                    m.addActionListener(loadFolder);
                                    popup.add(m);
                                }
                            }
                        }
                    } else {
                        File f = getSelectedFile(jtExplorer);
                        if (f.isDirectory()) {
                            m = new JMenuItem(
                                    Bundle.getBundle().getString("menuItem.openDocumentsInThisFolder"));
                            m.addActionListener(loadFolder);
                            popup.add(m);
                            m = new JMenuItem(
                                    Bundle.getBundle().getString("menuItem.openDocumentsThisFolderRecursive"));
                            m.addActionListener(loadFolderRecursively);
                            popup.add(m);
                        } else if (files.contains(getSelectedFile(jtExplorer))) {
                            m = new JMenuItem(
                                    Bundle.getBundle().getString("menuItem.removeFromLoadedDocuments"));
                            m.addActionListener(remove);
                            popup.add(m);
                        } else {
                            m = new JMenuItem(Bundle.getBundle().getString("menuItem.addToLoadedDocuments"));
                            m.addActionListener(loadFile);
                            popup.add(m);
                        }
                    }
                    popup.show(e.getComponent(), e.getX(), e.getY());
                }
            }
        }
    });

    jtExplorer.setCellRenderer(new TooltipTreeCellRenderer());
    ToolTipManager.sharedInstance().registerComponent(jtExplorer);

    FileListTreeCellRenderer renderer1 = new FileListTreeCellRenderer((MainWindow) this);
    jtOpenedDocuments.setCellRenderer(renderer1);
    ToolTipManager.sharedInstance().registerComponent(jtOpenedDocuments);
}