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:io.heming.accountbook.ui.MainFrame.java

private void initToolBar() {
    toolbar = new JToolBar("ToolBar", JToolBar.HORIZONTAL);

    // Add Button
    addButton = new JButton();
    addButton.setActionCommand("");
    addButton.setToolTipText("");
    addButton.setIcon(new ImageIcon(getClass().getResource("edit-add-3.png")));

    // Search date range radio buttons
    ButtonGroup group = new ButtonGroup();
    yearToggleButton = new JToggleButton();
    yearToggleButton.setToolTipText("");
    yearToggleButton.setIcon(new ImageIcon(getClass().getResource("year-s.png")));
    group.add(yearToggleButton);//w  w  w . j a  v a  2 s. c  om
    monthToggleButton = new JToggleButton();
    monthToggleButton.setToolTipText("");
    monthToggleButton.setIcon(new ImageIcon(getClass().getResource("month-s.png")));
    group.add(monthToggleButton);
    dayToggleButton = new JToggleButton();
    dayToggleButton.setToolTipText("");
    dayToggleButton.setIcon(new ImageIcon(getClass().getResource("day-s.png")));
    group.add(dayToggleButton);
    customToggleButton = new JToggleButton();
    customToggleButton.setToolTipText("");
    customToggleButton.setIcon(new ImageIcon(getClass().getResource("all-s.png")));
    group.add(customToggleButton);

    // ??Checkbox
    monthToggleButton.setSelected(true);

    Calendar earliestCalendar = Calendar.getInstance();
    earliestCalendar.add(Calendar.YEAR, -100);
    java.util.Date earliestDate = earliestCalendar.getTime();

    Calendar latestCalendar = Calendar.getInstance();
    latestCalendar.add(Calendar.YEAR, 100);
    java.util.Date latestDate = latestCalendar.getTime();
    // 3?
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MONTH, -1);
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    java.util.Date initDate = calendar.getTime();

    SpinnerDateModel startDateModel = new SpinnerDateModel(DateUtil.getStartOfWeek(), earliestDate, latestDate,
            Calendar.MONTH);
    startDateSpinner = new JSpinner(startDateModel);
    JSpinner.DateEditor startDateEditor = new JSpinner.DateEditor(startDateSpinner, "yyyy-MM-dd");
    startDateSpinner.setEditor(startDateEditor);

    calendar.add(Calendar.MONTH, 1);
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    initDate = calendar.getTime();
    SpinnerDateModel endDateModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.MONTH);
    endDateSpinner = new JSpinner(endDateModel);
    JSpinner.DateEditor endDateEditor = new JSpinner.DateEditor(endDateSpinner, "yyyy-MM-dd");
    endDateSpinner.setEditor(endDateEditor);

    // Keyword text field
    keywordTextField = new JTextField();
    keywordTextField.setPreferredSize(new Dimension(250, 20));
    keywordTextField.setMaximumSize(keywordTextField.getPreferredSize());

    // Search Button
    searchButton = new JButton();
    searchButton.setActionCommand("?");
    searchButton.setToolTipText("?");
    searchButton.setIcon(new ImageIcon(getClass().getResource("edit-find-5.png")));

    // Layout
    cards = new JPanel();
    cards.setLayout(new CardLayout());
    Box box = Box.createHorizontalBox();
    box.add(Box.createHorizontalGlue());

    startDateSpinner.setPreferredSize(new Dimension(90, 20));
    startDateSpinner.setMaximumSize(startDateSpinner.getPreferredSize());
    box.add(startDateSpinner);

    box.add(Box.createHorizontalStrut(6));

    endDateSpinner.setPreferredSize(new Dimension(90, 20));
    endDateSpinner.setMaximumSize(endDateSpinner.getPreferredSize());
    box.add(endDateSpinner);

    cards.add(new JPanel(), HIDE_DATE_CHOOSER);
    cards.add(box, SHOW_DATE_CHOOSER);

    Box dateRangeBox = Box.createHorizontalBox();
    dateRangeBox.add(Box.createHorizontalGlue());
    dateRangeBox.add(cards);

    toolbar.add(addButton);
    toolbar.add(dateRangeBox);
    toolbar.add(customToggleButton);
    toolbar.add(yearToggleButton);
    toolbar.add(monthToggleButton);
    toolbar.add(dayToggleButton);
    toolbar.add(keywordTextField);
    toolbar.add(searchButton);

    add(toolbar, BorderLayout.NORTH);

    // Event listener
    addButton.addActionListener(e -> showAddRecordDialog());

    ActionListener listener = e -> searchRecords();
    yearToggleButton.addActionListener(listener);
    monthToggleButton.addActionListener(listener);
    dayToggleButton.addActionListener(listener);
    customToggleButton.addActionListener(listener);
    keywordTextField.addActionListener(listener);
    searchButton.addActionListener(listener);

    customToggleButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                chooseDateRange();
            }
        }
    });
}

From source file:com.vgi.mafscaling.LogView.java

private void createGraghPanel() {
    JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false,
            true, false);/*from   w  w w .  ja v a2  s  .com*/
    chartPanel = new ChartPanel(chart, true, true, true, true, true);
    chartPanel.setAutoscrolls(true);
    chartPanel.setPopupMenu(null);
    chart.setBackgroundPaint(new Color(60, 60, 65));

    rpmDataset = new XYSeriesCollection();
    rpmPlotRenderer = new XYLineAndShapeRenderer();
    dataset = new XYSeriesCollection();
    plotRenderer = new XYLineAndShapeRenderer();

    NumberAxis xAxis = new NumberAxis();
    xAxis.setTickLabelsVisible(false);
    xAxis.setTickLabelPaint(Color.WHITE);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickLabelPaint(Color.WHITE);
    yAxis.setAutoRangeIncludesZero(false);
    NumberAxis y2Axis = new NumberAxis();
    y2Axis.setTickLabelsVisible(false);
    y2Axis.setTickLabelPaint(Color.WHITE);
    y2Axis.setAutoRangeIncludesZero(false);

    plot = chartPanel.getChart().getXYPlot();
    plot.setRangePannable(true);
    plot.setDomainPannable(true);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setBackgroundPaint(new Color(80, 80, 85));

    plot.setDataset(0, rpmDataset);
    plot.setRenderer(0, rpmPlotRenderer);
    plot.setDomainAxis(0, xAxis);
    plot.setRangeAxis(0, yAxis);
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);

    plot.setDataset(1, dataset);
    plot.setRenderer(1, plotRenderer);
    plot.setRangeAxis(1, y2Axis);
    plot.mapDatasetToDomainAxis(1, 0);
    plot.mapDatasetToRangeAxis(1, 1);

    LegendTitle legend = new LegendTitle(plot);
    legend.setItemFont(new Font("Arial", 0, 10));
    legend.setPosition(RectangleEdge.TOP);
    legend.setItemPaint(Color.WHITE);
    chart.addLegend(legend);

    xyMarker = new XYDomainMutilineAnnotation();
    plot.addAnnotation(xyMarker);

    chartMouseListener = new ChartMouseListener() {
        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            try {
                Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
                Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
                double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge());
                boolean isLeft = (p.getX() < (dataArea.getMaxX() - dataArea.getMinX()) / 2) ? true : false;
                if (setMarkers(x, isLeft)) {
                    try {
                        int selectedCol = logDataTable.getTable().getSelectedColumn();
                        if (selectedCol < 0)
                            selectedCol = 0;
                        if (logPlayWindow == null || startMarker != null || endMarker != null) {
                            logDataTable.getTable().setRowSelectionInterval((int) x, (int) x);
                            logDataTable.getTable().changeSelection((int) x, selectedCol, false, false);
                        } else {
                            logPlayWindow.setProgressBar((int) x);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            if (logPlayWindow == null)
                return;
            if (xyMarker.count() == 0)
                return;
            Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
            Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
            double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge());
            if (x < 0 || (int) x >= logDataTable.getRowCount())
                return;
            if (SwingUtilities.isLeftMouseButton(event.getTrigger())) {
                if (startMarker == null) {
                    startMarker = new ValueMarker(x);
                    startMarker.setPaint(Color.GREEN);
                    startMarker.setStroke(new BasicStroke(1.5f));
                    plot.addDomainMarker(startMarker);
                } else {
                    plot.removeDomainMarker(startMarker);
                    startMarker = null;
                }
            } else if (SwingUtilities.isRightMouseButton(event.getTrigger())) {
                if (endMarker == null) {
                    endMarker = new ValueMarker(x);
                    endMarker.setPaint(Color.GREEN);
                    endMarker.setStroke(new BasicStroke(1.5f));
                    plot.addDomainMarker(endMarker);
                } else {
                    plot.removeDomainMarker(endMarker);
                    endMarker = null;
                }
            }
            chartPanel.repaint();
            logPlayWindow.setStartEndArea(startMarker, endMarker);
        }
    };

    chartPanel.addChartMouseListener(chartMouseListener);
}

From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java

/**
 * Handle event in chart//  w ww . j a v  a2 s  .  co  m
 *
 * @param event The event
 *
 * @return Did we handle this event
 */
public boolean chartPanelMouseReleased(MouseEvent event) {

    if (SwingUtilities.isRightMouseButton(event)) {
        return EVENT_PASSON;
    }
    closestAnnotation = null;

    dragging = false;
    if (draggedAnnotation != null) {
        if ((draggedAnnotation instanceof WayPoint) || (draggedAnnotation instanceof TrackSegment)) {
            firePropertyChange(PROP_TIMERANGE, null, segments);
        }
        if (getDriveTime() && (animationWidget != null)) {
            if (draggedAnnotation instanceof WayPoint) {
                lastTimeWeDrove = System.currentTimeMillis();
                double value = ((WayPoint) draggedAnnotation).getDomainValue();
                animationWidget.setTimeFromUser(new Real(RealType.Time, value / 1000));
            }
        }
    }
    draggedAnnotation = null;
    if (isOnAxis(event) && SwingUtilities.isRightMouseButton(event)) {
        return EVENT_DONTPASSON;
    }

    return EVENT_PASSON;
}

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

private JComponent createTokenTreePanel() {
    final JTree tree = new JTree();
    tokenPanelTreeModel = new TokenPanelTreeModel(tree);
    tree.setModel(tokenPanelTreeModel);/*w  ww .j  av  a2 s  . c  om*/
    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:com.diversityarrays.kdxplore.curate.TrialDataEditor.java

public TrialDataEditor(CurationData cd, WindowOpener<JFrame> windowOpener, MessageLogger messageLogger,
        KdxploreDatabase kdxdb, IntFunction<Trait> traitProvider, SampleType[] sampleTypes) throws IOException {
    super(new BorderLayout());

    this.traitProvider = traitProvider;
    this.windowOpener = windowOpener;

    this.curationData = cd;
    this.curationData.setChangeManager(changeManager);
    this.curationData.setKDSmartDatabase(kdxdb.getKDXploreKSmartDatabase());

    inactiveTagFilterIcon = KDClientUtils.getIcon(ImageId.TAG_FILTER_24);
    activeTagFilterIcon = KDClientUtils.getIcon(ImageId.TAG_FILTER_ACTIVE_24);

    inactivePlotOrSpecimenFilterIcon = KDClientUtils.getIcon(ImageId.FILTER_PLOT_SPEC_INACTIVE);
    activePlotFilterIcon = KDClientUtils.getIcon(ImageId.FILTER_PLOT_ACTIVE);
    activeSpecimenFilterIcon = KDClientUtils.getIcon(ImageId.FILTER_SPEC_ACTIVE);

    updatePlotSpecimenIcon();// ww  w  .j a va 2  s  .co  m

    TraitColorProvider traitColourProvider = new TraitColorProvider(false);
    this.curationData.setTraitColorProvider(traitColourProvider);

    curationData.addCurationDataChangeListener(new CurationDataChangeListener() {
        @Override
        public void plotActivationChanged(Object source, boolean activated, List<Plot> plots) {
            updateRowFilter();
            if (toolController != null) {
                toolController.plotActivationsChanged(activated, plots);
            }
        }

        @Override
        public void editedSamplesChanged(Object source, List<CurationCellId> curationCellIds) {
            if (toolController != null) {
                toolController.editedSamplesChanged();
            }
        }
    });

    this.selectedValueStore = new SelectedValueStore(curationData.getTrial().getTrialName());

    this.messageLogger = messageLogger;

    smallFont = KDClientUtils.makeSmallFont(this);

    // undockViewAction.putValue(Action.SHORT_DESCRIPTION, "Click to undock
    // this view");

    KDClientUtils.initAction(ImageId.HELP_24, curationHelpAction, Msg.TOOLTIP_HELP_DATA_CURATION(), false);

    KDClientUtils.initAction(ImageId.SAVE_24, saveChangesAction, Msg.TOOLTIP_SAVE_CHANGES(), true);
    KDClientUtils.initAction(ImageId.EXPORT_24, exportCuratedData, Msg.TOOLTIP_EXPORT(), true);

    KDClientUtils.initAction(ImageId.UNDO_24, undoAction, Msg.TOOLTIP_UNDO(), true);
    KDClientUtils.initAction(ImageId.REDO_24, redoAction, Msg.TOOLTIP_REDO(), true);

    KDClientUtils.initAction(ImageId.FIELD_VIEW_24, showFieldViewAction, Msg.TOOLTIP_FIELD_VIEW(), false);

    KDClientUtils.initAction(ImageId.GET_TRIALINFO_24, importCuratedData, Msg.TOOLTIP_IMPORT_DATA(), true);

    Function<TraitInstance, List<KdxSample>> sampleProvider = new Function<TraitInstance, List<KdxSample>>() {
        @Override
        public List<KdxSample> apply(TraitInstance ti) {
            return curationData.getSampleMeasurements(ti);
        }
    };
    tivrByTi = VisToolUtil.buildTraitInstanceValueRetrieverMap(curationData.getTrial(),
            curationData.getTraitInstances(), sampleProvider);

    // = = = = = = = =

    boolean readOnly = false;
    // FIXME work out if the Trial can be edited or not
    curationTableModel = new CurationTableModel(curationData, readOnly);
    // See FIXME comment in CurationTableModel.isReadOnly()

    curationTableSelectionModel = new CurationTableSelectionModelImpl(selectedValueStore, curationTableModel);

    curationTableSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    curationTable = new CurationTable("CurationTable-" + (++UNIQUE_CURATION_TABLE_ID), //$NON-NLS-1$
            curationTableModel, curationTableSelectionModel);
    curationTable.setCellSelectionEnabled(true);
    curationTable.setAutoCreateRowSorter(true);

    // = = = = = = = =
    this.sampleSourcesTablePanel = new SampleSourcesTablePanel(curationData, curationTableModel, handler);

    @SuppressWarnings("unchecked")
    TableRowSorter<CurationTableModel> rowSorter = (TableRowSorter<CurationTableModel>) curationTable
            .getRowSorter();
    rowSorter.setSortsOnUpdates(true);
    rowSorter.addRowSorterListener(rowSorterListener);

    curationCellRenderer = new CurationTableCellRenderer(curationTableModel, colorProviderFactory,
            curationTableSelectionModel);

    curationTable.setDefaultRenderer(Object.class, curationCellRenderer);
    curationTable.setDefaultRenderer(Integer.class, curationCellRenderer);
    curationTable.setDefaultRenderer(String.class, curationCellRenderer);
    curationTable.setDefaultRenderer(CurationCellValue.class, curationCellRenderer);
    curationTable.setDefaultRenderer(Double.class, curationCellRenderer);
    curationTable.setDefaultRenderer(TraitValue.class, curationCellRenderer);

    // If either the rows selected change or the columns selected change
    // then we
    // need to inform the visualisation tools.
    curationTable.getSelectionModel().addListSelectionListener(curationTableCellSelectionListener);
    curationTable.getColumnModel().addColumnModelListener(curationTableCellSelectionListener);

    fieldLayoutView = new InterceptFieldLayoutView();

    this.curationCellEditor = new CurationCellEditorImpl(curationTableModel, fieldLayoutView, curationData,
            refreshFieldLayoutView, kdxdb, traitProvider, sampleTypes);

    SuppressionInfoProvider suppressionInfoProvider = new SuppressionInfoProvider(curationData,
            curationTableModel, curationTable);

    suppressionHandler = new SuppressionHandler(curationContext, curationData, curationCellEditor,
            suppressionInfoProvider);

    loadVisualisationTools();

    curationMenuProvider = new CurationMenuProvider(curationContext, curationData, messages, visualisationTools,
            suppressionHandler);

    curationMenuProvider.setSuppressionInfoProvider(suppressionInfoProvider);

    fieldLayoutView.addTraitInstanceSelectionListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (ItemEvent.SELECTED == e.getStateChange()) {
                TraitInstance traitInstance = fieldLayoutView.getActiveTraitInstance(true);
                if (traitInstance == null) {
                    curationCellEditor.setCurationCellValue(null);
                } else {
                    // startEdit(HowStarted.FIELD_VIEW_CHANGED_ACTIVE_TRAIT_INSTANCE);
                }
                fieldLayoutView.updateSamplesSelectedInTable();
            }
        }
    });

    // = = = = = = =

    curationData.addUnsavedChangesListener(new UnsavedChangesListener() {
        @Override
        public void unsavedChangesExist(Object source, int nChanges) {
            int unsavedCount = curationData.getUnsavedChangesCount();
            saveChangesAction.setEnabled(unsavedCount > 0);

            if (unsavedCount > 0) {
                statusInfoLine.setMessage("Unsaved changes: " + unsavedCount);
            } else {
                statusInfoLine.setMessage("No Unsaved changes");
            }
        }
    });

    // curationData.addEditedSampleChangeListener(new ChangeListener() {
    // @Override
    // public void stateChanged(ChangeEvent e) {
    // handleEditedSampleChanges();
    // }
    // });
    saveChangesAction.setEnabled(false);
    changeManager.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            updateUndoRedoActions();
        }
    });
    undoAction.setEnabled(false);
    redoAction.setEnabled(false);

    // = = = = = = = =

    // TODO provide one of these for each relevant device type
    DeviceType deviceTypeForSamples = null;

    StatsData statsData = curationData.getStatsData(deviceTypeForSamples);

    TIStatsTableModel statsTableModel = new TIStatsTableModel2(curationData, statsData, deviceTypeForSamples);

    traitColourProvider.generateColorMap(statsData.getTraitInstancesWithData());

    Set<Integer> instanceNumbers = statsData.getInstanceNumbers();
    String nonHtmlLabel;
    if (instanceNumbers.size() > 1) {
        tAndIpanelLabel = "<HTML><i>Plot Info</i> &amp; Trait Instances";
        nonHtmlLabel = "Plot Info & Trait Instances";
    } else {
        tAndIpanelLabel = "<HTML><i>Plot Info</i> &amp; Traits";
        nonHtmlLabel = "Plot Info & Traits";
    }

    traitsAndInstancesPanel = new TraitsAndInstancesPanel2(curationContext, smallFont, statsTableModel,
            instanceNumbers.size() > 1, statsData.getInvalidRuleCount(), nonHtmlLabel, curationMenuProvider,
            outlierConsumer);

    traitsAndInstancesPanel.addTraitInstanceStatsItemListener(new ItemListener() {
        boolean busy;

        @Override
        public void itemStateChanged(ItemEvent e) {
            // NOTE: we want to process both SELECTED and DESELECTED
            // variants
            if (busy) {
                Shared.Log.d(TAG, "***** LOOPED in traitsAndInstancesPanel.ItemListener"); //$NON-NLS-1$
            } else {
                Shared.Log.d(TAG, "traitsAndInstancesPanel.ItemListener BEGIN"); //$NON-NLS-1$
                busy = true;
                try {
                    updateViewedTraitInstances(e); // !!!!!
                } finally {
                    busy = false;
                    Shared.Log.d(TAG, "traitsAndInstancesPanel.ItemListener END\n"); //$NON-NLS-1$
                }
            }
        }
    });

    // = = = = = = = =

    plotCellChoicesPanel = new PlotCellChoicesPanel(curationContext, curationData, deviceTypeForSamples,
            tAndIpanelLabel, curationMenuProvider, colorProviderFactory);

    // plotCellChoicesPanel.setData(
    // curationData.getPlotAttributes(),
    // traitsAndInstancesPanel.getTraitInstancesWithData());

    plotCellChoicesPanel.addPlotCellChoicesListener(new PlotCellChoicesListener() {
        @Override
        public void traitInstanceChoicesChanged(Object source, boolean choiceAdded, TraitInstance[] choice,
                Map<Integer, Set<TraitInstance>> traitInstancesByTraitId) {
            traitsAndInstancesPanel.changeTraitInstanceChoice(choiceAdded, choice);
        }

        @Override
        public void plotAttributeChoicesChanged(Object source, List<ValueRetriever<?>> vrList) {
            curationTableModel.setSelectedPlotAttributes(vrList);
        }
    });

    // = = = = = = = =

    statsAndSamplesSplit = createStatsAndSamplesTable(traitsAndInstancesPanel.getComponent());

    mainTabbedPane.addTab(TAB_SAMPLES, samplesTableIcon, statsAndSamplesSplit, Msg.TOOLTIP_SAMPLES_TABLE());

    // = = = = = = = =

    checkForInvalidTraits();

    leftSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, createCurationCellEditorComponent(),
            plotCellChoicesPanel);
    leftSplit.setResizeWeight(0.5);
    // traitToDoTaskPaneContainer);

    // rightSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
    // traitsAndInstancesPanel, fieldViewAndPlots);
    // rightSplit.setResizeWeight(0.5);
    // rightSplit.setOneTouchExpandable(true);

    leftAndRightSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftSplit, mainTabbedPane);
    leftAndRightSplit.setOneTouchExpandable(true);

    mainVerticalSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, messages, leftAndRightSplit);
    mainVerticalSplit.setOneTouchExpandable(true);
    mainVerticalSplit.setResizeWeight(0.0);

    add(statusInfoLine, BorderLayout.NORTH);
    add(mainVerticalSplit, BorderLayout.CENTER);

    fieldLayoutView.addCellSelectionListener(fieldViewCellSelectionListener);

    curationTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent me) {
            if (SwingUtilities.isRightMouseButton(me) && 1 == me.getClickCount()) {
                me.consume();
                displayPopupMenu(me);
            }

        }
    });
}

From source file:net.rptools.maptool.client.ui.MapToolFrame.java

private JComponent createDrawTreePanel() {
    final JTree tree = new JTree();
    drawablesPanel = new DrawablesPanel();
    drawPanelTreeModel = new DrawPanelTreeModel(tree);
    tree.setModel(drawPanelTreeModel);//ww w.ja v  a2 s . c  om
    tree.setCellRenderer(new DrawPanelTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setContinuousLayout(true);

    splitPane.setTopComponent(new JScrollPane(tree));
    splitPane.setBottomComponent(drawablesPanel);
    splitPane.setDividerLocation(100);
    // Add mouse Event for right click menu
    tree.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            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) && !SwingUtil.isControlDown(e)) {
                    tree.clearSelection();
                }
                tree.addSelectionInterval(rowIndex, rowIndex);
                if (row instanceof DrawnElement) {
                    if (e.getClickCount() == 2) {
                        DrawnElement de = (DrawnElement) row;
                        getCurrentZoneRenderer()
                                .centerOn(new ZonePoint((int) de.getDrawable().getBounds().getCenterX(),
                                        (int) de.getDrawable().getBounds().getCenterY()));
                    }
                }

                int[] treeRows = tree.getSelectionRows();
                java.util.Arrays.sort(treeRows);
                drawablesPanel.clearSelectedIds();
                for (int i = 0; i < treeRows.length; i++) {
                    TreePath p = tree.getPathForRow(treeRows[i]);
                    if (p.getLastPathComponent() instanceof DrawnElement) {
                        DrawnElement de = (DrawnElement) p.getLastPathComponent();
                        drawablesPanel.addSelectedId(de.getDrawable().getId());
                    }
                }
            }
            if (SwingUtilities.isRightMouseButton(e)) {
                if (!isRowSelected(tree.getSelectionRows(), rowIndex) && !SwingUtil.isShiftDown(e)) {
                    tree.clearSelection();
                    tree.addSelectionInterval(rowIndex, rowIndex);
                    drawablesPanel.clearSelectedIds();
                }
                final int x = e.getX();
                final int y = e.getY();
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        DrawnElement firstElement = null;
                        Set<GUID> selectedDrawSet = new HashSet<GUID>();
                        for (TreePath path : tree.getSelectionPaths()) {
                            if (path.getLastPathComponent() instanceof DrawnElement) {
                                DrawnElement de = (DrawnElement) path.getLastPathComponent();
                                if (firstElement == null) {
                                    firstElement = de;
                                }
                                selectedDrawSet.add(de.getDrawable().getId());
                            }
                        }
                        if (!selectedDrawSet.isEmpty()) {
                            try {
                                new DrawPanelPopupMenu(selectedDrawSet, x, y, getCurrentZoneRenderer(),
                                        firstElement).showPopup(tree);
                            } catch (IllegalComponentStateException icse) {
                                log.info(tree.toString(), icse);
                            }
                        }
                    }
                });
            }
        }

    });
    // Add Zone Change event
    MapTool.getEventDispatcher().addListener(new AppEventListener() {
        public void handleAppEvent(AppEvent event) {
            drawPanelTreeModel.setZone((Zone) event.getNewValue());
        }
    }, MapTool.ZoneEvent.Activated);
    return splitPane;
}

From source file:io.heming.accountbook.ui.MainFrame.java

private void initTablePopupMenu() {
    JPopupMenu popupMenu = new JPopupMenu();

    JMenuItem deleteMenuItem = new JMenuItem("(D)",
            new ImageIcon(getClass().getResource("edit-delete-6.png")));
    deleteMenuItem.setMnemonic('D');
    popupMenu.add(deleteMenuItem);/*w w w  .j  a v a  2 s .  co m*/
    deleteMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            deleteRecord();
        }
    });

    popupMenu.addSeparator();

    JMenuItem editMenuItem = new JMenuItem("(E)", new ImageIcon(getClass().getResource("edit-4.png")));
    editMenuItem.setMnemonic('E');
    popupMenu.add(editMenuItem);
    editMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Record record = model.getRecord(table.convertRowIndexToModel(table.getSelectedRow()));
            showUpdateRecordDialog(record);
        }
    });

    // ??popup menu
    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (disable)
                return;
            JTable table = (JTable) e.getSource();
            Point point = e.getPoint();
            int row = table.rowAtPoint(point);
            int col = table.columnAtPoint(e.getPoint());
            if (SwingUtilities.isRightMouseButton(e)) {
                if (row >= 0 && col >= 0) {
                    table.setRowSelectionInterval(row, row);
                }
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            } else if (SwingUtilities.isLeftMouseButton(e)) {
                if (e.getClickCount() == 2) {
                    if (row >= 0 && col >= 0) {
                        //                            Record record = model.getRecord(table.convertRowIndexToModel(row));
                        //                            showUpdateRecordDialog(record);
                    }
                }
            }
        }

    });

    table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter");
    table.getActionMap().put("Enter", new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            if (disable)
                return;
            //do something on JTable enter pressed
            int row = table.getSelectedRow();
            if (row >= 0) {
                Record record = model.getRecord(table.convertRowIndexToModel(row));
                showUpdateRecordDialog(record);
            }
        }
    });

}

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

private AssetPanel createAssetPanel() {
    final AssetPanel panel = new AssetPanel("mainAssetPanel");
    panel.addImagePanelMouseListener(new MouseAdapter() {
        @Override/*from   ww  w. j av  a  2s  .co m*/
        public void mouseReleased(MouseEvent e) {
            // TODO use for real popup logic
            //            if (SwingUtilities.isLeftMouseButton(e)) {
            //               if (e.getClickCount() == 2) {
            //
            //                  List<Object> idList = panel.getSelectedIds();
            //                  if (idList == null || idList.size() == 0) {
            //                     return;
            //                  }
            //
            //                  final int index = (Integer) idList.get(0);
            //                  createZone(panel.getAsset(index));
            //               }
            //            }
            if (SwingUtilities.isRightMouseButton(e) && TabletopTool.getPlayer().isGM()) {
                List<Object> idList = panel.getSelectedIds();
                if (idList == null || idList.size() == 0) {
                    return;
                }
                final int index = (Integer) idList.get(0);

                JPopupMenu menu = new JPopupMenu();
                menu.add(new JMenuItem(new AbstractAction() {
                    {
                        putValue(NAME, I18N.getText("action.newMap"));
                    }

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        createZone(panel.getAsset(index));
                    }
                }));
                panel.showImagePanelPopup(menu, e.getX(), e.getY());
            }
        }

        private void createZone(Asset asset) {
            Zone zone = ZoneFactory.createZone();
            zone.setName(asset.getName());
            BufferedImage image = ImageManager.getImageAndWait(asset.getId());
            if (image.getWidth() < 200 || image.getHeight() < 200) {
                zone.setBackgroundPaint(new DrawableTexturePaint(asset));
            } else {
                zone.setMapAsset(asset.getId());
                zone.setBackgroundPaint(new DrawableColorPaint(Color.black));
            }
            MapPropertiesDialog newMapDialog = new MapPropertiesDialog(TabletopTool.getFrame());
            newMapDialog.setZone(zone);
            newMapDialog.setVisible(true);

            if (newMapDialog.getStatus() == MapPropertiesDialog.Status.OK) {
                TabletopTool.addZone(zone);
            }
        }
    });
    return panel;
}

From source file:net.rptools.maptool.client.ui.MapToolFrame.java

private JComponent createTokenTreePanel() {
    final JTree tree = new JTree();
    tokenPanelTreeModel = new TokenPanelTreeModel(tree);
    tree.setModel(tokenPanelTreeModel);/*from w  ww . ja v a  2  s .c  o 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) && !SwingUtil.isControlDown(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() {
                    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);
                            }
                        }
                    }
                });
            }
        }
    });
    MapTool.getEventDispatcher().addListener(new AppEventListener() {
        public void handleAppEvent(AppEvent event) {
            tokenPanelTreeModel.setZone((Zone) event.getNewValue());
        }
    }, MapTool.ZoneEvent.Activated);
    return tree;
}

From source file:com.SE.myPlayer.MusicPlayerGUI.java

private void songData_TableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_songData_TableMouseClicked
        try {/*from w ww. ja  va 2  s  . co  m*/
            if (evt.getClickCount() == 2 | next == 1 | previous == 1 && SwingUtilities.isLeftMouseButton(evt)) {
                currentSongRow = songData_Table.getSelectedRow();
                songLocation = songData[currentSongRow];
                sd.addToRecent(songLocation);
                for (ObjectBean list1 : list) {
                    list1.getMpg().addJmenuItemsToRecentSongs();
                }
                songPlay();
            } else if (SwingUtilities.isRightMouseButton(evt)) {
                Point point = evt.getPoint();
                int alreadySelectedRow = songData_Table.getSelectedRow();
                int currentRow = songData_Table.rowAtPoint(point);
                songData_Table.setRowSelectionInterval(alreadySelectedRow, currentRow);
                if (songData_Table.isRowSelected(currentRow)) {
                    songTable_PopUp.show(songData_Table, evt.getX(), evt.getY());
                } else {
                    songTable_PopUp.show(songTable_PopUp, evt.getX(), evt.getY());
                }
            }
        } catch (Exception e) {
            currentSongRow = songData_Table.getSelectedRow();
            songLocation = songData[currentSongRow];
            sd.addToRecent(songLocation);
            for (ObjectBean list1 : list) {
                list1.getMpg().addJmenuItemsToRecentSongs();
            }
            songPlay();
        }
        ;
    }