12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package holeg.ui;
- import holeg.HolegGateway;
- import holeg.HolegPowerFlowContext;
- import javax.swing.*;
- import java.awt.*;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.io.PrintStream;
- import java.nio.charset.StandardCharsets;
- public class FlowTableWindow extends JDialog {
- private JTextArea textArea;
- public FlowTableWindow(Frame owner) {
- super(owner);
- setTitle("HOLEG: Power flow table");
- setSize(500, 600);
- textArea = (JTextArea) add(new JTextArea("Updating..."));
- }
- public void update() {
- try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
- final String utf8 = StandardCharsets.UTF_8.name();
- try (PrintStream ps = new PrintStream(stream, true, utf8)) {
- for (HolegPowerFlowContext context : HolegGateway.getALlContext()) {
- synchronized (context.lock) {
- if (context.result != null && context.problem != null) {
- context.result.printTo(context.problem, ps, "M");
- }
- }
- }
- }
- String data = stream.toString(utf8);
- textArea.setText(data);
- } catch (IOException e) {
- e.printStackTrace();
- textArea.setText(e.toString());
- }
- doLayout();
- }
- }
|