From 6dba9f4de82670538baeef049805327139360702 Mon Sep 17 00:00:00 2001 From: Alyssa Date: Thu, 7 Dec 2023 08:28:12 +0000 Subject: [PATCH 1/2] more logger migration --- client/src/main/java/object/RoomTable.java | 8 +- .../src/main/java/online/screen/GameRoom.java | 79 +--- .../java/online/util/ResponseHandler.java | 42 +-- client/src/main/java/screen/GameScreen.java | 37 +- client/src/main/java/screen/HandPanelMk2.java | 36 +- client/src/main/java/screen/MainScreen.java | 90 +---- .../src/main/java/screen/ReplayInterface.java | 350 ++++++++---------- .../main/java/screen/SimulationDialog.java | 70 +--- .../main/java/util/AbstractDesktopClient.java | 31 -- .../src/main/java/util/ReplayConverter.java | 3 +- client/src/main/java/util/ReplayFileUtil.java | 16 +- client/src/main/kotlin/MainUtil.kt | 3 +- core/src/main/java/util/CoreRegistry.java | 3 +- core/src/main/java/util/Debug.java | 6 +- core/src/main/kotlin/logging/Logger.kt | 1 + core/src/main/kotlin/utils/MainUtil.kt | 3 + 16 files changed, 258 insertions(+), 520 deletions(-) create mode 100644 core/src/main/kotlin/utils/MainUtil.kt diff --git a/client/src/main/java/object/RoomTable.java b/client/src/main/java/object/RoomTable.java index 03abf52..09f121a 100644 --- a/client/src/main/java/object/RoomTable.java +++ b/client/src/main/java/object/RoomTable.java @@ -23,11 +23,12 @@ import org.w3c.dom.Document; -import util.Debug; import util.EntropyColour; import util.MessageUtil; import util.TableUtil; +import static utils.InjectedThings.logger; + public final class RoomTable extends JTable implements MouseListener { @@ -158,10 +159,7 @@ private void updateRooms(List rooms) RoomWrapper tableRoom = lobby.getRoomForName(roomName); if (tableRoom == null) { - Debug.append("roomName: " + roomName); - Debug.append("rowCount: " + rowCount); - Debug.append("rooms from server: " + rooms); - Debug.stackTraceNoError("NULL room in lobby hashmap, despite it being in tablemodel"); + logger.warn("missingRoom", roomName + " missing from lobby hashmap, despite being in our local table. Rooms from server: " + rooms); } RoomWrapper listRoom = getListRoomForName(rooms, roomName); diff --git a/client/src/main/java/online/screen/GameRoom.java b/client/src/main/java/online/screen/GameRoom.java index 25492e8..cdd08c2 100644 --- a/client/src/main/java/online/screen/GameRoom.java +++ b/client/src/main/java/online/screen/GameRoom.java @@ -1,71 +1,26 @@ package online.screen; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.Font; -import java.awt.Image; + +import object.*; +import online.util.XmlBuilderClient; +import org.w3c.dom.Document; +import screen.*; +import util.*; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyledDocument; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Random; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.prefs.Preferences; -import javax.swing.BorderFactory; -import javax.swing.DefaultListModel; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextPane; -import javax.swing.SwingConstants; -import javax.swing.border.EmptyBorder; -import javax.swing.text.SimpleAttributeSet; -import javax.swing.text.StyleConstants; -import javax.swing.text.StyledDocument; - -import object.Bid; -import object.BidListCellRenderer; -import object.ChallengeBid; -import object.IllegalBid; -import object.LeftBid; -import object.Player; -import object.PulsingTextLabel; -import object.RoomWrapper; -import online.util.XmlBuilderClient; - -import org.w3c.dom.Document; - -import screen.BackgroundPanel; -import screen.BidPanel; -import screen.HandPanelMk2; -import screen.ReplayDialog; -import screen.ScreenCache; -import screen.TransparentPanel; -import util.AchievementsUtil; -import util.BidListener; -import util.Debug; -import util.DialogUtil; -import util.EntropyUtil; -import util.GameConstants; -import util.GameUtil; -import util.MessageUtil; -import util.Registry; -import util.ReplayFileUtil; -import util.RevealListener; +import static utils.InjectedThings.logger; /** * This is an actual room as seen by the player @@ -788,8 +743,6 @@ public void startGame(int personToStart) } else { - Debug.append("Disabling bidPanel on start. personToStart = " + personToStart - + ", personToStartLocal = " + personToStartLocal); enableBidPanel(false); } } @@ -1225,7 +1178,7 @@ public void deleteReplayNode() } catch (Throwable t) { - Debug.append("Caught " + t + " when deleting online replay node."); + logger.error("preferenceError", "Error deleting replay node", t); } } diff --git a/client/src/main/java/online/util/ResponseHandler.java b/client/src/main/java/online/util/ResponseHandler.java index 637034c..36ef191 100644 --- a/client/src/main/java/online/util/ResponseHandler.java +++ b/client/src/main/java/online/util/ResponseHandler.java @@ -1,44 +1,24 @@ package online.util; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import javax.crypto.SecretKey; -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; - import object.Bid; import object.OnlineMessage; import object.OnlineUsername; import object.RoomWrapper; -import online.screen.AccountSettingsDialog; -import online.screen.ChangePasswordDialog; -import online.screen.ConnectingDialog; -import online.screen.EntropyLobby; -import online.screen.GameRoom; -import online.screen.Leaderboard; -import online.screen.LoginDialog; -import online.screen.NewAccountDialog; -import online.screen.OnlineChatPanel; -import online.screen.OnlineStatsPanel; - +import online.screen.*; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; - import screen.ScreenCache; -import util.AchievementsUtil; -import util.Debug; -import util.DialogUtil; -import util.EncryptionUtil; -import util.MessageUtil; -import util.OnlineConstants; -import util.Registry; -import util.UpdateChecker; -import util.XmlConstants; -import util.XmlUtil; +import util.*; + +import javax.crypto.SecretKey; +import javax.swing.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import static utils.InjectedThings.logger; public class ResponseHandler implements XmlConstants { @@ -155,7 +135,7 @@ else if (responseName.equals(RESPONSE_TAG_STACK_TRACE)) } else if (responseName.equals(RESPONSE_TAG_SOCKET_TIME_OUT)) { - Debug.append("Resending " + messageStr + " because Server had a SocketTimeout"); + logger.info("resendingMessage", "Resending " + messageStr + " because Server had a SocketTimeout"); MessageUtil.sendMessage(messageStr, 0); } else diff --git a/client/src/main/java/screen/GameScreen.java b/client/src/main/java/screen/GameScreen.java index a1b8968..429272c 100644 --- a/client/src/main/java/screen/GameScreen.java +++ b/client/src/main/java/screen/GameScreen.java @@ -1,29 +1,16 @@ package screen; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; -import java.util.Timer; -import java.util.TimerTask; - -import javax.swing.DefaultListModel; - import object.Bid; import object.ChallengeBid; import object.IllegalBid; import object.Player; -import util.AchievementsUtil; -import util.BidListener; -import util.CardsUtil; -import util.CpuStrategies; -import util.Debug; -import util.DialogUtil; -import util.GameUtil; -import util.Registry; -import util.RegistryUtil; -import util.ReplayFileUtil; -import util.RevealListener; -import util.StrategyParms; +import util.*; + +import javax.swing.*; +import java.util.Timer; +import java.util.*; + +import static utils.InjectedThings.logger; public abstract class GameScreen extends TransparentPanel implements BidListener, @@ -815,10 +802,9 @@ protected void randomlyReplaceCardsWithJokers() { Random random = new Random(); int jokersToAdd = random.nextInt(5) + 1; //1-5 - Debug.append("Adding " + jokersToAdd + " jokers"); + logger.info("rainingJokers", "Adding " + jokersToAdd + " jokers"); String[] allCards = getConcatenatedHands(); - Debug.append("allCards: " + CardsUtil.getHandStr(allCards)); while (CardsUtil.containsNonJoker(allCards) && jokersToAdd > 0) { @@ -826,8 +812,7 @@ protected void randomlyReplaceCardsWithJokers() allCards = getConcatenatedHands(); jokersToAdd--; } - - Debug.append("Done replacing. allCards = " + CardsUtil.getHandStr(allCards)); + displayHands(); } } @@ -846,8 +831,7 @@ private void replaceRandomCardWithJoker() replaceRandomCardWithJoker(); return; } - - Debug.append("Replacing " + hand[position] + " with " + jokerToAdd); + hand[position] = jokerToAdd; } @@ -863,7 +847,6 @@ private String[] pickHandWithNonJokerAtRandom() } else { - Debug.append("Picked " + CardsUtil.getHandStr(hand)); return hand; } } diff --git a/client/src/main/java/screen/HandPanelMk2.java b/client/src/main/java/screen/HandPanelMk2.java index 4405141..99fb410 100644 --- a/client/src/main/java/screen/HandPanelMk2.java +++ b/client/src/main/java/screen/HandPanelMk2.java @@ -1,9 +1,14 @@ package screen; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.Font; +import object.CardLabel; +import object.PlayerLabel; +import online.util.XmlBuilderClient; +import org.w3c.dom.Document; +import util.*; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; @@ -13,28 +18,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.prefs.Preferences; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; -import javax.swing.border.EmptyBorder; - -import object.CardLabel; -import object.PlayerLabel; -import online.util.XmlBuilderClient; - -import org.w3c.dom.Document; - -import util.AchievementsUtil; -import util.CardsUtil; -import util.Debug; -import util.MessageUtil; -import util.Registry; -import util.RevealListener; - public class HandPanelMk2 extends TransparentPanel implements ActionListener, MouseListener, @@ -981,7 +964,6 @@ private void playerCardClicked(CardLabel source) { if (isRevealed(source)) { - Debug.append("Player clicked a card that was already revealed."); return; } diff --git a/client/src/main/java/screen/MainScreen.java b/client/src/main/java/screen/MainScreen.java index 132473f..7a26321 100644 --- a/client/src/main/java/screen/MainScreen.java +++ b/client/src/main/java/screen/MainScreen.java @@ -1,73 +1,32 @@ package screen; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Font; -import java.awt.Frame; -import java.awt.Image; -import java.awt.Toolkit; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; -import java.util.ArrayList; -import java.util.Timer; -import java.util.TimerTask; -import java.util.prefs.BackingStoreException; -import java.util.prefs.PreferenceChangeEvent; -import java.util.prefs.PreferenceChangeListener; -import java.util.prefs.Preferences; - -import javax.swing.BorderFactory; -import javax.swing.DefaultListModel; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSplitPane; -import javax.swing.JTextPane; -import javax.swing.KeyStroke; -import javax.swing.SwingConstants; -import javax.swing.border.BevelBorder; -import javax.swing.text.SimpleAttributeSet; -import javax.swing.text.StyleConstants; -import javax.swing.text.StyledDocument; - +import bean.AbstractDevScreen; import object.Bid; import object.BidListCellRenderer; import object.Player; import online.screen.EntropyLobby; import online.screen.TestHarness; import online.util.XmlBuilderDesktop; - -import org.jetbrains.annotations.NotNull; import org.w3c.dom.Document; - -import util.AbstractClient; -import util.AchievementsUtil; -import util.CoreRegistry; -import util.Debug; -import util.DialogUtil; -import util.GameConstants; -import util.MessageUtil; -import util.OnlineConstants; -import util.Registry; -import util.ReplayConverter; -import util.ReplayFileUtil; -import bean.AbstractDevScreen; +import util.*; import utils.InjectedThings; +import javax.swing.*; +import javax.swing.border.BevelBorder; +import javax.swing.text.SimpleAttributeSet; +import javax.swing.text.StyleConstants; +import javax.swing.text.StyledDocument; +import java.awt.*; +import java.awt.event.*; +import java.util.ArrayList; +import java.util.Timer; +import java.util.TimerTask; +import java.util.prefs.BackingStoreException; +import java.util.prefs.PreferenceChangeEvent; +import java.util.prefs.PreferenceChangeListener; +import java.util.prefs.Preferences; + +import static utils.InjectedThings.logger; import static utils.ThreadUtilKt.dumpThreadStacks; public final class MainScreen extends AbstractDevScreen @@ -727,16 +686,6 @@ public String processCommand(String command) { Debug.sendContentsAsEmailInSeparateThread("Manual logs (" + OnlineConstants.ENTROPY_VERSION_NUMBER + ")", true, null); } - else if (command.equals("emailsoff")) - { - Debug.append("Emails disabled"); - instance.putBoolean(CoreRegistry.INSTANCE_BOOLEAN_ENABLE_EMAILS, false); - } - else if (command.equals("emailson")) - { - Debug.append("Emails enabled"); - instance.putBoolean(CoreRegistry.INSTANCE_BOOLEAN_ENABLE_EMAILS, true); - } else if (command.equals("simulator")) { SimulationDialog dialog = ScreenCache.getSimulationDialog(); @@ -838,7 +787,6 @@ private void cleanUpReplayNodes() String node = nodes[i]; if (node.startsWith(Registry.NODE_ONLINE_REPLAY)) { - Debug.appendWithoutDate("Removed replay node " + node); Preferences replay = Preferences.userRoot().node(node); replay.removeNode(); } @@ -1110,7 +1058,7 @@ public void keyPressed(KeyEvent arg0) if (AchievementsUtil.hasEnteredKonamiCode(lastTenKeys)) { - Debug.append("Entered konami code!"); + logger.info("konami", "Entered konami code!"); AchievementsUtil.unlockKonamiCode(); } } diff --git a/client/src/main/java/screen/ReplayInterface.java b/client/src/main/java/screen/ReplayInterface.java index 8c9faaf..4ed4479 100644 --- a/client/src/main/java/screen/ReplayInterface.java +++ b/client/src/main/java/screen/ReplayInterface.java @@ -1,39 +1,25 @@ package screen; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Font; +import bean.FileUploadListener; +import bean.FileUploader; +import object.ReplayTable; +import util.AchievementsUtil; +import util.DialogUtil; +import util.Registry; +import util.ReplayFileUtil; + +import javax.swing.*; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.filechooser.FileFilter; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.io.File; -import javax.swing.BorderFactory; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTabbedPane; -import javax.swing.JTextField; -import javax.swing.ListSelectionModel; -import javax.swing.SwingConstants; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.filechooser.FileFilter; - -import object.ReplayTable; -import util.AchievementsUtil; -import util.Debug; -import util.DialogUtil; -import util.Registry; -import util.ReplayFileUtil; -import bean.FileUploadListener; -import bean.FileUploader; +import static utils.InjectedThings.logger; public class ReplayInterface extends JFrame implements ListSelectionListener, @@ -46,105 +32,98 @@ public class ReplayInterface extends JFrame public ReplayInterface() { - try - { - setIconImage(new ImageIcon(AchievementsDialog.class.getResource("/icons/replay.png")).getImage()); - getContentPane().setLayout(new BorderLayout(0, 0)); - getContentPane().add(tabbedPane); - personalTab = new JPanel(); - tabbedPane.addTab(ReplayFileUtil.FOLDER_PERSONAL_REPLAYS, null, personalTab, null); - importedTab = new JPanel(); - tabbedPane.addTab(ReplayFileUtil.FOLDER_IMPORTED_REPLAYS, null, importedTab, null); - noMyReplays.setVerticalAlignment(SwingConstants.TOP); - noMyReplays.setHorizontalAlignment(SwingConstants.CENTER); - noMyReplays.setFont(new Font("Tahoma", Font.ITALIC, 12)); - noMyReplays.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - noImportedReplays.setVerticalAlignment(SwingConstants.TOP); - noImportedReplays.setHorizontalAlignment(SwingConstants.CENTER); - noImportedReplays.setFont(new Font("Tahoma", Font.ITALIC, 12)); - noImportedReplays.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); - myCount.setPreferredSize(new Dimension(46, 20)); - myCount.setFont(new Font("Tahoma", Font.ITALIC, 12)); - myCount.setHorizontalAlignment(SwingConstants.CENTER); - personalTab.setLayout(new BorderLayout(0, 0)); - personalTab.add(personalFilterPanel, BorderLayout.WEST); - personalTablePanel = new JPanel(); - personalTab.add(personalTablePanel, BorderLayout.CENTER); - personalTablePanel.setLayout(new BorderLayout(0, 0)); - personalTablePanel.add(personalReplaysScrollPane, BorderLayout.CENTER); - personalTablePanel.add(exportPanel, BorderLayout.NORTH); - personalTablePanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 10, 10)); - personalReplaysScrollPane.setViewportView(personalReplaysTable); - personalReplaysScrollPane.setVisible(false); - personalReplaysTable.setRowSelectionAllowed(true); - personalReplaysTable.setShowGrid(false); - personalReplaysTable.getTableHeader().setReorderingAllowed(false); - personalReplaysTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - personalReplaysTable.setFillsViewportHeight(true); - importedCount.setPreferredSize(new Dimension(46, 20)); - importedCount.setHorizontalAlignment(SwingConstants.CENTER); - importedCount.setFont(new Font("Tahoma", Font.ITALIC, 12)); - importedTab.setLayout(new BorderLayout(0, 0)); - importedTab.add(importedFilterPanel, BorderLayout.WEST); - importedFilterPanel.setBorder(BorderFactory.createEmptyBorder(27, 0, 0, 5)); - personalFilterPanel.setBorder(BorderFactory.createEmptyBorder(27, 0, 0, 5)); - importedTab.add(importedTablePanel); - importedTablePanel.setLayout(new BorderLayout(0, 0)); - importedTablePanel.add(importedReplaysScrollPane, BorderLayout.CENTER); - importedTablePanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 10, 10)); - importedReplaysScrollPane.setViewportView(importedReplaysTable); - importedReplaysScrollPane.setVisible(false); - importedReplaysTable.setRowSelectionAllowed(true); - importedReplaysTable.setShowGrid(false); - importedReplaysTable.getTableHeader().setReorderingAllowed(false); - importedReplaysTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); - importedReplaysTable.setFillsViewportHeight(true); - panel_3.setLayout(new BorderLayout(0, 0)); - panel_3.add(fileUploader, BorderLayout.CENTER); - panel = new JPanel(); - personalFilterPanel.add(panel, "2, 7, 2, 1, fill, center"); - btnConfigurePersonalColumns.setPreferredSize(new Dimension(155, 20)); - panel.add(btnConfigurePersonalColumns); - btnRefreshPersonal.setPreferredSize(new Dimension(80, 20)); - panel.add(btnRefreshPersonal); - personalTablePanel.add(myCount, BorderLayout.SOUTH); - importedTablePanel.add(importedCount, BorderLayout.SOUTH); - importedTablePanel.add(panel_3, BorderLayout.NORTH); - panel_3.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0)); - exportPanel.setLayout(new BorderLayout(0, 0)); - btnExport.setPreferredSize(new Dimension(80, 20)); - exportPanel.add(btnExport, BorderLayout.EAST); - exportPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - lblFilename.setHorizontalAlignment(SwingConstants.CENTER); - lblFilename.setText(""); - lblFilename.setOpaque(false); - lblFilename.setBackground(new Color(0,0,0,0)); - lblFilename.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); - ListSelectionModel plsm = personalReplaysTable.getSelectionModel(); - plsm.addListSelectionListener(this); - lblFilename.setEditable(false); - exportPanel.add(lblFilename, BorderLayout.CENTER); - importedFilterPanel.add(panel_1, "2, 7, 2, 1, fill, center"); - btnConfigureImportedColumns.setPreferredSize(new Dimension(155, 20)); - panel_1.add(btnConfigureImportedColumns); - btnRefreshImported.setPreferredSize(new Dimension(80, 20)); - panel_1.add(btnRefreshImported); - FileFilter[] filters = fc.getChoosableFileFilters(); - fc.removeChoosableFileFilter(filters[0]); - fc.addChoosableFileFilter(new EntSaveFilter()); - - btnExport.addActionListener(this); - btnRefreshPersonal.addActionListener(this); - btnRefreshImported.addActionListener(this); - btnConfigurePersonalColumns.addActionListener(this); - btnConfigureImportedColumns.addActionListener(this); - fileUploader.addFileUploadListener(this); - addWindowListener(this); - } - catch (Throwable t) - { - Debug.stackTrace(t); - } + setIconImage(new ImageIcon(AchievementsDialog.class.getResource("/icons/replay.png")).getImage()); + getContentPane().setLayout(new BorderLayout(0, 0)); + getContentPane().add(tabbedPane); + personalTab = new JPanel(); + tabbedPane.addTab(ReplayFileUtil.FOLDER_PERSONAL_REPLAYS, null, personalTab, null); + importedTab = new JPanel(); + tabbedPane.addTab(ReplayFileUtil.FOLDER_IMPORTED_REPLAYS, null, importedTab, null); + noMyReplays.setVerticalAlignment(SwingConstants.TOP); + noMyReplays.setHorizontalAlignment(SwingConstants.CENTER); + noMyReplays.setFont(new Font("Tahoma", Font.ITALIC, 12)); + noMyReplays.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + noImportedReplays.setVerticalAlignment(SwingConstants.TOP); + noImportedReplays.setHorizontalAlignment(SwingConstants.CENTER); + noImportedReplays.setFont(new Font("Tahoma", Font.ITALIC, 12)); + noImportedReplays.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + myCount.setPreferredSize(new Dimension(46, 20)); + myCount.setFont(new Font("Tahoma", Font.ITALIC, 12)); + myCount.setHorizontalAlignment(SwingConstants.CENTER); + personalTab.setLayout(new BorderLayout(0, 0)); + personalTab.add(personalFilterPanel, BorderLayout.WEST); + personalTablePanel = new JPanel(); + personalTab.add(personalTablePanel, BorderLayout.CENTER); + personalTablePanel.setLayout(new BorderLayout(0, 0)); + personalTablePanel.add(personalReplaysScrollPane, BorderLayout.CENTER); + personalTablePanel.add(exportPanel, BorderLayout.NORTH); + personalTablePanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 10, 10)); + personalReplaysScrollPane.setViewportView(personalReplaysTable); + personalReplaysScrollPane.setVisible(false); + personalReplaysTable.setRowSelectionAllowed(true); + personalReplaysTable.setShowGrid(false); + personalReplaysTable.getTableHeader().setReorderingAllowed(false); + personalReplaysTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + personalReplaysTable.setFillsViewportHeight(true); + importedCount.setPreferredSize(new Dimension(46, 20)); + importedCount.setHorizontalAlignment(SwingConstants.CENTER); + importedCount.setFont(new Font("Tahoma", Font.ITALIC, 12)); + importedTab.setLayout(new BorderLayout(0, 0)); + importedTab.add(importedFilterPanel, BorderLayout.WEST); + importedFilterPanel.setBorder(BorderFactory.createEmptyBorder(27, 0, 0, 5)); + personalFilterPanel.setBorder(BorderFactory.createEmptyBorder(27, 0, 0, 5)); + importedTab.add(importedTablePanel); + importedTablePanel.setLayout(new BorderLayout(0, 0)); + importedTablePanel.add(importedReplaysScrollPane, BorderLayout.CENTER); + importedTablePanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 10, 10)); + importedReplaysScrollPane.setViewportView(importedReplaysTable); + importedReplaysScrollPane.setVisible(false); + importedReplaysTable.setRowSelectionAllowed(true); + importedReplaysTable.setShowGrid(false); + importedReplaysTable.getTableHeader().setReorderingAllowed(false); + importedReplaysTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + importedReplaysTable.setFillsViewportHeight(true); + panel_3.setLayout(new BorderLayout(0, 0)); + panel_3.add(fileUploader, BorderLayout.CENTER); + panel = new JPanel(); + personalFilterPanel.add(panel, "2, 7, 2, 1, fill, center"); + btnConfigurePersonalColumns.setPreferredSize(new Dimension(155, 20)); + panel.add(btnConfigurePersonalColumns); + btnRefreshPersonal.setPreferredSize(new Dimension(80, 20)); + panel.add(btnRefreshPersonal); + personalTablePanel.add(myCount, BorderLayout.SOUTH); + importedTablePanel.add(importedCount, BorderLayout.SOUTH); + importedTablePanel.add(panel_3, BorderLayout.NORTH); + panel_3.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0)); + exportPanel.setLayout(new BorderLayout(0, 0)); + btnExport.setPreferredSize(new Dimension(80, 20)); + exportPanel.add(btnExport, BorderLayout.EAST); + exportPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); + lblFilename.setHorizontalAlignment(SwingConstants.CENTER); + lblFilename.setText(""); + lblFilename.setOpaque(false); + lblFilename.setBackground(new Color(0,0,0,0)); + lblFilename.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); + ListSelectionModel plsm = personalReplaysTable.getSelectionModel(); + plsm.addListSelectionListener(this); + lblFilename.setEditable(false); + exportPanel.add(lblFilename, BorderLayout.CENTER); + importedFilterPanel.add(panel_1, "2, 7, 2, 1, fill, center"); + btnConfigureImportedColumns.setPreferredSize(new Dimension(155, 20)); + panel_1.add(btnConfigureImportedColumns); + btnRefreshImported.setPreferredSize(new Dimension(80, 20)); + panel_1.add(btnRefreshImported); + FileFilter[] filters = fc.getChoosableFileFilters(); + fc.removeChoosableFileFilter(filters[0]); + fc.addChoosableFileFilter(new EntSaveFilter()); + + btnExport.addActionListener(this); + btnRefreshPersonal.addActionListener(this); + btnRefreshImported.addActionListener(this); + btnConfigurePersonalColumns.addActionListener(this); + btnConfigureImportedColumns.addActionListener(this); + fileUploader.addFileUploadListener(this); + addWindowListener(this); } private final JFileChooser fc = new JFileChooser(); @@ -177,33 +156,24 @@ public ReplayInterface() public void init() { - try - { - Debug.appendBanner("Initting replay interface..."); - long startTime = System.currentTimeMillis(); - - personalFilterPanel.setMoonAndStarVisibility(); - importedFilterPanel.setMoonAndStarVisibility(); - - boolean expectLongerDuration = personalReplaysTable.init(); - expectLongerDuration |= importedReplaysTable.init(); - - setScrollpaneViewport(personalReplaysScrollPane, personalReplaysTable, noMyReplays); - setScrollpaneViewport(importedReplaysScrollPane, importedReplaysTable, noImportedReplays); - - long endTime = System.currentTimeMillis(); - long initDuration = endTime - startTime; - Debug.append("Finished init, total duration = " + initDuration); - Debug.append("expectLongerDuration = " + expectLongerDuration); - if (initDuration > INIT_MILLIS_STACK_TRACE_THRESHOLD - && !expectLongerDuration) - { - Debug.stackTraceNoError("Took longer than " + INIT_MILLIS_STACK_TRACE_THRESHOLD + " millis to init ReplayInterface"); - } - } - catch (Throwable t) + logger.info("replayInit", "Initialising replay interface..."); + long startTime = System.currentTimeMillis(); + + personalFilterPanel.setMoonAndStarVisibility(); + importedFilterPanel.setMoonAndStarVisibility(); + + boolean expectLongerDuration = personalReplaysTable.init(); + expectLongerDuration |= importedReplaysTable.init(); + + setScrollpaneViewport(personalReplaysScrollPane, personalReplaysTable, noMyReplays); + setScrollpaneViewport(importedReplaysScrollPane, importedReplaysTable, noImportedReplays); + + long endTime = System.currentTimeMillis(); + long initDuration = endTime - startTime; + if (initDuration > INIT_MILLIS_STACK_TRACE_THRESHOLD + && !expectLongerDuration) { - Debug.stackTrace(t); + logger.error("slowReplayInit", "Took longer than " + INIT_MILLIS_STACK_TRACE_THRESHOLD + " millis to init ReplayInterface"); } } @@ -234,24 +204,16 @@ private void setScrollpaneViewport(JScrollPane scrollPane, ReplayTable table, JL private void importReplay(File file) { - try + String filePath = file.getPath(); + if (ReplayFileUtil.successfullyFilledRegistryFromFile(filePath, tempReplayStore)) { - String filePath = file.getPath(); - if (ReplayFileUtil.successfullyFilledRegistryFromFile(filePath, tempReplayStore)) - { - String filename = ReplayFileUtil.saveImportedReplay(); - importedReplaysTable.replayAdded(filename); - importedReplaysScrollPane.setViewportView(importedReplaysTable); - } - else - { - DialogUtil.showError("The file specified was not in the correct format and could not be imported."); - } + String filename = ReplayFileUtil.saveImportedReplay(); + importedReplaysTable.replayAdded(filename); + importedReplaysScrollPane.setViewportView(importedReplaysTable); } - catch (Throwable t) + else { - DialogUtil.showError("A serious error occurred importing the replay."); - Debug.stackTrace(t); + DialogUtil.showError("The file specified was not in the correct format and could not be imported."); } } @@ -263,40 +225,32 @@ private void exportReplay() DialogUtil.showError("You must select a replay to export."); return; } - - Debug.append("Exporting replay " + selectedFilename); - - try + + logger.info("exportReplay", "Exporting replay " + selectedFilename); + + int returnVal = fc.showSaveDialog(ReplayInterface.this); + if (returnVal != JFileChooser.APPROVE_OPTION) { - int returnVal = fc.showSaveDialog(ReplayInterface.this); - if (returnVal != JFileChooser.APPROVE_OPTION) - { - Debug.append("User cancelled save"); - return; - } - - File newFile = fc.getSelectedFile(); - String filePath = newFile.getPath(); - - filePath = adjustFileExtensionIfNecessary(filePath); - - String directory = ReplayFileUtil.getDirectoryFromPreferences(); - String fullPath = directory + "//Replays//" + ReplayFileUtil.FOLDER_PERSONAL_REPLAYS + "//" + selectedFilename; + logger.info("exportReplay", "User cancelled save"); + return; + } - if (ReplayFileUtil.successfullyFilledRegistryFromFile(fullPath, tempReplayStore)) - { - ReplayFileUtil.exportReplay(filePath); - AchievementsUtil.unlockAchievement(ACHIEVEMENTS_BOOLEAN_LOOK_AT_ME); - } - else - { - DialogUtil.showError("The file specified was not in the correct format and could not be exported."); - } + File newFile = fc.getSelectedFile(); + String filePath = newFile.getPath(); + + filePath = adjustFileExtensionIfNecessary(filePath); + + String directory = ReplayFileUtil.getDirectoryFromPreferences(); + String fullPath = directory + "//Replays//" + ReplayFileUtil.FOLDER_PERSONAL_REPLAYS + "//" + selectedFilename; + + if (ReplayFileUtil.successfullyFilledRegistryFromFile(fullPath, tempReplayStore)) + { + ReplayFileUtil.exportReplay(filePath); + AchievementsUtil.unlockAchievement(ACHIEVEMENTS_BOOLEAN_LOOK_AT_ME); } - catch (Throwable t) + else { - Debug.stackTrace(t); - DialogUtil.showError("A serious error has occurred. The file was not exported."); + DialogUtil.showError("The file specified was not in the correct format and could not be exported."); } } diff --git a/client/src/main/java/screen/SimulationDialog.java b/client/src/main/java/screen/SimulationDialog.java index 72306bb..6fac756 100644 --- a/client/src/main/java/screen/SimulationDialog.java +++ b/client/src/main/java/screen/SimulationDialog.java @@ -1,47 +1,16 @@ package screen; -import java.awt.Checkbox; -import java.awt.Color; -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.MouseEvent; -import java.util.HashMap; -import java.util.Vector; +import bean.NumberField; +import util.*; -import javax.swing.ButtonGroup; -import javax.swing.ComboBoxModel; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JScrollPane; -import javax.swing.JSeparator; -import javax.swing.JSlider; -import javax.swing.JSpinner; -import javax.swing.JTabbedPane; -import javax.swing.JTable; -import javax.swing.ListSelectionModel; -import javax.swing.SpinnerNumberModel; -import javax.swing.SwingConstants; +import javax.swing.*; import javax.swing.table.JTableHeader; +import java.awt.*; +import java.awt.event.*; +import java.util.HashMap; +import java.util.Vector; -import util.CpuStrategies; -import util.Debug; -import util.DialogUtil; -import util.GameConstants; -import util.GameSimulator; -import util.SimulationException; -import util.SimulationParms; -import util.SimulationResults; -import bean.NumberField; +import static utils.InjectedThings.logger; public class SimulationDialog extends JDialog { @@ -315,10 +284,7 @@ public void run() simulator.startNewGame(i); dialog.incrementProgressLater(); - if (i % tenPercentOfTotal == 0) - { - Debug.append("Done " + i + " games"); - } + logger.logProgress("simulationProgress", i, numberOfGames); if (dialog.cancelPressed()) { @@ -634,21 +600,21 @@ private SimulationParms factorySimulationParms() } private void dumpSimulationDetails(int i, int numberOfGames, SimulationParms parms) - { - Debug.append("Dumping simulation details:"); - Debug.append("Opponent 0: " + parms.getOpponentZeroStrategy()); - Debug.append("Opponent 1: " + parms.getOpponentOneStrategy()); - + { + logger.info("simulationDump", "Dumping simulation details"); + logger.info("simulationDump", "Opponent 0: " + parms.getOpponentZeroStrategy()); + logger.info("simulationDump", "Opponent 1: " + parms.getOpponentOneStrategy()); + if (parms.getOpponentTwoEnabled()) { - Debug.append("Opponent 2: " + parms.getOpponentTwoStrategy()); + logger.info("simulationDump", "Opponent 2: " + parms.getOpponentTwoStrategy()); } if (parms.getOpponentThreeEnabled()) { - Debug.append("Opponent 3: " + parms.getOpponentThreeStrategy()); + logger.info("simulationDump", "Opponent 3: " + parms.getOpponentThreeStrategy()); } - - Debug.append("Was simulating game " + i + "/" + numberOfGames); + + logger.info("simulationDump", "Was simulating game " + i + "/" + numberOfGames); } } \ No newline at end of file diff --git a/client/src/main/java/util/AbstractDesktopClient.java b/client/src/main/java/util/AbstractDesktopClient.java index 1cecc1d..d97e0f4 100644 --- a/client/src/main/java/util/AbstractDesktopClient.java +++ b/client/src/main/java/util/AbstractDesktopClient.java @@ -11,37 +11,6 @@ public void init() EncryptionUtil.setBase64Interface(new Base64Desktop()); MessageUtil.generatePublicKey(); - checkForUserName(); - ClientEmailer.tryToSendUnsentLogs(); - - - } - - private void checkForUserName() - { - String userName = instance.get(INSTANCE_STRING_USER_NAME, ""); - if (!userName.isEmpty()) - { - return; - } - - Debug.append("Username isn't specified - will prompt for one now"); - while (userName == null || userName.isEmpty()) - { - userName = JOptionPane.showInputDialog(null, "Please enter your name (for debugging purposes).\nThis will only be asked for once.", "Enter your name"); - } - - instance.put(INSTANCE_STRING_USER_NAME, userName); - - try - { - ClientEmailer.sendClientEmail("Username notification", userName + " has set their username.", false); - } - catch (Throwable t) - { - //If there's no internet connection or Google does something dumb, just log a line - Debug.append("Caught " + t + " trying to send username notification."); - } } } diff --git a/client/src/main/java/util/ReplayConverter.java b/client/src/main/java/util/ReplayConverter.java index 651842f..c6ba0ca 100644 --- a/client/src/main/java/util/ReplayConverter.java +++ b/client/src/main/java/util/ReplayConverter.java @@ -11,6 +11,7 @@ import org.w3c.dom.Element; import screen.ProgressDialog; +import utils.MainUtilKt; public class ReplayConverter implements Registry { @@ -123,7 +124,7 @@ private static void convertReplays(final String folder) int failedSize = filesFailed.size(); if (failedSize > 0) { - String username = instance.get(CoreRegistry.INSTANCE_STRING_USER_NAME, ""); + String username = MainUtilKt.getUsername(); String subject = "Failed " + folder + " replay examples for " + username + " (" + OnlineConstants.ENTROPY_VERSION_NUMBER + ")"; try diff --git a/client/src/main/java/util/ReplayFileUtil.java b/client/src/main/java/util/ReplayFileUtil.java index 34f42e9..7b33db6 100644 --- a/client/src/main/java/util/ReplayFileUtil.java +++ b/client/src/main/java/util/ReplayFileUtil.java @@ -1,5 +1,11 @@ package util; +import object.FlagImage; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import screen.ReplayDialog; + import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -13,14 +19,6 @@ import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; -import object.FlagImage; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -import screen.ReplayDialog; - public final class ReplayFileUtil implements Registry { public static final String FOLDER_PERSONAL_REPLAYS = "Personal"; @@ -144,7 +142,7 @@ public static void exportReplay(String filePath) RegistryUtil.clearNode(tempReplayStore); } - public static String saveImportedReplay() throws Throwable + public static String saveImportedReplay() { String directory = getDirectoryFromPreferences(); String filename = factoryFileNameForReplay(tempReplayStore); diff --git a/client/src/main/kotlin/MainUtil.kt b/client/src/main/kotlin/MainUtil.kt index 044b09b..ed872b5 100644 --- a/client/src/main/kotlin/MainUtil.kt +++ b/client/src/main/kotlin/MainUtil.kt @@ -8,10 +8,11 @@ import util.CoreRegistry.INSTANCE_STRING_DEVICE_ID import util.CoreRegistry.instance import util.OnlineConstants import utils.InjectedThings.logger +import utils.getUsername import java.util.* fun setLoggingContextFields() { - logger.addToContext(KEY_USERNAME, System.getProperty("user.name")) + logger.addToContext(KEY_USERNAME, getUsername()) logger.addToContext(KEY_APP_VERSION, OnlineConstants.ENTROPY_VERSION_NUMBER) logger.addToContext(KEY_OPERATING_SYSTEM, AbstractClient.operatingSystem) logger.addToContext(KEY_DEVICE_ID, getDeviceId()) diff --git a/core/src/main/java/util/CoreRegistry.java b/core/src/main/java/util/CoreRegistry.java index e1b191d..1630b50 100644 --- a/core/src/main/java/util/CoreRegistry.java +++ b/core/src/main/java/util/CoreRegistry.java @@ -5,8 +5,7 @@ public interface CoreRegistry { public static final Preferences instance = Preferences.userRoot().node("entropyInstance"); - - public static final String INSTANCE_STRING_USER_NAME = "userName"; + public static final String INSTANCE_BOOLEAN_ENABLE_EMAILS = "enableEmails"; public static final String INSTANCE_INT_REPLAY_CONVERSION = "replayConversion"; public static final String INSTANCE_STRING_DEVICE_ID = "deviceId"; diff --git a/core/src/main/java/util/Debug.java b/core/src/main/java/util/Debug.java index cecf4a3..2012aea 100644 --- a/core/src/main/java/util/Debug.java +++ b/core/src/main/java/util/Debug.java @@ -1,6 +1,8 @@ package util; +import utils.MainUtilKt; + import java.io.PrintWriter; import java.io.StringWriter; import java.sql.SQLException; @@ -310,7 +312,7 @@ public static void sendContentsAsEmailInSeparateThread(final String title, final } String fullTitle = title; - String username = instance.get(INSTANCE_STRING_USER_NAME, ""); + String username = MainUtilKt.getUsername(); if (!username.equals("")) { fullTitle += " - " + username; @@ -392,7 +394,7 @@ public static boolean sendBugReport(String description, String replication) { try { - String username = instance.get(INSTANCE_STRING_USER_NAME, ""); + String username = MainUtilKt.getUsername(); if (!username.equals("")) { description += " - " + username; diff --git a/core/src/main/kotlin/logging/Logger.kt b/core/src/main/kotlin/logging/Logger.kt index 0813923..f5ea7da 100644 --- a/core/src/main/kotlin/logging/Logger.kt +++ b/core/src/main/kotlin/logging/Logger.kt @@ -20,6 +20,7 @@ class Logger(private val destinations: List) { destinations.forEach { it.contextUpdated(loggingContext.toMap()) } } + @JvmOverloads fun logProgress(code: String, workDone: Long, workToDo: Long, percentageToLogAt: Int = 10) { // Convert 1 to 0.01, 50 to 0.5, etc. val percentageAsDecimal = percentageToLogAt.toDouble() / 100 diff --git a/core/src/main/kotlin/utils/MainUtil.kt b/core/src/main/kotlin/utils/MainUtil.kt new file mode 100644 index 0000000..882a56e --- /dev/null +++ b/core/src/main/kotlin/utils/MainUtil.kt @@ -0,0 +1,3 @@ +package utils + +fun getUsername(): String = System.getProperty("user.name") \ No newline at end of file From 21f7b9b034c5bde5e147996e63e1870c5e9bd5d5 Mon Sep 17 00:00:00 2001 From: Alyssa Date: Thu, 7 Dec 2023 08:31:54 +0000 Subject: [PATCH 2/2] fix ktlint --- core/src/main/kotlin/utils/MainUtil.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/kotlin/utils/MainUtil.kt b/core/src/main/kotlin/utils/MainUtil.kt index 882a56e..f03692a 100644 --- a/core/src/main/kotlin/utils/MainUtil.kt +++ b/core/src/main/kotlin/utils/MainUtil.kt @@ -1,3 +1,3 @@ package utils -fun getUsername(): String = System.getProperty("user.name") \ No newline at end of file +fun getUsername(): String = System.getProperty("user.name")