List of usage examples for javax.swing SwingUtilities isRightMouseButton
public static boolean isRightMouseButton(MouseEvent anEvent)
From source file:com.ivli.roim.controls.ChartControl.java
@Override public void mouseReleased(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e) && (iMarker instanceof DomainMarker || iSeries instanceof XYSeries)) { JPopupMenu mnu = new JPopupMenu( java.util.ResourceBundle.getBundle("com/ivli/roim/Bundle").getString("MNU_MARKER_OPERATIONS")); if (iSeries instanceof XYSeries) { mnu.add(MENUS.ADD.makeItem(this)); mnu.add(MENUS.EXPORT_CSV.makeItem(this)); mnu.add(MENUS.DELETE_ALL.makeItem(this)); } else if (iMarker instanceof DomainMarker) { JMenu mi1 = new JMenu(MENUS.MOVE_TO_MIN.iText); mi1.add(MENUS.MOVE_TO_MIN.makeItem(this)); // mi1.add(MENUS.MOVE_TO_MIN_LEFT.makeItem(this)); // mi1.add(MENUS.MOVE_TO_MIN_RIGHT.makeItem(this)); mnu.add(mi1);// www .jav a 2s. co m JMenu mi2 = new JMenu(MENUS.MOVE_TO_MAX.iText); mi2.add(MENUS.MOVE_TO_MAX.makeItem(this)); // mi2.add(MENUS.MOVE_TO_MAX_LEFT.makeItem(this)); // mi2.add(MENUS.MOVE_TO_MAX_RIGHT.makeItem(this)); mnu.add(mi2); mnu.add(MENUS.MOVE_TO_MEDIAN.makeItem(this)); //if(!getDomainMarkersForSeries()){ JMenu mi3 = new JMenu( java.util.ResourceBundle.getBundle("com/ivli/roim/Bundle").getString("MARKER_COMMAND.FIT")); mi3.add(MENUS.FIT_LEFT.makeItem(this)); mi3.add(MENUS.FIT_RIGHT.makeItem(this)); mnu.add(mi3); //} mnu.add(MENUS.DELETE.makeItem(this)); } mnu.show(this, e.getX(), e.getY()); } else { super.mouseReleased(e); dropSelection(); } }
From source file:apidemo.PanScrollZoomDemo.java
/** * Handles a mouse pressed event (to start panning). * //from ww w . ja v a2 s. c o m * @param event the event. */ public void mousePressed(final MouseEvent event) { try { if (this.panButton.isSelected() || this.panButton.isEnabled() && SwingUtilities.isRightMouseButton(event)) { // final Rectangle2D dataArea = this.chartPanel.getScaledDataArea(); // final Point2D point = event.getPoint(); // if (dataArea.contains(point)) { // setPanMode(true); // this.panStartPoint = point; // } } } catch (Exception e) { e.printStackTrace(); } }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java
/** * Callback method for receiving notification of a mouse click on a chart. * * @param event information about the event. * * @return Did we handle this event/* w w w.j a v a 2 s . c o m*/ */ public boolean chartPanelMousePressed(MouseEvent event) { if (SwingUtilities.isRightMouseButton(event)) { closestAnnotation = findClosestAnnotation(getAllAnnotations(), event.getX(), event.getY(), false, false); } return EVENT_PASSON; }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java
/** * Callback method for receiving notification of a mouse click on a chart. * * @param event information about the event. * * @return Did we handle this event/* www .j a v a 2 s . com*/ */ public boolean chartPanelMouseClicked(MouseEvent event) { if (SwingUtilities.isRightMouseButton(event)) { closestAnnotation = findClosestAnnotation(getAllAnnotations(), event.getX(), event.getY(), false, false); return EVENT_PASSON; } if (event.getClickCount() <= 1) { ChartAnnotation annotation = findClosestAnnotation(getAllAnnotations(), event.getX(), event.getY(), true, event.isShiftDown()); if (annotation == null) { return false; } signalChartChanged(); return EVENT_DONTPASSON; } try { if (isOnBottomDomainAxis(event)) { WayPoint waypoint = new WayPoint(getDomainValue(event.getX()), this); waypoint.addPropertyChangeListener(this); if (!waypoint.showProperties(chartPanel, event.getX(), event.getY())) { return EVENT_DONTPASSON; } wayPoints.add(waypoint); setSelectedAnnotation(waypoint, wayPoints, event.isShiftDown()); setLocationPositions(); plot.addAnnotation(waypoint); } else if (isOnLeftRangeAxis(event)) { // System.err.println("new x/y:" + event.getX() +"/" +event.getY()); RangeFilter rangeFilter = new RangeFilter(getRangeValue(event.getY()), this); if (!rangeFilter.showProperties(chartPanel, event.getX(), event.getY())) { return EVENT_DONTPASSON; } rangeFilters.add(rangeFilter); setSelectedAnnotation(rangeFilter, rangeFilters, event.isShiftDown()); plot.addAnnotation(rangeFilter); if (true || event.isShiftDown()) { RangeFilter attached = rangeFilter.doMakeAttached(event); rangeFilters.add(attached); plot.addAnnotation(attached); } rangeFiltersChanged(); } else { return EVENT_PASSON; } } catch (Exception exc) { LogUtil.logException("Error creating wayPoints", exc); } return EVENT_DONTPASSON; }
From source file:cl.almejo.vsim.gui.SimWindow.java
@Override public void mouseClicked(MouseEvent event) { if (SwingUtilities.isRightMouseButton(event)) { _toolHelper.rightClicked(this, event); return;//from w w w .j a v a 2 s . c o m } if (event.getClickCount() >= 2) { _toolHelper.mouseDoubleClicked(this, event); return; } _toolHelper.mouseClicked(this, event); }
From source file:com.diversityarrays.kdxplore.trials.TrialOverviewPanel.java
public TrialOverviewPanel(String title, OfflineData offdata, TrialExplorerManager manager, FileListTransferHandler flth, MessagePrinter mp, final Closure<List<Trial>> onTrialSelected) { super(new BorderLayout()); offlineData = offdata;//w w w . j a va2 s. c o m KdxploreDatabase kdxdb = offlineData.getKdxploreDatabase(); if (kdxdb != null) { kdxdb.addEntityChangeListener(trialChangeListener); kdxdb.addEntityChangeListener(traitChangeListener); } this.messagePrinter = mp; TableTransferHandler tth = TableTransferHandler.initialiseForCopySelectAll(trialsTable, true); trialsTable.setTransferHandler(new ChainingTransferHandler(flth, tth)); trialsTable.setAutoCreateRowSorter(true); trialsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { List<Trial> selectedTrials = getSelectedTrials(); if (selectedTrials.size() == 1) { trialTraitsTableModel.setSelectedTrial(selectedTrials.get(0)); } else { trialTraitsTableModel.setSelectedTrial(null); } onTrialSelected.execute(selectedTrials); } } }); trialsTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) { fireEditCommand(e); } } }); GuiUtil.setVisibleRowCount(trialsTable, MAX_INITIAL_VISIBLE_TRIAL_ROWS); offlineData.addOfflineDataChangeListener(offlineDataChangeListener); trialTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { updateRefreshAction(); } }); trialTraitsTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { updateAddTraitAction(); updateRemoveTraitAction(); updateScoringOrderAction(); } }); trialTraitsTable.addMouseListener(new MouseAdapter() { List<Trait> selectedTraits; JPopupMenu popupMenu; Action showTraitsAction = new AbstractAction("Select in Trait Explorer") { @Override public void actionPerformed(ActionEvent e) { manager.showTraitsInTraitExplorer(selectedTraits); } }; @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e) && 2 == e.getClickCount()) { // Start editing the Trait e.consume(); int vrow = trialTraitsTable.rowAtPoint(e.getPoint()); if (vrow >= 0) { int mrow = trialTraitsTable.convertRowIndexToModel(vrow); if (mrow >= 0) { Trait trait = trialTraitsTableModel.getTraitAt(mrow); if (trait != null) { traitExplorer.startEditing(trait); ; } } } } else if (SwingUtilities.isRightMouseButton(e) && 1 == e.getClickCount()) { // Select the traits in the traitExplorer e.consume(); List<Integer> modelRows = GuiUtil.getSelectedModelRows(trialTraitsTable); if (!modelRows.isEmpty()) { selectedTraits = modelRows.stream().map(trialTraitsTableModel::getTraitAt) .collect(Collectors.toList()); if (popupMenu == null) { popupMenu = new JPopupMenu(); popupMenu.add(showTraitsAction); } Point pt = e.getPoint(); popupMenu.show(trialTraitsTable, pt.x, pt.y); } } } }); trialTraitsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { updateRemoveTraitAction(); } } }); updateAddTraitAction(); updateRemoveTraitAction(); updateScoringOrderAction(); updateRefreshAction(); KDClientUtils.initAction(ImageId.REFRESH_24, refreshTrialTraitsAction, "Refresh"); KDClientUtils.initAction(ImageId.MINUS_GOLD_24, removeTraitAction, "Remove selected Traits"); KDClientUtils.initAction(ImageId.PLUS_BLUE_24, addTraitAction, "Add Traits to Trial"); KDClientUtils.initAction(ImageId.TRAIT_ORDER_24, setScoringOrderAction, "Define Trait Scoring Order"); Box buttons = Box.createHorizontalBox(); buttons.add(new JButton(setScoringOrderAction)); buttons.add(Box.createHorizontalGlue()); buttons.add(new JButton(addTraitAction)); buttons.add(new JButton(removeTraitAction)); buttons.add(Box.createHorizontalStrut(10)); buttons.add(refreshTrialTraitsButton); JPanel traitsPanel = new JPanel(new BorderLayout()); traitsPanel.add(GuiUtil.createLabelSeparator("Uses Traits", buttons), BorderLayout.NORTH); traitsPanel.add(new PromptScrollPane(trialTraitsTable, "If the (single) selected Trial has Traits they will appear here"), BorderLayout.CENTER); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(trialsTable), traitsPanel); splitPane.setResizeWeight(0.5); add(splitPane, BorderLayout.CENTER); }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
public void mousePressed(MouseEvent event) { try {/*w w w . j av a 2 s . c o m*/ if (chartPanButton.isSelected() || chartPanButton.isEnabled() && SwingUtilities.isRightMouseButton(event)) { Rectangle2D dataArea = this.chartPanel.getScaledDataArea(); Point2D point = event.getPoint(); if (dataArea.contains(point)) { setPanMode(true); panStartPoint = point; } } } catch (Exception e) { MsgBox.error(e.getMessage()); } }
From source file:com.diversityarrays.kdxplore.curate.fieldview.FieldLayoutViewPanel.java
@SuppressWarnings("unchecked") public FieldLayoutViewPanel(@SuppressWarnings("rawtypes") MutableComboBoxModel comboBoxModel, JCheckBox alwaysOnTopOption, CurationData cd, CurationTableModel ctm, SelectedValueStore svs, PlotCellChoicesPanel pccp, JPopupMenu popuMenu, Font fontForResizeControls, Action curationHelpAction, MessagePrinter mp, Closure<String> selectionClosure, CurationContext curationContext, CurationMenuProvider curationMenuProvider, FieldLayoutTableModel fieldLayoutTableModel, CellSelectableTable fieldLayoutTable, FieldViewSelectionModel fvsm,// w w w. j a va 2 s .c o m JButton undockButton) { super(new BorderLayout()); this.traitInstanceCombo.setModel(comboBoxModel); this.curationData = cd; this.messagePrinter = mp; this.selectionClosure = selectionClosure; this.curationTableModel = ctm; this.fieldLayoutTableModel = fieldLayoutTableModel; this.fieldLayoutTable = fieldLayoutTable; this.fieldViewSelectionModel = fvsm; traitInstanceCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object item = comboBoxModel.getSelectedItem(); if (item instanceof TraitInstance) { TraitInstance ti = (TraitInstance) item; plotCellRenderer.setActiveInstance(ti); } } }); rhtm = new RowHeaderTableModel(true, fieldLayoutTable, rowRemovable) { public String getRowLabel(int rowIndex) { int yCoord = FieldLayoutUtil.convertRowIndexToYCoord(rowIndex, trial, fieldLayoutTableModel.getFieldLayout()); return String.valueOf(yCoord); } }; rowHeaderTable = new RowHeaderTable(SwingConstants.CENTER, false, fieldLayoutTable, rowRemovable, rhtm, RowHeaderTable.createDefaultColumnModel("X/Y")) { public String getMarkerIndexName(int viewRow) { return "MIN-" + viewRow; //$NON-NLS-1$ } }; rhtTableRowResizer = new TableRowResizer(rowHeaderTable, true); curationData.addCurationDataChangeListener(plotActivationListener); curationTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { fieldLayoutTable.repaint(); } }); plotCellRenderer = new PlotCellRenderer(plotAttributeProvider, curationTableModel); TraitInstanceCellRenderer tiCellRenderer = new TraitInstanceCellRenderer( curationData.getTraitColorProvider(), instanceNameProvider); traitInstanceCombo.setRenderer(tiCellRenderer); traitInstanceCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateActiveTraitInstance(); } }); traitInstanceCombo.getModel().addListDataListener(new ListDataListener() { @Override public void intervalRemoved(ListDataEvent e) { updateActiveTraitInstance(); } @Override public void intervalAdded(ListDataEvent e) { updateActiveTraitInstance(); } @Override public void contentsChanged(ListDataEvent e) { updateActiveTraitInstance(); } }); this.trial = curationData.getTrial(); this.plotCellChoicesPanel = pccp; for (TraitInstance t : curationData.getTraitInstances()) { String id = InstanceIdentifierUtil.getInstanceIdentifier(t); traitById.put(id, t); } // fieldViewSelectionModel = new FieldViewSelectionModel( // fieldLayoutTable, // fieldLayoutTableModel, // svs); fieldLayoutTable.setSelectionModel(fieldViewSelectionModel); plotCellRenderer.setCurationData(curationData); plotCellRenderer.setSelectionModel(fieldViewSelectionModel); plotCellChoicesPanel.addPlotCellChoicesListener(plotCellChoicesListener); fieldLayoutTableModel.setTrial(trial); // IMPORTANT: DO NOT SORT THE FIELD LAYOUT TABLE fieldLayoutTable.setAutoCreateRowSorter(false); JScrollPane fieldTableScrollPane = new JScrollPane(fieldLayoutTable); if (undockButton != null) { fieldTableScrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, undockButton); } fieldTableScrollPane.setRowHeaderView(rowHeaderTable); ChangeListener scrollBarChangeListener = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { fireRefreshRequired(); } }; fieldTableScrollPane.getVerticalScrollBar().getModel().addChangeListener(scrollBarChangeListener); fieldTableScrollPane.getHorizontalScrollBar().getModel().addChangeListener(scrollBarChangeListener); fieldLayoutTable.setRowHeaderTable(rowHeaderTable); // fieldLayoutTable.setComponentPopupMenu(popuMenu); initFieldLayoutTable(); Map<Integer, Plot> plotById = new HashMap<>(); FieldLayout<Integer> plotIdLayout = FieldLayoutUtil.createPlotIdLayout(trial.getTrialLayout(), trial.getPlotIdentSummary(), curationData.getPlots(), plotById); KdxploreFieldLayout<Plot> kdxFieldLayout = new KdxploreFieldLayout<Plot>(Plot.class, plotIdLayout.imageId, plotIdLayout.xsize, plotIdLayout.ysize); kdxFieldLayout.warning = plotIdLayout.warning; for (int y = 0; y < plotIdLayout.ysize; ++y) { for (int x = 0; x < plotIdLayout.xsize; ++x) { Integer id = plotIdLayout.cells[y][x]; if (id != null) { Plot plot = plotById.get(id); kdxFieldLayout.store_xy(plot, x, y); } } } fieldLayoutTableModel.setFieldLayout(kdxFieldLayout); if (kdxFieldLayout.warning != null && !kdxFieldLayout.warning.isEmpty()) { warningMessage.setText(kdxFieldLayout.warning); } else { warningMessage.setText(""); //$NON-NLS-1$ } changeVisitOrderAction.putValue(Action.SMALL_ICON, KDClientUtils.getIcon(kdxFieldLayout.imageId)); List<Component> components = new ArrayList<>(); components.add(alwaysOnTopOption); Collections.addAll(components, new JButton(changeVisitOrderAction), new JButton(curationHelpAction), traitInstanceCombo); Box resizeControls = KDClientUtils.createResizeControls(fieldLayoutTable, fontForResizeControls, components.toArray(new Component[components.size()])); resizeCombo = KDClientUtils.findResizeCombo(resizeControls); if (RunMode.getRunMode().isDeveloper()) { new FieldLayoutViewPanel.DebugSettings(resizeControls, messagePrinter); } JPanel fieldPanel = new JPanel(new BorderLayout()); // if (useSeparator) { // SeparatorPanel separator = GuiUtil.createLabelSeparator("Field Layout:", resizeControls); // fieldPanel.add(separator, BorderLayout.NORTH); // fieldPanel.add(fieldTableScrollPane, BorderLayout.CENTER); // } // else { fieldPanel.add(resizeControls, BorderLayout.NORTH); fieldPanel.add(fieldTableScrollPane, BorderLayout.CENTER); // } // splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, // plotCellChoicesPanel, // fieldPanel); // splitPane.setResizeWeight(0.0); // splitPane.setOneTouchExpandable(true); add(warningMessage, BorderLayout.NORTH); add(fieldPanel, BorderLayout.CENTER); // splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, // plotCellChoicesPanel, // fieldPanel); // splitPane.setResizeWeight(0.0); // splitPane.setOneTouchExpandable(true); // // add(warningMessage, BorderLayout.NORTH); // add(splitPane, BorderLayout.CENTER); fieldLayoutTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { if (SwingUtilities.isRightMouseButton(me) && 1 == me.getClickCount()) { me.consume(); List<Plot> plots = getSelectedPlots(); List<TraitInstance> checkedInstances = new ArrayList<>(); for (int index = traitInstanceCombo.getItemCount(); --index >= 1;) { Object item = traitInstanceCombo.getItemAt(index); if (item instanceof TraitInstance) { checkedInstances.add((TraitInstance) item); } } TraitInstance ti = fieldViewSelectionModel.getActiveTraitInstance(true); List<PlotOrSpecimen> plotSpecimens = new ArrayList<>(); plotSpecimens.addAll(plots); curationMenuProvider.showFieldViewToolMenu(me, plotSpecimens, ti, checkedInstances); } } }); }
From source file:com.josue.tileset.editor.Editor.java
private void mountButtons(List<Tile> tiles, int cols, int rows) { imagePanel.removeAll();//from ww w . ja v a 2s.com if (animatedPerformer != null) { animatedPerformer.stop(); animatedPerformer = null; } imagePanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); Dimension dimension = new Dimension(cols * TILE_SIZE, rows * TILE_SIZE); for (Tile tile : tiles) { final JLabel tileLabel = new JLabel(); tileLabel.setIcon(new ImageIcon(tile.getImage())); Dimension labelDimension = new Dimension(TILE_SIZE, TILE_SIZE); tileLabel.setMinimumSize(labelDimension); tileLabel.setMaximumSize(labelDimension); tileLabel.setPreferredSize(labelDimension); tileLabel.setSize(labelDimension); tileLabel.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseClicked(java.awt.event.MouseEvent evt) { if (SwingUtilities.isRightMouseButton(evt)) {//select animated sequence if (animatedAction.isSelected()) { addAnimatedTile(tile); } else { addLightSourceTile(tile); } } else { if (animatedPerformer != null) { animatedPerformer.stop(); } Iterator<JLabel> iterator = tileLabels.values().iterator(); while (iterator.hasNext()) { JLabel next = iterator.next(); next.revalidate(); } imagePanel.repaint(); for (Map.Entry<Tile, JLabel> entry : tileLabels.entrySet()) { Tile key = entry.getKey(); JLabel value = entry.getValue(); value.setBorder(null); //clear borders } selectedTile = tile;//this isolate for the next operations tileLabel.setBorder(new LineBorder(Color.RED, 2)); previewLabel.setIcon(new ImageIcon(tile.getImage())); animatedTb.setSelected(selectedTile.isAnimated()); lightTb.setSelected(selectedTile.isLight()); solidTb.setSelected(selectedTile.isSolid()); if (tile.isAnimated()) { for (Integer animatesTileOffset : selectedTile.getAnimation().getAnimatedSequence()) { //display animated borders for (Map.Entry<Tile, JLabel> entry : tileLabels.entrySet()) { Tile key = entry.getKey(); JLabel value = entry.getValue(); if (key.getId() == selectedTile.getId() + animatesTileOffset) { value.setBorder(new LineBorder(Color.BLUE, 2)); } } } animatedPerformer = new Timer( (int) (selectedTile.getAnimation().getAnimationInterval()), new TileAnimator(selectedTile, previewLabel, loadedTiles)); animatedPerformer.start(); } if (selectedTile.isLight()) {//light color has preference for (Tile tile : tiles) { if (tile.getId() == selectedTile.getLightTileId()) { JLabel found = tileLabels.get(tile); found.setBorder(new LineBorder(Color.YELLOW, 2)); break; } } } } } @Override public void mouseExited(MouseEvent e) { if (selectedTile != null && selectedTile.getAnimation() != null && selectedTile.getAnimation() .getAnimatedSequence().contains(tile.getId() - selectedTile.getId())) { tileLabel.setBorder(new LineBorder(Color.BLUE, 2)); } else if (selectedTile != null && selectedTile.isLight() && selectedTile.getLightTileId() == tile.getId()) { tileLabel.setBorder(new LineBorder(Color.YELLOW, 2)); } else if (selectedTile != null) { JLabel get = tileLabels.get(selectedTile); if (!get.equals(tileLabel)) { //keep the red border if is the selected tileLabel.setBorder(null); } } else { tileLabel.setBorder(null); } } @Override public void mouseEntered(MouseEvent e) { if (selectedTile != null && selectedTile.getAnimation() != null && !selectedTile.getAnimation().getAnimatedSequence() .contains(tile.getId() - selectedTile.getId()) && tile.getLight() != null && tile.getLight().getLightTileOffset() != 0) { tileLabel.setBorder(new LineBorder(Color.RED, 2)); } else if (selectedTile == null) { tileLabel.setBorder(new LineBorder(Color.RED, 2)); } } }); tileLabels.put(tile, tileLabel); imagePanel.add(tileLabel); } imagePanel.setMaximumSize(dimension); imagePanel.setMinimumSize(dimension); imagePanel.setPreferredSize(dimension); imagePanel.revalidate(); imagePanel.repaint(); this.pack(); }
From source file:com.diversityarrays.kdxplore.trials.TrialViewPanel.java
public TrialViewPanel(WindowOpener<JFrame> windowOpener, OfflineData od, Transformer<Trial, Boolean> checkIfEditorActive, Consumer<Trial> onTraitInstancesRemoved, MessagePrinter mp) {// w w w . ja va2 s. c o m super(new BorderLayout()); this.windowOpener = windowOpener; this.checkIfEditorActive = checkIfEditorActive; this.onTraitInstancesRemoved = onTraitInstancesRemoved; this.messagePrinter = mp; this.offlineData = od; this.offlineData.addOfflineDataChangeListener(offlineDataChangeListener); KdxploreDatabase db = offlineData.getKdxploreDatabase(); if (db != null) { db.addEntityChangeListener(trialChangeListener); } trialDataTable.setTransferHandler(TableTransferHandler.initialiseForCopySelectAll(trialDataTable, true)); trialPropertiesTable .setTransferHandler(TableTransferHandler.initialiseForCopySelectAll(trialPropertiesTable, true)); // Note: Can't use renderers because the TM always returns String.class // for getColumnClass() // trialPropertiesTable.setDefaultRenderer(TrialLayout.class, new // TrialLayoutRenderer(trialPropertiesTableModel)); // trialPropertiesTable.setDefaultRenderer(PlotIdentOption.class, new // PlotIdentOptionRenderer(trialPropertiesTableModel)); trialPropertiesTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if (trialPropertiesTableModel.getRowCount() > 0) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { GuiUtil.initialiseTableColumnWidths(trialPropertiesTable); } }); trialPropertiesTableModel.removeTableModelListener(this); } } }); // int tnsColumnIndex = -1; // for (int col = trialPropertiesTableModel.getColumnCount(); --col >= 0; ) { // if (TraitNameStyle.class == trialPropertiesTableModel.getColumnClass(col)) { // tnsColumnIndex = col; // break; // } // } editAction.setEnabled(false); trialPropertiesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int vrow = trialPropertiesTable.getSelectedRow(); editAction.setEnabled(vrow >= 0 && trialPropertiesTableModel.isCellEditable(vrow, 1)); } } }); errorMessage.setForeground(Color.RED); Box top = Box.createHorizontalBox(); top.add(errorMessage); top.add(Box.createHorizontalGlue()); top.add(new JButton(editAction)); JPanel main = new JPanel(new BorderLayout()); main.add(new JScrollPane(trialPropertiesTable), BorderLayout.CENTER); main.add(legendPanel, BorderLayout.SOUTH); JScrollPane trialDataTableScrollPane = new JScrollPane(trialDataTable); // The preferred height of the viewport is determined // by whether or not we need to use hh:mm:ss in the name of any of // the scoring data sets. JViewport viewPort = new JViewport() { @Override public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); d.height = 32; TableModel model = trialDataTable.getModel(); if (model instanceof TrialData) { if (((TrialData) model).isUsingHMSformat()) { d.height = 48; } } return d; } }; trialDataTableScrollPane.setColumnHeader(viewPort); JTableHeader th = trialDataTable.getTableHeader(); th.setDefaultRenderer(trialDataTableHeaderRenderer); th.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int column = th.columnAtPoint(e.getPoint()); trialDataTableHeaderRenderer.columnSelected = column; boolean shifted = 0 != (MouseEvent.SHIFT_MASK & e.getModifiers()); boolean right = SwingUtilities.isRightMouseButton(e); updateDeleteSamplesAction(shifted, right); e.consume(); } }); trialDataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { removeTraitInstancesAction.setEnabled(trialDataTable.getSelectedRowCount() > 0); } } }); removeTraitInstancesAction.setEnabled(false); KDClientUtils.initAction(ImageId.PLUS_BLUE_24, addSampleGroupAction, Msg.TOOLTIP_ADD_SAMPLES_FOR_SCORING()); KDClientUtils.initAction(ImageId.TRASH_24, deleteSamplesAction, Msg.TOOLTIP_DELETE_COLLECTED_SAMPLES()); KDClientUtils.initAction(ImageId.EXPORT_24, exportSamplesAction, Msg.TOOLTIP_EXPORT_SAMPLES_OR_TRAITS()); KDClientUtils.initAction(ImageId.MINUS_GOLD_24, removeTraitInstancesAction, Msg.TOOLTIP_REMOVE_TRAIT_INSTANCES_WITH_NO_DATA()); JPanel trialDataPanel = new JPanel(new BorderLayout()); Box buttons = Box.createHorizontalBox(); buttons.add(new JButton(removeTraitInstancesAction)); buttons.add(Box.createHorizontalGlue()); buttons.add(new JButton(exportSamplesAction)); buttons.add(Box.createHorizontalGlue()); buttons.add(new JButton(addSampleGroupAction)); buttons.add(Box.createHorizontalStrut(8)); buttons.add(new JButton(deleteSamplesAction)); trialDataPanel.add(GuiUtil.createLabelSeparator("Measurements by Source", buttons), BorderLayout.NORTH); trialDataPanel.add(trialDataTableScrollPane, BorderLayout.CENTER); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, main, trialDataPanel); splitPane.setResizeWeight(0.5); add(top, BorderLayout.NORTH); add(splitPane, BorderLayout.CENTER); trialDataTable.setDefaultRenderer(Object.class, new TrialDataCellRenderer()); trialDataTable.addPropertyChangeListener("model", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { trialDataTableHeaderRenderer.columnSelected = -1; updateDeleteSamplesAction(false, false); } }); }