diff --git a/src/main/java/mpo/dayon/assistant/AssistantRunner.java b/src/main/java/mpo/dayon/assistant/AssistantRunner.java index 1b7777b8..cebdbac5 100644 --- a/src/main/java/mpo/dayon/assistant/AssistantRunner.java +++ b/src/main/java/mpo/dayon/assistant/AssistantRunner.java @@ -13,15 +13,12 @@ public static void main(String[] args) { private static String[] appendAssistant(String[] args) { String[] combined = Arrays.copyOf(args, args.length + 1); - String[] additional = new String[1]; - additional[0] = "assistant"; + String[] additional = new String[]{"assistant"}; System.arraycopy(additional, 0, combined, args.length, 1); return combined; } public static void launchAssistant() { - final Assistant assistant = new Assistant(); - assistant.configure(); - assistant.start(); + new Assistant(); } } diff --git a/src/main/java/mpo/dayon/assistant/gui/Assistant.java b/src/main/java/mpo/dayon/assistant/gui/Assistant.java index 367edeaf..15e0f37e 100644 --- a/src/main/java/mpo/dayon/assistant/gui/Assistant.java +++ b/src/main/java/mpo/dayon/assistant/gui/Assistant.java @@ -59,8 +59,6 @@ public class Assistant implements ClipboardOwner { private final NetworkAssistantEngine network; - private final ControlEngine control; - private final BitCounter receivedBitCounter; private final TileCounter receivedTileCounter; @@ -73,7 +71,7 @@ public class Assistant implements ClipboardOwner { private AssistantFrame frame; - private AssistantActions actions; + private final AssistantActions actions; private AssistantConfiguration configuration; @@ -91,8 +89,6 @@ public class Assistant implements ClipboardOwner { private int prevHeight = -1; - private final Set> counters; - private final AtomicBoolean fitToScreenActivated = new AtomicBoolean(false); private String token; @@ -117,7 +113,7 @@ public Assistant() { captureCompressionCounter = new CaptureCompressionCounter("captureCompression", translate("captureCompression")); captureCompressionCounter.start(1000); - counters = new HashSet<>(Arrays.asList(receivedBitCounter, receivedTileCounter, skippedTileCounter, mergedTileCounter, captureCompressionCounter)); + Set> counters = new HashSet<>(Arrays.asList(receivedBitCounter, receivedTileCounter, skippedTileCounter, mergedTileCounter, captureCompressionCounter)); DeCompressorEngine decompressor = new DeCompressorEngine(new MyDeCompressorEngineListener()); decompressor.start(8); @@ -129,14 +125,9 @@ public Assistant() { network.configure(networkConfiguration); network.addListener(new MyNetworkAssistantEngineListener()); - control = new ControlEngine(network); - control.start(); - captureEngineConfiguration = new CaptureEngineConfiguration(); compressorEngineConfiguration = new CompressorEngineConfiguration(); - } - public void configure() { this.configuration = new AssistantConfiguration(); final String lnf = configuration.getLookAndFeelClassName(); try { @@ -144,13 +135,11 @@ public void configure() { } catch (Exception ex) { Log.warn("Could not set the [" + lnf + "] L&F!", ex); } - } - public void start() { actions = createAssistantActions(); frame = new AssistantFrame(actions, counters); FatalErrorHandler.attachFrame(frame); - frame.addListener(control); + frame.addListener(new ControlEngine(network)); frame.setVisible(true); initUpnp(); } @@ -716,32 +705,33 @@ private JMenu createLookAndFeelSubmenu() { submenu.setIcon(getOrCreateIcon(ImageNames.LNF)); submenu.setToolTipText(translate("lnf.switch")); - final LookAndFeel current = UIManager.getLookAndFeel(); - submenu.add(new JMenuItem(current.getName())); + final String current = UIManager.getLookAndFeel().getName(); + submenu.add(new JMenuItem(current)); submenu.addSeparator(); for (final UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { - if (info.getName().equals(current.getName())) { + String lnf = info.getName(); + if (lnf.equals(current)) { continue; } - final JMenuItem mi = new JMenuItem(info.getName()); - mi.addActionListener(ev1 -> switchLookAndFeel(info)); - mi.setText(info.getName()); + final JMenuItem mi = new JMenuItem(lnf); + mi.addActionListener(ev1 -> switchLookAndFeel(lnf)); + mi.setText(lnf); submenu.add(mi); } return submenu; } - private void switchLookAndFeel(UIManager.LookAndFeelInfo lnf) { + private void switchLookAndFeel(String lnf) { try { if (frame != null) { - UIManager.setLookAndFeel(lnf.getClassName()); + UIManager.setLookAndFeel(lnf); SwingUtilities.updateComponentTreeUI(frame); - configuration = new AssistantConfiguration(lnf.getClassName()); + configuration = new AssistantConfiguration(lnf); configuration.persist(); } } catch (Exception ex) { - Log.warn("Could not set the L&F [" + lnf.getName() + "]", ex); + Log.warn(format("Could not set the L&F [%s]", lnf), ex); } } diff --git a/src/main/java/mpo/dayon/assisted/AssistedRunner.java b/src/main/java/mpo/dayon/assisted/AssistedRunner.java index 06e5cbda..1794583e 100644 --- a/src/main/java/mpo/dayon/assisted/AssistedRunner.java +++ b/src/main/java/mpo/dayon/assisted/AssistedRunner.java @@ -25,7 +25,6 @@ public static void main(String[] args) { public static void launchAssisted(String assistantHost, String assistantPort) { final Assisted assisted = new Assisted(); - assisted.setup(); // cli args have precedence if (assistantHost == null || assistantPort == null) { final Map config = readPresetFile(); diff --git a/src/main/java/mpo/dayon/assisted/gui/Assisted.java b/src/main/java/mpo/dayon/assisted/gui/Assisted.java index 35a0f79f..fe115ea9 100644 --- a/src/main/java/mpo/dayon/assisted/gui/Assisted.java +++ b/src/main/java/mpo/dayon/assisted/gui/Assisted.java @@ -55,12 +55,12 @@ public class Assisted implements Subscriber, ClipboardOwner { private final AtomicBoolean shareAllScreens = new AtomicBoolean(false); - public void setup() { + public Assisted() { final String lnf = getDefaultLookAndFeel(); try { UIManager.setLookAndFeel(lnf); } catch (Exception ex) { - Log.warn(format("Could not set the [%s] L&F", lnf), ex); + Log.warn(format("Could not set the L&F [%s]", lnf), ex); } } diff --git a/src/test/java/mpo/dayon/assisted/gui/AssistedTest.java b/src/test/java/mpo/dayon/assisted/gui/AssistedTest.java index 4d950102..a88b2961 100644 --- a/src/test/java/mpo/dayon/assisted/gui/AssistedTest.java +++ b/src/test/java/mpo/dayon/assisted/gui/AssistedTest.java @@ -17,8 +17,8 @@ class AssistedTest { - Assisted assisted; - LogAppender logApp; + private Assisted assisted; + private LogAppender logApp; @BeforeEach void init() throws NoSuchFieldException, IllegalAccessException { @@ -33,13 +33,10 @@ void init() throws NoSuchFieldException, IllegalAccessException { void startWithoutConfig() { // given if (!GraphicsEnvironment.isHeadless()) { - // when - boolean value = assisted.start("localhost", null, false); - - // then + // when then + assertTrue(assisted.start("localhost", null, false)); verify(logApp).append(LogLevel.INFO, "Assisted start"); verify(logApp, never()).append(LogLevel.INFO, "Autoconfigured [ip:localhost][port:null]"); - assertTrue(value); } } @@ -47,13 +44,10 @@ void startWithoutConfig() { void startAutoconnect() { // given if (!GraphicsEnvironment.isHeadless()) { - // when - boolean value = assisted.start("localhost", "12345", true); - - // then + // when then + assertTrue(assisted.start("localhost", "12345", true)); verify(logApp).append(LogLevel.INFO, "Autoconfigured [ip:localhost][port:12345]"); verify(logApp).append(LogLevel.INFO, "Connecting to [localhost][12345]..."); - assertTrue(value); } } @@ -61,13 +55,10 @@ void startAutoconnect() { void startAutoconnectFalse() { // given if (!GraphicsEnvironment.isHeadless()) { - // when - boolean value = assisted.start("localhost", "23456", false); - - // then + // when then + assertTrue(assisted.start("localhost", "23456", false)); verify(logApp).append(LogLevel.INFO, "Autoconfigured [ip:localhost][port:23456]"); verify(logApp, never()).append(LogLevel.INFO, "Connecting to [localhost][23456]..."); - assertTrue(value); } } } \ No newline at end of file