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

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target/

74
pom.xml
View File

@@ -1,21 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.psi</groupId>
<artifactId>MXSC</artifactId>
<version>1.4.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>pshell</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<name>MXSC</name>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.psi</groupId>
<artifactId>MXSC</artifactId>
<version>1.5.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>pshell</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>releases</id>
<name>releases</name>
<url>https://artifacts.psi.ch/artifactory/releases</url>
</repository>
<repository>
<id>libs-releases</id>
<name>libs-releases</name>
<url>https://artifacts.psi.ch/artifactory/libs-releases-local</url>
</repository>
<repository>
<id>libs-snapshots</id>
<name>libs-snapshots</name>
<url>https://artifacts.psi.ch/artifactory/libs-snapshots-local</url>
</repository>
</repositories>
<name>MXSC</name>
<build>
<!-- To remove the version numnber from jar
<finalName>${project.name}</finalName>
-->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>../pshell/home/plugins</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,141 +1,147 @@
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.plugin;
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 java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.io.IOException;
import java.util.ArrayList;
/**
*
*/
public class BasePlate extends DeviceBase {
final static PointDouble[] pucksPosition = new PointDouble[]{
new PointDouble(0, 75),
new PointDouble(0, 150),
new PointDouble(64.95, 187.5),
new PointDouble(129.9, 150),
new PointDouble(64.95, 112.5),
new PointDouble(64.95, 37.5),
new PointDouble(129.9, 75),
new PointDouble(194.85, 37.5),
new PointDouble(194.85, -37.5),
new PointDouble(129.9, 0),
new PointDouble(64.95, -37.5),
new PointDouble(129.9, -75),
new PointDouble(129.9, -150),
new PointDouble(64.95, -187.5),
new PointDouble(64.95, -112.5),
new PointDouble(0, -75),
new PointDouble(0, -150),
new PointDouble(-64.95, -187.5),
new PointDouble(-129.9, -150),
new PointDouble(-64.95, -112.5),
new PointDouble(-64.95, -37.5),
new PointDouble(-129.9, -75),
new PointDouble(-194.85, -37.5),
new PointDouble(-194.85, 37.5),
new PointDouble(-129.9, 0),
new PointDouble(-64.95, 37.5),
new PointDouble(-129.9, 75),
new PointDouble(-129.9, 150),
new PointDouble(-64.95, 187.5),
new PointDouble(-64.95, 112.5)
};
final static int numberOfPucks = pucksPosition.length;
//final static DimensionDouble size = new DimensionDouble(580.0, 580.0);
final static DimensionDouble size = new DimensionDouble(580.0, 580.0);
BasePlate() {
super("BasePlate", new BasePlateConfig());
ArrayList<Puck> pucks = new ArrayList<>();
for (int i = 0; i < numberOfPucks; i++) {
Puck puck = new Puck();
puck.index = i;
puck.basePlate = this;
this.addChild(puck);
}
getPucks()[0].setSelected(true);
}
@Override
protected void doInitialize() throws IOException, InterruptedException {
super.doInitialize();
}
@Override
public BasePlateConfig getConfig() {
return (BasePlateConfig) super.getConfig();
}
public Puck[] getPucks() {
ArrayList<Puck> ret = new ArrayList<>();
for (Device d : getChildren()) {
ret.add((Puck) d);
}
return ret.toArray(new Puck[0]);
}
Puck getSelectedPuck(){
for (Puck p:getPucks()){
if (p.isSelected()){
return p;
}
}
return null;
}
Sample getSelectedSample(){
Puck puck = getSelectedPuck();
if (puck != null){
for (Sample s: puck.getSamples()){
if (s.isSelected()){
return s;
}
}
}
return null;
}
DimensionDouble getSize(){
return size;
}
public int getNumberOfPucks() {
return numberOfPucks;
}
public PointDouble getPuckPosition(Puck puck) {
return pucksPosition[puck.index];
}
Rectangle plotRect = new Rectangle(0, 0, 0, 0);
public Rectangle getPlotRect() {
return plotRect;
}
void draw(Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawIds) {
this.plotRect = plotRect;
g.setColor(Color.BLACK);
int size = Math.min(plotRect.width, plotRect.height);
g.drawOval((int)(plotRect.getCenterX() - size/2),(int)(plotRect.getCenterY() - size/2), size, size);
for (Puck puck : getPucks()) {
puck.draw(g, null, drawSamples, drawIds) ;
}
}
}
/*
* 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 java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.io.IOException;
import java.util.ArrayList;
/**
*
*/
public class BasePlate extends DeviceBase {
final static PointDouble[] pucksPosition = new PointDouble[]{
new PointDouble(0, 75),
new PointDouble(0, 150),
new PointDouble(64.95, 187.5),
new PointDouble(129.9, 150),
new PointDouble(64.95, 112.5),
new PointDouble(64.95, 37.5),
new PointDouble(129.9, 75),
new PointDouble(194.85, 37.5),
new PointDouble(194.85, -37.5),
new PointDouble(129.9, 0),
new PointDouble(64.95, -37.5),
new PointDouble(129.9, -75),
new PointDouble(129.9, -150),
new PointDouble(64.95, -187.5),
new PointDouble(64.95, -112.5),
new PointDouble(0, -75),
new PointDouble(0, -150),
new PointDouble(-64.95, -187.5),
new PointDouble(-129.9, -150),
new PointDouble(-64.95, -112.5),
new PointDouble(-64.95, -37.5),
new PointDouble(-129.9, -75),
new PointDouble(-194.85, -37.5),
new PointDouble(-194.85, 37.5),
new PointDouble(-129.9, 0),
new PointDouble(-64.95, 37.5),
new PointDouble(-129.9, 75),
new PointDouble(-129.9, 150),
new PointDouble(-64.95, 187.5),
new PointDouble(-64.95, 112.5)
};
final static int numberOfPucks = pucksPosition.length;
//final static DimensionDouble size = new DimensionDouble(580.0, 580.0);
final static DimensionDouble size = new DimensionDouble(580.0, 580.0);
BasePlate() {
super("BasePlate", new BasePlateConfig());
ArrayList<Puck> pucks = new ArrayList<>();
for (int i = 0; i < numberOfPucks; i++) {
Puck puck = new Puck();
puck.index = i;
puck.basePlate = this;
this.addChild(puck);
}
getPucks()[0].setSelected(true);
}
@Override
protected void doInitialize() throws IOException, InterruptedException {
super.doInitialize();
}
@Override
public BasePlateConfig getConfig() {
return (BasePlateConfig) super.getConfig();
}
public Puck[] getPucks() {
ArrayList<Puck> ret = new ArrayList<>();
for (Device d : getChildren()) {
ret.add((Puck) d);
}
return ret.toArray(new Puck[0]);
}
Puck getSelectedPuck(){
for (Puck p:getPucks()){
if (p.isSelected()){
return p;
}
}
return null;
}
Sample getSelectedSample(){
Puck puck = getSelectedPuck();
if (puck != null){
for (Sample s: puck.getSamples()){
if (s.isSelected()){
return s;
}
}
}
return null;
}
DimensionDouble getSize(){
return size;
}
public int getNumberOfPucks() {
return numberOfPucks;
}
public PointDouble getPuckPosition(Puck puck) {
return pucksPosition[puck.index];
}
Rectangle plotRect = new Rectangle(0, 0, 0, 0);
public Rectangle getPlotRect() {
return plotRect;
}
void draw(Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawIds, boolean drawContour) {
this.plotRect = plotRect;
g.setColor(Color.BLACK);
if (drawContour){
//int size = Math.min(plotRect.width, plotRect.height);
//g.drawOval((int)(plotRect.getCenterX() - size/2),(int)(plotRect.getCenterY() - size/2), size, size);
g.drawOval((int)(plotRect.width*0.05),
(int)(plotRect.height * 0.05),
(int)(plotRect.width*0.90),
(int)(plotRect.height*0.90));
}
for (Puck puck : getPucks()) {
puck.draw(g, null, drawSamples, drawIds) ;
}
}
}

View File

@@ -1,13 +1,13 @@
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.plugin;
import ch.psi.pshell.device.DeviceConfig;
/**
*
*/
public class BasePlateConfig extends DeviceConfig{
}
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.mxsc;
import ch.psi.pshell.device.DeviceConfig;
/**
*
*/
public class BasePlateConfig extends DeviceConfig{
}

View File

@@ -1,276 +1,276 @@
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.plugin;
import ch.psi.pshell.swing.DevicePanel;
import ch.psi.utils.State;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
*/
public class BasePlatePanel extends DevicePanel {
/**
* Creates new form BasePlatePanel
*/
public BasePlatePanel() {
initComponents();
//addMouseListener(mouseAdapter);
}
@Override
public BasePlate getDevice() {
return (BasePlate) super.getDevice();
}
Mode mode = Mode.single;
enum Mode {
single,
horizontal,
vertical,
overlapped,
}
public Mode getMode() {
return mode;
}
public void setMode(Mode mode) {
this.mode = mode;
repaint();
}
/**
* 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
@Override
protected void onDeviceStateChanged(State state, State former) {
repaint();
}
Rectangle platePlotRect;
Rectangle puckPlotRect;
@Override
public void paint(Graphics g) {
super.paint(g);
if (getDevice() != null) {
Graphics2D g2d = (Graphics2D) g;
Dimension size = getSize();
if ((size.width > 40) && (size.height > 40)) {
int border = 0;
int borderPuck = 20;
Rectangle plotRect = new Rectangle(border, border, size.width - 2 * border, size.height - 2 * border);
Puck selectedPuck = getDevice().getSelectedPuck();
platePlotRect = null;
puckPlotRect = null;
switch (mode) {
case single:
platePlotRect = plotRect;
puckPlotRect = null;
getDevice().draw(g2d, platePlotRect, true, false);
break;
case horizontal:
platePlotRect = new Rectangle(plotRect.x, plotRect.y, plotRect.width / 2, plotRect.height);
getDevice().draw(g2d, platePlotRect, false, true);
if (selectedPuck!=null){
puckPlotRect = new Rectangle(plotRect.x + plotRect.width / 2 + borderPuck, plotRect.y + borderPuck, plotRect.width / 2 - 2 * borderPuck, plotRect.height - 2 * borderPuck);
selectedPuck.draw(g2d, puckPlotRect, true, false);
}
break;
case vertical:
platePlotRect = new Rectangle(plotRect.x, plotRect.y, plotRect.width, plotRect.height / 2);
getDevice().draw(g2d, platePlotRect, false, true);
if (selectedPuck!=null){
puckPlotRect = new Rectangle(plotRect.x + borderPuck, plotRect.y + plotRect.height / 2 + borderPuck, plotRect.width - 2 * borderPuck, plotRect.height / 2 - 2 * borderPuck);
selectedPuck.draw(g2d, puckPlotRect, true, false);
}
break;
case overlapped:
//getDevice().draw(g2d, plotRect, false, true);
platePlotRect = new Rectangle(plotRect.x - ((int) (plotRect.width * 0.14)), plotRect.y - ((int) (plotRect.height * 0.14)), (int) (plotRect.width * 1.28), (int) (plotRect.height * 1.28));
getDevice().draw(g2d, platePlotRect, false, true);
if (selectedPuck!=null){
int overlappedSize = (int) (1.5 * selectedPuck.getDrawSize());
puckPlotRect = new Rectangle((int) (plotRect.getCenterX() - overlappedSize / 2), (int) (plotRect.getCenterY() - overlappedSize / 2), overlappedSize, overlappedSize);
selectedPuck.draw(g2d, puckPlotRect, true, false);
}
break;
}
}
}
}
MouseAdapter mouseAdapter = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
checkMouseEvent(e, true);
}
@Override
public void mouseReleased(MouseEvent e) {
checkMouseEvent(e, false);
}
private void checkMouseEvent(MouseEvent e, boolean pressed) {
if (isEnabled()) {
try {
Sample sample = getSample(e.getX(), e.getY());
Puck puck = getPuck(e.getX(), e.getY());
if (e.isPopupTrigger()) {
if (sample != null) {
onSamplePopupMenu(e, sample);
} else if (puck != null){
onPuckPopupMenu(e, puck);
} else {
onBasePlatePopupMenu(e);
}
} else if ((pressed) && (e.getClickCount() % 2 == 0)) {
if (sample != null) {
onSampleDoubleClicked(e, sample);
} else if (puck != null){
onPuckDoubleClicked(e, puck);
}
} else if ((e.getButton() == java.awt.event.MouseEvent.BUTTON1)) {
if (sample != null) {
if (pressed) {
onSamplePressed(e, sample);
} else {
onSampleReleased(e, sample);
}
}else if (puck != null){
if (pressed) {
onPuckPressed(e, puck);
} else {
onPuckReleased(e, puck);
}
}
}
} catch (Exception ex) {
Logger.getLogger(BasePlatePanel.class.getName()).log(Level.WARNING, null, ex);
}
}
}
@Override
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 getSample(int x, int y) {
return getDevice().getPucks()[0].getSamples()[0];
/*
Point point = new Point(x, y);
for (int basket = 0; basket < mBaskets; basket++) {
for (int position = 0; position < mPositions; position++) {
Point center = getSampleCenter(basket, position);
double dist = center.distance(point);
if (dist <= (((double) getSampleSize()) / 2)) {
return new Sample(basket, position);
}
}
Point center = getBasketCenter(basket);
double dist = center.distance(point);
if (dist <= (((double) getBasketSize()) / 2)) {
return new Sample(basket, -1);
}
}
return null;
*/
}
Puck getPuck(int x, int y) {
return getDevice().getPucks()[0];
}
void onSampleClicked(MouseEvent e, Sample sample){
}
void onSamplePressed(MouseEvent e, Sample sample){
sample.setSelected(true);
repaint();
}
void onSampleReleased(MouseEvent e, Sample sample){
}
void onSamplePopupMenu(MouseEvent e,Sample sample){
}
void onSampleDoubleClicked(MouseEvent e,Sample sample){
}
void onPuckClicked(MouseEvent e, Puck puck){
}
void onPuckPressed(MouseEvent e, Puck puck){
puck.setSelected(true);
repaint();
}
void onPuckReleased(MouseEvent e, Puck puck){
}
void onPuckPopupMenu(MouseEvent e, Puck puck){
}
void onPuckDoubleClicked(MouseEvent e, Puck puck){
}
void onBasePlatePopupMenu(MouseEvent e){
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.mxsc;
import ch.psi.pshell.swing.DevicePanel;
import ch.psi.utils.State;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
*/
public class BasePlatePanel extends DevicePanel {
/**
* Creates new form BasePlatePanel
*/
public BasePlatePanel() {
initComponents();
//addMouseListener(mouseAdapter);
}
@Override
public BasePlate getDevice() {
return (BasePlate) super.getDevice();
}
Mode mode = Mode.single;
enum Mode {
single,
horizontal,
vertical,
overlapped,
}
public Mode getMode() {
return mode;
}
public void setMode(Mode mode) {
this.mode = mode;
repaint();
}
/**
* 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
@Override
protected void onDeviceStateChanged(State state, State former) {
repaint();
}
Rectangle platePlotRect;
Rectangle puckPlotRect;
@Override
public void paint(Graphics g) {
super.paint(g);
if (getDevice() != null) {
Graphics2D g2d = (Graphics2D) g;
Dimension size = getSize();
if ((size.width > 40) && (size.height > 40)) {
int border = 0;
int borderPuck = 20;
Rectangle plotRect = new Rectangle(border, border, size.width - 2 * border, size.height - 2 * border);
Puck selectedPuck = getDevice().getSelectedPuck();
platePlotRect = null;
puckPlotRect = null;
switch (mode) {
case single:
platePlotRect = plotRect;
puckPlotRect = null;
getDevice().draw(g2d, platePlotRect, true, false, true);
break;
case horizontal:
platePlotRect = new Rectangle(plotRect.x, plotRect.y, plotRect.width / 2, plotRect.height);
getDevice().draw(g2d, platePlotRect, false, true, true);
if (selectedPuck!=null){
puckPlotRect = new Rectangle(plotRect.x + plotRect.width / 2 + borderPuck, plotRect.y + borderPuck, plotRect.width / 2 - 2 * borderPuck, plotRect.height - 2 * borderPuck);
selectedPuck.draw(g2d, puckPlotRect, true, false);
}
break;
case vertical:
platePlotRect = new Rectangle(plotRect.x, plotRect.y, plotRect.width, plotRect.height / 2);
getDevice().draw(g2d, platePlotRect, false, true, true);
if (selectedPuck!=null){
puckPlotRect = new Rectangle(plotRect.x + borderPuck, plotRect.y + plotRect.height / 2 + borderPuck, plotRect.width - 2 * borderPuck, plotRect.height / 2 - 2 * borderPuck);
selectedPuck.draw(g2d, puckPlotRect, true, false);
}
break;
case overlapped:
//getDevice().draw(g2d, plotRect, false, true);
platePlotRect = new Rectangle(plotRect.x - ((int) (plotRect.width * 0.14)), plotRect.y - ((int) (plotRect.height * 0.14)), (int) (plotRect.width * 1.28), (int) (plotRect.height * 1.28));
getDevice().draw(g2d, platePlotRect, false, true, false);
if (selectedPuck!=null){
int overlappedSize = (int) (1.5 * selectedPuck.getDrawSize());
puckPlotRect = new Rectangle((int) (plotRect.getCenterX() - overlappedSize / 2), (int) (plotRect.getCenterY() - overlappedSize / 2), overlappedSize, overlappedSize);
selectedPuck.draw(g2d, puckPlotRect, true, false);
}
break;
}
}
}
}
MouseAdapter mouseAdapter = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
checkMouseEvent(e, true);
}
@Override
public void mouseReleased(MouseEvent e) {
checkMouseEvent(e, false);
}
private void checkMouseEvent(MouseEvent e, boolean pressed) {
if (isEnabled()) {
try {
Sample sample = getSample(e.getX(), e.getY());
Puck puck = getPuck(e.getX(), e.getY());
if (e.isPopupTrigger()) {
if (sample != null) {
onSamplePopupMenu(e, sample);
} else if (puck != null){
onPuckPopupMenu(e, puck);
} else {
onBasePlatePopupMenu(e);
}
} else if ((pressed) && (e.getClickCount() % 2 == 0)) {
if (sample != null) {
onSampleDoubleClicked(e, sample);
} else if (puck != null){
onPuckDoubleClicked(e, puck);
}
} else if ((e.getButton() == java.awt.event.MouseEvent.BUTTON1)) {
if (sample != null) {
if (pressed) {
onSamplePressed(e, sample);
} else {
onSampleReleased(e, sample);
}
}else if (puck != null){
if (pressed) {
onPuckPressed(e, puck);
} else {
onPuckReleased(e, puck);
}
}
}
} catch (Exception ex) {
Logger.getLogger(BasePlatePanel.class.getName()).log(Level.WARNING, null, ex);
}
}
}
@Override
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 getSample(int x, int y) {
return getDevice().getPucks()[0].getSamples()[0];
/*
Point point = new Point(x, y);
for (int basket = 0; basket < mBaskets; basket++) {
for (int position = 0; position < mPositions; position++) {
Point center = getSampleCenter(basket, position);
double dist = center.distance(point);
if (dist <= (((double) getSampleSize()) / 2)) {
return new Sample(basket, position);
}
}
Point center = getBasketCenter(basket);
double dist = center.distance(point);
if (dist <= (((double) getBasketSize()) / 2)) {
return new Sample(basket, -1);
}
}
return null;
*/
}
Puck getPuck(int x, int y) {
return getDevice().getPucks()[0];
}
void onSampleClicked(MouseEvent e, Sample sample){
}
void onSamplePressed(MouseEvent e, Sample sample){
sample.setSelected(true);
repaint();
}
void onSampleReleased(MouseEvent e, Sample sample){
}
void onSamplePopupMenu(MouseEvent e,Sample sample){
}
void onSampleDoubleClicked(MouseEvent e,Sample sample){
}
void onPuckClicked(MouseEvent e, Puck puck){
}
void onPuckPressed(MouseEvent e, Puck puck){
puck.setSelected(true);
repaint();
}
void onPuckReleased(MouseEvent e, Puck puck){
}
void onPuckPopupMenu(MouseEvent e, Puck puck){
}
void onPuckDoubleClicked(MouseEvent e, Puck puck){
}
void onBasePlatePopupMenu(MouseEvent e){
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}

View File

@@ -26,20 +26,46 @@
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="ch.psi.plugin.BasePlatePanel" name="basePlatePanel">
<Container class="ch.psi.mxsc.BasePlatePanel" name="basePlatePanel">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="442" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="0" pref="386" max="32767" attributes="0"/>
<Component id="comboMode" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="comboMode" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="280" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JComboBox" name="comboMode">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringItem index="0" value="Item 1"/>
<StringItem index="1" value="Item 2"/>
<StringItem index="2" value="Item 3"/>
<StringItem index="3" value="Item 4"/>
</StringArray>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="comboModeActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View File

@@ -1,69 +1,102 @@
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.plugin;
import ch.psi.pshell.ui.Panel;
/**
*
*/
public class MainPanel extends Panel {
BasePlate basePlate;
/** Creates new form Panel */
public MainPanel() {
initComponents();
basePlate = new BasePlate();
}
@Override
public void onInitialize(int runCount) {
basePlatePanel.setDevice(basePlate);
//basePlatePanel.setShowSamples(true);
//puckPanel.setDevice(basePlate.getPucks()[0]);
addDevice(basePlate);
}
/** 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
basePlatePanel = new ch.psi.plugin.BasePlatePanel();
javax.swing.GroupLayout basePlatePanelLayout = new javax.swing.GroupLayout(basePlatePanel);
basePlatePanel.setLayout(basePlatePanelLayout);
basePlatePanelLayout.setHorizontalGroup(
basePlatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 442, Short.MAX_VALUE)
);
basePlatePanelLayout.setVerticalGroup(
basePlatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(basePlatePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(basePlatePanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private ch.psi.plugin.BasePlatePanel basePlatePanel;
// End of variables declaration//GEN-END:variables
}
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.mxsc;
import ch.psi.pshell.device.GenericDevice;
import ch.psi.pshell.ui.Panel;
import ch.psi.utils.swing.SwingUtils;
import java.awt.Component;
/**
*
*/
public class MainPanel extends Panel {
BasePlate basePlate;
/** Creates new form Panel */
static MainPanel instance;
public static MainPanel getInstance(){
return instance;
}
public MainPanel() {
initComponents();
instance = this;
basePlate = new BasePlate();
SwingUtils.setEnumCombo(comboMode, BasePlatePanel.Mode.class);
comboMode.setSelectedItem(basePlatePanel.getMode());
this.setPersistedComponents(new Component[]{comboMode});
}
@Override
public void onInitialize(int runCount) {
basePlatePanel.setDevice(basePlate);
//basePlatePanel.setShowSamples(true);
//puckPanel.setDevice(basePlate.getPucks()[0]);
GenericDevice former = getDevice("BasePlate");
if (former!=null){
removeDevice(former);
}
addDevice(basePlate);
}
/** 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
basePlatePanel = new ch.psi.mxsc.BasePlatePanel();
comboMode = new javax.swing.JComboBox<>();
comboMode.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
comboMode.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboModeActionPerformed(evt);
}
});
javax.swing.GroupLayout basePlatePanelLayout = new javax.swing.GroupLayout(basePlatePanel);
basePlatePanel.setLayout(basePlatePanelLayout);
basePlatePanelLayout.setHorizontalGroup(
basePlatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, basePlatePanelLayout.createSequentialGroup()
.addGap(0, 386, Short.MAX_VALUE)
.addComponent(comboMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
basePlatePanelLayout.setVerticalGroup(
basePlatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(basePlatePanelLayout.createSequentialGroup()
.addComponent(comboMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 280, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(basePlatePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(basePlatePanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
private void comboModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboModeActionPerformed
basePlatePanel.setMode((BasePlatePanel.Mode) comboMode.getSelectedItem());
}//GEN-LAST:event_comboModeActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private ch.psi.mxsc.BasePlatePanel basePlatePanel;
private javax.swing.JComboBox<String> comboMode;
// End of variables declaration//GEN-END:variables
}

View File

@@ -1,261 +1,292 @@
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.plugin;
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;
import java.util.ArrayList;
/**
*
*/
public class Puck extends DeviceBase {
final static PointDouble[] samplesPosition = new PointDouble[]{
new PointDouble(0, 24.24),
new PointDouble(23.05360995, 7.490571944),
new PointDouble(14.24791452, -19.61057194),
new PointDouble(-14.24791452, -19.61057194),
new PointDouble(-23.05360995, 7.490571944),
new PointDouble(0, 52.52),
new PointDouble(28.39445573, 44.18263554),
new PointDouble(47.7738724, 21.81759648),
new PointDouble(51.98542213, -7.474375306),
new PointDouble(39.69196765, -34.39328575),
new PointDouble(14.79659389, -50.39257097),
new PointDouble(-14.79659389, -50.39257097),
new PointDouble(-39.69196765, -34.39328575),
new PointDouble(-51.98542213, -7.474375306),
new PointDouble(-47.7738724, 21.81759648),
new PointDouble(-28.39445573, 44.18263554)
};
final static PointDouble referencePosition = new PointDouble(0, -66.9);
final static Double referenceSize = 6.2;
final int numberOfSamples = samplesPosition.length;
Puck() {
super();
for (int i =0; i< numberOfSamples; i++){
Sample sample = new Sample();
sample.puck = this;
sample.index = i;
addChild(sample);
}
}
BasePlate basePlate;
public BasePlate getBasePlate() {
return basePlate;
}
DimensionDouble getSize(){
return new DimensionDouble(67.0, 67.0);
}
public Sample[] getSamples() {
ArrayList<Sample> ret = new ArrayList<>();
for (Device d : getChildren()) {
ret.add((Sample) d);
}
return ret.toArray(new Sample[0]);
}
public PointDouble getSamplePosition(Sample sample) {
return samplesPosition[sample.index];
}
int index;
public int getIndex() {
return index;
}
public void setIndex(int value) {
index = value;
}
String id;
public String getId() {
//return "XXX000" + index;
return id;
}
public void seId(String value) {
id = 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){
for (Device d : getParent().getChildren()){
if (d instanceof Puck){
((Puck)d).selected = false;
}
}
}
selected = value;
}
}
public int getNumberOfSamples() {
return numberOfSamples;
}
Color getColor() {
Color ret = Color.LIGHT_GRAY;
boolean selected = isSelected();
if (isSelected()) {
ret = ret.brighter();
}
return ret;
}
int getDrawSize() {
//Single puck plot
if (plotRect != null){
return Math.min(plotRect.width, plotRect.height);
}
//All pucks
Rectangle plotRect = basePlate.getPlotRect();
int ret = Math.min(
(int)((getSize().getWidth() / basePlate.getSize().getWidth()) * plotRect.width),
(int)((getSize().getHeight() / basePlate.getSize().getHeight()) * plotRect.height)
);
if (isSelected()) {
ret += 2;
}
return ret;
}
Point getDrawPosition() {
//Single puck plot
if (plotRect != null){
return new Point((int)plotRect.getCenterX(), (int)plotRect.getCenterY());
}
//All pucks
Rectangle plotRect = basePlate.getPlotRect();
DimensionDouble plateSize = basePlate.getSize();
PointDouble pos = basePlate.getPuckPosition(this);
return new Point( (int) ((pos.x / plateSize.getWidth())*plotRect.width + plotRect.getCenterX()) ,
(int) ((pos.y / plateSize.getHeight())*plotRect.height + plotRect.getCenterY())
);
}
Color getLabelColor() {
return Color.BLACK;
}
Font getLabelFont() {
return new Font("Times New Roman", Font.BOLD, 12);
}
Font getIdFont() {
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, center.y + (g.getFontMetrics().getAscent()/2));
}
Color getBorderColor() {
if (!isEnabled()){
return Color.GRAY;
} else if (isSelected()){
return Color.BLACK;
}
return Color.GRAY;
}
int getReferenceDrawSize() {
return (int)((referenceSize / getSize().getWidth()) * getDrawSize());
}
Point getReferenceDrawPosition() {
Point puckCenter = getDrawPosition();
int puckDrawSize = getDrawSize();
DimensionDouble puckSize = getSize();
int size = getReferenceDrawSize();
return new Point( (int) ((referencePosition.x / puckSize.getWidth())* puckDrawSize/2 + puckCenter.x) ,
(int) ((referencePosition.y / puckSize.getHeight())* puckDrawSize/2 + puckCenter.y) );
}
Rectangle plotRect;
void draw (Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawId){
this.plotRect = plotRect;
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);
if (drawSamples){
//Draw samples
for (Sample sample: getSamples()) {
sample.draw(g);
}
}
//Draw reference
g.setColor(Color.DARK_GRAY);
position = getReferenceDrawPosition();
size = getReferenceDrawSize();
g.fillArc(position.x - size / 2, position.y - size / 2, size, size, 180, 180);
//Draw text
String text = String.valueOf(getIndex() + 1);
Point labelPosition = getLabelPosition(text, g);
g.setColor(getLabelColor());
if (drawId){
String id = getId();
if (id!=null) {
labelPosition.setLocation(labelPosition.x, labelPosition.y - 6);
g.setFont(getIdFont());
Dimension textSize = SwingUtils.getTextSize(id, g.getFontMetrics());
g.drawString(id, getDrawPosition().x - textSize.width/2 , getDrawPosition().y + 10 );
}
}
g.setFont(getLabelFont());
g.drawString(text, labelPosition.x, labelPosition.y);
}
}
/*
* 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;
import java.util.ArrayList;
/**
*
*/
public class Puck extends DeviceBase {
final static PointDouble[] samplesPosition = new PointDouble[]{
new PointDouble(0, 24.24),
new PointDouble(23.05360995, 7.490571944),
new PointDouble(14.24791452, -19.61057194),
new PointDouble(-14.24791452, -19.61057194),
new PointDouble(-23.05360995, 7.490571944),
new PointDouble(0, 52.52),
new PointDouble(28.39445573, 44.18263554),
new PointDouble(47.7738724, 21.81759648),
new PointDouble(51.98542213, -7.474375306),
new PointDouble(39.69196765, -34.39328575),
new PointDouble(14.79659389, -50.39257097),
new PointDouble(-14.79659389, -50.39257097),
new PointDouble(-39.69196765, -34.39328575),
new PointDouble(-51.98542213, -7.474375306),
new PointDouble(-47.7738724, 21.81759648),
new PointDouble(-28.39445573, 44.18263554)
};
final static PointDouble referencePosition = new PointDouble(0.0, -66.9);
final static Double referenceSize = 6.2;
final int numberOfSamples = samplesPosition.length;
Puck() {
super();
for (int i =0; i< numberOfSamples; i++){
Sample sample = new Sample();
sample.puck = this;
sample.index = i;
addChild(sample);
}
}
BasePlate basePlate;
public BasePlate getBasePlate() {
return basePlate;
}
DimensionDouble getSize(){
return new DimensionDouble(67.0, 67.0);
}
public Sample[] getSamples() {
ArrayList<Sample> ret = new ArrayList<>();
for (Device d : getChildren()) {
ret.add((Sample) d);
}
return ret.toArray(new Sample[0]);
}
public PointDouble getSamplePosition(Sample sample) {
return samplesPosition[sample.index];
}
int index;
public int getIndex() {
return index;
}
public void setIndex(int value) {
index = value;
}
String id;
public String getId() {
//return "XXX000" + index;
return id;
}
public void seId(String value) {
id = value;
}
boolean enabled;
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean value) {
enabled = value;
}
public enum Detection{
Empty,
Present,
Offline,
Error
}
Detection detection;
public Detection getDetection() {
return detection;
}
boolean detectionError;
public boolean isDetectionError() {
return detectionError;
}
boolean selected;
public boolean isSelected() {
return selected;
}
public void setSelected(boolean value) {
if (value != selected){
if (value == true){
for (Device d : getParent().getChildren()){
if (d instanceof Puck){
((Puck)d).selected = false;
}
}
}
selected = value;
}
}
public int getNumberOfSamples() {
return numberOfSamples;
}
Color getColor() {
Color ret = Color.LIGHT_GRAY;
switch (detection){
case Empty:
ret = Color.LIGHT_GRAY;
break;
case Present:
ret = new Color(0, 92, 92);
break;
case Error:
ret = new Color(128, 0, 0);
break;
case Offline:
ret = new Color(92, 92, 0);
break;
}
boolean selected = isSelected();
if (isSelected()) {
ret = ret.brighter();
}
return ret;
}
int getDrawSize() {
//Single puck plot
if (plotRect != null){
return Math.min(plotRect.width, plotRect.height);
}
//All pucks
Rectangle plotRect = basePlate.getPlotRect();
int ret = Math.min(
(int)((getSize().getWidth() / basePlate.getSize().getWidth()) * plotRect.width),
(int)((getSize().getHeight() / basePlate.getSize().getHeight()) * plotRect.height)
);
if (isSelected()) {
ret += 2;
}
return ret;
}
Point getDrawPosition() {
//Single puck plot
if (plotRect != null){
return new Point((int)plotRect.getCenterX(), (int)plotRect.getCenterY());
}
//All pucks
Rectangle plotRect = basePlate.getPlotRect();
DimensionDouble plateSize = basePlate.getSize();
PointDouble pos = basePlate.getPuckPosition(this);
return new Point( (int) ((pos.x / plateSize.getWidth())*plotRect.width + plotRect.getCenterX()) ,
(int) ((pos.y / plateSize.getHeight())*plotRect.height + plotRect.getCenterY())
);
}
Color getLabelColor() {
return Color.BLACK;
}
Font getLabelFont() {
return new Font("Times New Roman", Font.BOLD, 12);
}
Font getIdFont() {
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, center.y + (g.getFontMetrics().getAscent()/2));
}
Color getBorderColor() {
if (!isEnabled()){
return Color.GRAY;
} else if (isSelected()){
return Color.BLACK;
}
return Color.GRAY;
}
int getReferenceDrawSize() {
return (int)((referenceSize / getSize().getWidth()) * getDrawSize());
}
Point getReferenceDrawPosition() {
Point puckCenter = getDrawPosition();
int puckDrawSize = getDrawSize();
DimensionDouble puckSize = getSize();
int size = getReferenceDrawSize();
return new Point( (int) ((referencePosition.x / puckSize.getWidth())* puckDrawSize/2 + puckCenter.x) ,
(int) ((referencePosition.y / puckSize.getHeight())* puckDrawSize/2 + puckCenter.y) );
}
Rectangle plotRect;
void draw (Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawId){
this.plotRect = plotRect;
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);
if (drawSamples){
//Draw samples
for (Sample sample: getSamples()) {
sample.draw(g);
}
}
//Draw reference
g.setColor(Color.DARK_GRAY);
position = getReferenceDrawPosition();
size = getReferenceDrawSize();
g.fillArc(position.x - size / 2, position.y - size / 2, size, size, 180, 180);
//Draw text
String text = String.valueOf(getIndex() + 1);
Point labelPosition = getLabelPosition(text, g);
g.setColor(getLabelColor());
if (drawId){
String id = getId();
if (id!=null) {
labelPosition.setLocation(labelPosition.x, labelPosition.y - 6);
g.setFont(getIdFont());
Dimension textSize = SwingUtils.getTextSize(id, g.getFontMetrics());
g.drawString(id, getDrawPosition().x - textSize.width/2 , getDrawPosition().y + 10 );
}
}
g.setFont(getLabelFont());
g.drawString(text, labelPosition.x, labelPosition.y);
}
}

View File

@@ -0,0 +1,213 @@
package ch.psi.mxsc;
import ch.psi.mxsc.Puck.Detection;
import ch.psi.pshell.device.DeviceBase;
import ch.psi.utils.Arr;
import ch.psi.utils.Chrono;
import ch.psi.utils.State;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import javax.swing.SwingUtilities;
public class PuckDetection extends DeviceBase{
public static final int PUCKS_NUMBER = 30;
final String server;
public volatile Chrono chrono;
public PuckDetection(String name, String server){
super(name);
this.server = server.startsWith("tcp://") ? server : "tcp://" + server;
}
void updateGraphics(){
if (MainPanel.getInstance()!=null){
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
MainPanel.getInstance().repaint();
}
});
}
}
public static class PuckState{
public final int id;
public boolean online;
public boolean mecSwitch;
public boolean indSwitch;
PuckState(int id){
this.id = id;
}
BasePlate getBasePlate(){
if (MainPanel.getInstance()==null){
return null;
}
return MainPanel.getInstance().basePlate;
}
void clear(){
online = false;
mecSwitch = false;
indSwitch = false;
BasePlate basePlate = getBasePlate();
if (basePlate!=null){
basePlate.getPucks()[id-1].detection = Detection.Offline;
}
}
void set(boolean mecSwitch, boolean indSwitch){
online = true;
this.mecSwitch = mecSwitch;
this.indSwitch = indSwitch;
BasePlate basePlate = getBasePlate();
if (basePlate!=null){
if (mecSwitch!=indSwitch){
basePlate.getPucks()[id-1].detection = Detection.Error;
} else if (mecSwitch){
basePlate.getPucks()[id-1].detection = Detection.Present;
} else {
basePlate.getPucks()[id-1].detection = Detection.Empty;
}
}
}
@Override
public String toString(){
return "Online = " + online + "\ns1 = " + mecSwitch+ "\ns2 = " + indSwitch;
}
}
PuckState[] pucks;
public PuckState[] getPucks(){
return pucks;
}
//From 1 to PUCKS_NUMBER
public PuckState getPuck(int id) throws Exception{
assertInitialized();
if ((id<=0) || (id>PUCKS_NUMBER)){
throw new Exception("invalid puck id: "+ id);
}
return pucks[id-1];
}
Thread thread;
Thread watchDog;
@Override
protected void doInitialize() throws IOException, InterruptedException{
doClose();
super.doInitialize();
pucks = new PuckState[PUCKS_NUMBER];
for (int i=0; i<PUCKS_NUMBER; i++ ){
pucks[i] = new PuckState(i+1);
}
chrono = new Chrono();
thread = new Thread(new Runnable() {
@Override
public void run() {
subscriberTask();
}
});
thread.setDaemon(true);
thread.start();
watchDog = new Thread(new Runnable() {
@Override
public void run() {
try{
while (!Thread.currentThread().isInterrupted()) {
if (chrono.isTimeout(3000)){
setState(State.Offline);
for (PuckState puck:pucks){
puck.clear();
}
}
updateGraphics();
Thread.sleep(1000);
}
} catch (Exception ex){
getLogger().log(Level.INFO, null, ex);
}
}
});
watchDog.setDaemon(true);
watchDog.start();
}
void subscriberTask(){
try{
setState(State.Ready);
org.zeromq.ZMQ.Context context = org.zeromq.ZMQ.context(1);
org.zeromq.ZMQ.Socket subscriber = context.socket(org.zeromq.ZMQ.SUB);
subscriber.connect(server);
subscriber.subscribe("Status".getBytes());
try{
while (!Thread.currentThread().isInterrupted()) {
String type = subscriber.recvStr();
System.out.println(type);
String contents = subscriber.recvStr();
System.out.println(contents);
processMessage(contents);
updateGraphics();
setState(State.Ready);
chrono = new Chrono();
}
} finally{
for (PuckState puck:pucks){
puck.clear();
}
updateGraphics();
subscriber.close();
context.term();
}
} catch (Exception ex){
getLogger().log(Level.INFO, null, ex);
}
setState(State.Offline);
}
void processMessage(String msg){
ArrayList<Integer> present = new ArrayList<>();
for (String line:msg.split("\t")){
try{
line = line.trim();
String[] tokens = line.split(" ");
int id = Integer.valueOf(tokens[0].substring(1));
present.add(id);
PuckState puck = getPuck(id);
if (tokens.length<3){
puck.clear();
} else {
puck.set(tokens[1].trim().equals("1"),tokens[2].trim().equals("1"));
}
} catch (Exception ex){
getLogger().log(Level.INFO, null, ex);
}
}
for (int i=1; i<= PUCKS_NUMBER; i++){
if (!Arr.containsEqual(present.toArray(), i)){
pucks[i-1].clear();
}
}
}
@Override
protected void doClose(){
if (watchDog!=null){
watchDog.interrupt();
watchDog = null;
}
if (thread!=null){
thread.interrupt();
thread = null;
}
}
}

View File

@@ -1,73 +1,73 @@
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.plugin;
import ch.psi.pshell.swing.DevicePanel;
import ch.psi.utils.State;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
/**
*
*/
public class PuckPanel extends DevicePanel {
/**
* Creates new form BasePlatePanel
*/
public PuckPanel() {
initComponents();
}
@Override
public Puck getDevice(){
return (Puck) super.getDevice();
}
/**
* 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
@Override
protected void onDeviceStateChanged(State state, State former) {
repaint();
}
@Override
public void paint(Graphics g) {
super.paint(g);
if (getDevice()!=null){
Graphics2D g2d = (Graphics2D) g;
Dimension size = getSize();
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);
}
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.mxsc;
import ch.psi.pshell.swing.DevicePanel;
import ch.psi.utils.State;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
/**
*
*/
public class PuckPanel extends DevicePanel {
/**
* Creates new form BasePlatePanel
*/
public PuckPanel() {
initComponents();
}
@Override
public Puck getDevice(){
return (Puck) super.getDevice();
}
/**
* 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
@Override
protected void onDeviceStateChanged(State state, State former) {
repaint();
}
@Override
public void paint(Graphics g) {
super.paint(g);
if (getDevice()!=null){
Graphics2D g2d = (Graphics2D) g;
Dimension size = getSize();
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);
}
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}

View File

@@ -1,182 +1,182 @@
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.plugin;
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();
}
}
/*
* 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();
}
}