consolidate duplicate code into super class.

master
lodici 2017-02-04 17:06:12 +00:00
parent 297ed6c188
commit 141fcc7e1c
4 changed files with 6 additions and 16 deletions

View File

@ -10,7 +10,6 @@ import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelEvent;
import javax.swing.table.JTableHeader;
import magic.model.MagicCardDefinition; import magic.model.MagicCardDefinition;
import magic.ui.FontsAndBorders; import magic.ui.FontsAndBorders;
@ -33,10 +32,6 @@ public class CardTablePanelA extends CardsTablePanel {
// listener to change card image on selection // listener to change card image on selection
table.getSelectionModel().addListSelectionListener(getTableListSelectionListener()); table.getSelectionModel().addListSelectionListener(getTableListSelectionListener());
// listener to sort on column header click
final JTableHeader header = table.getTableHeader();
header.addMouseListener(new ColumnListener());
// add table to scroll pane // add table to scroll pane
scrollpane.setViewportView(table); scrollpane.setViewportView(table);
scrollpane.setBorder(FontsAndBorders.NO_BORDER); scrollpane.setBorder(FontsAndBorders.NO_BORDER);

View File

@ -12,7 +12,6 @@ import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelEvent;
import javax.swing.table.JTableHeader;
import magic.model.MagicCardDefinition; import magic.model.MagicCardDefinition;
import magic.model.MagicRandom; import magic.model.MagicRandom;
import magic.ui.FontsAndBorders; import magic.ui.FontsAndBorders;
@ -32,10 +31,6 @@ public class CardTablePanelB extends CardsTablePanel
// listener to change card image on selection // listener to change card image on selection
table.getSelectionModel().addListSelectionListener(this); table.getSelectionModel().addListSelectionListener(this);
// listener to sort on column header click
final JTableHeader header = table.getTableHeader();
header.addMouseListener(new ColumnListener());
// add table to scroll pane // add table to scroll pane
scrollpane.setViewportView(table); scrollpane.setViewportView(table);
scrollpane.setBorder(FontsAndBorders.NO_BORDER); scrollpane.setBorder(FontsAndBorders.NO_BORDER);

View File

@ -5,6 +5,7 @@ import java.awt.event.MouseEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelEvent;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel; import javax.swing.table.TableColumnModel;
import magic.data.GeneralConfig; import magic.data.GeneralConfig;
import magic.model.MagicCardDefinition; import magic.model.MagicCardDefinition;
@ -38,6 +39,10 @@ abstract class CardsTablePanel extends TexturedPanel {
table.addMouseMotionListener(getRowMouseOverListener()); table.addMouseMotionListener(getRowMouseOverListener());
} }
// listener to sort on column header click
final JTableHeader header = table.getTableHeader();
header.addMouseListener(new ColumnListener());
setLayout(migLayout); setLayout(migLayout);
refreshLayout(); refreshLayout();
} }
@ -84,7 +89,7 @@ abstract class CardsTablePanel extends TexturedPanel {
} }
} }
protected class ColumnListener extends MouseAdapter { private class ColumnListener extends MouseAdapter {
@Override @Override
public void mouseClicked(final MouseEvent e) { public void mouseClicked(final MouseEvent e) {
final TableColumnModel colModel = table.getColumnModel(); final TableColumnModel colModel = table.getColumnModel();

View File

@ -10,7 +10,6 @@ import javax.swing.SwingUtilities;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelEvent;
import javax.swing.table.JTableHeader;
import magic.model.MagicCardDefinition; import magic.model.MagicCardDefinition;
import magic.model.MagicDeck; import magic.model.MagicDeck;
import magic.ui.FontsAndBorders; import magic.ui.FontsAndBorders;
@ -35,10 +34,6 @@ public class DeckTablePanel extends CardsTablePanel {
this.listSelListener = getTableListSelectionListener(); this.listSelListener = getTableListSelectionListener();
table.getSelectionModel().addListSelectionListener(listSelListener); table.getSelectionModel().addListSelectionListener(listSelListener);
// listener to sort on column header click
final JTableHeader header = table.getTableHeader();
header.addMouseListener(new ColumnListener());
// add table to scroll pane // add table to scroll pane
scrollpane.setViewportView(table); scrollpane.setViewportView(table);
scrollpane.setBorder(FontsAndBorders.NO_BORDER); scrollpane.setBorder(FontsAndBorders.NO_BORDER);