Reset table selection when clicked on empty space
This commit is contained in:
parent
65b824adcb
commit
0852a9cf02
@ -449,6 +449,7 @@ public class SimulationPanel extends JPanel {
|
|||||||
simulationTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
simulationTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
||||||
simulationTable.setDefaultRenderer(Object.class, new JLabelRenderer());
|
simulationTable.setDefaultRenderer(Object.class, new JLabelRenderer());
|
||||||
simulationTableModel.setColumnWidths(simulationTable.getColumnModel());
|
simulationTableModel.setColumnWidths(simulationTable.getColumnModel());
|
||||||
|
simulationTable.setFillsViewportHeight(true);
|
||||||
|
|
||||||
pm = new JPopupMenu();
|
pm = new JPopupMenu();
|
||||||
pm.add(new EditSimulationAction());
|
pm.add(new EditSimulationAction());
|
||||||
@ -465,19 +466,33 @@ public class SimulationPanel extends JPanel {
|
|||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
int selectedRow = simulationTable.getSelectedRow();
|
int selectedRow = simulationTable.getSelectedRow();
|
||||||
|
|
||||||
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
|
if (e.getButton() == MouseEvent.BUTTON1) {
|
||||||
int selected = simulationTable.convertRowIndexToModel(selectedRow);
|
// Clear the table selection when clicked outside the table rows.
|
||||||
|
if (e.getClickCount() == 1) {
|
||||||
|
int row = simulationTable.rowAtPoint(e.getPoint());
|
||||||
|
int column = simulationTable.columnAtPoint(e.getPoint());
|
||||||
|
|
||||||
int column = simulationTable.columnAtPoint(e.getPoint());
|
if (row == -1 || column == -1) {
|
||||||
if (column == 0) {
|
simulationTable.clearSelection();
|
||||||
SimulationWarningDialog.showWarningDialog(SimulationPanel.this, document.getSimulations().get(selected));
|
}
|
||||||
} else {
|
|
||||||
simulationTable.clearSelection();
|
|
||||||
simulationTable.addRowSelectionInterval(selectedRow, selectedRow);
|
|
||||||
|
|
||||||
openDialog(document.getSimulations().get(selected));
|
|
||||||
}
|
}
|
||||||
} else if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) {
|
// Edit the simulation or plot/export
|
||||||
|
else if (e.getClickCount() == 2) {
|
||||||
|
int selected = simulationTable.convertRowIndexToModel(selectedRow);
|
||||||
|
|
||||||
|
int column = simulationTable.columnAtPoint(e.getPoint());
|
||||||
|
if (column == 0) {
|
||||||
|
SimulationWarningDialog.showWarningDialog(SimulationPanel.this, document.getSimulations().get(selected));
|
||||||
|
} else {
|
||||||
|
simulationTable.clearSelection();
|
||||||
|
simulationTable.addRowSelectionInterval(selectedRow, selectedRow);
|
||||||
|
|
||||||
|
openDialog(document.getSimulations().get(selected));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Show context menu
|
||||||
|
else if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 1) {
|
||||||
// Get the row that the right-click action happened on
|
// Get the row that the right-click action happened on
|
||||||
int r = simulationTable.rowAtPoint(e.getPoint());
|
int r = simulationTable.rowAtPoint(e.getPoint());
|
||||||
|
|
||||||
@ -762,7 +777,8 @@ public class SimulationPanel extends JPanel {
|
|||||||
|
|
||||||
private void openDialog(final Simulation sim) {
|
private void openDialog(final Simulation sim) {
|
||||||
boolean plotMode = false;
|
boolean plotMode = false;
|
||||||
if (sim.hasSimulationData() && (sim.getStatus() == Status.UPTODATE || sim.getStatus() == Status.EXTERNAL)) {
|
if (sim.hasSimulationData() && (sim.getStatus() == Status.UPTODATE || sim.getStatus() == Status.LOADED
|
||||||
|
|| sim.getStatus() == Status.EXTERNAL)) {
|
||||||
plotMode = true;
|
plotMode = true;
|
||||||
}
|
}
|
||||||
openDialog(plotMode, sim);
|
openDialog(plotMode, sim);
|
||||||
|
@ -3,6 +3,8 @@ package net.sf.openrocket.gui.main.flightconfigpanel;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -87,6 +89,7 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
|||||||
*/
|
*/
|
||||||
private final JTable doTableInitialization() {
|
private final JTable doTableInitialization() {
|
||||||
JTable table = this.initializeTable();
|
JTable table = this.initializeTable();
|
||||||
|
table.setFillsViewportHeight(true);
|
||||||
FlightConfigurationId current = this.rocket.getSelectedConfiguration().getFlightConfigurationID();
|
FlightConfigurationId current = this.rocket.getSelectedConfiguration().getFlightConfigurationID();
|
||||||
int col = (table.getColumnCount() > 1) ? table.getColumnCount() - 1 : 0;
|
int col = (table.getColumnCount() > 1) ? table.getColumnCount() - 1 : 0;
|
||||||
for (int row = 0; row < table.getRowCount(); row++) {
|
for (int row = 0; row < table.getRowCount(); row++) {
|
||||||
@ -163,6 +166,20 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Clear the table selection when clicked outside the table rows.
|
||||||
|
table.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 1) {
|
||||||
|
int row = table.rowAtPoint(e.getPoint());
|
||||||
|
int col = table.columnAtPoint(e.getPoint());
|
||||||
|
if (row == -1 || col == -1) {
|
||||||
|
table.clearSelection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user