Fix indention of ViewRSSI.java

This commit is contained in:
Moritz 'Morty' Strübe 2013-08-14 16:27:05 +02:00
parent fe0a0423cb
commit fae6c530de

View file

@ -13,77 +13,79 @@
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.io.*; import java.io.*;
public class ViewRSSI extends JPanel { public class ViewRSSI extends JPanel {
private int[] rssi = new int[80]; private int[] rssi = new int[80];
private int[] rssiMax = new int[80]; private int[] rssiMax = new int[80];
/* this is the max value of the RSSI from the cc2420 */ /* this is the max value of the RSSI from the cc2420 */
private static final int RSSI_MAX_VALUE = 200; private static final int RSSI_MAX_VALUE = 200;
public ViewRSSI() { public ViewRSSI() {
} }
public void paint(Graphics g) { public void paint(Graphics g) {
int h = getHeight(); int h = getHeight();
int w = getWidth(); int w = getWidth();
double factor = (h - 20.0) / RSSI_MAX_VALUE; double factor = (h - 20.0) / RSSI_MAX_VALUE;
double sSpacing = (w - 15 ) / 80.0; double sSpacing = (w - 15) / 80.0;
int sWidth = (int) (sSpacing - 1); int sWidth = (int) (sSpacing - 1);
if (sWidth == 0) sWidth = 1; if (sWidth == 0)
sWidth = 1;
g.setColor(Color.white);
g.fillRect(0, 0, w, h); g.setColor(Color.white);
g.fillRect(0, 0, w, h);
g.setColor(Color.gray);
double xpos = 10; g.setColor(Color.gray);
for (int i = 0, n = rssi.length; i < n; i++) { double xpos = 10;
int rssi = (int) (rssiMax[i] * factor); for (int i = 0, n = rssi.length; i < n; i++) {
g.fillRect((int) xpos, h - 20 - rssi, int rssi = (int) (rssiMax[i] * factor);
sWidth, rssi + 1); g.fillRect((int) xpos, h - 20 - rssi, sWidth, rssi + 1);
xpos += sSpacing; xpos += sSpacing;
} }
g.setColor(Color.black); g.setColor(Color.black);
xpos = 10; xpos = 10;
for (int i = 0, n = rssi.length; i < n; i++) { for (int i = 0, n = rssi.length; i < n; i++) {
int rssiVal = (int) (rssi[i] * factor); int rssiVal = (int) (rssi[i] * factor);
g.fillRect((int) xpos, h - 20 - rssiVal, g.fillRect((int) xpos, h - 20 - rssiVal, sWidth, rssiVal + 1);
sWidth, rssiVal + 1); xpos += sSpacing;
xpos += sSpacing; }
} }
}
private void handleInput() throws IOException {
private void handleInput() throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
BufferedReader reader = while (true) {
new BufferedReader(new InputStreamReader(System.in)); String line = reader.readLine();
while(true) { if (line.startsWith("RSSI:")) {
String line = reader.readLine(); try {
if (line.startsWith("RSSI:")) { String[] parts = line.substring(5).split(" ");
try { for (int i = 0, n = parts.length; i < n; i++) {
String[] parts = line.substring(5).split(" "); rssi[i] = 3 * Integer.parseInt(parts[i]);
for (int i = 0, n = parts.length; i < n; i++) { if (rssi[i] > rssiMax[i])
rssi[i] = 3 * Integer.parseInt(parts[i]); rssiMax[i] = rssi[i];
if (rssi[i] > rssiMax[i]) rssiMax[i] = rssi[i]; else if (rssiMax[i] > 0)
else if (rssiMax[i] > 0) rssiMax[i]--; rssiMax[i]--;
} }
} catch (Exception e) { } catch (Exception e) {
/* report but do not fail... */ /* report but do not fail... */
e.printStackTrace(); e.printStackTrace();
}
repaint();
}
}
}
public static void main(String[] args) throws IOException {
JFrame win = new JFrame("RSSI Viewer");
ViewRSSI panel;
win.setBounds(10, 10, 300, 300);
win.getContentPane().add(panel = new ViewRSSI());
win.setVisible(true);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.handleInput();
} }
repaint();
}
}
}
public static void main(String[] args) throws IOException {
JFrame win = new JFrame("RSSI Viewer");
ViewRSSI panel;
win.setBounds(10, 10, 300, 300);
win.getContentPane().add(panel = new ViewRSSI());
win.setVisible(true);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.handleInput();
}
} }