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

@@ -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) ;
}
}
}