Most control frames now working.

This commit is contained in:
Sandy Noble 2015-09-05 16:00:22 +01:00
parent f9ab305fad
commit d005b1bb0c
7 changed files with 496 additions and 366 deletions

View File

@ -46,5 +46,7 @@ public class ControlFrame extends PApplet {
public void draw() {
background(abc);
}
}

View File

@ -6,45 +6,47 @@ public Integer renderStartDirection = DRAW_DIR_SE; // default start drawing in S
public Integer renderStartPosition = DRAW_DIR_NE; // default top right hand corner for start
public Integer renderStyle = PIXEL_STYLE_SQ_FREQ; // default pixel style square wave
class DrawPixelsWindow extends ControlFrame {
public DrawPixelsWindow () {
super(parentPapplet, 450, 150);
int xPos = 100;
int yPos = 100;
String name = DRAW_PIXELS_WINDOW_NAME;
final Frame f = new Frame(DRAW_PIXELS_WINDOW_NAME);
f.add(this);
this.init();
f.setTitle(CHANGE_SERIAL_PORT_WINDOW_NAME);
f.setSize(super.w, super.h);
f.setLocation(xPos, yPos);
f.setResizable(false);
f.setVisible(true);
ControlFrameSimple addDrawPixelsControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) {
final Frame f = new Frame( theName );
final ControlFrameSimple p = new ControlFrameSimple( this, theWidth, theHeight, theColor );
f.add( p );
p.init();
f.setTitle(theName);
f.setSize( p.w, p.h );
f.setLocation( theX, theY );
f.addWindowListener( new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
p.dispose();
f.dispose();
}
});
}
);
f.setResizable( true );
f.setVisible( true );
// sleep a little bit to allow p to call setup.
// otherwise a nullpointerexception might be caused.
try {
Thread.sleep( 100 );
}
catch(Exception e) {
}
RadioButton rPos = cp5().addRadioButton("radio_startPosition",10,10)
// set up controls
RadioButton rPos = p.cp5().addRadioButton("radio_startPosition",10,10)
.add("Top-right", DRAW_DIR_NE)
.add("Bottom-right", DRAW_DIR_SE)
.add("Bottom-left", DRAW_DIR_SW)
.add("Top-left", DRAW_DIR_NW)
.plugTo("radio_startPosition");
.plugTo(this, "radio_startPosition");
RadioButton rSkip = cp5().addRadioButton("radio_pixelSkipStyle",10,100)
RadioButton rSkip = p.cp5().addRadioButton("radio_pixelSkipStyle",10,100)
.add("Lift pen over masked pixels", 1)
.add("Draw masked pixels as blanks", 2)
.plugTo("radio_pixelSkipStyle");
.plugTo(this, "radio_pixelSkipStyle");
RadioButton rStyle = cp5().addRadioButton("radio_pixelStyle",100,10);
RadioButton rStyle = p.cp5().addRadioButton("radio_pixelStyle",100,10);
rStyle.add("Variable frequency square wave", PIXEL_STYLE_SQ_FREQ);
rStyle.add("Variable size square wave", PIXEL_STYLE_SQ_SIZE);
rStyle.add("Solid square wave", PIXEL_STYLE_SQ_SOLID);
@ -53,12 +55,14 @@ class DrawPixelsWindow extends ControlFrame {
rStyle.add("Spiral", PIXEL_STYLE_CIRCLE);
rStyle.add("Sawtooth", PIXEL_STYLE_SAW);
}
rStyle.plugTo("radio_pixelStyle");
rStyle.plugTo(this, "radio_pixelStyle");
Button submitButton = cp5().addButton("submitDrawWindow",0,280,10,120,20)
Button submitButton = p.cp5().addButton("submitDrawWindow",0,280,10,120,20)
.setLabel("Generate commands")
.plugTo("submitDrawWindow");
.plugTo(this, "submitDrawWindow");
return p;
}
void radio_startPosition(int pos) {
@ -99,4 +103,36 @@ class DrawPixelsWindow extends ControlFrame {
case PIXEL_STYLE_SAW: button_mode_renderSawPixel(); break;
}
}
class DrawPixelsWindow extends ControlFrame {
public DrawPixelsWindow () {
super(parentPapplet, 450, 150);
int xPos = 100;
int yPos = 100;
String name = DRAW_PIXELS_WINDOW_NAME;
final Frame f = new Frame(DRAW_PIXELS_WINDOW_NAME);
f.add(this);
this.init();
f.setTitle(CHANGE_SERIAL_PORT_WINDOW_NAME);
f.setSize(super.w, super.h);
f.setLocation(xPos, yPos);
f.setResizable(false);
f.setVisible(true);
f.addWindowListener( new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
f.dispose();
}
});
}
}

View File

@ -1,48 +1,64 @@
class MachineExecWindow extends ControlFrame {
ControlFrameSimple addMachineExecControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) {
final Frame f = new Frame( theName );
final ControlFrameSimple p = new ControlFrameSimple( this, theWidth, theHeight, theColor );
void execFilename(String filename) {
f.add( p );
p.init();
f.setTitle(theName);
f.setSize( p.w, p.h );
f.setLocation( theX, theY );
f.addWindowListener( new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
p.dispose();
f.dispose();
}
}
);
f.setResizable( true );
f.setVisible( true );
// sleep a little bit to allow p to call setup.
// otherwise a nullpointerexception might be caused.
try {
Thread.sleep( 100 );
}
catch(Exception e) {
}
// set up controls
Textfield filenameField = p.cp5().addTextfield("machineExec_execFilename",20,20,150,20)
.setText(getStoreFilename())
.setLabel("Filename to execute from")
.addListener( new ControlListener() {
public void controlEvent( ControlEvent ev ) {
machineExec_execFilename(ev.getController().getStringValue());
Textfield tf = p.cp5().get(Textfield.class, "machineExec_execFilename");
}
});
Button submitButton = p.cp5().addButton("machineExec_submitExecFilenameWindow",0,180,20,60,20)
.setLabel("Submit")
.addListener( new ControlListener() {
public void controlEvent( ControlEvent ev ) {
p.cp5().get(Textfield.class, "machineExec_execFilename").submit();
p.cp5().get(Textfield.class, "machineExec_execFilename").setText(getStoreFilename());
}
});
filenameField.setFocus(true);
return p;
}
void machineExec_execFilename(String filename) {
println("Filename event: "+ filename);
if (filename != null && filename.length() <= 12) {
if (filename != null
&& filename.length() <= 12
&& !"".equals(filename.trim())) {
filename = filename.trim();
setStoreFilename(filename);
sendMachineExecMode();
}
}
void submitExecFilenameWindow(int theValue) {
cp5().get(Textfield.class, "execFilename").submit();
}
public MachineExecWindow() {
super(parentPapplet, 450, 150);
int xPos = 100;
int yPos = 100;
String name = MACHINE_EXEC_WINDOW_NAME;
final Frame f = new Frame(name);
f.add(this);
this.init();
f.setTitle(name);
f.setSize(super.w, super.h);
f.setLocation(xPos, yPos);
f.setResizable(false);
f.setVisible(true);
f.addWindowListener( new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
f.dispose();
}
});
Textfield filenameField = cp5().addTextfield("execFilename",20,20,150,20)
.setText(getStoreFilename())
.setLabel("Filename to execute from")
.plugTo("execFilename");
Button submitButton = cp5().addButton("submitExecFilenameWindow",0,180,20,60,20)
.setLabel("Submit")
.plugTo("submitExecFilenameWindow");
filenameField.setFocus(true);
}
}

View File

@ -11,9 +11,7 @@ class MachineStoreWindow extends ControlFrame {
}
}
void toggleAppendToFile(boolean theFlag) {
setOverwriteExistingStoreFile(theFlag);
}
void submitStoreFilenameWindow(int theValue) {
cp5().get(Textfield.class, "storeFilename").submit();
@ -57,3 +55,78 @@ class MachineStoreWindow extends ControlFrame {
filenameField.setFocus(true);
}
}
ControlFrameSimple addMachineStoreControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) {
final Frame f = new Frame( theName );
final ControlFrameSimple p = new ControlFrameSimple( this, theWidth, theHeight, theColor );
f.add( p );
p.init();
f.setTitle(theName);
f.setSize( p.w, p.h );
f.setLocation( theX, theY );
f.addWindowListener( new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
p.dispose();
f.dispose();
}
}
);
f.setResizable( true );
f.setVisible( true );
// sleep a little bit to allow p to call setup.
// otherwise a nullpointerexception might be caused.
try {
Thread.sleep( 100 );
}
catch(Exception e) {
}
// set up controls
Textfield filenameField = p.cp5().addTextfield("machineStore_storeFilename",20,20,150,20)
.setText(getStoreFilename())
.setLabel("Filename to store to")
.addListener( new ControlListener() {
public void controlEvent( ControlEvent ev ) {
machineStore_storeFilename(ev.getController().getStringValue());
Textfield tf = p.cp5().get(Textfield.class, "machineExec_execFilename");
}
});
Button submitButton = p.cp5().addButton("machineStore_submitStoreFilenameWindow",0,180,20,60,20)
.setLabel("Submit")
.addListener( new ControlListener() {
public void controlEvent( ControlEvent ev ) {
p.cp5().get(Textfield.class, "machineStore_storeFilename").submit();
p.cp5().get(Textfield.class, "machineStore_storeFilename").setText(getStoreFilename());
}
});
Toggle overwriteToggle = p.cp5().addToggle("machineStore_toggleAppendToFile",true,180,50,20,20)
.setCaptionLabel("Overwrite existing file")
.plugTo(this, "machineStore_toggleAppendToFile");
filenameField.setFocus(true);
return p;
}
void machineStore_toggleAppendToFile(boolean theFlag) {
setOverwriteExistingStoreFile(theFlag);
}
void machineStore_storeFilename(String filename) {
println("Filename event: "+ filename);
if (filename != null
&& filename.length() <= 12
&& !"".equals(filename.trim())) {
filename = filename.trim();
setStoreFilename(filename);
sendMachineStoreMode();
}
}

View File

@ -2,34 +2,39 @@
Class and controllers on the "serial port" subwindow
------------------------------------------------------------------------*/
class SerialPortWindow extends ControlFrame {
public SerialPortWindow() {
super(parentPapplet, 150, 350);
int xPos = 100;
int yPos = 100;
final Frame f = new Frame(CHANGE_SERIAL_PORT_WINDOW_NAME);
f.add(this);
this.init();
f.setTitle(CHANGE_SERIAL_PORT_WINDOW_NAME);
f.setSize(super.w, super.h);
f.setLocation(xPos, yPos);
f.setResizable(true);
f.setVisible(true);
ControlFrameSimple addSerialPortControlFrame(String theName, int theWidth, int theHeight, int theX, int theY, int theColor ) {
final Frame f = new Frame( theName );
final ControlFrameSimple p = new ControlFrameSimple( this, theWidth, theHeight, theColor );
f.add( p );
p.init();
f.setTitle(theName);
f.setSize( p.w, p.h );
f.setLocation( theX, theY );
f.addWindowListener( new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
p.dispose();
f.dispose();
}
});
}
);
f.setResizable( true );
f.setVisible( true );
// sleep a little bit to allow p to call setup.
// otherwise a nullpointerexception might be caused.
try {
Thread.sleep( 100 );
}
catch(Exception e) {
}
RadioButton r = cp5().addRadioButton("radio_serialPort")
// set up controls
RadioButton r = p.cp5().addRadioButton("radio_serialPort")
.setPosition(10, 10)
.setSize(15, 15)
.setSpacingRow(5)
.plugTo(parentPapplet, "radio_serialPort");
.plugTo(this, "radio_serialPort");
r.addItem("No serial connection", -1);
@ -45,8 +50,10 @@ class SerialPortWindow extends ControlFrame {
r.activate(ports[portNo]);
else
r.activate("No serial connection");
return p;
}
}
void radio_serialPort(int newSerialPort)
{
@ -54,8 +61,7 @@ void radio_serialPort(int newSerialPort)
if (newSerialPort == -2)
{
}
else if (newSerialPort == -1)
{
else if (newSerialPort == -1) {
println("Disconnecting serial port.");
useSerialPortConnection = false;
if (myPort != null)
@ -67,21 +73,18 @@ void radio_serialPort(int newSerialPort)
drawbotConnected = false;
serialPortNumber = newSerialPort;
}
else if (newSerialPort != getSerialPortNumber())
{
else if (newSerialPort != getSerialPortNumber()) {
println("About to connect to serial port in slot " + newSerialPort);
// Print a list of the serial ports, for debugging purposes:
if (newSerialPort < Serial.list().length)
{
try
{
if (newSerialPort < Serial.list().length) {
try {
drawbotReady = false;
drawbotConnected = false;
if (myPort != null)
{
if (myPort != null) {
myPort.stop();
myPort = null;
}
if (getSerialPortNumber() >= 0)
println("closing " + Serial.list()[getSerialPortNumber()]);
@ -94,20 +97,16 @@ void radio_serialPort(int newSerialPort)
useSerialPortConnection = true;
println("Successfully connected to port " + portName);
}
catch (Exception e)
{
catch (Exception e) {
println("Attempting to connect to serial port in slot " + getSerialPortNumber()
+ " caused an exception: " + e.getMessage());
}
}
else
{
} else {
println("No serial ports found.");
useSerialPortConnection = false;
}
}
else
{
} else {
println("no serial port change.");
}
}

View File

@ -38,19 +38,22 @@ String DRAW_PIXELS_WINDOW_NAME = "drawPixelsWindow";
String DRAW_WRITING_WINDOW_NAME = "drawWritingWindow";
void button_mode_serialPortDialog() {
final SerialPortWindow serialPortWindow = new SerialPortWindow();
ControlFrameSimple cf = addSerialPortControlFrame("Serial Port", 200, 200, 20, 240, color( 100 ) );
}
void button_mode_machineStoreDialog() {
final MachineStoreWindow machineStoreWindow = new MachineStoreWindow();
ControlFrameSimple cf = addMachineStoreControlFrame("Machine Store", 450, 250, 20, 240, color( 100 ) );
// final MachineStoreWindow machineStoreWindow = new MachineStoreWindow();
}
void button_mode_machineExecDialog() {
final MachineExecWindow machineExecWindow = new MachineExecWindow();
ControlFrameSimple cf = addMachineExecControlFrame("Machine Execute", 450, 250, 20, 240, color( 100 ) );
// final MachineExecWindow machineExecWindow = new MachineExecWindow();
}
void button_mode_drawPixelsDialog() {
final DrawPixelsWindow drawPixelsWindow = new DrawPixelsWindow();
ControlFrameSimple cf = addDrawPixelsControlFrame("Render pixels", 450, 250, 20, 240, color( 100 ) );
// final DrawPixelsWindow drawPixelsWindow = new DrawPixelsWindow();
}
void button_mode_drawWritingDialog() {
@ -84,7 +87,8 @@ public class DrawWritingWindow extends ControlFrame {
public void windowClosing(WindowEvent we) {
f.dispose();
}
});
}
);
Textfield spriteFileField = cp5().addTextfield("spriteFilePrefixField", 20, 20, 150, 20)
.setText(getSpriteFilePrefix())
.setLabel("File prefix")

View File

@ -944,7 +944,7 @@ void sendMachineStoreMode()
}
void sendMachineLiveMode()
{
addToRealtimeCommandQueue(CMD_MACHINE_MODE_LIVE+"END");
addToCommandQueue(CMD_MACHINE_MODE_LIVE+"END");
}
void sendMachineExecMode()
{