mirror of
https://github.com/OtusTeam/Spring.git
synced 2026-05-30 10:50:42 +00:00
some changes in examples
This commit is contained in:
+2
-1
@@ -1,11 +1,12 @@
|
||||
package ru.otus.ioservice.example.swing;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
@ConditionalOnBean(SwingIOService.class)
|
||||
@Service
|
||||
public class MessageSystem {
|
||||
private final LinkedBlockingQueue<String> pollQueue;
|
||||
|
||||
+11
-1
@@ -3,6 +3,7 @@ package ru.otus.ioservice.example.swing;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.plaf.FontUIResource;
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
@@ -26,25 +27,34 @@ public class PollMainForm extends JFrame {
|
||||
super("Poll");
|
||||
this.ms = ms;
|
||||
|
||||
FontUIResource tahoma16 = new FontUIResource("Tahoma", Font.BOLD, 16);
|
||||
UIManager.put("Label.font", tahoma16);
|
||||
UIManager.put("TextField.font", tahoma16);
|
||||
UIManager.put("Button.font", tahoma16);
|
||||
|
||||
runFlag = new AtomicBoolean(true);
|
||||
uiFlow = Executors.newSingleThreadExecutor();
|
||||
|
||||
GridLayout layout = new GridLayout(3, 1);
|
||||
contentPane = new JPanel(layout);
|
||||
contentPane.setBackground(Color.decode("#546E7A"));
|
||||
setContentPane(contentPane);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
inLabel = new JLabel("");
|
||||
inLabel.setForeground(Color.decode("#FFAB40"));
|
||||
contentPane.add(inLabel);
|
||||
|
||||
outTextField = new JTextField(15);
|
||||
outTextField.setColumns(20);
|
||||
outTextField.setForeground(Color.decode("#388E3C"));
|
||||
contentPane.add(outTextField);
|
||||
|
||||
outBtn = new JButton("Ответить");
|
||||
outBtn.addActionListener(e -> ms.putToPollQueue(outTextField.getText()));
|
||||
contentPane.add(outBtn);
|
||||
setOnCloseHandler();
|
||||
setSize(450, 100);
|
||||
setSize(450, 180);
|
||||
}
|
||||
|
||||
void init() {
|
||||
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
package ru.otus.testing.example.services;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Component
|
||||
public class ConsoleContext {
|
||||
private PrintStream out = System.out;
|
||||
private InputStream in = System.in;
|
||||
}
|
||||
+6
-3
@@ -1,7 +1,9 @@
|
||||
package ru.otus.testing.example.services;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Scanner;
|
||||
|
||||
@@ -11,9 +13,10 @@ public class OpenedConsoleIOService implements IOService {
|
||||
private final Scanner sc;
|
||||
|
||||
|
||||
public OpenedConsoleIOService(ConsoleContext ctx) {
|
||||
this.out = ctx.getOut();
|
||||
this.sc = new Scanner(ctx.getIn());
|
||||
public OpenedConsoleIOService(@Value("#{ T(java.lang.System).in}") InputStream in,
|
||||
@Value("#{ T(java.lang.System).out}") PrintStream out) {
|
||||
this.out = out;
|
||||
this.sc = new Scanner(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-3
@@ -20,7 +20,6 @@ class OpenedIOServiceTest {
|
||||
private static final String TEXT_TO_PRINT2 = "Все дозволено";
|
||||
|
||||
private ByteArrayOutputStream bos;
|
||||
private ConsoleContext consoleContext;
|
||||
private IOService ioService;
|
||||
|
||||
@BeforeEach
|
||||
@@ -28,8 +27,7 @@ class OpenedIOServiceTest {
|
||||
System.out.println(Thread.currentThread().getName());
|
||||
|
||||
bos = new ByteArrayOutputStream();
|
||||
consoleContext = new ConsoleContext(new PrintStream(bos), System.in);
|
||||
ioService = new OpenedConsoleIOService(consoleContext);
|
||||
ioService = new OpenedConsoleIOService(System.in, new PrintStream(bos));
|
||||
}
|
||||
|
||||
@DisplayName("должно печатать \"" + TEXT_TO_PRINT1 + "\"")
|
||||
|
||||
Reference in New Issue
Block a user