diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a6f89c2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ \ No newline at end of file diff --git a/pom.xml b/pom.xml index cdc78de..73ea2f5 100644 --- a/pom.xml +++ b/pom.xml @@ -1,21 +1,55 @@ - - - 4.0.0 - ch.psi - MXSC - 1.4.0 - jar - - - ${project.groupId} - pshell - ${project.version} - - - - UTF-8 - 1.7 - 1.7 - - MXSC + + + 4.0.0 + ch.psi + MXSC + 1.5.0 + jar + + + ${project.groupId} + pshell + ${project.version} + + + + UTF-8 + 1.7 + 1.7 + + + + releases + releases + https://artifacts.psi.ch/artifactory/releases + + + libs-releases + libs-releases + https://artifacts.psi.ch/artifactory/libs-releases-local + + + libs-snapshots + libs-snapshots + https://artifacts.psi.ch/artifactory/libs-snapshots-local + + + + MXSC + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.3.1 + + ../pshell/home/plugins + + + + \ No newline at end of file diff --git a/src/main/java/ch/psi/plugin/BasePlate.java b/src/main/java/ch/psi/mxsc/BasePlate.java similarity index 84% rename from src/main/java/ch/psi/plugin/BasePlate.java rename to src/main/java/ch/psi/mxsc/BasePlate.java index a98c9a3..11cbf71 100644 --- a/src/main/java/ch/psi/plugin/BasePlate.java +++ b/src/main/java/ch/psi/mxsc/BasePlate.java @@ -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 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; - 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 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, 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) ; + } + } +} diff --git a/src/main/java/ch/psi/plugin/BasePlateConfig.java b/src/main/java/ch/psi/mxsc/BasePlateConfig.java similarity index 84% rename from src/main/java/ch/psi/plugin/BasePlateConfig.java rename to src/main/java/ch/psi/mxsc/BasePlateConfig.java index dad66d0..598f4d6 100644 --- a/src/main/java/ch/psi/plugin/BasePlateConfig.java +++ b/src/main/java/ch/psi/mxsc/BasePlateConfig.java @@ -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{ +} diff --git a/src/main/java/ch/psi/plugin/BasePlatePanel.form b/src/main/java/ch/psi/mxsc/BasePlatePanel.form similarity index 100% rename from src/main/java/ch/psi/plugin/BasePlatePanel.form rename to src/main/java/ch/psi/mxsc/BasePlatePanel.form diff --git a/src/main/java/ch/psi/plugin/BasePlatePanel.java b/src/main/java/ch/psi/mxsc/BasePlatePanel.java similarity index 96% rename from src/main/java/ch/psi/plugin/BasePlatePanel.java rename to src/main/java/ch/psi/mxsc/BasePlatePanel.java index 50cf77f..7039586 100644 --- a/src/main/java/ch/psi/plugin/BasePlatePanel.java +++ b/src/main/java/ch/psi/mxsc/BasePlatePanel.java @@ -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") - // //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.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") + // //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, 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 +} diff --git a/src/main/java/ch/psi/plugin/MainPanel.form b/src/main/java/ch/psi/mxsc/MainPanel.form similarity index 53% rename from src/main/java/ch/psi/plugin/MainPanel.form rename to src/main/java/ch/psi/mxsc/MainPanel.form index 901c478..74346f2 100644 --- a/src/main/java/ch/psi/plugin/MainPanel.form +++ b/src/main/java/ch/psi/mxsc/MainPanel.form @@ -26,20 +26,46 @@ - + - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/ch/psi/plugin/MainPanel.java b/src/main/java/ch/psi/mxsc/MainPanel.java similarity index 52% rename from src/main/java/ch/psi/plugin/MainPanel.java rename to src/main/java/ch/psi/mxsc/MainPanel.java index b334c02..58b4f8e 100644 --- a/src/main/java/ch/psi/plugin/MainPanel.java +++ b/src/main/java/ch/psi/mxsc/MainPanel.java @@ -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") - // //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) - ); - }// //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") + // //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) + ); + }// //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 comboMode; + // End of variables declaration//GEN-END:variables + +} diff --git a/src/main/java/ch/psi/plugin/Puck.java b/src/main/java/ch/psi/mxsc/Puck.java similarity index 87% rename from src/main/java/ch/psi/plugin/Puck.java rename to src/main/java/ch/psi/mxsc/Puck.java index 14a09c9..e4b66b2 100644 --- a/src/main/java/ch/psi/plugin/Puck.java +++ b/src/main/java/ch/psi/mxsc/Puck.java @@ -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 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 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); + } +} diff --git a/src/main/java/ch/psi/mxsc/PuckDetection.java b/src/main/java/ch/psi/mxsc/PuckDetection.java new file mode 100644 index 0000000..d38e2bb --- /dev/null +++ b/src/main/java/ch/psi/mxsc/PuckDetection.java @@ -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 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; + } + } +} diff --git a/src/main/java/ch/psi/plugin/PuckPanel.form b/src/main/java/ch/psi/mxsc/PuckPanel.form similarity index 100% rename from src/main/java/ch/psi/plugin/PuckPanel.form rename to src/main/java/ch/psi/mxsc/PuckPanel.form diff --git a/src/main/java/ch/psi/plugin/PuckPanel.java b/src/main/java/ch/psi/mxsc/PuckPanel.java similarity index 95% rename from src/main/java/ch/psi/plugin/PuckPanel.java rename to src/main/java/ch/psi/mxsc/PuckPanel.java index 66d5290..d008241 100644 --- a/src/main/java/ch/psi/plugin/PuckPanel.java +++ b/src/main/java/ch/psi/mxsc/PuckPanel.java @@ -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") - // //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 -} +/* + * 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") + // //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/mxsc/Sample.java similarity index 95% rename from src/main/java/ch/psi/plugin/Sample.java rename to src/main/java/ch/psi/mxsc/Sample.java index e169762..079635c 100644 --- a/src/main/java/ch/psi/plugin/Sample.java +++ b/src/main/java/ch/psi/mxsc/Sample.java @@ -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(); + + } + +}