Added mouse interaction to puck panel

This commit is contained in:
2017-03-16 12:14:34 +01:00
parent 02c75df33d
commit 4d0b19d801
6 changed files with 845 additions and 760 deletions

View File

@@ -1,73 +1,72 @@
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.mxsc;
import ch.psi.pshell.swing.DevicePanel;
import ch.psi.utils.State;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
/**
*
*/
public class PuckPanel extends DevicePanel {
/**
* Creates new form BasePlatePanel
*/
public PuckPanel() {
initComponents();
}
@Override
public Puck getDevice(){
return (Puck) super.getDevice();
}
/**
* This method is called from within the constructor to initialize the form. WARNING: Do NOT
* modify this code. The content of this method is always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <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
}
/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
package ch.psi.mxsc;
import ch.psi.pshell.swing.DevicePanel;
import ch.psi.utils.State;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
/**
*
*/
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, null);
}
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}