MainPanel prototype

This commit is contained in:
gac-S_Changer
2018-04-10 09:50:23 +02:00
parent fd15d2cf48
commit 1e2fee44d0
7 changed files with 75 additions and 37 deletions

View File

@@ -149,9 +149,12 @@ public class BasePlate extends DeviceBase {
return plotRect;
}
Color getBorderColor() {
Color getBorderColor(boolean drawBackground) {
//return new Color(32,32,32);
return MainFrame.isDark() ? new Color(32,32,32) : Color.DARK_GRAY;
if (drawBackground){
return MainFrame.isDark() ? new Color(32,32,32) : Color.DARK_GRAY;
}
return MainFrame.isDark() ? new Color(0,32,0) : new Color(0,64,0);
}
Color getColor() {
@@ -204,7 +207,7 @@ public class BasePlate extends DeviceBase {
g.setColor(getColor());
g.fillOval(boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height);
}
g.setColor(getBorderColor());
g.setColor(getBorderColor(drawBackground));
g.drawOval(boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height);
}

View File

@@ -83,6 +83,16 @@ public class BasePlatePanel extends DevicePanel {
repaint();
}
boolean selectable;
public boolean getSelectable() {
return selectable;
}
public void setSelectable(boolean selectable) {
this.selectable = selectable;
}
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT
* modify this code. The content of this method is always regenerated by the Form Editor.
@@ -201,7 +211,7 @@ public class BasePlatePanel extends DevicePanel {
}
private void checkMouseEvent(MouseEvent e, boolean pressed) {
if (isEnabled()) {
if (isEnabled() && selectable) {
try {
Sample sample = getSample(e.getX(), e.getY());
Puck puck = getPuck(e.getX(), e.getY());
@@ -244,13 +254,13 @@ public class BasePlatePanel extends DevicePanel {
public void mouseClicked(MouseEvent e) {
if (isEnabled()) {
if (e.getButton() == java.awt.event.MouseEvent.BUTTON1) {
Sample sample = getSample(e.getX(), e.getY());
Puck puck = getPuck(e.getX(), e.getY());
if (sample != null) {
onSampleClicked(e, sample);
} else {
onPuckClicked(e, puck);
}
Sample sample = getSample(e.getX(), e.getY());
Puck puck = getPuck(e.getX(), e.getY());
if (sample != null) {
onSampleClicked(e, sample);
} else {
onPuckClicked(e, puck);
}
}
}
}

View File

@@ -29,7 +29,7 @@ public class MainPanel extends Panel {
public void onInitialize(int runCount) {
Controller.getInstance().onInitialize(runCount);
basePlatePanel.setDevice((Device) getDevice("BasePlate"));
basePlatePanel.setEnabled(false);
basePlatePanel.setSelectable(false);
}

View File

@@ -206,8 +206,8 @@ public class Puck extends DeviceBase {
);
}
Color getLabelColor() {
return Color.BLACK;
Color getLabelColor(boolean drawBackground) {
return drawBackground ? Color.BLACK : new Color (0,196,0);
}
Font getLabelFont() {
@@ -230,13 +230,16 @@ public class Puck extends DeviceBase {
return new Point(center.x - textSize.width / 2, center.y + (g.getFontMetrics().getAscent()/2));
}
Color getBorderColor() {
if (!isEnabled()){
Color getBorderColor(boolean drawBackground) {
if (drawBackground){
if (!isEnabled()){
return Color.GRAY;
} else if (isSelected()){
return new Color(32,32,32);
}
return Color.GRAY;
} else if (isSelected()){
return new Color(32,32,32);
}
return Color.GRAY;
}
return isSelected() ? new Color(0,32,0) : new Color(0,128,0);
}
int getReferenceDrawSize() {
@@ -263,7 +266,7 @@ public class Puck extends DeviceBase {
g.setColor(getColor());
g.fillOval(position.x - size / 2, position.y - size / 2, size, size);
}
g.setColor(getBorderColor());
g.setColor(getBorderColor(drawBackground));
g.drawOval(position.x - size / 2, position.y - size / 2, size, size);
if (drawSamples){
@@ -287,7 +290,7 @@ public class Puck extends DeviceBase {
//Draw text
String text = String.valueOf(getIndex() + 1);
Point labelPosition = getLabelPosition(text, g);
g.setColor(getLabelColor());
g.setColor(getLabelColor(drawBackground));
if (drawId){
String id = getId();
if (id!=null) {

View File

@@ -17,12 +17,21 @@ import java.util.logging.Level;
public class PuckDetection extends DeviceBase{
final String server;
public volatile Chrono chrono;
boolean debug;
public PuckDetection(String name, String server){
super(name);
this.server = server.startsWith("tcp://") ? server : "tcp://" + server;
}
public boolean isDebug(){
return debug;
}
public void setDebug(boolean value){
debug = value;
}
Thread thread;
Thread watchDog;
@@ -72,11 +81,16 @@ public class PuckDetection extends DeviceBase{
//subscriber.subscribe("Status".getBytes());
subscriber.subscribe("".getBytes());
try{
if (debug){
System.out.println("Start listening");
}
while (!Thread.currentThread().isInterrupted()) {
//String type = subscriber.recvStr();
//System.out.println(type);
String contents = subscriber.recvStr();
//System.out.println(contents);
if (debug){
System.out.println(contents);
}
processMessage(contents);
if (Controller.getInstance()!=null){
@@ -86,6 +100,10 @@ public class PuckDetection extends DeviceBase{
chrono = new Chrono();
}
} finally{
if (debug){
System.out.println("Stop listening");
}
if (Controller.getInstance()!=null){
Controller.getInstance().clearPuckStates();
}
@@ -107,7 +125,7 @@ public class PuckDetection extends DeviceBase{
for (List<List> bus : detection){
for (List<Integer> sensor : bus){
Integer indDetector = sensor.get(0);
Integer mecDetector = sensor.get(0);
Integer mecDetector = sensor.get(1);
PuckState puck = Controller.getInstance().getPuckState(id);
puck.set(mecDetector, indDetector);
@@ -132,9 +150,10 @@ public class PuckDetection extends DeviceBase{
}
public static void main(String[] args) throws IOException, InterruptedException {
PuckDetection pd = new PuckDetection("PD","129.129.110.83:5556");
pd.initialize();
PuckDetection pd = new PuckDetection("PD","129.129.110.99:5556");
//PuckDetection pd = new PuckDetection("PD","raspberrypi:5556");
pd.setDebug(true);
pd.initialize();
Thread.sleep(100000);
}
}

View File

@@ -61,7 +61,7 @@ public class PuckPanel extends DevicePanel {
if ((size.width > 10) && (size.height > 10)) {
int border = 5;
Rectangle plotRect = new Rectangle(border, border, size.width - 2*border, size.height - 2*border);
getDevice().draw(g2d, plotRect, true, false, null);
getDevice().draw(g2d, plotRect, true, false, true, null);
}
}
}

View File

@@ -140,8 +140,8 @@ public class Sample extends DeviceBase {
}
Color getLabelColor() {
return Color.DARK_GRAY;
Color getLabelColor(boolean drawBackground) {
return drawBackground ? Color.DARK_GRAY : new Color (0,128,0);
}
Font getLabelFont() {
@@ -155,13 +155,16 @@ public class Sample extends DeviceBase {
return new Point(center.x - textSize.width / 2 + 1, center.y + (g.getFontMetrics().getAscent()/2));
}
Color getBorderColor() {
if (!isEnabled()) {
Color getBorderColor(boolean drawBackground) {
if (drawBackground){
if (!isEnabled()) {
return Color.GRAY;
} else if (isSelected()) {
return new Color(32,32,32);
}
return Color.GRAY;
} else if (isSelected()) {
return new Color(32,32,32);
}
return Color.GRAY;
return isSelected() ? new Color(0,32,0) : new Color(0,128,0);
}
void draw (Graphics2D g, boolean drawBackground){
@@ -172,13 +175,13 @@ public class Sample extends DeviceBase {
g.setColor(getColor());
g.fillOval(position.x - size / 2, position.y - size / 2, size, size);
}
g.setColor(getBorderColor());
g.setColor(getBorderColor(drawBackground));
g.drawOval(position.x - size / 2, position.y - size / 2, size, size);
String text = String.valueOf(index + 1);
Point labelPosition = getLabelPosition(text, g);
if (getNormalDrawSize()>10){
g.setColor(getLabelColor());
g.setColor(getLabelColor(drawBackground));
g.setFont(getLabelFont());
g.drawString(text, labelPosition.x, labelPosition.y);
}