diff --git a/nb-configuration.xml b/nb-configuration.xml
new file mode 100644
index 0000000..ec4540c
--- /dev/null
+++ b/nb-configuration.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+ none
+
+
diff --git a/nbactions.xml b/nbactions.xml
index 877f07e..8a93fef 100644
--- a/nbactions.xml
+++ b/nbactions.xml
@@ -10,7 +10,7 @@
org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
- -classpath %classpath ch.psi.pshell.ui.App -p=ch.psi.plugin.TestPlugin
+ -classpath %classpath ch.psi.pshell.ui.App -b -l -dlaf -p=ch.psi.plugin.MainPanel
java
../../pshell
@@ -26,7 +26,7 @@
org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
- -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath ch.psi.pshell.ui.App -p=ch.psi.plugin.TestPlugin
+ -Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath ch.psi.pshell.ui.App -b -l -dlaf -p=ch.psi.plugin.MainPanel
java
true
../../pshell
@@ -43,7 +43,7 @@
org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
- -classpath %classpath ch.psi.pshell.ui.App -p=ch.psi.plugin.TestPlugin
+ -classpath %classpath ch.psi.pshell.ui.App -b -l -dlaf -p=ch.psi.plugin.MainPanel
java
../../pshell
diff --git a/pom.xml b/pom.xml
index 5e3b7c1..cdc78de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,8 +2,8 @@
4.0.0
ch.psi
- plugin
- 1.0-SNAPSHOT
+ MXSC
+ 1.4.0
jar
@@ -17,4 +17,5 @@
1.7
1.7
+ MXSC
\ No newline at end of file
diff --git a/src/main/java/ch/psi/plugin/BasePlate.java b/src/main/java/ch/psi/plugin/BasePlate.java
new file mode 100644
index 0000000..d6d8f27
--- /dev/null
+++ b/src/main/java/ch/psi/plugin/BasePlate.java
@@ -0,0 +1,135 @@
+/*
+ * 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.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, -57),
+ 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(500.0, 500.0);
+
+ BasePlate() {
+ super("BasePlate", new BasePlateConfig());
+ ArrayList 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 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;
+ for (Puck puck : getPucks()) {
+ puck.draw(g, null, drawSamples, drawIds) ;
+ }
+ }
+}
diff --git a/src/main/java/ch/psi/plugin/BasePlateConfig.java b/src/main/java/ch/psi/plugin/BasePlateConfig.java
new file mode 100644
index 0000000..dad66d0
--- /dev/null
+++ b/src/main/java/ch/psi/plugin/BasePlateConfig.java
@@ -0,0 +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{
+}
diff --git a/src/main/java/ch/psi/plugin/BasePlatePanel.form b/src/main/java/ch/psi/plugin/BasePlatePanel.form
new file mode 100644
index 0000000..c638b68
--- /dev/null
+++ b/src/main/java/ch/psi/plugin/BasePlatePanel.form
@@ -0,0 +1,28 @@
+
+
+
diff --git a/src/main/java/ch/psi/plugin/BasePlatePanel.java b/src/main/java/ch/psi/plugin/BasePlatePanel.java
new file mode 100644
index 0000000..7a446df
--- /dev/null
+++ b/src/main/java/ch/psi/plugin/BasePlatePanel.java
@@ -0,0 +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.horizontal;
+
+ 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")
+ // //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)
+ );
+ }// //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.12)), plotRect.y - ((int) (plotRect.height * 0.12)), (int) (plotRect.width * 1.24), (int) (plotRect.height * 1.24));
+ 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.5), 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
+}
diff --git a/src/main/java/ch/psi/plugin/MainPanel.form b/src/main/java/ch/psi/plugin/MainPanel.form
index c9d9744..901c478 100644
--- a/src/main/java/ch/psi/plugin/MainPanel.form
+++ b/src/main/java/ch/psi/plugin/MainPanel.form
@@ -16,140 +16,30 @@
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/main/java/ch/psi/plugin/MainPanel.java b/src/main/java/ch/psi/plugin/MainPanel.java
index 1caf8e2..b334c02 100644
--- a/src/main/java/ch/psi/plugin/MainPanel.java
+++ b/src/main/java/ch/psi/plugin/MainPanel.java
@@ -1,207 +1,69 @@
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
+
package ch.psi.plugin;
-import ch.psi.pshell.device.Device;
-import ch.psi.utils.State;
+import ch.psi.pshell.ui.Panel;
/**
*
*/
-public class MainPanel extends javax.swing.JPanel {
- /**
- * Creates new form MainPanel
- */
- public MainPanel() {
- initComponents();
+public class MainPanel extends Panel {
+ BasePlate basePlate;
+ /** Creates new form Panel */
+ public MainPanel() {
+ initComponents();
+ basePlate = new BasePlate();
}
- void setState(State state) {
- try{
- boolean ready = state==State.Ready;
- if (!state.isInitialized()){
- motorPanel.setDevice(null);
- }
- buttonStart1.setEnabled(ready);
- buttonStart2.setEnabled(ready);
- buttonStart3.setEnabled(ready);
- buttonStart4.setEnabled(ready);
- buttonStart5.setEnabled(ready);
- //motorPanel1.setEnabled(newState==State.Ready);
- //motorPanel2.setEnabled(newState==State.Ready);
- }
- catch (Exception ex){
- ex.printStackTrace();
- }
+
+ @Override
+ public void onInitialize(int runCount) {
+ basePlatePanel.setDevice(basePlate);
+ //basePlatePanel.setShowSamples(true);
+ //puckPanel.setDevice(basePlate.getPucks()[0]);
+ addDevice(basePlate);
}
+
- void setDevice(Device device){
- motorPanel.setDevice(device);
- }
-
- protected void run(String name){
- }
-
- /**
- * 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.
+ /** 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")
// //GEN-BEGIN:initComponents
private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- buttonStart1 = new javax.swing.JButton();
- buttonStart2 = new javax.swing.JButton();
- buttonStart3 = new javax.swing.JButton();
- buttonStart4 = new javax.swing.JButton();
- buttonStart5 = new javax.swing.JButton();
- jPanel2 = new javax.swing.JPanel();
- motorPanel = new ch.psi.pshell.swing.MotorPanel();
+ basePlatePanel = new ch.psi.plugin.BasePlatePanel();
- jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Tasks"));
-
- buttonStart1.setText("Start Data Acquisition 1");
- buttonStart1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- buttonStart1ActionPerformed(evt);
- }
- });
-
- buttonStart2.setText("Start Data Acquisition 2");
- buttonStart2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- buttonStart2ActionPerformed(evt);
- }
- });
-
- buttonStart3.setText("Start Data Acquisition 3");
- buttonStart3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- buttonStart3ActionPerformed(evt);
- }
- });
-
- buttonStart4.setText("Start Data Acquisition 4");
- buttonStart4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- buttonStart4ActionPerformed(evt);
- }
- });
-
- buttonStart5.setText("Start Data Acquisition 5");
- buttonStart5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- buttonStart5ActionPerformed(evt);
- }
- });
-
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap(58, Short.MAX_VALUE)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(buttonStart1)
- .addComponent(buttonStart2)
- .addComponent(buttonStart3)
- .addComponent(buttonStart4)
- .addComponent(buttonStart5))
- .addContainerGap(59, Short.MAX_VALUE))
+ 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)
);
-
- jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonStart1, buttonStart2, buttonStart3, buttonStart4, buttonStart5});
-
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap(17, Short.MAX_VALUE)
- .addComponent(buttonStart1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(18, 18, 18)
- .addComponent(buttonStart2)
- .addGap(18, 18, 18)
- .addComponent(buttonStart3)
- .addGap(18, 18, 18)
- .addComponent(buttonStart4)
- .addGap(18, 18, 18)
- .addComponent(buttonStart5)
- .addContainerGap(27, Short.MAX_VALUE))
- );
-
- jPanel1Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {buttonStart1, buttonStart2, buttonStart3, buttonStart4, buttonStart5});
-
- jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Devices"));
-
- javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
- jPanel2.setLayout(jPanel2Layout);
- jPanel2Layout.setHorizontalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(motorPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap())
- );
- jPanel2Layout.setVerticalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(motorPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, 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)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .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(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(basePlatePanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
}// //GEN-END:initComponents
- private void buttonStart1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStart1ActionPerformed
- // TODO add your handling code here:
- run("test1");
- }//GEN-LAST:event_buttonStart1ActionPerformed
-
- private void buttonStart2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStart2ActionPerformed
- // TODO add your handling code here:
- run("test2");
- }//GEN-LAST:event_buttonStart2ActionPerformed
-
- private void buttonStart3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStart3ActionPerformed
- // TODO add your handling code here:
- run("test3");
- }//GEN-LAST:event_buttonStart3ActionPerformed
-
- private void buttonStart4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStart4ActionPerformed
- // TODO add your handling code here:
- run("test4");
- }//GEN-LAST:event_buttonStart4ActionPerformed
-
- private void buttonStart5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStart5ActionPerformed
- // TODO add your handling code here:
- run("test5");
- }//GEN-LAST:event_buttonStart5ActionPerformed
-
// Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton buttonStart1;
- private javax.swing.JButton buttonStart2;
- private javax.swing.JButton buttonStart3;
- private javax.swing.JButton buttonStart4;
- private javax.swing.JButton buttonStart5;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JPanel jPanel2;
- private ch.psi.pshell.swing.MotorPanel motorPanel;
+ private ch.psi.plugin.BasePlatePanel basePlatePanel;
// End of variables declaration//GEN-END:variables
+
}
diff --git a/src/main/java/ch/psi/plugin/Puck.java b/src/main/java/ch/psi/plugin/Puck.java
new file mode 100644
index 0000000..c374680
--- /dev/null
+++ b/src/main/java/ch/psi/plugin/Puck.java
@@ -0,0 +1,261 @@
+/*
+ * 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, -67.0);
+ 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 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);
+ }
+}
diff --git a/src/main/java/ch/psi/plugin/PuckPanel.form b/src/main/java/ch/psi/plugin/PuckPanel.form
new file mode 100644
index 0000000..c638b68
--- /dev/null
+++ b/src/main/java/ch/psi/plugin/PuckPanel.form
@@ -0,0 +1,28 @@
+
+
+
diff --git a/src/main/java/ch/psi/plugin/PuckPanel.java b/src/main/java/ch/psi/plugin/PuckPanel.java
new file mode 100644
index 0000000..66d5290
--- /dev/null
+++ b/src/main/java/ch/psi/plugin/PuckPanel.java
@@ -0,0 +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")
+ // //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)
+ );
+ }// //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
+}
diff --git a/src/main/java/ch/psi/plugin/Sample.java b/src/main/java/ch/psi/plugin/Sample.java
new file mode 100644
index 0000000..e169762
--- /dev/null
+++ b/src/main/java/ch/psi/plugin/Sample.java
@@ -0,0 +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();
+
+ }
+
+}
diff --git a/src/main/java/ch/psi/plugin/TestPlugin.java b/src/main/java/ch/psi/plugin/TestPlugin.java
deleted file mode 100644
index 3bf95bd..0000000
--- a/src/main/java/ch/psi/plugin/TestPlugin.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
- */
-
-package ch.psi.plugin;
-
-import ch.psi.pshell.device.Device;
-import ch.psi.pshell.ui.Plugin;
-import ch.psi.utils.State;
-import ch.psi.utils.swing.SwingUtils;
-
-/**
- *
- */
-public class TestPlugin implements Plugin{
- MainPanel panel;
- @Override
- public void onStart() {
- panel = new MainPanel(){
- protected void run(String name){
- try {
- TestPlugin.this.runAsync(name);
- } catch (Exception ex) {
- SwingUtils.showException(panel, ex);
- }
- }
- };
- getView().getDocumentsTab().insertTab("Main",null,panel,null,0);
- getView().getDocumentsTab().setSelectedComponent(panel);
- }
-
- @Override
- public void onStop() {
-
- }
-
- public void onStateChange(State state, State former){
- panel.setState(state);
- }
-
- @Override
- public void onInitialize(int runCount){
- panel.setDevice((Device)getDevice("motor"));
- }
-
-
-
-}