Minor refactoring

This commit is contained in:
Eiren Rain committed 2021-10-05 14:18:13 +03:00
1 parent f3e2b2ca40
commit 4f042de2f4
11 files changed
+10 -12

No files matched your search

@@ -0,0 +1,24 @@
package dev.slimevr.gui;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
public abstract class AbstractComponentListener implements ComponentListener {
@Override
public void componentResized(ComponentEvent e) {
}
@Override
public void componentMoved(ComponentEvent e) {
}
@Override
public void componentShown(ComponentEvent e) {
}
@Override
public void componentHidden(ComponentEvent e) {
}
}
@@ -0,0 +1,35 @@
package dev.slimevr.gui;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public abstract class AbstractWindowListener implements WindowListener {
@Override
public void windowOpened(WindowEvent e) {
}
@Override
public void windowClosing(WindowEvent e) {
}
@Override
public void windowClosed(WindowEvent e) {
}
@Override
public void windowIconified(WindowEvent e) {
}
@Override
public void windowDeiconified(WindowEvent e) {
}
@Override
public void windowActivated(WindowEvent e) {
}
@Override
public void windowDeactivated(WindowEvent e) {
}
}
@@ -13,7 +13,6 @@ import java.util.List;
import java.util.Map.Entry;
import java.util.concurrent.Future;
import io.eiren.gui.SkeletonConfig;
import io.eiren.util.StringUtils;
import io.eiren.util.ann.AWTThread;
import io.eiren.util.collections.FastList;
@@ -0,0 +1,90 @@
package dev.slimevr.gui;
import java.awt.Container;
import java.awt.event.MouseEvent;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;
import javax.swing.event.MouseInputAdapter;
import dev.slimevr.gui.swing.EJBox;
import io.eiren.util.ann.AWTThread;
import io.eiren.vr.trackers.CalibratingTracker;
import io.eiren.vr.trackers.Tracker;
public class CalibrationWindow extends JFrame {
public final Tracker tracker;
private JTextArea currentCalibration;
private JTextArea newCalibration;
private JButton calibrateButton;
public CalibrationWindow(Tracker t) {
super(t.getName() + " calibration");
this.tracker = t;
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.LINE_AXIS));
build();
}
public void currentCalibrationRecieved(String str) {
java.awt.EventQueue.invokeLater(() -> {
currentCalibration.setText(str);
pack();
});
}
public void newCalibrationRecieved(String str) {
java.awt.EventQueue.invokeLater(() -> {
calibrateButton.setText("Calibrate");
newCalibration.setText(str);
pack();
});
}
@AWTThread
private void build() {
Container pane = getContentPane();
pane.add(calibrateButton = new JButton("Calibrate") {{
addMouseListener(new MouseInputAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
calibrateButton.setText("Calibrating...");
((CalibratingTracker) tracker).startCalibration(CalibrationWindow.this::newCalibrationRecieved);
}
});
}});
pane.add(new EJBox(BoxLayout.PAGE_AXIS) {{
setBorder(new EmptyBorder(i(5)));
add(new JLabel("Current calibration"));
add(currentCalibration = new JTextArea(10, 25));
((CalibratingTracker) tracker).requestCalibrationData(CalibrationWindow.this::currentCalibrationRecieved);
}});
pane.add(new EJBox(BoxLayout.PAGE_AXIS) {{
setBorder(new EmptyBorder(i(5)));
add(new JLabel("New calibration"));
add(newCalibration = new JTextArea(10, 25));
}});
// Pack and display
pack();
setLocationRelativeTo(null);
setVisible(true);
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
toFront();
repaint();
}
});
}
}
@@ -0,0 +1,91 @@
package dev.slimevr.gui;
import java.awt.Font;
import java.text.AttributedCharacterIterator.Attribute;
import java.util.Map;
public class ScalableFont extends Font {
protected float scale = 1.0f;
protected int initSize;
protected float initPointSize;
public ScalableFont(Map<? extends Attribute, ?> attributes) {
super(attributes);
this.initSize = this.size;
this.initPointSize = this.pointSize;
}
public ScalableFont(Font font) {
super(font);
if(font instanceof ScalableFont) {
ScalableFont sourceFont = (ScalableFont)font;
this.initSize = sourceFont.getInitSize();
this.initPointSize = sourceFont.getInitSize2D();
this.size = this.initSize;
this.pointSize = this.initPointSize;
} else {
this.initSize = this.size;
this.initPointSize = this.pointSize;
}
}
public ScalableFont(Font font, float scale) {
super(font);
if(font instanceof ScalableFont) {
ScalableFont sourceFont = (ScalableFont)font;
this.initSize = sourceFont.getInitSize();
this.initPointSize = sourceFont.getInitSize2D();
} else {
this.initSize = this.size;
this.initPointSize = this.pointSize;
}
setScale(scale);
}
public ScalableFont(String name, int style, int size) {
super(name, style, size);
this.initSize = this.size;
this.initPointSize = this.pointSize;
}
public ScalableFont(String name, int style, int size, float scale) {
super(name, style, size);
this.initSize = this.size;
this.initPointSize = this.pointSize;
setScale(scale);
}
public int getInitSize() {
return initSize;
}
public float getInitSize2D() {
return initPointSize;
}
public float getScale() {
return scale;
}
private void setScale(float scale) {
this.scale = scale;
float newPointSize = initPointSize * scale;
this.size = (int)(newPointSize + 0.5);
this.pointSize = newPointSize;
}
}
@@ -0,0 +1,249 @@
package dev.slimevr.gui;
import java.awt.event.MouseEvent;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.event.MouseInputAdapter;
import dev.slimevr.gui.swing.ButtonTimer;
import dev.slimevr.gui.swing.EJBagNoStretch;
import io.eiren.util.StringUtils;
import io.eiren.util.ann.ThreadSafe;
import io.eiren.vr.VRServer;
import io.eiren.vr.processor.HumanSkeleton;
public class SkeletonConfig extends EJBagNoStretch {
private final VRServer server;
private final VRServerGUI gui;
private final AutoBoneWindow autoBone;
private Map<String, SkeletonLabel> labels = new HashMap<>();
public SkeletonConfig(VRServer server, VRServerGUI gui) {
super(false, true);
this.server = server;
this.gui = gui;
this.autoBone = new AutoBoneWindow(server, this);
setAlignmentY(TOP_ALIGNMENT);
server.humanPoseProcessor.addSkeletonUpdatedCallback(this::skeletonUpdated);
skeletonUpdated(null);
}
@ThreadSafe
public void skeletonUpdated(HumanSkeleton newSkeleton) {
java.awt.EventQueue.invokeLater(() -> {
removeAll();
int row = 0;
/**
add(new JCheckBox("Extended pelvis model") {{
addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED) {//checkbox has been selected
if(newSkeleton != null && newSkeleton instanceof HumanSkeletonWithLegs) {
HumanSkeletonWithLegs hswl = (HumanSkeletonWithLegs) newSkeleton;
hswl.setSkeletonConfigBoolean("Extended pelvis model", true);
}
} else {
if(newSkeleton != null && newSkeleton instanceof HumanSkeletonWithLegs) {
HumanSkeletonWithLegs hswl = (HumanSkeletonWithLegs) newSkeleton;
hswl.setSkeletonConfigBoolean("Extended pelvis model", false);
}
}
}
});
if(newSkeleton != null && newSkeleton instanceof HumanSkeletonWithLegs) {
HumanSkeletonWithLegs hswl = (HumanSkeletonWithLegs) newSkeleton;
setSelected(hswl.getSkeletonConfigBoolean("Extended pelvis model"));
}
}}, s(c(0, row, 2), 3, 1));
row++;
//*/
/*
add(new JCheckBox("Extended knee model") {{
addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED) {//checkbox has been selected
if(newSkeleton != null && newSkeleton instanceof HumanSkeletonWithLegs) {
HumanSkeletonWithLegs hswl = (HumanSkeletonWithLegs) newSkeleton;
hswl.setSkeletonConfigBoolean("Extended knee model", true);
}
} else {
if(newSkeleton != null && newSkeleton instanceof HumanSkeletonWithLegs) {
HumanSkeletonWithLegs hswl = (HumanSkeletonWithLegs) newSkeleton;
hswl.setSkeletonConfigBoolean("Extended knee model", false);
}
}
}
});
if(newSkeleton != null && newSkeleton instanceof HumanSkeletonWithLegs) {
HumanSkeletonWithLegs hswl = (HumanSkeletonWithLegs) newSkeleton;
setSelected(hswl.getSkeletonConfigBoolean("Extended knee model"));
}
}}, s(c(0, row, 2), 3, 1));
row++;
//*/
add(new TimedResetButton("Reset All", "All"), s(c(1, row, 2), 3, 1));
add(new JButton("Auto") {{
addMouseListener(new MouseInputAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
autoBone.setVisible(true);
autoBone.toFront();
}
});
}}, s(c(4, row, 2), 3, 1));
row++;
add(new JLabel("Chest"), c(0, row, 2));
add(new AdjButton("+", "Chest", 0.01f), c(1, row, 2));
add(new SkeletonLabel("Chest"), c(2, row, 2));
add(new AdjButton("-", "Chest", -0.01f), c(3, row, 2));
add(new ResetButton("Reset", "Chest"), c(4, row, 2));
row++;
add(new JLabel("Waist"), c(0, row, 2));
add(new AdjButton("+", "Waist", 0.01f), c(1, row, 2));
add(new SkeletonLabel("Waist"), c(2, row, 2));
add(new AdjButton("-", "Waist", -0.01f), c(3, row, 2));
add(new TimedResetButton("Reset", "Waist"), c(4, row, 2));
row++;
add(new JLabel("Hips width"), c(0, row, 2));
add(new AdjButton("+", "Hips width", 0.01f), c(1, row, 2));
add(new SkeletonLabel("Hips width"), c(2, row, 2));
add(new AdjButton("-", "Hips width", -0.01f), c(3, row, 2));
add(new ResetButton("Reset", "Hips width"), c(4, row, 2));
row++;
add(new JLabel("Legs length"), c(0, row, 2));
add(new AdjButton("+", "Legs length", 0.01f), c(1, row, 2));
add(new SkeletonLabel("Legs length"), c(2, row, 2));
add(new AdjButton("-", "Legs length", -0.01f), c(3, row, 2));
add(new TimedResetButton("Reset", "Legs length"), c(4, row, 2));
row++;
add(new JLabel("Knee height"), c(0, row, 2));
add(new AdjButton("+", "Knee height", 0.01f), c(1, row, 2));
add(new SkeletonLabel("Knee height"), c(2, row, 2));
add(new AdjButton("-", "Knee height", -0.01f), c(3, row, 2));
add(new TimedResetButton("Reset", "Knee height"), c(4, row, 2));
row++;
add(new JLabel("Foot length"), c(0, row, 2));
add(new AdjButton("+", "Foot length", 0.01f), c(1, row, 2));
add(new SkeletonLabel("Foot length"), c(2, row, 2));
add(new AdjButton("-", "Foot length", -0.01f), c(3, row, 2));
add(new ResetButton("Reset", "Foot length"), c(4, row, 2));
row++;
add(new JLabel("Head offset"), c(0, row, 2));
add(new AdjButton("+", "Head", 0.01f), c(1, row, 2));
add(new SkeletonLabel("Head"), c(2, row, 2));
add(new AdjButton("-", "Head", -0.01f), c(3, row, 2));
add(new ResetButton("Reset", "Head"), c(4, row, 2));
row++;
add(new JLabel("Neck length"), c(0, row, 2));
add(new AdjButton("+", "Neck", 0.01f), c(1, row, 2));
add(new SkeletonLabel("Neck"), c(2, row, 2));
add(new AdjButton("-", "Neck", -0.01f), c(3, row, 2));
add(new ResetButton("Reset", "Neck"), c(4, row, 2));
row++;
add(new JLabel("Virtual waist"), c(0, row, 2));
add(new AdjButton("+", "Virtual waist", 0.01f), c(1, row, 2));
add(new SkeletonLabel("Virtual waist"), c(2, row, 2));
add(new AdjButton("-", "Virtual waist", -0.01f), c(3, row, 2));
add(new ResetButton("Reset", "Virtual waist"), c(4, row, 2));
row++;
gui.refresh();
});
}
@ThreadSafe
public void refreshAll() {
java.awt.EventQueue.invokeLater(() -> {
labels.forEach((joint, label) -> {
label.setText(StringUtils.prettyNumber(server.humanPoseProcessor.getSkeletonConfig(joint) * 100, 0));
});
});
}
private void change(String joint, float diff) {
float current = server.humanPoseProcessor.getSkeletonConfig(joint);
server.humanPoseProcessor.setSkeletonConfig(joint, current + diff);
server.saveConfig();
labels.get(joint).setText(StringUtils.prettyNumber((current + diff) * 100, 0));
}
private void reset(String joint) {
server.humanPoseProcessor.resetSkeletonConfig(joint);
server.saveConfig();
if(!"All".equals(joint)) {
float current = server.humanPoseProcessor.getSkeletonConfig(joint);
labels.get(joint).setText(StringUtils.prettyNumber((current) * 100, 0));
} else {
labels.forEach((jnt, label) -> {
float current = server.humanPoseProcessor.getSkeletonConfig(jnt);
label.setText(StringUtils.prettyNumber((current) * 100, 0));
});
}
}
private class SkeletonLabel extends JLabel {
public SkeletonLabel(String joint) {
super(StringUtils.prettyNumber(server.humanPoseProcessor.getSkeletonConfig(joint) * 100, 0));
labels.put(joint, this);
}
}
private class AdjButton extends JButton {
public AdjButton(String text, String joint, float diff) {
super(text);
addMouseListener(new MouseInputAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
change(joint, diff);
}
});
}
}
private class ResetButton extends JButton {
public ResetButton(String text, String joint) {
super(text);
addMouseListener(new MouseInputAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
reset(joint);
}
});
}
}
private class TimedResetButton extends JButton {
public TimedResetButton(String text, String joint) {
super(text);
addMouseListener(new MouseInputAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
ButtonTimer.runTimer(TimedResetButton.this, 3, text, () -> reset(joint));
}
});
}
}
}
@@ -0,0 +1,110 @@
package dev.slimevr.gui;
import java.awt.GridBagConstraints;
import java.util.List;
import javax.swing.JLabel;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import dev.slimevr.gui.swing.EJBagNoStretch;
import io.eiren.util.StringUtils;
import io.eiren.util.ann.ThreadSafe;
import io.eiren.util.ann.VRServerThread;
import io.eiren.util.collections.FastList;
import io.eiren.vr.VRServer;
import io.eiren.vr.processor.HumanSkeleton;
import io.eiren.vr.processor.TransformNode;
public class SkeletonList extends EJBagNoStretch {
private static final long UPDATE_DELAY = 50;
Quaternion q = new Quaternion();
Vector3f v = new Vector3f();
float[] angles = new float[3];
private final VRServerGUI gui;
private final List<NodeStatus> nodes = new FastList<>();
private long lastUpdate = 0;
public SkeletonList(VRServer server, VRServerGUI gui) {
super(false, true);
this.gui = gui;
setAlignmentY(TOP_ALIGNMENT);
server.addSkeletonUpdatedCallback(this::skeletonUpdated);
}
@ThreadSafe
public void skeletonUpdated(HumanSkeleton newSkeleton) {
java.awt.EventQueue.invokeLater(() -> {
removeAll();
nodes.clear();
add(new JLabel("Joint"), c(0, 0, 2));
add(new JLabel("X"), c(1, 0, 2));
add(new JLabel("Y"), c(2, 0, 2));
add(new JLabel("Z"), c(3, 0, 2));
add(new JLabel("Pitch"), c(4, 0, 2));
add(new JLabel("Yaw"), c(5, 0, 2));
add(new JLabel("Roll"), c(6, 0, 2));
newSkeleton.getRootNode().depthFirstTraversal((node) -> {
int n = nodes.size();
nodes.add(new NodeStatus(node, n + 1));
});
gui.refresh();
});
}
@VRServerThread
public void updateBones() {
if(lastUpdate + UPDATE_DELAY > System.currentTimeMillis())
return;
lastUpdate = System.currentTimeMillis();
java.awt.EventQueue.invokeLater(() -> {
for(int i = 0; i < nodes.size(); ++i)
nodes.get(i).update();
});
}
private class NodeStatus {
TransformNode n;
JLabel x;
JLabel y;
JLabel z;
JLabel a1;
JLabel a2;
JLabel a3;
public NodeStatus(TransformNode node, int n) {
this.n = node;
add(new JLabel(node.getName()), c(0, n, 2, GridBagConstraints.FIRST_LINE_START));
add(x = new JLabel("0"), c(1, n, 2, GridBagConstraints.FIRST_LINE_START));
add(y = new JLabel("0"), c(2, n, 2, GridBagConstraints.FIRST_LINE_START));
add(z = new JLabel("0"), c(3, n, 2, GridBagConstraints.FIRST_LINE_START));
add(a1 = new JLabel("0"), c(4, n, 2, GridBagConstraints.FIRST_LINE_START));
add(a2 = new JLabel("0"), c(5, n, 2, GridBagConstraints.FIRST_LINE_START));
add(a3 = new JLabel("0"), c(6, n, 2, GridBagConstraints.FIRST_LINE_START));
}
public void update() {
n.worldTransform.getTranslation(v);
n.worldTransform.getRotation(q);
q.toAngles(angles);
x.setText(StringUtils.prettyNumber(v.x, 2));
y.setText(StringUtils.prettyNumber(v.y, 2));
z.setText(StringUtils.prettyNumber(v.z, 2));
a1.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0));
a2.setText(StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0));
a3.setText(StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
}
}
}
@@ -0,0 +1,342 @@
package dev.slimevr.gui;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import dev.slimevr.gui.swing.EJBagNoStretch;
import dev.slimevr.gui.swing.EJBoxNoStretch;
import io.eiren.util.StringUtils;
import io.eiren.util.ann.AWTThread;
import io.eiren.util.ann.ThreadSafe;
import io.eiren.util.collections.FastList;
import io.eiren.vr.VRServer;
import io.eiren.vr.trackers.ReferenceAdjustedTracker;
import io.eiren.vr.trackers.ComputedTracker;
import io.eiren.vr.trackers.HMDTracker;
import io.eiren.vr.trackers.IMUTracker;
import io.eiren.vr.trackers.Tracker;
import io.eiren.vr.trackers.TrackerConfig;
import io.eiren.vr.trackers.TrackerMountingRotation;
import io.eiren.vr.trackers.TrackerPosition;
import io.eiren.vr.trackers.TrackerWithBattery;
import io.eiren.vr.trackers.TrackerWithTPS;
public class TrackersList extends EJBoxNoStretch {
private static final long UPDATE_DELAY = 50;
Quaternion q = new Quaternion();
Vector3f v = new Vector3f();
float[] angles = new float[3];
private List<TrackerPanel> trackers = new FastList<>();
private final VRServer server;
private final VRServerGUI gui;
private long lastUpdate = 0;
public TrackersList(VRServer server, VRServerGUI gui) {
super(BoxLayout.PAGE_AXIS, false, true);
this.server = server;
this.gui = gui;
setAlignmentY(TOP_ALIGNMENT);
server.addNewTrackerConsumer(this::newTrackerAdded);
}
@AWTThread
private void build() {
removeAll();
trackers.sort((tr1, tr2) -> getTrackerSort(tr1.t) - getTrackerSort(tr2.t));
Class<? extends Tracker> currentClass = null;
EJBoxNoStretch line = null;
boolean first = true;
for(int i = 0; i < trackers.size(); ++i) {
TrackerPanel tr = trackers.get(i);
Tracker t = tr.t;
if(t instanceof ReferenceAdjustedTracker)
t = ((ReferenceAdjustedTracker<?>) t).getTracker();
if(currentClass != t.getClass()) {
currentClass = t.getClass();
if(line != null)
line.add(Box.createHorizontalGlue());
line = null;
line = new EJBoxNoStretch(BoxLayout.LINE_AXIS, false, true);
line.add(Box.createHorizontalGlue());
JLabel nameLabel;
line.add(nameLabel = new JLabel(currentClass.getSimpleName()));
nameLabel.setFont(nameLabel.getFont().deriveFont(Font.BOLD));
line.add(Box.createHorizontalGlue());
add(line);
line = null;
}
if(line == null) {
line = new EJBoxNoStretch(BoxLayout.LINE_AXIS, false, true);
add(Box.createVerticalStrut(3));
add(line);
first = true;
} else {
line.add(Box.createHorizontalStrut(3));
first = false;
}
tr.build();
line.add(tr);
if(!first)
line = null;
}
validate();
gui.refresh();
}
@ThreadSafe
public void updateTrackers() {
if(lastUpdate + UPDATE_DELAY > System.currentTimeMillis())
return;
lastUpdate = System.currentTimeMillis();
java.awt.EventQueue.invokeLater(() -> {
for(int i = 0; i < trackers.size(); ++i)
trackers.get(i).update();
});
}
@ThreadSafe
public void newTrackerAdded(Tracker t) {
java.awt.EventQueue.invokeLater(() -> {
trackers.add(new TrackerPanel(t));
build();
});
}
private class TrackerPanel extends EJBagNoStretch {
final Tracker t;
JLabel position;
JLabel rotation;
JLabel status;
JLabel tps;
JLabel bat;
JLabel ping;
JLabel raw;
JLabel rawMag;
JLabel calibration;
JLabel magAccuracy;
JLabel adj;
JLabel adjYaw;
JLabel correction;
@AWTThread
public TrackerPanel(Tracker t) {
super(false, true);
this.t = t;
}
@SuppressWarnings("unchecked")
@AWTThread
public TrackerPanel build() {
int row = 0;
Tracker realTracker = t;
if(t instanceof ReferenceAdjustedTracker)
realTracker = ((ReferenceAdjustedTracker<? extends Tracker>) t).getTracker();
removeAll();
JLabel nameLabel;
add(nameLabel = new JLabel(t.getDescriptiveName()), s(c(0, row, 2, GridBagConstraints.FIRST_LINE_START), 4, 1));
nameLabel.setFont(nameLabel.getFont().deriveFont(Font.BOLD));
row++;
if(t.userEditable()) {
TrackerConfig cfg = server.getTrackerConfig(t);
JComboBox<String> desSelect;
add(desSelect = new JComboBox<>(), s(c(0, row, 2, GridBagConstraints.FIRST_LINE_START), 2, 1));
for(TrackerPosition p : TrackerPosition.values) {
desSelect.addItem(p.name());
}
if(cfg.designation != null) {
TrackerPosition p = TrackerPosition.getByDesignation(cfg.designation);
if(p != null)
desSelect.setSelectedItem(p.name());
}
desSelect.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
TrackerPosition p = TrackerPosition.valueOf(String.valueOf(desSelect.getSelectedItem()));
t.setBodyPosition(p);
server.trackerUpdated(t);
}
});
if(realTracker instanceof IMUTracker) {
IMUTracker imu = (IMUTracker) realTracker;
TrackerMountingRotation tr = imu.getMountingRotation();
JComboBox<String> mountSelect;
add(mountSelect = new JComboBox<>(), s(c(2, row, 2, GridBagConstraints.FIRST_LINE_START), 2, 1));
for(TrackerMountingRotation p : TrackerMountingRotation.values) {
mountSelect.addItem(p.name());
}
if(tr != null) {
mountSelect.setSelectedItem(tr.name());
} else {
mountSelect.setSelectedItem(TrackerMountingRotation.BACK.name());
}
mountSelect.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
TrackerMountingRotation tr = TrackerMountingRotation.valueOf(String.valueOf(mountSelect.getSelectedItem()));
imu.setMountingRotation(tr);
server.trackerUpdated(t);
}
});
}
row++;
}
if(t.hasRotation())
add(new JLabel("Rotation"), c(0, row, 2, GridBagConstraints.FIRST_LINE_START));
if(t.hasPosition())
add(new JLabel("Position"), c(1, row, 2, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("TPS"), c(3, row, 2, GridBagConstraints.FIRST_LINE_START));
if(realTracker instanceof IMUTracker) {
add(new JLabel("Ping"), c(2, row, 2, GridBagConstraints.FIRST_LINE_START));
}
row++;
if(t.hasRotation())
add(rotation = new JLabel("0 0 0"), c(0, row, 2, GridBagConstraints.FIRST_LINE_START));
if(t.hasPosition())
add(position = new JLabel("0 0 0"), c(1, row, 2, GridBagConstraints.FIRST_LINE_START));
if(realTracker instanceof IMUTracker) {
add(ping = new JLabel(""), c(2, row, 2, GridBagConstraints.FIRST_LINE_START));
}
if(realTracker instanceof TrackerWithTPS) {
add(tps = new JLabel("0"), c(3, row, 2, GridBagConstraints.FIRST_LINE_START));
} else {
add(new JLabel(""), c(3, row, 2, GridBagConstraints.FIRST_LINE_START));
}
row++;
add(new JLabel("Status:"), c(0, row, 2, GridBagConstraints.FIRST_LINE_START));
add(status = new JLabel(t.getStatus().toString().toLowerCase()), c(1, row, 2, GridBagConstraints.FIRST_LINE_START));
if(realTracker instanceof TrackerWithBattery) {
add(new JLabel("Battery:"), c(2, row, 2, GridBagConstraints.FIRST_LINE_START));
add(bat = new JLabel("0"), c(3, row, 2, GridBagConstraints.FIRST_LINE_START));
}
row++;
add(new JLabel("Raw:"), c(0, row, 2, GridBagConstraints.FIRST_LINE_START));
add(raw = new JLabel("0 0 0"), s(c(1, row, 2, GridBagConstraints.FIRST_LINE_START), 3, 1));
row++;
if(realTracker instanceof IMUTracker) {
add(new JLabel("Raw mag:"), c(0, row, 2, GridBagConstraints.FIRST_LINE_START));
add(rawMag = new JLabel("0 0 0"), s(c(1, row, 2, GridBagConstraints.FIRST_LINE_START), 3, 1));
row++;
add(new JLabel("Cal:"), c(0, row, 2, GridBagConstraints.FIRST_LINE_START));
add(calibration = new JLabel("0"), c(1, row, 2, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("Mag acc:"), c(2, row, 2, GridBagConstraints.FIRST_LINE_START));
add(magAccuracy = new JLabel("0°"), c(3, row, 2, GridBagConstraints.FIRST_LINE_START));
row++;
add(new JLabel("Correction:"), c(0, row, 2, GridBagConstraints.FIRST_LINE_START));
add(correction = new JLabel("0 0 0"), s(c(1, row, 2, GridBagConstraints.FIRST_LINE_START), 3, 1));
row++;
}
if(t instanceof ReferenceAdjustedTracker) {
add(new JLabel("Adj:"), c(0, row, 2, GridBagConstraints.FIRST_LINE_START));
add(adj = new JLabel("0 0 0 0"), c(1, row, 2, GridBagConstraints.FIRST_LINE_START));
add(new JLabel("AdjY:"), c(2, row, 2, GridBagConstraints.FIRST_LINE_START));
add(adjYaw = new JLabel("0 0 0 0"), c(3, row, 2, GridBagConstraints.FIRST_LINE_START));
}
setBorder(BorderFactory.createLineBorder(new Color(0x663399), 2, false));
TrackersList.this.add(this);
return this;
}
@SuppressWarnings("unchecked")
@AWTThread
public void update() {
if(position == null && rotation == null)
return;
Tracker realTracker = t;
if(t instanceof ReferenceAdjustedTracker)
realTracker = ((ReferenceAdjustedTracker<? extends Tracker>) t).getTracker();
t.getRotation(q);
t.getPosition(v);
q.toAngles(angles);
if(position != null)
position.setText(StringUtils.prettyNumber(v.x, 1)
+ " " + StringUtils.prettyNumber(v.y, 1)
+ " " + StringUtils.prettyNumber(v.z, 1));
if(rotation != null)
rotation.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
status.setText(t.getStatus().toString().toLowerCase());
if(realTracker instanceof TrackerWithTPS) {
tps.setText(StringUtils.prettyNumber(((TrackerWithTPS) realTracker).getTPS(), 1));
}
if(realTracker instanceof TrackerWithBattery)
bat.setText(StringUtils.prettyNumber(((TrackerWithBattery) realTracker).getBatteryVoltage(), 1));
if(t instanceof ReferenceAdjustedTracker) {
((ReferenceAdjustedTracker<Tracker>) t).attachmentFix.toAngles(angles);
adj.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
((ReferenceAdjustedTracker<Tracker>) t).yawFix.toAngles(angles);
adjYaw.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
}
if(realTracker instanceof IMUTracker) {
ping.setText(String.valueOf(((IMUTracker) realTracker).ping));
}
realTracker.getRotation(q);
q.toAngles(angles);
raw.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
if(realTracker instanceof IMUTracker) {
((IMUTracker) realTracker).rotMagQuaternion.toAngles(angles);
rawMag.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
calibration.setText(((IMUTracker) realTracker).calibrationStatus + " / " + ((IMUTracker) realTracker).magCalibrationStatus);
magAccuracy.setText(StringUtils.prettyNumber(((IMUTracker) realTracker).magnetometerAccuracy * FastMath.RAD_TO_DEG, 1) + "°");
((IMUTracker) realTracker).getCorrection(q);
q.toAngles(angles);
correction.setText(StringUtils.prettyNumber(angles[0] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[1] * FastMath.RAD_TO_DEG, 0)
+ " " + StringUtils.prettyNumber(angles[2] * FastMath.RAD_TO_DEG, 0));
}
}
}
private static int getTrackerSort(Tracker t) {
if(t instanceof ReferenceAdjustedTracker)
t = ((ReferenceAdjustedTracker<?>) t).getTracker();
if(t instanceof IMUTracker)
return 0;
if(t instanceof HMDTracker)
return 100;
if(t instanceof ComputedTracker)
return 200;
return 1000;
}
}
@@ -0,0 +1,339 @@
package dev.slimevr.gui;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.MouseInputAdapter;
import dev.slimevr.bridge.NamedPipeBridge;
import dev.slimevr.bridge.NamedPipeVRBridge;
import dev.slimevr.gui.swing.ButtonTimer;
import dev.slimevr.gui.swing.EJBagNoStretch;
import dev.slimevr.gui.swing.EJBox;
import dev.slimevr.gui.swing.EJBoxNoStretch;
import io.eiren.util.MacOSX;
import io.eiren.util.OperatingSystem;
import io.eiren.util.StringUtils;
import io.eiren.util.ann.AWTThread;
import io.eiren.vr.Main;
import io.eiren.vr.VRServer;
import io.eiren.vr.trackers.TrackerRole;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GraphicsConfiguration;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static javax.swing.BoxLayout.PAGE_AXIS;
import static javax.swing.BoxLayout.LINE_AXIS;
public class VRServerGUI extends JFrame {
public static final String TITLE = "SlimeVR Server (" + Main.VERSION + ")";
public final VRServer server;
private final TrackersList trackersList;
private final SkeletonList skeletonList;
private JButton resetButton;
private EJBox pane;
private float zoom = 1.5f;
private float initZoom = zoom;
@AWTThread
public VRServerGUI(VRServer server) {
super(TITLE);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) {
e.printStackTrace();
}
if(OperatingSystem.getCurrentPlatform() == OperatingSystem.OSX)
MacOSX.setTitle(TITLE);
try {
List<BufferedImage> images = new ArrayList<BufferedImage>(6);
images.add(ImageIO.read(VRServerGUI.class.getResource("/icon16.png")));
images.add(ImageIO.read(VRServerGUI.class.getResource("/icon32.png")));
images.add(ImageIO.read(VRServerGUI.class.getResource("/icon48.png")));
images.add(ImageIO.read(VRServerGUI.class.getResource("/icon64.png")));
images.add(ImageIO.read(VRServerGUI.class.getResource("/icon128.png")));
images.add(ImageIO.read(VRServerGUI.class.getResource("/icon256.png")));
setIconImages(images);
if(OperatingSystem.getCurrentPlatform() == OperatingSystem.OSX) {
MacOSX.setIcons(images);
}
} catch(IOException e1) {
e1.printStackTrace();
}
this.server = server;
this.zoom = server.config.getFloat("zoom", zoom);
this.initZoom = zoom;
setDefaultFontSize(zoom);
// All components should be constructed to the current zoom level by default
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setLayout(new BoxLayout(getContentPane(), PAGE_AXIS));
this.trackersList = new TrackersList(server, this);
this.skeletonList = new SkeletonList(server, this);
add(new JScrollPane(pane = new EJBox(PAGE_AXIS), ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED));
GraphicsConfiguration gc = getGraphicsConfiguration();
Rectangle screenBounds = gc.getBounds();
setMinimumSize(new Dimension(100, 100));
setSize(Math.min(server.config.getInt("window.width", 800), screenBounds.width), Math.min(server.config.getInt("window.height", 800), screenBounds.height));
setLocation(server.config.getInt("window.posx", screenBounds.x + (screenBounds.width - getSize().width) / 2), screenBounds.y + server.config.getInt("window.posy", (screenBounds.height - getSize().height) / 2));
// Resize and close listeners to save position and size betwen launcher starts
addComponentListener(new AbstractComponentListener() {
@Override
public void componentResized(ComponentEvent e) {
saveFrameInfo();
}
@Override
public void componentMoved(ComponentEvent e) {
saveFrameInfo();
}
});
build();
}
protected void saveFrameInfo() {
Rectangle b = getBounds();
server.config.setProperty("window.width", b.width);
server.config.setProperty("window.height", b.height);
server.config.setProperty("window.posx", b.x);
server.config.setProperty("window.posy", b.y);
server.saveConfig();
}
public float getZoom() {
return this.zoom;
}
public void refresh() {
// Pack and display
//pack();
setVisible(true);
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
repaint();
}
});
}
@AWTThread
private void build() {
pane.removeAll();
pane.add(new EJBoxNoStretch(LINE_AXIS, false, true) {{
setBorder(new EmptyBorder(i(5)));
add(Box.createHorizontalGlue());
add(resetButton = new JButton("RESET") {{
addMouseListener(new MouseInputAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
reset();
}
});
}});
add(Box.createHorizontalStrut(10));
add(new JButton("Fast Reset") {{
addMouseListener(new MouseInputAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
resetFast();
}
});
}});
add(Box.createHorizontalGlue());
add(new JButton("GUI Zoom (x" + StringUtils.prettyNumber(zoom, 2) + ")") {{
addMouseListener(new MouseInputAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
guiZoom();
setText("GUI Zoom (x" + StringUtils.prettyNumber(zoom, 2) + ")");
}
});
}});
add(Box.createHorizontalStrut(10));
add(new JButton("WiFi") {{
addMouseListener(new MouseInputAdapter() {
@SuppressWarnings("unused")
@Override
public void mouseClicked(MouseEvent e) {
new WiFiWindow(VRServerGUI.this);
}
});
}});
add(Box.createHorizontalStrut(10));
}});
pane.add(new EJBox(LINE_AXIS) {{
setBorder(new EmptyBorder(i(5)));
add(new EJBoxNoStretch(PAGE_AXIS, false, true) {{
setAlignmentY(TOP_ALIGNMENT);
JLabel l;
add(l = new JLabel("Trackers list"));
l.setFont(l.getFont().deriveFont(Font.BOLD));
l.setAlignmentX(0.5f);
add(trackersList);
add(Box.createVerticalGlue());
}});
add(new EJBoxNoStretch(PAGE_AXIS, false, true) {{
setAlignmentY(TOP_ALIGNMENT);
JLabel l;
add(l = new JLabel("Body proportions"));
l.setFont(l.getFont().deriveFont(Font.BOLD));
l.setAlignmentX(0.5f);
add(new SkeletonConfig(server, VRServerGUI.this));
add(Box.createVerticalStrut(10));
if(server.hasBridge(NamedPipeBridge.class)) {
NamedPipeBridge br = server.getVRBridge(NamedPipeBridge.class);
add(l = new JLabel("SteamVR Trackers"));
l.setFont(l.getFont().deriveFont(Font.BOLD));
l.setAlignmentX(0.5f);
add(l = new JLabel("Changes may require restart of SteamVR"));
l.setFont(l.getFont().deriveFont(Font.ITALIC));
l.setAlignmentX(0.5f);
add(new EJBagNoStretch(false, true) {{
JCheckBox waistCb;
add(waistCb = new JCheckBox("Waist"), c(1, 1));
waistCb.setSelected(br.getShareSetting(TrackerRole.WAIST));
waistCb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
server.queueTask(() -> {
br.changeShareSettings(TrackerRole.WAIST, waistCb.isSelected());
});
}
});
JCheckBox legsCb;
add(legsCb = new JCheckBox("Legs"), c(2, 1));
legsCb.setSelected(br.getShareSetting(TrackerRole.LEFT_FOOT) && br.getShareSetting(TrackerRole.RIGHT_FOOT));
legsCb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
server.queueTask(() -> {
br.changeShareSettings(TrackerRole.LEFT_FOOT, legsCb.isSelected());
br.changeShareSettings(TrackerRole.RIGHT_FOOT, legsCb.isSelected());
});
}
});
JCheckBox chestCb;
add(chestCb = new JCheckBox("Chest"), c(1, 2));
chestCb.setSelected(br.getShareSetting(TrackerRole.CHEST));
chestCb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
server.queueTask(() -> {
br.changeShareSettings(TrackerRole.CHEST, chestCb.isSelected());
});
}
});
JCheckBox kneesCb;
add(kneesCb = new JCheckBox("Knees"), c(2, 2));
kneesCb.setSelected(br.getShareSetting(TrackerRole.LEFT_KNEE) && br.getShareSetting(TrackerRole.RIGHT_KNEE));
kneesCb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
server.queueTask(() -> {
br.changeShareSettings(TrackerRole.LEFT_KNEE, kneesCb.isSelected());
br.changeShareSettings(TrackerRole.RIGHT_KNEE, kneesCb.isSelected());
});
}
});
}});
add(Box.createVerticalStrut(10));
}
add(new JLabel("Skeleton data"));
add(skeletonList);
add(Box.createVerticalGlue());
}});
}});
pane.add(Box.createVerticalGlue());
refresh();
server.addOnTick(trackersList::updateTrackers);
server.addOnTick(skeletonList::updateBones);
}
// For now only changes font size, but should change fixed components size in the future too
private void guiZoom() {
if(zoom <= 1.0f) {
zoom = 1.5f;
} else if(zoom <= 1.5f) {
zoom = 1.75f;
} else if(zoom <= 1.75f) {
zoom = 2.0f;
} else if(zoom <= 2.0f) {
zoom = 2.5f;
} else {
zoom = 1.0f;
}
processNewZoom(zoom / initZoom, pane);
refresh();
server.config.setProperty("zoom", zoom);
server.saveConfig();
}
private static void processNewZoom(float zoom, Component comp) {
if(comp.isFontSet()) {
Font newFont = new ScalableFont(comp.getFont(), zoom);
comp.setFont(newFont);
}
if(comp instanceof Container) {
Container cont = (Container) comp;
for(Component child : cont.getComponents())
processNewZoom(zoom, child);
}
}
private static void setDefaultFontSize(float zoom) {
java.util.Enumeration<Object> keys = UIManager.getDefaults().keys();
while(keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if(value instanceof javax.swing.plaf.FontUIResource) {
javax.swing.plaf.FontUIResource f = (javax.swing.plaf.FontUIResource) value;
javax.swing.plaf.FontUIResource f2 = new javax.swing.plaf.FontUIResource(f.deriveFont(f.getSize() * zoom));
UIManager.put(key, f2);
}
}
}
@AWTThread
private void resetFast() {
server.resetTrackersYaw();
}
@AWTThread
private void reset() {
ButtonTimer.runTimer(resetButton, 3, "RESET", server::resetTrackers);
}
}
@@ -0,0 +1,172 @@
package dev.slimevr.gui;
import java.awt.Container;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.WindowConstants;
import javax.swing.event.MouseInputAdapter;
import com.fazecast.jSerialComm.SerialPort;
import dev.slimevr.gui.swing.EJBox;
import io.eiren.util.ann.AWTThread;
public class WiFiWindow extends JFrame {
private static final Timer timer = new Timer();
private static String savedSSID = "";
private static String savedPassword = "";
JTextField ssidField;
JTextField passwdField;
SerialPort trackerPort = null;
JTextArea log;
TimerTask readTask;
public WiFiWindow(VRServerGUI gui) {
super("WiFi Settings");
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.LINE_AXIS));
build();
}
@AWTThread
private void build() {
Container pane = getContentPane();
SerialPort[] ports = SerialPort.getCommPorts();
for(SerialPort port : ports) {
if(port.getDescriptivePortName().toLowerCase().contains("ch340") || port.getDescriptivePortName().toLowerCase().contains("cp21") || port.getDescriptivePortName().toLowerCase().contains("ch910")) {
trackerPort = port;
break;
}
}
pane.add(new EJBox(BoxLayout.PAGE_AXIS) {{
if(trackerPort == null) {
add(new JLabel("No trackers connected, connect tracker to USB and reopen window"));
timer.schedule(new TimerTask() {
@Override
public void run() {
WiFiWindow.this.dispose();
}
}, 5000);
} else {
add(new JLabel("Tracker connected to " + trackerPort.getSystemPortName() + " (" + trackerPort.getDescriptivePortName() + ")"));
JScrollPane scroll;
add(scroll = new JScrollPane(log = new JTextArea(10, 20), ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
log.setLineWrap(true);
scroll.setAutoscrolls(true);
if(trackerPort.openPort()) {
trackerPort.setBaudRate(115200);
log.append("[OK] Port opened\n");
readTask = new ReadTask();
timer.schedule(readTask, 500, 500);
} else {
log.append("ERROR: Can't open port");
}
add(new JLabel("Enter WiFi credentials:"));
add(new EJBox(BoxLayout.LINE_AXIS) {{
add(new JLabel("Network name:"));
add(ssidField = new JTextField(savedSSID));
}});
add(new EJBox(BoxLayout.LINE_AXIS) {{
add(new JLabel("Network password:"));
add(passwdField = new JTextField(savedPassword));
}});
add(new JButton("Send") {{
addMouseListener(new MouseInputAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
send(ssidField.getText(), passwdField.getText());
}
});
}});
}
}});
// Pack and display
pack();
setLocationRelativeTo(null);
setVisible(true);
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
toFront();
repaint();
}
});
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent windowEvent) {
if(trackerPort != null)
trackerPort.closePort();
if(readTask != null)
readTask.cancel();
System.out.println("Port closed okay");
dispose();
}
});
}
protected void send(String ssid, String passwd) {
savedSSID = ssid;
savedPassword = passwd;
OutputStream os = trackerPort.getOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(os);
try {
writer.append("SET WIFI \"" + ssid + "\" \"" + passwd + "\"\n");
writer.flush();
} catch(IOException e) {
log.append(e.toString() + "\n");
e.printStackTrace();
}
}
private class ReadTask extends TimerTask {
final InputStream is;
final Reader reader;
StringBuffer sb = new StringBuffer();
public ReadTask() {
is = trackerPort.getInputStreamWithSuppressedTimeoutExceptions();
reader = new InputStreamReader(is);
}
@Override
public void run() {
try {
while(reader.ready())
sb.appendCodePoint(reader.read());
if(sb.length() > 0)
log.append(sb.toString());
sb.setLength(0);
} catch(Exception e) {
log.append(e.toString() + "\n");
e.printStackTrace();
}
}
}
}