This commit is contained in:
gac-S_Changer
2017-02-10 16:34:00 +01:00
parent 4ccd5f6ca1
commit 69e745730d
13 changed files with 1382 additions and 1038 deletions

View File

@@ -0,0 +1,182 @@
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.mxsc;
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.SwingUtils;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
/**
*
*/
public class Sample extends DeviceBase {
Puck puck;
public Puck getPuck() {
return puck;
}
DimensionDouble getSize(){
return new DimensionDouble(12.0, 12.0);
}
int index;
public int getIndex() {
return index;
}
public void setIndex(int value) {
index = value;
}
boolean enabled;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean value) {
enabled = value;
}
boolean selected;
public boolean isSelected() {
return selected;
}
public void setSelected(boolean value) {
if (value != selected){
if (value == true){
((Puck)getParent()).setSelected(true);
for (Device d : getParent().getChildren()){
if (d instanceof Sample){
((Sample)d).selected = false;
}
}
}
selected = value;
}
}
boolean present;
public boolean isPresent() {
return present;
}
public void setPresent(boolean value) {
present = value;
}
boolean loaded;
public boolean isLoaded() {
return loaded;
}
public void setLoaded(boolean value) {
loaded = value;
if (value) {
wasLoaded = true;
}
}
boolean wasLoaded;
public boolean wasLoaded() {
return wasLoaded;
}
Color getColor() {
Color ret = Color.LIGHT_GRAY;
if (isLoaded()) {
ret = Color.BLUE;
} else if (wasLoaded()) {
ret = Color.GREEN;
} else if (isPresent()) {
ret = Color.CYAN.darker().darker();
}
if (selected) {
ret = ret.brighter();
}
return ret;
}
int getDrawSize() {
int ret = (int)((getSize().getWidth() / puck.getSize().getWidth()) * puck.getDrawSize());
if (isSelected()) {
ret += 2;
}
return ret;
}
Point getDrawPosition() {
Point puckCenter = puck.getDrawPosition();
int puckDrawSize = puck.getDrawSize();
DimensionDouble puckSize = puck.getSize();
int size = getDrawSize();
PointDouble pos = puck.getSamplePosition(this);
return new Point( (int) ((pos.x / puckSize.getWidth())* puckDrawSize/2 + puckCenter.x) ,
(int) ((pos.y / puckSize.getHeight())* puckDrawSize/2 + puckCenter.y) );
}
Color getLabelColor() {
return Color.BLACK;
}
Font getLabelFont() {
return new Font("Times New Roman", Font.PLAIN, 9);
}
Point getLabelPosition(String text, Graphics g) {
Point center = getDrawPosition();
Dimension textSize = SwingUtils.getTextSize(text, g.getFontMetrics());
return new Point(center.x - textSize.width / 2 + 1, center.y + (g.getFontMetrics().getAscent()/2));
}
Color getBorderColor() {
if (!isEnabled()) {
return Color.GRAY;
} else if (isSelected()) {
return Color.BLACK;
}
return Color.GRAY;
}
void draw (Graphics2D g){
Point position = getDrawPosition();
int size = getDrawSize();
g.setColor(getColor());
g.fillOval(position.x - size / 2, position.y - size / 2, size, size);
g.setColor(getBorderColor());
g.drawOval(position.x - size / 2, position.y - size / 2, size, size);
String text = String.valueOf(index + 1);
Point labelPosition = getLabelPosition(text, g);
g.setColor(getLabelColor());
g.setFont(getLabelFont());
g.drawString(text, labelPosition.x, labelPosition.y);
g.setPaintMode();
}
}