Add username search field into console

This commit is contained in:
spjspj 2018-02-11 21:28:10 +11:00
parent ab964a47c5
commit ad19aa4854
2 changed files with 177 additions and 96 deletions

View file

@ -21,7 +21,7 @@
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jSplitPane1" alignment="1" max="32767" attributes="0"/>
<Component id="jSplitPane1" alignment="1" pref="521" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
@ -70,7 +70,7 @@
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" alignment="0" pref="339" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="0" pref="462" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
@ -227,7 +227,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="jPanel5" max="32767" attributes="0"/>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanel6" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
@ -239,12 +239,12 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane2" alignment="0" pref="453" max="32767" attributes="0"/>
<Component id="jScrollPane2" alignment="0" pref="606" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane2" alignment="0" pref="340" max="32767" attributes="0"/>
<Component id="jScrollPane2" alignment="0" pref="459" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
@ -272,8 +272,12 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jUserName" min="-2" pref="134" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="btnRemoveTable" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
@ -282,8 +286,13 @@
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="btnRemoveTable" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="31" max="32767" attributes="0"/>
<EmptySpace pref="20" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnRemoveTable" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jUserName" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -297,6 +306,17 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnRemoveTableActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JTextField" name="jUserName">
<Properties>
<Property name="text" type="java.lang.String" value=""/>
<Property name="name" type="java.lang.String" value="Username" noResource="true"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="Username:"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>

View file

@ -135,6 +135,8 @@ public class ConsolePanel extends javax.swing.JPanel {
tblTables = new javax.swing.JTable();
jPanel6 = new javax.swing.JPanel();
btnRemoveTable = new javax.swing.JButton();
jUserName = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jSplitPane1.setDividerLocation(250);
jSplitPane1.setResizeWeight(0.5);
@ -150,28 +152,48 @@ public class ConsolePanel extends javax.swing.JPanel {
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)
);
jPanel4.setVerifyInputWhenFocusTarget(false);
btnDisconnect.setText("Disconnect");
btnDisconnect.addActionListener(evt -> btnDisconnectActionPerformed(evt));
btnDisconnect.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDisconnectActionPerformed(evt);
}
});
btnEndSession.setText("End session");
btnEndSession.addActionListener(evt -> btnEndSessionActionPerformed(evt));
btnEndSession.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnEndSessionActionPerformed(evt);
}
});
btnMuteUser.setText("Mute user");
btnMuteUser.setActionCommand("Mute 1h");
btnMuteUser.addActionListener(evt -> btnMuteUserActionPerformed(evt));
btnMuteUser.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnMuteUserActionPerformed(evt);
}
});
btnDeActivate.setText("(de)activate");
btnDeActivate.setActionCommand("Mute 1h");
btnDeActivate.addActionListener(evt -> btnDeActivateActionPerformed(evt));
btnDeActivate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnDeActivateActionPerformed(evt);
}
});
btnLockUser.setText("Lock user");
btnLockUser.setActionCommand("Mute 1h");
btnLockUser.addActionListener(evt -> btnLockUserActionPerformed(evt));
btnLockUser.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnLockUserActionPerformed(evt);
}
});
lblMinutes.setText("Minutes");
@ -244,15 +266,24 @@ public class ConsolePanel extends javax.swing.JPanel {
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 453, Short.MAX_VALUE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 606, Short.MAX_VALUE)
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 459, Short.MAX_VALUE)
);
btnRemoveTable.setText("Remove Table");
btnRemoveTable.addActionListener(evt -> btnRemoveTableActionPerformed(evt));
btnRemoveTable.setLabel("Remove Table");
btnRemoveTable.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnRemoveTableActionPerformed(evt);
}
});
jUserName.setText("");
jUserName.setName("Username"); // NOI18N
jLabel1.setText("Username:");
javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
jPanel6.setLayout(jPanel6Layout);
@ -260,14 +291,22 @@ public class ConsolePanel extends javax.swing.JPanel {
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnRemoveTable)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel6Layout.setVerticalGroup(
jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel6Layout.createSequentialGroup()
.addContainerGap(20, Short.MAX_VALUE)
.addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnRemoveTable)
.addContainerGap(31, Short.MAX_VALUE))
.addComponent(jUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addContainerGap())
);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
@ -281,7 +320,7 @@ public class ConsolePanel extends javax.swing.JPanel {
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(0, 0, 0)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
@ -295,7 +334,7 @@ public class ConsolePanel extends javax.swing.JPanel {
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 521, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
@ -304,11 +343,6 @@ public class ConsolePanel extends javax.swing.JPanel {
ConsoleFrame.getSession().disconnectUser((String) tableUserModel.getValueAt(row, TableUserModel.POS_SESSION_ID));
}//GEN-LAST:event_btnDisconnectActionPerformed
private void btnRemoveTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveTableActionPerformed
int row = this.tblTables.convertRowIndexToModel(tblTables.getSelectedRow());
ConsoleFrame.getSession().removeTable((UUID) tableTableModel.getValueAt(row, 7));
}//GEN-LAST:event_btnRemoveTableActionPerformed
private void btnEndSessionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEndSessionActionPerformed
int row = this.tblUsers.convertRowIndexToModel(tblUsers.getSelectedRow());
ConsoleFrame.getSession().endUserSession((String) tableUserModel.getValueAt(row, TableUserModel.POS_GAME_INFO));
@ -329,6 +363,11 @@ public class ConsolePanel extends javax.swing.JPanel {
ConsoleFrame.getSession().lockUser((String) tableUserModel.getValueAt(row, TableUserModel.POS_USER_NAME), ((Number) spinnerMuteDurationMinutes.getValue()).longValue());
}//GEN-LAST:event_btnLockUserActionPerformed
private void btnRemoveTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveTableActionPerformed
int row = this.tblTables.convertRowIndexToModel(tblTables.getSelectedRow());
ConsoleFrame.getSession().removeTable((UUID) tableTableModel.getValueAt(row, 7));
}//GEN-LAST:event_btnRemoveTableActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnDeActivate;
private javax.swing.JButton btnDisconnect;
@ -336,6 +375,7 @@ public class ConsolePanel extends javax.swing.JPanel {
private javax.swing.JButton btnLockUser;
private javax.swing.JButton btnMuteUser;
private javax.swing.JButton btnRemoveTable;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
@ -345,6 +385,7 @@ public class ConsolePanel extends javax.swing.JPanel {
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JSplitPane jSplitPane1;
public javax.swing.JTextField jUserName;
private javax.swing.JLabel lblMinutes;
private javax.swing.JSpinner spinnerMuteDurationMinutes;
private javax.swing.JTable tblTables;
@ -525,6 +566,15 @@ class UpdateUsersTask extends SwingWorker<Void, List<UserView>> {
protected Void doInBackground() throws Exception {
while (!isCancelled()) {
List<UserView> users = session.getUsers();
if (!panel.jUserName.getText().equals("")) {
List<UserView> users2 = new ArrayList<>();
for (UserView user : users) {
if (user.getUserName().toUpperCase().matches(".*" + panel.jUserName.getText().toUpperCase() + ".*")) {
users2.add(user);
}
}
users = users2;
}
if (previousUsers == null || checkUserListChanged(users)) {
logger.debug("Need to update the user list");
@ -600,7 +650,18 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
@Override
protected Void doInBackground() throws Exception {
while (!isCancelled()) {
this.publish(session.getTables(roomId));
Collection<TableView> tableViews = session.getTables(roomId);
if (!panel.jUserName.getText().equals("")) {
Collection<TableView> tableViews2 = new ArrayList<>();
for (TableView table : tableViews) {
if (table.getControllerName().toUpperCase().matches(".*" + panel.jUserName.getText().toUpperCase() + ".*")) {
tableViews2.add(table);
}
}
tableViews = tableViews2;
}
this.publish(tableViews);
Thread.sleep(3000);
}
return null;