Added mouse interaction to puck panel

This commit is contained in:
2017-03-16 12:14:34 +01:00
parent 02c75df33d
commit 4d0b19d801
6 changed files with 845 additions and 760 deletions

View File

@@ -7,6 +7,7 @@ import ch.psi.pshell.device.Device;
import ch.psi.pshell.device.DeviceBase;
import ch.psi.pshell.imaging.DimensionDouble;
import ch.psi.pshell.imaging.PointDouble;
import ch.psi.utils.swing.MainFrame;
import ch.psi.utils.swing.SwingUtils;
import java.awt.Color;
import java.awt.Dimension;
@@ -40,27 +41,25 @@ public class Puck extends DeviceBase {
new PointDouble(-28.39445573, 44.18263554)
};
final static PointDouble referencePosition = new PointDouble(0.0, -66.9);
final static Double referenceSize = 6.2;
final static PointDouble referencePosition = new PointDouble(0.0, -66.9 - 0.2);
final static Double referenceSize = 6.2 + 0.2;
final int numberOfSamples = samplesPosition.length;
final int index;
Puck() {
super();
Puck(BasePlate basePlate, int index) {
super(String.valueOf(index+1));
this.setParent(basePlate);
this.index = index;
for (int i =0; i< numberOfSamples; i++){
Sample sample = new Sample();
sample.puck = this;
sample.index = i;
addChild(sample);
new Sample(this, i);
}
}
BasePlate basePlate;
}
public BasePlate getBasePlate() {
return basePlate;
return (BasePlate) getParent();
}
DimensionDouble getSize(){
@@ -82,16 +81,11 @@ public class Puck extends DeviceBase {
}
int index;
public int getIndex() {
return index;
}
public void setIndex(int value) {
index = value;
}
String id;
public String getId() {
@@ -145,7 +139,10 @@ public class Puck extends DeviceBase {
}
}
}
selected = value;
for (Sample sample: getSamples()) {
sample.selected = false;
}
selected = value;
}
}
@@ -184,10 +181,10 @@ public class Puck extends DeviceBase {
return Math.min(plotRect.width, plotRect.height);
}
//All pucks
Rectangle plotRect = basePlate.getPlotRect();
Rectangle plotRect = getBasePlate().getPlotRect();
int ret = Math.min(
(int)((getSize().getWidth() / basePlate.getSize().getWidth()) * plotRect.width),
(int)((getSize().getHeight() / basePlate.getSize().getHeight()) * plotRect.height)
(int)((getSize().getWidth() / getBasePlate().getSize().getWidth()) * plotRect.width),
(int)((getSize().getHeight() / getBasePlate().getSize().getHeight()) * plotRect.height)
);
if (isSelected()) {
ret += 2;
@@ -201,9 +198,9 @@ public class Puck extends DeviceBase {
return new Point((int)plotRect.getCenterX(), (int)plotRect.getCenterY());
}
//All pucks
Rectangle plotRect = basePlate.getPlotRect();
DimensionDouble plateSize = basePlate.getSize();
PointDouble pos = basePlate.getPuckPosition(this);
Rectangle plotRect = getBasePlate().getPlotRect();
DimensionDouble plateSize = getBasePlate().getSize();
PointDouble pos = getBasePlate().getPuckPosition(this);
return new Point( (int) ((pos.x / plateSize.getWidth())*plotRect.width + plotRect.getCenterX()) ,
(int) ((pos.y / plateSize.getHeight())*plotRect.height + plotRect.getCenterY())
);
@@ -231,7 +228,7 @@ public class Puck extends DeviceBase {
if (!isEnabled()){
return Color.GRAY;
} else if (isSelected()){
return Color.BLACK;
return new Color(32,32,32);
}
return Color.GRAY;
}
@@ -250,8 +247,9 @@ public class Puck extends DeviceBase {
(int) ((referencePosition.y / puckSize.getHeight())* puckDrawSize/2 + puckCenter.y) );
}
Rectangle plotRect;
void draw (Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawId){
void draw (Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawId, BasePlate enclosingPlate){
this.plotRect = plotRect;
Point position = getDrawPosition();
int size = getDrawSize();
@@ -268,7 +266,12 @@ public class Puck extends DeviceBase {
}
//Draw reference
g.setColor(Color.DARK_GRAY);
Color refColor = MainFrame.isDark() ? Color.DARK_GRAY : new Color(214,217,223);
if ((enclosingPlate!=null) && enclosingPlate.drawContour){
refColor = enclosingPlate.getColor();
}
g.setColor(refColor);
position = getReferenceDrawPosition();
size = getReferenceDrawSize();
g.fillArc(position.x - size / 2, position.y - size / 2, size, size, 180, 180);