[97] | 1 | package com.framsticks.gui.console; |
---|
| 2 | |
---|
[98] | 3 | import java.awt.BorderLayout; |
---|
| 4 | import java.awt.event.ActionEvent; |
---|
| 5 | import java.awt.event.ActionListener; |
---|
| 6 | |
---|
| 7 | import javax.swing.Box; |
---|
| 8 | import javax.swing.BoxLayout; |
---|
| 9 | import javax.swing.JCheckBox; |
---|
| 10 | |
---|
[97] | 11 | import com.framsticks.communication.Connection; |
---|
| 12 | import com.framsticks.communication.ConnectionListener; |
---|
| 13 | import com.framsticks.params.annotations.AutoAppendAnnotation; |
---|
| 14 | import com.framsticks.params.annotations.FramsClassAnnotation; |
---|
| 15 | |
---|
| 16 | @FramsClassAnnotation |
---|
| 17 | public class TrackConsole extends Console implements ConnectionListener { |
---|
| 18 | |
---|
[98] | 19 | volatile boolean writeOut = true; |
---|
| 20 | volatile boolean writeIn = true; |
---|
| 21 | |
---|
[97] | 22 | public TrackConsole() { |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | @AutoAppendAnnotation |
---|
| 26 | public TrackConsole setConnection(Connection connection) { |
---|
| 27 | this.connection = connection; |
---|
| 28 | return this; |
---|
| 29 | } |
---|
| 30 | |
---|
| 31 | @Override |
---|
| 32 | protected void joinableStart() { |
---|
| 33 | super.joinableStart(); |
---|
| 34 | connection.getListeners().add(this); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | @Override |
---|
| 38 | protected void joinableInterrupt() { |
---|
| 39 | connection.getListeners().remove(this); |
---|
| 40 | super.joinableInterrupt(); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | @Override |
---|
| 44 | public void connectionOutgoing(String line) { |
---|
[98] | 45 | if (writeOut) { |
---|
| 46 | dispatchWrite(line); |
---|
| 47 | } |
---|
[97] | 48 | } |
---|
| 49 | |
---|
| 50 | @Override |
---|
| 51 | public void connectionIncomming(String line) { |
---|
[98] | 52 | if (writeIn) { |
---|
| 53 | dispatchWrite(line); |
---|
| 54 | } |
---|
[97] | 55 | } |
---|
| 56 | |
---|
[98] | 57 | @Override |
---|
| 58 | protected void initializeGui() { |
---|
| 59 | super.initializeGui(); |
---|
| 60 | |
---|
| 61 | final Box box = new Box(BoxLayout.LINE_AXIS); |
---|
| 62 | |
---|
| 63 | final JCheckBox outCheckbox = new JCheckBox(); |
---|
| 64 | outCheckbox.setText("Show out"); |
---|
| 65 | outCheckbox.setSelected(true); |
---|
| 66 | outCheckbox.addActionListener(new ActionListener() { |
---|
| 67 | @Override |
---|
| 68 | public void actionPerformed(ActionEvent arg0) { |
---|
| 69 | writeOut = outCheckbox.isSelected(); |
---|
| 70 | } |
---|
| 71 | }); |
---|
| 72 | |
---|
| 73 | final JCheckBox inCheckbox = new JCheckBox(); |
---|
| 74 | inCheckbox.setText("Show in"); |
---|
| 75 | inCheckbox.setSelected(true); |
---|
| 76 | inCheckbox.addActionListener(new ActionListener() { |
---|
| 77 | @Override |
---|
| 78 | public void actionPerformed(ActionEvent arg0) { |
---|
| 79 | writeIn = inCheckbox.isSelected(); |
---|
| 80 | } |
---|
| 81 | }); |
---|
| 82 | |
---|
| 83 | box.add(outCheckbox); |
---|
| 84 | box.add(Box.createHorizontalStrut(10)); |
---|
| 85 | box.add(inCheckbox); |
---|
| 86 | |
---|
| 87 | panel.add(box, BorderLayout.PAGE_END); |
---|
| 88 | } |
---|
| 89 | |
---|
[97] | 90 | } |
---|