MapWithAIProvidersPanel: Avoid setting final static field to final field

Signed-off-by: Taylor Smock <tsmock@fb.com>
pull/1/head
Taylor Smock 2021-07-20 10:33:58 -06:00
rodzic b00a35b953
commit 0aaa1b6ba7
1 zmienionych plików z 18 dodań i 20 usunięć

Wyświetl plik

@ -106,11 +106,9 @@ public class MapWithAIProvidersPanel extends JPanel {
// Public models // Public models
/** The model of active providers **/ /** The model of active providers **/
private static final MapWithAILayerTableModel ACTIVE_MODEL = new MapWithAILayerTableModel(); public static final MapWithAILayerTableModel ACTIVE_MODEL = new MapWithAILayerTableModel();
public final MapWithAILayerTableModel activeModel = ACTIVE_MODEL;
/** The model of default providers **/ /** The model of default providers **/
private static final MapWithAIDefaultLayerTableModel DEFAULT_MODEL = new MapWithAIDefaultLayerTableModel(); public static final MapWithAIDefaultLayerTableModel DEFAULT_MODEL = new MapWithAIDefaultLayerTableModel();
public final MapWithAIDefaultLayerTableModel defaultModel = DEFAULT_MODEL;
// Public JToolbars // Public JToolbars
/** The toolbar on the right of active providers **/ /** The toolbar on the right of active providers **/
@ -308,7 +306,7 @@ public class MapWithAIProvidersPanel extends JPanel {
this.options = options; this.options = options;
boolean showActive = Stream.of(options).anyMatch(Options.SHOW_ACTIVE::equals); boolean showActive = Stream.of(options).anyMatch(Options.SHOW_ACTIVE::equals);
activeTable = new JTable(activeModel) { activeTable = new JTable(ACTIVE_MODEL) {
private static final long serialVersionUID = -6136421378119093719L; private static final long serialVersionUID = -6136421378119093719L;
@ -316,7 +314,7 @@ public class MapWithAIProvidersPanel extends JPanel {
public String getToolTipText(MouseEvent e) { public String getToolTipText(MouseEvent e) {
java.awt.Point p = e.getPoint(); java.awt.Point p = e.getPoint();
try { try {
return activeModel.getValueAt(rowAtPoint(p), columnAtPoint(p)).toString(); return ACTIVE_MODEL.getValueAt(rowAtPoint(p), columnAtPoint(p)).toString();
} catch (ArrayIndexOutOfBoundsException ex) { } catch (ArrayIndexOutOfBoundsException ex) {
Logging.debug(ex); Logging.debug(ex);
return null; return null;
@ -325,12 +323,12 @@ public class MapWithAIProvidersPanel extends JPanel {
}; };
activeTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); activeTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
defaultTable = new JTable(defaultModel); defaultTable = new JTable(DEFAULT_MODEL);
defaultTable.setAutoCreateRowSorter(true); defaultTable.setAutoCreateRowSorter(true);
defaultFilter = new FilterField().filter(defaultTable, defaultModel); defaultFilter = new FilterField().filter(defaultTable, DEFAULT_MODEL);
defaultModel.addTableModelListener(e -> activeTable.repaint()); DEFAULT_MODEL.addTableModelListener(e -> activeTable.repaint());
activeModel.addTableModelListener(e -> defaultTable.repaint()); ACTIVE_MODEL.addTableModelListener(e -> defaultTable.repaint());
setupDefaultTable(defaultTable, options, areaListeners); setupDefaultTable(defaultTable, options, areaListeners);
@ -660,13 +658,13 @@ public class MapWithAIProvidersPanel extends JPanel {
final ESRISourceReader reader = new ESRISourceReader(info); final ESRISourceReader reader = new ESRISourceReader(info);
try { try {
for (MapWithAIInfo i : reader.parse()) { for (MapWithAIInfo i : reader.parse()) {
activeModel.addRow(i); ACTIVE_MODEL.addRow(i);
} }
} catch (IOException e) { } catch (IOException e) {
Logging.error(e); Logging.error(e);
} }
} else { } else {
activeModel.addRow(info); ACTIVE_MODEL.addRow(info);
} }
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
if (ex.getMessage() == null || ex.getMessage().isEmpty()) { if (ex.getMessage() == null || ex.getMessage().isEmpty()) {
@ -743,7 +741,7 @@ public class MapWithAIProvidersPanel extends JPanel {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Integer i; Integer i;
while ((i = activeTable.getSelectedRow()) != -1) { while ((i = activeTable.getSelectedRow()) != -1) {
activeModel.removeRow(i); ACTIVE_MODEL.removeRow(i);
} }
} }
} }
@ -805,19 +803,19 @@ public class MapWithAIProvidersPanel extends JPanel {
.collect(Collectors.toList()); .collect(Collectors.toList());
activeTable.getSelectionModel().clearSelection(); activeTable.getSelectionModel().clearSelection();
for (MapWithAIInfo info : toAdd) { for (MapWithAIInfo info : toAdd) {
activeModel.addRow(new MapWithAIInfo(info)); ACTIVE_MODEL.addRow(new MapWithAIInfo(info));
int lastLine = activeModel.getRowCount() - 1; int lastLine = ACTIVE_MODEL.getRowCount() - 1;
activeTable.getSelectionModel().setSelectionInterval(lastLine, lastLine); activeTable.getSelectionModel().setSelectionInterval(lastLine, lastLine);
activeTable.scrollRectToVisible(activeTable.getCellRect(lastLine, 0, true)); activeTable.scrollRectToVisible(activeTable.getCellRect(lastLine, 0, true));
} }
selected.removeIf(toAdd::contains); selected.removeIf(toAdd::contains);
selected.stream().mapToInt(activeModel::getRowIndex).filter(i -> i >= 0).forEach(j -> { selected.stream().mapToInt(ACTIVE_MODEL::getRowIndex).filter(i -> i >= 0).forEach(j -> {
activeTable.getSelectionModel().addSelectionInterval(j, j); activeTable.getSelectionModel().addSelectionInterval(j, j);
activeTable.scrollRectToVisible(activeTable.getCellRect(j, 0, true)); activeTable.scrollRectToVisible(activeTable.getCellRect(j, 0, true));
}); });
} else { } else {
selected.stream().mapToInt(activeModel::getRowIndex).filter(i -> i >= 0).boxed() selected.stream().mapToInt(ACTIVE_MODEL::getRowIndex).filter(i -> i >= 0).boxed()
.sorted(Collections.reverseOrder()).forEach(activeModel::removeRow); .sorted(Collections.reverseOrder()).forEach(ACTIVE_MODEL::removeRow);
} }
updateEnabledState(); updateEnabledState();
if (Stream.of(options).noneMatch(Options.SHOW_ACTIVE::equals)) { if (Stream.of(options).noneMatch(Options.SHOW_ACTIVE::equals)) {
@ -846,11 +844,11 @@ public class MapWithAIProvidersPanel extends JPanel {
@Override @Override
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
MapWithAILayerInfo.getInstance().loadDefaults(true, MainApplication.worker, false, () -> { MapWithAILayerInfo.getInstance().loadDefaults(true, MainApplication.worker, false, () -> {
GuiHelper.runInEDT(defaultModel::fireTableDataChanged); GuiHelper.runInEDT(DEFAULT_MODEL::fireTableDataChanged);
GuiHelper.runInEDT(defaultTable.getSelectionModel()::clearSelection); GuiHelper.runInEDT(defaultTable.getSelectionModel()::clearSelection);
GuiHelper.runInEDT(defaultTableListener::clearMap); GuiHelper.runInEDT(defaultTableListener::clearMap);
/* loading new file may change active layers */ /* loading new file may change active layers */
GuiHelper.runInEDT(activeModel::fireTableDataChanged); GuiHelper.runInEDT(ACTIVE_MODEL::fireTableDataChanged);
}); });
} }
} }