Merge pull request #2000 from aastrand/aastrand/password

Add TablesPanel filter for passworded games
This commit is contained in:
LevelX2 2016-06-17 13:44:23 +02:00 committed by GitHub
commit 469febfafd
3 changed files with 114 additions and 19 deletions

View file

@ -418,6 +418,40 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnFilterActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JToolBar$Separator" name="jSeparator5">
</Component>
<Component class="javax.swing.JToggleButton" name="btnOpen">
<Properties>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="Open"/>
<Property name="toolTipText" type="java.lang.String" value="Show open games"/>
<Property name="focusPainted" type="boolean" value="false"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="requestFocusEnabled" type="boolean" value="false"/>
<Property name="verifyInputWhenFocusTarget" type="boolean" value="false"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnFilterActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JToggleButton" name="btnPassword">
<Properties>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="PW"/>
<Property name="toolTipText" type="java.lang.String" value="Show passworded games"/>
<Property name="focusPainted" type="boolean" value="false"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="requestFocusEnabled" type="boolean" value="false"/>
<Property name="verifyInputWhenFocusTarget" type="boolean" value="false"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnFilterActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="btnQuickStart">

View file

@ -158,7 +158,7 @@ public class TablesPanel extends javax.swing.JPanel {
filterButtons = new JToggleButton[]{btnStateWaiting, btnStateActive, btnStateFinished,
btnTypeMatch, btnTypeTourneyConstructed, btnTypeTourneyLimited,
btnFormatBlock, btnFormatStandard, btnFormatModern, btnFormatLegacy, btnFormatVintage, btnFormatCommander, btnFormatTinyLeader, btnFormatLimited, btnFormatOther,
btnSkillBeginner, btnSkillCasual, btnSkillSerious, btnRated, btnUnrated};
btnSkillBeginner, btnSkillCasual, btnSkillSerious, btnRated, btnUnrated, btnOpen, btnPassword};
JComponent[] components = new JComponent[]{chatPanelMain, jSplitPane1, jScrollPaneTablesActive, jScrollPaneTablesFinished, jPanelTop, jPanelTables};
for (JComponent component : components) {
@ -626,8 +626,18 @@ public class TablesPanel extends javax.swing.JPanel {
ratingFilterList.add(RowFilter.regexFilter("^Unrated", TableTableModel.COLUMN_RATING));
}
// Password
List<RowFilter<Object, Object>> passwordFilterList = new ArrayList<>();
if (btnOpen.isSelected()) {
passwordFilterList.add(RowFilter.regexFilter("^$", TableTableModel.COLUMN_PASSWORD));
}
if (btnPassword.isSelected()) {
passwordFilterList.add(RowFilter.regexFilter("^\\*\\*\\*$", TableTableModel.COLUMN_PASSWORD));
}
if (stateFilterList.isEmpty() || typeFilterList.isEmpty() || formatFilterList.isEmpty()
|| skillFilterList.isEmpty() || ratingFilterList.isEmpty()) { // no selection
|| skillFilterList.isEmpty() || ratingFilterList.isEmpty()
|| passwordFilterList.isEmpty()) { // no selection
activeTablesSorter.setRowFilter(RowFilter.regexFilter("Nothing", TableTableModel.COLUMN_SKILL));
} else {
List<RowFilter<Object, Object>> filterList = new ArrayList<>();
@ -662,6 +672,12 @@ public class TablesPanel extends javax.swing.JPanel {
filterList.addAll(ratingFilterList);
}
if (passwordFilterList.size() > 1) {
filterList.add(RowFilter.orFilter(passwordFilterList));
} else if (passwordFilterList.size() == 1) {
filterList.addAll(passwordFilterList);
}
if (filterList.size() == 1) {
activeTablesSorter.setRowFilter(filterList.get(0));
} else {
@ -710,6 +726,9 @@ public class TablesPanel extends javax.swing.JPanel {
jSeparator2 = new javax.swing.JToolBar.Separator();
btnFormatLimited = new javax.swing.JToggleButton();
btnFormatOther = new javax.swing.JToggleButton();
jSeparator5 = new javax.swing.JToolBar.Separator();
btnOpen = new javax.swing.JToggleButton();
btnPassword = new javax.swing.JToggleButton();
btnQuickStart = new javax.swing.JButton();
jSplitPane1 = new javax.swing.JSplitPane();
jPanelTables = new javax.swing.JPanel();
@ -1079,6 +1098,39 @@ public class TablesPanel extends javax.swing.JPanel {
}
});
filterBar2.add(btnFormatOther);
filterBar2.add(jSeparator5);
btnOpen.setSelected(true);
btnOpen.setText("Open");
btnOpen.setToolTipText("Show open games");
btnOpen.setFocusPainted(false);
btnOpen.setFocusable(false);
btnOpen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
btnOpen.setRequestFocusEnabled(false);
btnOpen.setVerifyInputWhenFocusTarget(false);
btnOpen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
btnOpen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnFilterActionPerformed(evt);
}
});
filterBar2.add(btnOpen);
btnPassword.setSelected(true);
btnPassword.setText("PW");
btnPassword.setToolTipText("Show passworded games");
btnPassword.setFocusPainted(false);
btnPassword.setFocusable(false);
btnPassword.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
btnPassword.setRequestFocusEnabled(false);
btnPassword.setVerifyInputWhenFocusTarget(false);
btnPassword.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
btnPassword.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnFilterActionPerformed(evt);
}
});
filterBar2.add(btnPassword);
btnQuickStart.setText("Quick Start");
btnQuickStart.setFocusable(false);
@ -1290,6 +1342,8 @@ public class TablesPanel extends javax.swing.JPanel {
private javax.swing.JToggleButton btnFormatVintage;
private javax.swing.JButton btnNewTable;
private javax.swing.JButton btnNewTournament;
private javax.swing.JToggleButton btnOpen;
private javax.swing.JToggleButton btnPassword;
private javax.swing.JButton btnQuickStart;
private javax.swing.JToggleButton btnSkillBeginner;
private javax.swing.JToggleButton btnSkillCasual;
@ -1337,12 +1391,14 @@ class TableTableModel extends AbstractTableModel {
public static final int COLUMN_GAME_TYPE = 3;
public static final int COLUMN_INFO = 4;
public static final int COLUMN_STATUS = 5;
public static final int COLUMN_SKILL = 7;
public static final int COLUMN_RATING = 8;
public static final int COLUMN_QUIT_RATIO = 9;
public static final int ACTION_COLUMN = 10; // column the action is located (starting with 0)
public static final int COLUMN_PASSWORD = 6;
public static final int COLUMN_CREATED = 7;
public static final int COLUMN_SKILL = 8;
public static final int COLUMN_RATING = 9;
public static final int COLUMN_QUIT_RATIO = 10;
public static final int ACTION_COLUMN = 11; // column the action is located (starting with 0)
private final String[] columnNames = new String[]{"M/T", "Deck Type", "Owner / Players", "Game Type", "Info", "Status", "Created / Started", "Skill Level", "Rating", "Quit %", "Action"};
private final String[] columnNames = new String[]{"M/T", "Deck Type", "Owner / Players", "Game Type", "Info", "Status", "Password", "Created / Started", "Skill Level", "Rating", "Quit %", "Action"};
private TableView[] tables = new TableView[0];
private static final DateFormat timeFormatter = new SimpleDateFormat("HH:mm:ss");
@ -1385,14 +1441,16 @@ class TableTableModel extends AbstractTableModel {
case 5:
return tables[arg0].getTableStateText();
case 6:
return timeFormatter.format(tables[arg0].getCreateTime());
return tables[arg0].isPassworded() ? "***" : "";
case 7:
return tables[arg0].getSkillLevel();
return timeFormatter.format(tables[arg0].getCreateTime());
case 8:
return tables[arg0].isRated() ? "Rated" : "Unrated";
return tables[arg0].getSkillLevel();
case 9:
return tables[arg0].getQuitRatio();
return tables[arg0].isRated() ? "Rated" : "Unrated";
case 10:
return tables[arg0].getQuitRatio();
case 11:
switch (tables[arg0].getTableState()) {
case WAITING:
@ -1419,14 +1477,14 @@ class TableTableModel extends AbstractTableModel {
default:
return "";
}
case 11:
return tables[arg0].isTournament();
case 12:
return tables[arg0].isTournament();
case 13:
if (!tables[arg0].getGames().isEmpty()) {
return tables[arg0].getGames().get(0);
}
return null;
case 13:
case 14:
return tables[arg0].getTableId();
}
return "";

View file

@ -65,6 +65,7 @@ public class TableView implements Serializable {
private final String quitRatio;
private final boolean limited;
private final boolean rated;
private final boolean passworded;
public TableView(Table table) {
this.tableId = table.getId();
@ -94,8 +95,7 @@ public class TableView implements Serializable {
if (!table.isTournament()) {
// MATCH
if (table.getState().equals(TableState.WAITING) || table.getState().equals(TableState.READY_TO_START)) {
tableStateText = table.getState().toString() + " (" + table.getMatch().getPlayers().size() + "/"+ table.getSeats().length + ")" +
(table.getMatch().getOptions().getPassword().isEmpty() ? "":" PW");
tableStateText = table.getState().toString() + " (" + table.getMatch().getPlayers().size() + "/"+ table.getSeats().length + ")";
} else {
tableStateText = table.getState().toString();
}
@ -136,6 +136,7 @@ public class TableView implements Serializable {
this.quitRatio = Integer.toString(table.getMatch().getOptions().getQuitRatio());
this.limited = table.getMatch().getOptions().isLimited();
this.rated = table.getMatch().getOptions().isRated();
this.passworded = !table.getMatch().getOptions().getPassword().isEmpty();
} else {
// TOURNAMENT
if (table.getTournament().getOptions().getNumberRounds() > 0) {
@ -155,9 +156,6 @@ public class TableView implements Serializable {
switch (table.getState()) {
case WAITING:
stateText.append(" (").append(table.getTournament().getPlayers().size()).append("/").append(table.getNumberOfSeats()).append(")");
if (!table.getTournament().getOptions().getPassword().isEmpty()) {
stateText.append(" PW");
}
case READY_TO_START:
case STARTING:
infoText.append(" Time: ").append(table.getTournament().getOptions().getMatchOptions().getMatchTimeLimit().toString());
@ -185,6 +183,7 @@ public class TableView implements Serializable {
this.quitRatio = Integer.toString(table.getTournament().getOptions().getQuitRatio());
this.limited = table.getTournament().getOptions().getMatchOptions().isLimited();
this.rated = table.getTournament().getOptions().getMatchOptions().isRated();
this.passworded = !table.getTournament().getOptions().getPassword().isEmpty();
}
}
@ -250,4 +249,8 @@ public class TableView implements Serializable {
public boolean isRated() {
return rated;
}
public boolean isPassworded() {
return passworded;
}
}