Manage {config} token in -setp option

This commit is contained in:
2018-08-23 09:53:19 +02:00
parent 52a8daf5c0
commit 810740ddca
12 changed files with 624 additions and 534 deletions

View File

@@ -7,14 +7,6 @@ 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.pshell.imaging.Utils;
import ch.psi.utils.swing.MainFrame;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
@@ -78,19 +70,7 @@ public class BasePlate extends DeviceBase {
return (BasePlateConfig) super.getConfig();
}
enum SelectionMode{
Samples,
Pucks,
None
}
SelectionMode selectionMode = SelectionMode.None;
public SelectionMode getSelectionMode() {
return selectionMode;
}
public void setSelectionMode(SelectionMode selectionMode) {
this.selectionMode = selectionMode;
}
public Puck[] getPucks() {
ArrayList<Puck> ret = new ArrayList<>();
@@ -102,24 +82,20 @@ public class BasePlate extends DeviceBase {
Puck getSelectedPuck(){
if (selectionMode!=SelectionMode.None){
for (Puck p:getPucks()){
if (p.isSelected()){
return p;
}
for (Puck p:getPucks()){
if (p.isSelected()){
return p;
}
}
return null;
}
Sample getSelectedSample(){
if (selectionMode==SelectionMode.Samples){
Puck puck = getSelectedPuck();
if (puck != null){
for (Sample s: puck.getSamples()){
if (s.isSelected()){
return s;
}
Puck puck = getSelectedPuck();
if (puck != null){
for (Sample s: puck.getSamples()){
if (s.isSelected()){
return s;
}
}
}
@@ -173,87 +149,6 @@ public class BasePlate extends DeviceBase {
}
return null;
}
Rectangle plotRect = new Rectangle(0, 0, 0, 0);
Rectangle boundingBox;
public Rectangle getPlotRect() {
return plotRect;
}
public Rectangle getBoundingBox() {
return boundingBox;
}
Color getBorderColor(boolean drawBackground) {
//return new Color(32,32,32);
if (drawBackground){
return MainFrame.isDark() ? new Color(32,32,32) : Color.DARK_GRAY;
}
return MainFrame.isDark() ? new Color(0,32,0) : new Color(0,64,0);
}
Color getColor() {
return MainFrame.isDark() ? new Color(67,71,73) /*new Color(65,81,109)*/ : new Color(200, 204, 213);
}
boolean drawContour;
enum DrawMode{
fill,
center,
left,
right,
top,
bottom
}
void draw(Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawIds, boolean drawContour, DrawMode mode, BufferedImage img) {
if (mode != DrawMode.fill){
int length = Math.min(plotRect.width, plotRect.height);
Point center= new Point(plotRect.x + plotRect.width/2, plotRect.y + plotRect.height/2); //center;
switch (mode){
case left:
center.setLocation(length/2, center.y);
break;
case right:
center.setLocation(plotRect.width - length/2, center.y);
break;
case top:
center.setLocation(center.x, length/2);
break;
case bottom:
center.setLocation(center.x, plotRect.height - length/2);
break;
}
plotRect = new Rectangle(center.x - length/2, center.y - length/2, length, length);
}
this.plotRect = plotRect;
this.drawContour = drawContour;
boundingBox = new Rectangle((int)(plotRect.x+plotRect.width*0.05), (int)(plotRect.y+plotRect.height * 0.05), (int)(plotRect.width*0.90), (int)(plotRect.height*0.90));
if (img!=null){
img = Utils.stretch(img, boundingBox.width, boundingBox.height);
g.setClip(new Ellipse2D.Float(boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height));
g.drawImage(img, boundingBox.x, boundingBox.y, null);
}
boolean drawBackground = (img==null);
if (drawContour){
if (drawBackground){
g.setColor(getColor());
g.fillOval(boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height);
}
g.setColor(getBorderColor(drawBackground));
g.drawOval(boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height);
}
for (Puck puck : getPucks()) {
puck.draw(g, null, drawSamples, drawIds, drawBackground, this) ;
}
}
public void loadSample(Sample sample) throws Exception{

View File

@@ -0,0 +1,111 @@
package ch.psi.mxsc;
import ch.psi.pshell.imaging.Utils;
import ch.psi.utils.swing.MainFrame;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
/**
*
*/
public class BasePlateGraphics {
final BasePlate basePlate;
List<PuckGraphics> puckGraphics = new ArrayList<>();
public BasePlateGraphics(BasePlate basePlate){
this.basePlate = basePlate;
for (Puck puck : basePlate.getPucks()){
puckGraphics.add(new PuckGraphics(puck, this));
}
}
Rectangle plotRect = new Rectangle(0, 0, 0, 0);
Rectangle boundingBox;
public Rectangle getPlotRect() {
return plotRect;
}
public Rectangle getBoundingBox() {
return boundingBox;
}
Color getBorderColor(boolean drawBackground) {
//return new Color(32,32,32);
if (drawBackground){
return MainFrame.isDark() ? new Color(32,32,32) : Color.DARK_GRAY;
}
return MainFrame.isDark() ? new Color(0,32,0) : new Color(0,64,0);
}
Color getColor() {
return MainFrame.isDark() ? new Color(67,71,73) /*new Color(65,81,109)*/ : new Color(200, 204, 213);
}
boolean drawContour;
enum DrawMode{
fill,
center,
left,
right,
top,
bottom
}
void draw(Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawIds, boolean drawContour, DrawMode mode, BufferedImage img) {
if (mode != DrawMode.fill){
int length = Math.min(plotRect.width, plotRect.height);
Point center= new Point(plotRect.x + plotRect.width/2, plotRect.y + plotRect.height/2); //center;
switch (mode){
case left:
center.setLocation(length/2, center.y);
break;
case right:
center.setLocation(plotRect.width - length/2, center.y);
break;
case top:
center.setLocation(center.x, length/2);
break;
case bottom:
center.setLocation(center.x, plotRect.height - length/2);
break;
}
plotRect = new Rectangle(center.x - length/2, center.y - length/2, length, length);
}
this.plotRect = plotRect;
this.drawContour = drawContour;
boundingBox = new Rectangle((int)(plotRect.x+plotRect.width*0.05), (int)(plotRect.y+plotRect.height * 0.05), (int)(plotRect.width*0.90), (int)(plotRect.height*0.90));
if (img!=null){
img = Utils.stretch(img, boundingBox.width, boundingBox.height);
g.setClip(new Ellipse2D.Float(boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height));
g.drawImage(img, boundingBox.x, boundingBox.y, null);
}
boolean drawBackground = (img==null);
if (drawContour){
if (drawBackground){
g.setColor(getColor());
g.fillOval(boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height);
}
g.setColor(getBorderColor(drawBackground));
g.drawOval(boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height);
}
for (PuckGraphics pg : puckGraphics) {
pg.draw(g, null, drawSamples, drawIds, drawBackground) ;
}
}
}

View File

@@ -3,8 +3,8 @@
*/
package ch.psi.mxsc;
import ch.psi.mxsc.BasePlate.DrawMode;
import ch.psi.mxsc.BasePlate.SelectionMode;
import ch.psi.mxsc.BasePlateGraphics.DrawMode;
import ch.psi.pshell.device.Device;
import ch.psi.pshell.imaging.Data;
import ch.psi.pshell.imaging.ImageListener;
import ch.psi.pshell.imaging.Source;
@@ -32,6 +32,8 @@ public class BasePlatePanel extends DevicePanel {
JPopupMenu samplePopupMenu;
JMenuItem menuLoadSample;
JMenuItem menuUnloadSample;
BasePlateGraphics basePlateGraphics;
PuckGraphics puckGraphics;
boolean TOGGLE_SELECTION = false;
/**
@@ -65,6 +67,16 @@ public class BasePlatePanel extends DevicePanel {
public BasePlate getDevice() {
return (BasePlate) super.getDevice();
}
@Override
public void setDevice(Device device){
super.setDevice(device);
if (mode==Mode.puck){
basePlateGraphics = null;
} else {
basePlateGraphics = (device==null) ? null : new BasePlateGraphics((BasePlate)device);
}
}
Mode mode = Mode.horizontal;
@@ -85,6 +97,20 @@ public class BasePlatePanel extends DevicePanel {
repaint();
}
enum SelectionMode{
Samples,
Pucks,
None
}
SelectionMode selectionMode = SelectionMode.None;
public SelectionMode getSelectionMode() {
return selectionMode;
}
public void setSelectionMode(SelectionMode selectionMode) {
this.selectionMode = selectionMode;
}
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT
@@ -114,6 +140,17 @@ public class BasePlatePanel extends DevicePanel {
Rectangle platePlotRect;
Rectangle puckPlotRect;
Source source;
void createPuckGraphics(){
Puck selectedPuck = getDevice().getSelectedPuck();
if (selectedPuck==null){
puckGraphics=null;
} else {
if ((puckGraphics==null) || (puckGraphics.puck!= selectedPuck)){
puckGraphics = new PuckGraphics(selectedPuck, null);
}
}
}
@Override
public void paint(Graphics g) {
@@ -123,7 +160,7 @@ public class BasePlatePanel extends DevicePanel {
Dimension size = getSize();
if ((size.width > 40) && (size.height > 40)) {
int border = 0;
int borderPuck = 20;
int borderPuck = 0;
Rectangle plotRect = new Rectangle(border, border, size.width - 2 * border, size.height - 2 * border);
Puck selectedPuck = getDevice().getSelectedPuck();
platePlotRect = null;
@@ -133,38 +170,42 @@ public class BasePlatePanel extends DevicePanel {
case single:
platePlotRect = plotRect;
puckPlotRect = null;
getDevice().draw(g2d, platePlotRect, (img==null), false, true, DrawMode.center, img);
basePlateGraphics.draw(g2d, platePlotRect, (img==null), false, true, DrawMode.center, img);
break;
case horizontal:
platePlotRect = new Rectangle(plotRect.x, plotRect.y, plotRect.width / 2, plotRect.height);
getDevice().draw(g2d, platePlotRect, false, true, true, DrawMode.fill, null);
basePlateGraphics.draw(g2d, platePlotRect, false, true, true, DrawMode.fill, null);
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, true, null);
createPuckGraphics();
puckGraphics.draw(g2d, puckPlotRect, true, false, true);
}
break;
case vertical:
platePlotRect = new Rectangle(plotRect.x, plotRect.y, plotRect.width, plotRect.height / 2);
getDevice().draw(g2d, platePlotRect, false, true, true, DrawMode.fill, null);
basePlateGraphics.draw(g2d, platePlotRect, false, true, true, DrawMode.fill, null);
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, true, null);
createPuckGraphics();
puckGraphics.draw(g2d, puckPlotRect, true, false, true);
}
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, DrawMode.fill, null);
basePlateGraphics.draw(g2d, platePlotRect, false, true, false, DrawMode.fill, null);
if (selectedPuck!=null){
int overlappedSize = (int) (1.5 * selectedPuck.getDrawSize());
createPuckGraphics();
int overlappedSize = (int) (1.5 * puckGraphics.getDrawSize());
puckPlotRect = new Rectangle((int) (plotRect.getCenterX() - overlappedSize / 2), (int) (plotRect.getCenterY() - overlappedSize / 2), overlappedSize, overlappedSize);
selectedPuck.draw(g2d, puckPlotRect, true, false, true, null);
puckGraphics.draw(g2d, puckPlotRect, true, false, true);
}
break;
case puck:
if (selectedPuck!=null){
puckPlotRect = new Rectangle(plotRect.x + borderPuck, plotRect.y + borderPuck, plotRect.width - 2 * borderPuck, plotRect.height - 2 * borderPuck);
selectedPuck.draw(g2d, puckPlotRect, true, true, true, null);
createPuckGraphics();
puckGraphics.draw(g2d, puckPlotRect, true, true, true);
}
break;
}
@@ -273,12 +314,21 @@ public class BasePlatePanel extends DevicePanel {
Sample getSample(int x, int y) {
Point p = new Point(x, y);
for (Puck puck : getDevice().getPucks()){
if (puck.isSelected() || (mode==Mode.single)){
for (Sample sample :puck.getSamples()){
if (sample.getDrawPosition().distance(p) <= (sample.getDrawSize() / 2)) {
return sample;
}
if (puckGraphics!=null){
for (SampleGraphics sample :puckGraphics.sampleGraphics){
if (sample.getDrawPosition().distance(p) <= (sample.getDrawSize() / 2)) {
return sample.sample;
}
}
}
if (basePlateGraphics!=null){
for (PuckGraphics puck : basePlateGraphics.puckGraphics){
if ((mode==Mode.single) || puck.puck.isSelected()){
for (SampleGraphics sample :puck.sampleGraphics){
if (sample.getDrawPosition().distance(p) <= (sample.getDrawSize() / 2)) {
return sample.sample;
}
}
}
}
}
@@ -289,10 +339,20 @@ public class BasePlatePanel extends DevicePanel {
Puck getPuck(int x, int y) {
Point p = new Point(x, y);
for (Puck puck : getDevice().getPucks()){
if (puck.getDrawPosition().distance(p) <= (puck.getDrawSize() / 2)) {
return puck;
}
if (puckGraphics!=null){
if (puckGraphics.getDrawPosition().distance(p) <= (puckGraphics.getDrawSize() / 2)) {
return puckGraphics.puck;
}
}
if (mode == Mode.puck){
return getDevice().getSelectedPuck(); //Won't de-select it by clicking outside
}
if (basePlateGraphics!=null){
for (PuckGraphics puck : basePlateGraphics.puckGraphics){
if (puck.getDrawPosition().distance(p) <= (puck.getDrawSize() / 2)) {
return puck.puck;
}
}
}
return null;
}
@@ -303,7 +363,7 @@ public class BasePlatePanel extends DevicePanel {
}
void selectSample(Sample sample){
if (getDevice().getSelectionMode()==SelectionMode.Samples){
if (getSelectionMode()==SelectionMode.Samples){
sample.setSelected(true);
repaint();
Controller.getInstance().onSamplePressed(sample);
@@ -311,7 +371,7 @@ public class BasePlatePanel extends DevicePanel {
}
void onSamplePressed(MouseEvent e, Sample sample){
if (getDevice().getSelectionMode()==SelectionMode.Samples){
if (getSelectionMode()==SelectionMode.Samples){
if (TOGGLE_SELECTION){
sample.toggleSelected(true);
} else {
@@ -319,7 +379,7 @@ public class BasePlatePanel extends DevicePanel {
}
repaint();
Controller.getInstance().onSamplePressed(sample);
} else if (getDevice().getSelectionMode()==SelectionMode.Pucks){
} else if (getSelectionMode()==SelectionMode.Pucks){
onPuckPressed(e, sample.getPuck());
}
}
@@ -344,7 +404,7 @@ public class BasePlatePanel extends DevicePanel {
}
void selectPuck(Puck puck){
if (getDevice().getSelectionMode()!=SelectionMode.None){
if (getSelectionMode()!=SelectionMode.None){
puck.setSelected(true);
repaint();
Controller.getInstance().onPuckPressed(puck);
@@ -352,7 +412,7 @@ public class BasePlatePanel extends DevicePanel {
}
void onPuckPressed(MouseEvent e, Puck puck){
if (getDevice().getSelectionMode()!=SelectionMode.None){
if (getSelectionMode()!=SelectionMode.None){
if (TOGGLE_SELECTION){
puck.toggleSelected(true);
} else {

View File

@@ -344,8 +344,9 @@ public class Controller {
if ((puckPanel==null) || (puckPanel != getMainFrame().getDetail())){
puckPanel = new BasePlatePanel();
puckPanel.setMode(BasePlatePanel.Mode.puck);
puckPanel.setSelectionMode(BasePlatePanel.SelectionMode.Samples);
puckPanel.setDevice((Device) getDevice("BasePlate"));
puckPanel.setEnabled(false); //TODO: Puck cannot be shared between two panels (device store single coordinates foe comparing to click)
puckPanel.setEnabled(true); //TODO: Puck cannot be shared between two panels (device store single coordinates foe comparing to click)
getMainFrame().setDetail(puckPanel);
}
}

View File

@@ -31,7 +31,7 @@
<Group type="102" alignment="1" attributes="0">
<Component id="panelTop" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="panelBottom" pref="88" max="32767" attributes="0"/>
<Component id="panelBottom" pref="82" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
</Group>
</Group>
@@ -334,21 +334,21 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="13" max="32767" attributes="0"/>
<EmptySpace pref="9" max="32767" attributes="0"/>
<Group type="103" groupAlignment="2" attributes="0">
<Component id="buttonDetectCover" alignment="2" min="-2" max="-2" attributes="0"/>
<Component id="hexiposiPanel" alignment="2" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="14" max="32767" attributes="0"/>
<EmptySpace pref="9" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace pref="15" max="32767" attributes="0"/>
<EmptySpace pref="14" max="32767" attributes="0"/>
<Component id="hexiposiPanel" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="10" max="32767" attributes="0"/>
<EmptySpace pref="9" max="32767" attributes="0"/>
<Component id="buttonDetectCover" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
@@ -381,12 +381,12 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<EmptySpace pref="8" max="32767" attributes="0"/>
<Group type="103" groupAlignment="2" attributes="0">
<Component id="buttonDrawing" linkSize="25" alignment="2" min="-2" max="-2" attributes="0"/>
<Component id="buttonCamera" linkSize="25" alignment="2" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
<EmptySpace pref="8" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@@ -733,7 +733,7 @@
<Component id="buttonRelease" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Component id="filler1" pref="38" max="32767" attributes="0"/>
<Component id="filler1" max="32767" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="4" max="-2" attributes="0"/>
</Group>
@@ -917,9 +917,9 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="panelDetail" pref="240" max="32767" attributes="0"/>
<Component id="panelDetail" pref="276" max="32767" attributes="0"/>
<Component id="panelDisplayMode" alignment="0" max="32767" attributes="0"/>
<Component id="panelDevices" alignment="1" pref="240" max="32767" attributes="0"/>
<Component id="panelDevices" alignment="1" pref="276" max="32767" attributes="0"/>
</Group>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
</Group>
@@ -929,7 +929,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="panelDetail" pref="93" max="32767" attributes="0"/>
<Component id="panelDetail" pref="102" max="32767" attributes="0"/>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Component id="panelDevices" min="-2" pref="280" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
@@ -1037,16 +1037,16 @@
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Component id="devicesPanel" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="10" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="panelExpert" min="-2" pref="93" max="-2" attributes="0"/>
<EmptySpace pref="13" max="32767" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace pref="14" max="32767" attributes="0"/>
<EmptySpace pref="15" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="panelExpert" max="32767" attributes="0"/>
<Component id="devicesPanel" pref="232" max="32767" attributes="0"/>
@@ -1088,7 +1088,7 @@
<Group type="102" attributes="0">
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Component id="checkExpert" min="-2" max="-2" attributes="0"/>
<EmptySpace type="separate" max="32767" attributes="0"/>
<EmptySpace type="separate" pref="19" max="32767" attributes="0"/>
<Component id="buttonExpertCommands" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="buttonRecovery" min="-2" max="-2" attributes="0"/>

View File

@@ -3,6 +3,7 @@
*/
package ch.psi.mxsc;
import ch.psi.mxsc.BasePlatePanel.SelectionMode;
import ch.psi.pshell.core.Context;
import ch.psi.pshell.core.JsonSerializer;
import ch.psi.pshell.core.Plugin;
@@ -15,7 +16,6 @@ import ch.psi.pshell.ui.App;
import ch.psi.pshell.ui.Panel;
import ch.psi.utils.State;
import ch.psi.utils.swing.SwingUtils;
import ch.psi.mxsc.BasePlate.SelectionMode;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
@@ -88,8 +88,8 @@ public class MainPanel extends Panel {
Image img = new ImageIcon(this.getClass().getResource("/apple_transparent_white_100x50.png")).getImage();
SwingUtils.getWindow(this).setIconImage(img);
}
basePlatePanel.setSelectionMode(SelectionMode.Pucks);
basePlatePanel.setDevice(Controller.getInstance().basePlate);
basePlatePanel.getDevice().setSelectionMode(SelectionMode.Pucks);
}
@Override
@@ -98,7 +98,6 @@ public class MainPanel extends Panel {
Controller.getInstance().onInitialize(runCount);
if (basePlatePanel.getDevice() != (Device) getDevice("BasePlate")){
basePlatePanel.setDevice((Device) getDevice("BasePlate"));
basePlatePanel.getDevice().setSelectionMode(SelectionMode.Pucks);
}
try {
devicesPanel.initialize();

View File

@@ -3,21 +3,10 @@
*/
package ch.psi.mxsc;
import ch.psi.mxsc.BasePlate.SelectionMode;
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.MainFrame;
import ch.psi.utils.swing.SwingUtils;
import java.awt.BasicStroke;
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;
/**
@@ -80,7 +69,7 @@ public class Puck extends DeviceBase {
final static PointDouble ledMinispinePosition = new PointDouble(0.0, -36.0);
final static Double unipuckLedSize = 10.0;
final static Double minispineLedSize = 8.0;
final static PointDouble labelPositionWithImage = new PointDouble(0.0, 36.0);
PuckType puckType = PuckType.Unknown;
@@ -155,52 +144,7 @@ public class Puck extends DeviceBase {
}
return ret.toArray(new Sample[0]);
}
public PointDouble getRotatedPosition(PointDouble ref) {
double rotation = - angle * Math.PI / 180.0;
double x = ref.x * Math.cos(rotation) - ref.y * Math.sin(rotation);
double y = ref.y * Math.cos(rotation) + ref.x * Math.sin(rotation);
return new PointDouble(x,y );
}
public PointDouble getSamplePosition(Sample sample) {
//PointDouble ref = samplesPosition[sample.index];
//return getRotatedPosition(ref);
return samplesPosition[sample.index];
}
public Point getDrawUnipuckLedPosition(){
PointDouble ref = ledUnipuckPosition;
return getDrawPosition(ref);
}
public Point getDrawMinispineLedPosition(){
PointDouble ref = ledMinispinePosition;
return getDrawPosition(ref);
}
int getUnipuckLedSize() {
return getDrawSize(unipuckLedSize) ;
}
int getMinispineLedSize() {
return getDrawSize(minispineLedSize) ;
}
int getDrawSize(double refSize) {
return (int) ((refSize / getSize().getWidth()) * getDrawSize()) ;
}
Point getDrawPosition(PointDouble refPosition) {
Point puckCenter = getDrawPosition();
int puckDrawSize = getDrawSize();
DimensionDouble puckSize = getSize();
PointDouble pos = getRotatedPosition(refPosition);
return new Point( (int) ((pos.x / puckSize.getWidth())* puckDrawSize/2 + puckCenter.x) ,
(int) ((pos.y / puckSize.getHeight())* puckDrawSize/2 + puckCenter.y) );
}
public boolean isSegmentSelected() {
/*
@@ -219,10 +163,6 @@ public class Puck extends DeviceBase {
return ("" + getSegment()).equalsIgnoreCase(Controller.getInstance().getHexiposiPosition());
}
public boolean isHighlithted() {
return isSelected() || isSegmentSelected();
}
public int getIndex() {
return index;
}
@@ -285,7 +225,7 @@ public class Puck extends DeviceBase {
private boolean selected;
public boolean isSelected() {
return selected && (getBasePlate().getSelectionMode()!=SelectionMode.None);
return selected;
}
public void toggleSelected(boolean value) {
@@ -315,192 +255,5 @@ public class Puck extends DeviceBase {
public int getNumberOfSamples() {
return numberOfSamples;
}
Color getColor() {
Color ret = Color.LIGHT_GRAY;
switch (detection) {
case Empty:
//ret = isHighlithted() ? new Color(224, 224, 224) : Color.LIGHT_GRAY;
ret = isHighlithted() ? new Color(212, 212, 212) : Color.LIGHT_GRAY;
break;
case Present:
if ((puckType != null) && (puckType != PuckType.Unknown)){
switch (puckType){
case Minispine:
ret = isHighlithted() ? new Color(0, 200, 80) : new Color(128, 232, 152);
break;
case Unipuck:
ret = isHighlithted() ? new Color(0, 140, 140) : new Color(128, 192, 192);
break;
case Empty:
case Error:
ret = isHighlithted() ? new Color(192, 10, 10) : new Color(192, 128, 128);
break;
}
} else {
ret = isHighlithted() ? new Color(0, 140, 140) : new Color(128, 192, 192);
}
break;
case Error:
ret = isHighlithted() ? new Color(192, 10, 10) : new Color(192, 128, 128);
break;
case Offline:
ret = isHighlithted() ? new Color(250, 255, 48) : new Color(253, 194, 41);
//ret = isHighlithted() ? new Color(230, 142, 40) : new Color(216, 159, 93);
break;
}
return ret;
}
int getDrawSize() {
//Single puck plot
if (plotRect != null) {
return Math.min(plotRect.width, plotRect.height);
}
//All pucks
Rectangle plotRect = getBasePlate().getBoundingBox();
int ret = Math.min(
(int) ((getSize().getWidth() / getBasePlate().getSize().getWidth()) * plotRect.width),
(int) ((getSize().getHeight() / getBasePlate().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 = getBasePlate().getBoundingBox();
DimensionDouble plateSize = getBasePlate().getSize();
PointDouble pos = getBasePlate().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(boolean drawBackground) {
return drawBackground ? (isHighlithted() ? Color.BLACK : new Color(92, 92, 92)) : (isHighlithted() ? new Color(0, 255, 0) : new Color(0, 162, 0));
}
Font getLabelFont() {
/*
if (plotRect != null) {
return new Font("Times New Roman", Font.BOLD, 18);
}
return new Font("Times New Roman", Font.BOLD, 10);
*/
if (plotRect != null) {
return new Font("Segoe UI", Font.BOLD, 18);
}
return new Font("Segoe UI", Font.BOLD, 12);
}
Font getIdFont() {
if (plotRect != null) {
return new Font("Times New Roman", Font.PLAIN, 12);
}
return new Font("Times New Roman", Font.PLAIN, 9);
}
Point getLabelDrawPosition(String text, Graphics g, boolean drawBackground) {
Point pos = drawBackground ? getDrawPosition() : getDrawPosition(labelPositionWithImage);
Dimension textSize = SwingUtils.getTextSize(text, g.getFontMetrics());
return new Point(pos.x - textSize.width / 2 , pos.y + (g.getFontMetrics().getAscent() / 2));
}
Color getBorderColor(boolean drawBackground) {
if (drawBackground) {
/*if (!isEnabled()){
return Color.GRAY;
} else */
if (isHighlithted()) {
return new Color(0, 0, 0);
}
return Color.GRAY;
}
return isHighlithted() ? new Color(0, 208, 0) : new Color(0, 128, 0);
}
int getBorderWidth(boolean drawBackground) {
return drawBackground ? isSegmentSelected() ? 2 : 1 : isSegmentSelected() ? 2 : 1;
}
int getReferenceDrawSize() {
return getDrawSize(referenceSize) ;
}
Point getReferenceDrawPosition() {
return getDrawPosition(new PointDouble(0, -67.0));
}
Rectangle plotRect;
void draw(Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawId, boolean drawBackground, BasePlate enclosingPlate) {
this.plotRect = plotRect;
Point position = getDrawPosition();
int size = getDrawSize();
if (drawBackground) {
g.setColor(getColor());
g.fillOval(position.x - size / 2, position.y - size / 2, size, size);
}
g.setColor(getBorderColor(drawBackground));
g.setStroke(new BasicStroke(getBorderWidth(drawBackground)));
g.drawOval(position.x - size / 2, position.y - size / 2, size, size);
g.setStroke(new BasicStroke(1f));
if (drawSamples) {
//Draw samples
for (Sample sample : getSamples()) {
sample.draw(g, drawBackground);
}
}
//Draw reference
Color refColor = MainFrame.isDark() ? Color.DARK_GRAY : new Color(214, 217, 223);
if ((enclosingPlate != null) && enclosingPlate.drawContour) {
refColor = enclosingPlate.getColor();
}
if (drawBackground){
g.setColor(refColor);
position = getReferenceDrawPosition();
size = getReferenceDrawSize();
//size+=1;
g.fillArc(position.x - size / 2, position.y - size / 2 , size, size, (int) (180 + angle), 180);
g.setColor(getBorderColor(drawBackground));
g.drawArc(position.x - size / 2, position.y - size / 2 , size, size, (int) (180 + angle), 180);
} else {
Point pu = getDrawUnipuckLedPosition();
Point pm = getDrawMinispineLedPosition();
int unipuckSize = getUnipuckLedSize();
int minispineSize = getMinispineLedSize();
g.setColor(getBorderColor(drawBackground));
g.drawOval(pu.x - unipuckSize / 2, pu.y - unipuckSize / 2, unipuckSize, unipuckSize);
g.drawOval(pm.x - minispineSize / 2, pm.y - minispineSize / 2, minispineSize, minispineSize);
}
//Draw text
String text = getName(); //String.valueOf(getIndex() + 1);
g.setColor(getLabelColor(drawBackground));
g.setFont(getLabelFont());
Point labelPosition = getLabelDrawPosition(text, g, drawBackground);
g.drawString(text, labelPosition.x, labelPosition.y);
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 );
}
}
}
}

View File

@@ -0,0 +1,279 @@
package ch.psi.mxsc;
import ch.psi.mxsc.Puck.PuckType;
import ch.psi.pshell.imaging.DimensionDouble;
import ch.psi.pshell.imaging.PointDouble;
import ch.psi.utils.swing.MainFrame;
import ch.psi.utils.swing.SwingUtils;
import java.awt.BasicStroke;
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;
import java.util.List;
/**
*
*/
public class PuckGraphics {
final static PointDouble labelPositionWithImage = new PointDouble(0.0, 36.0);
Puck puck;
final BasePlate basePlate ;
final BasePlateGraphics basePlateGraphics;
List<SampleGraphics> sampleGraphics = new ArrayList<>();
public PuckGraphics(Puck puck, BasePlateGraphics basePlateGraphics){
this.puck = puck;
basePlate = puck.getBasePlate();
this.basePlateGraphics = basePlateGraphics;
for (Sample sample : puck.getSamples()){
sampleGraphics.add(new SampleGraphics(sample, this));
}
}
public PointDouble getRotatedPosition(PointDouble ref) {
double rotation = - puck.angle * Math.PI / 180.0;
double x = ref.x * Math.cos(rotation) - ref.y * Math.sin(rotation);
double y = ref.y * Math.cos(rotation) + ref.x * Math.sin(rotation);
return new PointDouble(x,y );
}
public PointDouble getSamplePosition(Sample sample) {
//PointDouble ref = samplesPosition[sample.index];
//return getRotatedPosition(ref);
return puck.samplesPosition[sample.index];
}
public Point getDrawUnipuckLedPosition(){
PointDouble ref = puck.ledUnipuckPosition;
return getDrawPosition(ref);
}
public Point getDrawMinispineLedPosition(){
PointDouble ref = puck.ledMinispinePosition;
return getDrawPosition(ref);
}
int getUnipuckLedSize() {
return getDrawSize(puck.unipuckLedSize) ;
}
int getMinispineLedSize() {
return getDrawSize(puck.minispineLedSize) ;
}
int getDrawSize(double refSize) {
return (int) ((refSize / puck.getSize().getWidth()) * getDrawSize()) ;
}
Point getDrawPosition(PointDouble refPosition) {
Point puckCenter = getDrawPosition();
int puckDrawSize = getDrawSize();
DimensionDouble puckSize = puck.getSize();
PointDouble pos = getRotatedPosition(refPosition);
return new Point( (int) ((pos.x / puckSize.getWidth())* puckDrawSize/2 + puckCenter.x) ,
(int) ((pos.y / puckSize.getHeight())* puckDrawSize/2 + puckCenter.y) );
}
public boolean isHighlithted() {
return puck.isSelected() || puck.isSegmentSelected();
}
Color getColor() {
Color ret = Color.LIGHT_GRAY;
switch (puck.detection) {
case Empty:
//ret = isHighlithted() ? new Color(224, 224, 224) : Color.LIGHT_GRAY;
ret = isHighlithted() ? new Color(212, 212, 212) : Color.LIGHT_GRAY;
break;
case Present:
if ((puck.puckType != null) && (puck.puckType != PuckType.Unknown)){
switch (puck.puckType){
case Minispine:
ret = isHighlithted() ? new Color(0, 200, 80) : new Color(128, 232, 152);
break;
case Unipuck:
ret = isHighlithted() ? new Color(0, 140, 140) : new Color(128, 192, 192);
break;
case Empty:
case Error:
ret = isHighlithted() ? new Color(192, 10, 10) : new Color(192, 128, 128);
break;
}
} else {
ret = isHighlithted() ? new Color(0, 140, 140) : new Color(128, 192, 192);
}
break;
case Error:
ret = isHighlithted() ? new Color(192, 10, 10) : new Color(192, 128, 128);
break;
case Offline:
ret = isHighlithted() ? new Color(250, 255, 48) : new Color(253, 194, 41);
//ret = isHighlithted() ? new Color(230, 142, 40) : new Color(216, 159, 93);
break;
}
return ret;
}
int getDrawSize() {
//All pucks
if (basePlateGraphics!=null) {
Rectangle rect = basePlateGraphics.getBoundingBox(); //TODO
int ret = Math.min((int) ((puck.getSize().getWidth() / basePlate.getSize().getWidth()) * rect.width),
(int) ((puck.getSize().getHeight() / basePlate.getSize().getHeight()) * rect.height)
);
if (puck.isSelected()) {
ret += 2;
}
return ret;
} else {
//Single puck plot
assertPlottingBoundariesDefined() ;
return Math.min(plotRect.width, plotRect.height);
}
}
void assertPlottingBoundariesDefined(){
if ((basePlateGraphics==null) && (plotRect==null)){
throw new RuntimeException ("No plotting boundaries defined");
}
}
Point getDrawPosition() {
//All pucks
if (basePlateGraphics!=null) {
Rectangle rect = basePlateGraphics.getBoundingBox();
DimensionDouble plateSize = basePlate.getSize();
PointDouble pos = basePlate.getPuckPosition(puck);
return new Point((int) ((pos.x / plateSize.getWidth()) * rect.width + rect.getCenterX()),
(int) ((pos.y / plateSize.getHeight()) * rect.height + rect.getCenterY())
);
} else {
//Single puck plot
assertPlottingBoundariesDefined() ;
return new Point((int) plotRect.getCenterX(), (int) plotRect.getCenterY());
}
}
Color getLabelColor(boolean drawBackground) {
return drawBackground ? (isHighlithted() ? Color.BLACK : new Color(92, 92, 92)) : (isHighlithted() ? new Color(0, 255, 0) : new Color(0, 162, 0));
}
Font getLabelFont() {
if (basePlateGraphics!=null) {
return new Font("Segoe UI", Font.BOLD, 12);
}
return new Font("Segoe UI", Font.BOLD, 18);
}
Font getIdFont() {
if (basePlateGraphics!=null) {
return new Font("Times New Roman", Font.PLAIN, 9);
}
return new Font("Times New Roman", Font.PLAIN, 12);
}
Point getLabelDrawPosition(String text, Graphics g, boolean drawBackground) {
Point pos = drawBackground ? getDrawPosition() : getDrawPosition(labelPositionWithImage);
Dimension textSize = SwingUtils.getTextSize(text, g.getFontMetrics());
return new Point(pos.x - textSize.width / 2 , pos.y + (g.getFontMetrics().getAscent() / 2));
}
Color getBorderColor(boolean drawBackground) {
if (drawBackground) {
/*if (!isEnabled()){
return Color.GRAY;
} else */
if (isHighlithted()) {
return new Color(0, 0, 0);
}
return Color.GRAY;
}
return isHighlithted() ? new Color(0, 208, 0) : new Color(0, 128, 0);
}
int getBorderWidth(boolean drawBackground) {
return drawBackground ? puck.isSegmentSelected() ? 2 : 1 : puck.isSegmentSelected() ? 2 : 1;
}
int getReferenceDrawSize() {
return getDrawSize(puck.referenceSize) ;
}
Point getReferenceDrawPosition() {
return getDrawPosition(new PointDouble(0, -67.0));
}
Rectangle plotRect;
void draw(Graphics2D g, Rectangle plotRect, boolean drawSamples, boolean drawId, boolean drawBackground) {
this.plotRect = plotRect;
Point position = getDrawPosition();
int size = getDrawSize();
if (drawBackground) {
g.setColor(getColor());
g.fillOval(position.x - size / 2, position.y - size / 2, size, size);
}
g.setColor(getBorderColor(drawBackground));
g.setStroke(new BasicStroke(getBorderWidth(drawBackground)));
g.drawOval(position.x - size / 2, position.y - size / 2, size, size);
g.setStroke(new BasicStroke(1f));
if (drawSamples) {
//Draw samples
for (SampleGraphics sg : sampleGraphics) {
sg.draw(g, drawBackground);
}
}
//Draw reference
Color refColor = MainFrame.isDark() ? Color.DARK_GRAY : new Color(214, 217, 223);
if ((basePlateGraphics != null) && basePlateGraphics.drawContour) {
refColor = basePlateGraphics.getColor();
}
if (drawBackground){
g.setColor(refColor);
position = getReferenceDrawPosition();
size = getReferenceDrawSize();
//size+=1;
g.fillArc(position.x - size / 2, position.y - size / 2 , size, size, (int) (180 + puck.angle), 180);
g.setColor(getBorderColor(drawBackground));
g.drawArc(position.x - size / 2, position.y - size / 2 , size, size, (int) (180 + puck.angle), 180);
} else {
Point pu = getDrawUnipuckLedPosition();
Point pm = getDrawMinispineLedPosition();
int unipuckSize = getUnipuckLedSize();
int minispineSize = getMinispineLedSize();
g.setColor(getBorderColor(drawBackground));
g.drawOval(pu.x - unipuckSize / 2, pu.y - unipuckSize / 2, unipuckSize, unipuckSize);
g.drawOval(pm.x - minispineSize / 2, pm.y - minispineSize / 2, minispineSize, minispineSize);
}
//Draw text
String text = puck.getName(); //String.valueOf(getIndex() + 1);
g.setColor(getLabelColor(drawBackground));
g.setFont(getLabelFont());
Point labelPosition = getLabelDrawPosition(text, g, drawBackground);
g.drawString(text, labelPosition.x, labelPosition.y);
if (drawId) {
String id = puck.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 );
}
}
}
}

View File

@@ -3,6 +3,7 @@
*/
package ch.psi.mxsc;
import ch.psi.pshell.device.Device;
import ch.psi.pshell.swing.DevicePanel;
import ch.psi.utils.State;
import java.awt.Dimension;
@@ -17,6 +18,7 @@ public class PuckPanel extends DevicePanel {
/**
* Creates new form BasePlatePanel
*/
PuckGraphics puckGraphics;
public PuckPanel() {
initComponents();
}
@@ -26,6 +28,12 @@ public class PuckPanel extends DevicePanel {
return (Puck) super.getDevice();
}
@Override
public void setDevice(Device device){
super.setDevice(device);
puckGraphics = new PuckGraphics((Puck)device, null);
}
/**
* 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.
@@ -55,13 +63,13 @@ public class PuckPanel extends DevicePanel {
@Override
public void paint(Graphics g) {
super.paint(g);
if (getDevice()!=null){
if (puckGraphics!=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, true, null);
puckGraphics.draw(g2d, plotRect, true, false, true);
}
}
}

View File

@@ -3,18 +3,9 @@
*/
package ch.psi.mxsc;
import ch.psi.mxsc.BasePlate.SelectionMode;
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;
/**
*
@@ -56,7 +47,7 @@ public class Sample extends DeviceBase {
boolean selected;
public boolean isSelected() {
return selected && (getPuck().getBasePlate().getSelectionMode() == SelectionMode.Samples);
return selected;
}
public void toggleSelected(boolean value) {
@@ -107,87 +98,4 @@ public class Sample extends DeviceBase {
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 (isSelected()) {
ret = ret.brighter();
}
return ret;
}
int getNormalDrawSize() {
return getPuck().getDrawSize(getSize().getWidth() );
}
int getDrawSize() {
int ret = getNormalDrawSize();
if (isSelected()) {
ret += 2;
}
return ret;
}
Point getDrawPosition() {
return getPuck().getDrawPosition(getPuck().getSamplePosition(this));
}
Color getLabelColor(boolean drawBackground) {
return drawBackground ? getPuck().isHighlithted() ? Color.DARK_GRAY : new Color(92, 92, 92) : new Color (0,96,0);
}
Font getLabelFont() {
////return new Font("Times New Roman", Font.PLAIN, 8);
//return new Font("Courier New", Font.PLAIN, 8);
return new Font("Tahoma", Font.PLAIN, 8);
}
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(boolean drawBackground) {
if (drawBackground){
if (!isEnabled()) {
return Color.GRAY;
} else if (isSelected()) {
return new Color(32,32,32);
}
return Color.GRAY;
}
return isSelected() ? new Color(0,32,0) : new Color(0,128,0);
}
void draw (Graphics2D g, boolean drawBackground){
Point position = getDrawPosition();
int size = getDrawSize();
if (drawBackground){
g.setColor(getColor());
g.fillOval(position.x - size / 2, position.y - size / 2, size, size);
}
g.setColor(getBorderColor(drawBackground));
g.drawOval(position.x - size / 2, position.y - size / 2, size, size);
if (getNormalDrawSize()>10){
String text = String.valueOf(index + 1);
g.setColor(getLabelColor(drawBackground));
g.setFont(getLabelFont());
Point labelPosition = getLabelPosition(text, g);
g.drawString(text, labelPosition.x, labelPosition.y);
}
g.setPaintMode();
}
}

View File

@@ -0,0 +1,107 @@
package ch.psi.mxsc;
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;
/**
*
*/
public class SampleGraphics {
final Sample sample;
final PuckGraphics puckGraphics;
public SampleGraphics(Sample sample, PuckGraphics graphics){
this.sample = sample;
this.puckGraphics = graphics;
}
Color getColor() {
Color ret = Color.LIGHT_GRAY;
if (sample.isLoaded()) {
ret = Color.BLUE;
} else if (sample.wasLoaded()) {
ret = Color.GREEN;
} else if (sample.isPresent()) {
ret = Color.CYAN.darker().darker();
}
if (sample.isSelected()) {
ret = ret.brighter();
}
return ret;
}
int getNormalDrawSize() {
return puckGraphics.getDrawSize(sample.getSize().getWidth() );
}
int getDrawSize() {
int ret = getNormalDrawSize();
if (sample.isSelected()) {
ret += 2;
}
return ret;
}
Point getDrawPosition() {
return puckGraphics.getDrawPosition(puckGraphics.getSamplePosition(sample));
}
Color getLabelColor(boolean drawBackground) {
return drawBackground ? puckGraphics.isHighlithted() ? Color.DARK_GRAY : new Color(92, 92, 92) : new Color (0,96,0);
}
Font getLabelFont() {
////return new Font("Times New Roman", Font.PLAIN, 8);
//return new Font("Courier New", Font.PLAIN, 8);
return new Font("Tahoma", Font.PLAIN, 8);
}
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(boolean drawBackground) {
if (drawBackground){
if (!sample.isEnabled()) {
return Color.GRAY;
} else if (sample.isSelected()) {
return new Color(32,32,32);
}
return Color.GRAY;
}
return sample.isSelected() ? new Color(0,32,0) : new Color(0,128,0);
}
void draw (Graphics2D g, boolean drawBackground){
Point position = getDrawPosition();
int size = getDrawSize();
if (drawBackground){
g.setColor(getColor());
g.fillOval(position.x - size / 2, position.y - size / 2, size, size);
}
g.setColor(getBorderColor(drawBackground));
g.drawOval(position.x - size / 2, position.y - size / 2, size, size);
if (getNormalDrawSize()>10){
String text = String.valueOf(sample.index + 1);
g.setColor(getLabelColor(drawBackground));
g.setFont(getLabelFont());
Point labelPosition = getLabelPosition(text, g);
g.drawString(text, labelPosition.x, labelPosition.y);
}
g.setPaintMode();
}
}

View File

@@ -1,31 +0,0 @@
package ch.psi.mxsc;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JPanel;
/**
*
*/
public class SinglePuckPanel extends JPanel {
int puckBorder = 20;
Puck puck;
public SinglePuckPanel(Puck puck) {
this.puck = puck;
}
@Override
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
super.paint(g);
Dimension size = getSize();
Rectangle puckPlotRect = new Rectangle(puckBorder, puckBorder, size.width - 2 * puckBorder, size.height - 2 * puckBorder);
puck.draw(g2d, puckPlotRect, true, true, true, null);
}
}