Initial panels
This commit is contained in:
135
src/main/java/ch/psi/plugin/BasePlate.java
Normal file
135
src/main/java/ch/psi/plugin/BasePlate.java
Normal file
@@ -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<Puck> pucks = new ArrayList<>();
|
||||
for (int i = 0; i < numberOfPucks; i++) {
|
||||
Puck puck = new Puck();
|
||||
puck.index = i;
|
||||
puck.basePlate = this;
|
||||
this.addChild(puck);
|
||||
}
|
||||
getPucks()[0].setSelected(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInitialize() throws IOException, InterruptedException {
|
||||
super.doInitialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BasePlateConfig getConfig() {
|
||||
return (BasePlateConfig) super.getConfig();
|
||||
}
|
||||
|
||||
|
||||
public Puck[] getPucks() {
|
||||
ArrayList<Puck> ret = new ArrayList<>();
|
||||
for (Device d : getChildren()) {
|
||||
ret.add((Puck) d);
|
||||
}
|
||||
return ret.toArray(new Puck[0]);
|
||||
}
|
||||
|
||||
|
||||
Puck getSelectedPuck(){
|
||||
for (Puck p:getPucks()){
|
||||
if (p.isSelected()){
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Sample getSelectedSample(){
|
||||
Puck puck = getSelectedPuck();
|
||||
if (puck != null){
|
||||
for (Sample s: puck.getSamples()){
|
||||
if (s.isSelected()){
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
DimensionDouble getSize(){
|
||||
return size;
|
||||
}
|
||||
|
||||
public int getNumberOfPucks() {
|
||||
return numberOfPucks;
|
||||
}
|
||||
|
||||
public PointDouble getPuckPosition(Puck puck) {
|
||||
return pucksPosition[puck.index];
|
||||
}
|
||||
|
||||
|
||||
Rectangle plotRect = new Rectangle(0, 0, 0, 0);
|
||||
|
||||
public Rectangle getPlotRect() {
|
||||
return plotRect;
|
||||
}
|
||||
|
||||
void draw(Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawIds) {
|
||||
this.plotRect = plotRect;
|
||||
for (Puck puck : getPucks()) {
|
||||
puck.draw(g, null, drawSamples, drawIds) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/main/java/ch/psi/plugin/BasePlateConfig.java
Normal file
13
src/main/java/ch/psi/plugin/BasePlateConfig.java
Normal file
@@ -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{
|
||||
}
|
||||
28
src/main/java/ch/psi/plugin/BasePlatePanel.form
Normal file
28
src/main/java/ch/psi/plugin/BasePlatePanel.form
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
</Form>
|
||||
276
src/main/java/ch/psi/plugin/BasePlatePanel.java
Normal file
276
src/main/java/ch/psi/plugin/BasePlatePanel.java
Normal file
@@ -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")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 400, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 300, Short.MAX_VALUE)
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
@Override
|
||||
protected void onDeviceStateChanged(State state, State former) {
|
||||
repaint();
|
||||
}
|
||||
|
||||
Rectangle platePlotRect;
|
||||
Rectangle puckPlotRect;
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
if (getDevice() != null) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
Dimension size = getSize();
|
||||
if ((size.width > 40) && (size.height > 40)) {
|
||||
int border = 0;
|
||||
int borderPuck = 20;
|
||||
Rectangle plotRect = new Rectangle(border, border, size.width - 2 * border, size.height - 2 * border);
|
||||
Puck selectedPuck = getDevice().getSelectedPuck();
|
||||
platePlotRect = null;
|
||||
puckPlotRect = null;
|
||||
|
||||
switch (mode) {
|
||||
case single:
|
||||
platePlotRect = plotRect;
|
||||
puckPlotRect = null;
|
||||
getDevice().draw(g2d, platePlotRect, true, false);
|
||||
break;
|
||||
case horizontal:
|
||||
platePlotRect = new Rectangle(plotRect.x, plotRect.y, plotRect.width / 2, plotRect.height);
|
||||
getDevice().draw(g2d, platePlotRect, false, true);
|
||||
if (selectedPuck!=null){
|
||||
puckPlotRect = new Rectangle(plotRect.x + plotRect.width / 2 + borderPuck, plotRect.y + borderPuck, plotRect.width / 2 - 2 * borderPuck, plotRect.height - 2 * borderPuck);
|
||||
selectedPuck.draw(g2d, puckPlotRect, true, false);
|
||||
}
|
||||
break;
|
||||
case vertical:
|
||||
platePlotRect = new Rectangle(plotRect.x, plotRect.y, plotRect.width, plotRect.height / 2);
|
||||
getDevice().draw(g2d, platePlotRect, false, true);
|
||||
if (selectedPuck!=null){
|
||||
puckPlotRect = new Rectangle(plotRect.x + borderPuck, plotRect.y + plotRect.height / 2 + borderPuck, plotRect.width - 2 * borderPuck, plotRect.height / 2 - 2 * borderPuck);
|
||||
selectedPuck.draw(g2d, puckPlotRect, true, false);
|
||||
}
|
||||
break;
|
||||
case overlapped:
|
||||
//getDevice().draw(g2d, plotRect, false, true);
|
||||
platePlotRect = new Rectangle(plotRect.x - ((int) (plotRect.width * 0.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
|
||||
}
|
||||
@@ -16,140 +16,30 @@
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="jPanel2" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jPanel1" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="basePlatePanel" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="jPanel1" max="32767" attributes="0"/>
|
||||
<Component id="jPanel2" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="basePlatePanel" alignment="1" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JPanel" name="jPanel1">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
|
||||
<TitledBorder title="Tasks"/>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Container class="ch.psi.plugin.BasePlatePanel" name="basePlatePanel">
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace pref="58" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="buttonStart1" linkSize="2" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="buttonStart2" linkSize="2" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="buttonStart3" linkSize="2" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="buttonStart4" linkSize="2" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="buttonStart5" linkSize="2" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace pref="59" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="0" pref="442" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace pref="17" max="32767" attributes="0"/>
|
||||
<Component id="buttonStart1" linkSize="1" min="-2" pref="32" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="buttonStart2" linkSize="1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="buttonStart3" linkSize="1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="buttonStart4" linkSize="1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="separate" max="-2" attributes="0"/>
|
||||
<Component id="buttonStart5" linkSize="1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="27" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="buttonStart1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Start Data Acquisition 1"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonStart1ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonStart2">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Start Data Acquisition 2"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonStart2ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonStart3">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Start Data Acquisition 3"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonStart3ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonStart4">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Start Data Acquisition 4"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonStart4ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="buttonStart5">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Start Data Acquisition 5"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonStart5ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JPanel" name="jPanel2">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
|
||||
<TitledBorder title="Devices"/>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="motorPanel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="motorPanel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="ch.psi.pshell.swing.MotorPanel" name="motorPanel">
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
||||
@@ -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")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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)
|
||||
);
|
||||
}// </editor-fold>//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
|
||||
|
||||
}
|
||||
|
||||
261
src/main/java/ch/psi/plugin/Puck.java
Normal file
261
src/main/java/ch/psi/plugin/Puck.java
Normal file
@@ -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<Sample> ret = new ArrayList<>();
|
||||
for (Device d : getChildren()) {
|
||||
ret.add((Sample) d);
|
||||
}
|
||||
return ret.toArray(new Sample[0]);
|
||||
}
|
||||
|
||||
public PointDouble getSamplePosition(Sample sample) {
|
||||
return samplesPosition[sample.index];
|
||||
}
|
||||
|
||||
|
||||
int index;
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int value) {
|
||||
index = value;
|
||||
}
|
||||
|
||||
String id;
|
||||
|
||||
public String getId() {
|
||||
//return "XXX000" + index;
|
||||
return id;
|
||||
}
|
||||
|
||||
public void seId(String value) {
|
||||
id = value;
|
||||
}
|
||||
|
||||
boolean enabled;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean value) {
|
||||
enabled = value;
|
||||
}
|
||||
|
||||
boolean selected;
|
||||
|
||||
public boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
public void setSelected(boolean value) {
|
||||
if (value != selected){
|
||||
if (value == true){
|
||||
for (Device d : getParent().getChildren()){
|
||||
if (d instanceof Puck){
|
||||
((Puck)d).selected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
selected = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int getNumberOfSamples() {
|
||||
return numberOfSamples;
|
||||
}
|
||||
|
||||
Color getColor() {
|
||||
Color ret = Color.LIGHT_GRAY;
|
||||
|
||||
boolean selected = isSelected();
|
||||
if (isSelected()) {
|
||||
ret = ret.brighter();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int getDrawSize() {
|
||||
//Single puck plot
|
||||
if (plotRect != null){
|
||||
return Math.min(plotRect.width, plotRect.height);
|
||||
}
|
||||
//All pucks
|
||||
Rectangle plotRect = basePlate.getPlotRect();
|
||||
int ret = Math.min(
|
||||
(int)((getSize().getWidth() / basePlate.getSize().getWidth()) * plotRect.width),
|
||||
(int)((getSize().getHeight() / basePlate.getSize().getHeight()) * plotRect.height)
|
||||
);
|
||||
if (isSelected()) {
|
||||
ret += 2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Point getDrawPosition() {
|
||||
//Single puck plot
|
||||
if (plotRect != null){
|
||||
return new Point((int)plotRect.getCenterX(), (int)plotRect.getCenterY());
|
||||
}
|
||||
//All pucks
|
||||
Rectangle plotRect = basePlate.getPlotRect();
|
||||
DimensionDouble plateSize = basePlate.getSize();
|
||||
PointDouble pos = basePlate.getPuckPosition(this);
|
||||
return new Point( (int) ((pos.x / plateSize.getWidth())*plotRect.width + plotRect.getCenterX()) ,
|
||||
(int) ((pos.y / plateSize.getHeight())*plotRect.height + plotRect.getCenterY())
|
||||
);
|
||||
}
|
||||
|
||||
Color getLabelColor() {
|
||||
return Color.BLACK;
|
||||
}
|
||||
|
||||
Font getLabelFont() {
|
||||
return new Font("Times New Roman", Font.BOLD, 12);
|
||||
}
|
||||
|
||||
Font getIdFont() {
|
||||
return new Font("Times New Roman", Font.PLAIN, 9);
|
||||
}
|
||||
|
||||
Point getLabelPosition(String text, Graphics g) {
|
||||
Point center = getDrawPosition();
|
||||
Dimension textSize = SwingUtils.getTextSize(text, g.getFontMetrics());
|
||||
return new Point(center.x - textSize.width / 2, center.y + (g.getFontMetrics().getAscent()/2));
|
||||
}
|
||||
|
||||
Color getBorderColor() {
|
||||
if (!isEnabled()){
|
||||
return Color.GRAY;
|
||||
} else if (isSelected()){
|
||||
return Color.BLACK;
|
||||
}
|
||||
return Color.GRAY;
|
||||
}
|
||||
|
||||
int getReferenceDrawSize() {
|
||||
return (int)((referenceSize / getSize().getWidth()) * getDrawSize());
|
||||
}
|
||||
|
||||
|
||||
Point getReferenceDrawPosition() {
|
||||
Point puckCenter = getDrawPosition();
|
||||
int puckDrawSize = getDrawSize();
|
||||
DimensionDouble puckSize = getSize();
|
||||
int size = getReferenceDrawSize();
|
||||
return new Point( (int) ((referencePosition.x / puckSize.getWidth())* puckDrawSize/2 + puckCenter.x) ,
|
||||
(int) ((referencePosition.y / puckSize.getHeight())* puckDrawSize/2 + puckCenter.y) );
|
||||
}
|
||||
|
||||
Rectangle plotRect;
|
||||
void draw (Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawId){
|
||||
this.plotRect = plotRect;
|
||||
Point position = getDrawPosition();
|
||||
int size = getDrawSize();
|
||||
g.setColor(getColor());
|
||||
g.fillOval(position.x - size / 2, position.y - size / 2, size, size);
|
||||
g.setColor(getBorderColor());
|
||||
g.drawOval(position.x - size / 2, position.y - size / 2, size, size);
|
||||
|
||||
if (drawSamples){
|
||||
//Draw samples
|
||||
for (Sample sample: getSamples()) {
|
||||
sample.draw(g);
|
||||
}
|
||||
}
|
||||
|
||||
//Draw reference
|
||||
g.setColor(Color.DARK_GRAY);
|
||||
position = getReferenceDrawPosition();
|
||||
size = getReferenceDrawSize();
|
||||
g.fillArc(position.x - size / 2, position.y - size / 2, size, size, 180, 180);
|
||||
|
||||
//Draw text
|
||||
String text = String.valueOf(getIndex() + 1);
|
||||
Point labelPosition = getLabelPosition(text, g);
|
||||
g.setColor(getLabelColor());
|
||||
if (drawId){
|
||||
String id = getId();
|
||||
if (id!=null) {
|
||||
labelPosition.setLocation(labelPosition.x, labelPosition.y - 6);
|
||||
g.setFont(getIdFont());
|
||||
Dimension textSize = SwingUtils.getTextSize(id, g.getFontMetrics());
|
||||
g.drawString(id, getDrawPosition().x - textSize.width/2 , getDrawPosition().y + 10 );
|
||||
}
|
||||
}
|
||||
g.setFont(getLabelFont());
|
||||
g.drawString(text, labelPosition.x, labelPosition.y);
|
||||
}
|
||||
}
|
||||
28
src/main/java/ch/psi/plugin/PuckPanel.form
Normal file
28
src/main/java/ch/psi/plugin/PuckPanel.form
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
</Form>
|
||||
73
src/main/java/ch/psi/plugin/PuckPanel.java
Normal file
73
src/main/java/ch/psi/plugin/PuckPanel.java
Normal file
@@ -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")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 400, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGap(0, 300, Short.MAX_VALUE)
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
@Override
|
||||
protected void onDeviceStateChanged(State state, State former) {
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
super.paint(g);
|
||||
if (getDevice()!=null){
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
Dimension size = getSize();
|
||||
if ((size.width > 10) && (size.height > 10)) {
|
||||
int border = 5;
|
||||
Rectangle plotRect = new Rectangle(border, border, size.width - 2*border, size.height - 2*border);
|
||||
getDevice().draw(g2d, plotRect, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
182
src/main/java/ch/psi/plugin/Sample.java
Normal file
182
src/main/java/ch/psi/plugin/Sample.java
Normal file
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user