This is a further refinement to the sketch I posted in my previous question. I want to divide the main window into panels, and from some of the panels, I want to open a child window. The code below works fine without panels, but if I add panels to the main window (see comments in code below), then the objects in the child window don’t work. For example, the droplist in the child window works if I don’t have panels in the main window, but seems to be disabled if I have panels in the main window. I added a call to ‘setEnabled()’ but it doesn’t seem to help. Once again, there’s probably something I’m missing, but I don’t know what. I looked through the examples provided, but couldn’t find any example that opens a child window from a panel.
This is the working version of the sketch (without panels). But if you uncomment the indicated lines, the droplist no longer works.
import g4p_controls.*;
GPanel panel = null;
GButton button = null;
GWindow window;
GDropList dropList;
String[] dest = {"Selection 1","Selection 2","Selection 3"};
int selected = 0;
public void setup() {
size(600,400,JAVA2D);
G4P.setCtrlMode(GControlMode.CORNER);
G4P.setGlobalColorScheme(GCScheme.GREEN_SCHEME);
G4P.setMouseOverEnabled(true);
//panel = new GPanel(this,0,0,200,200,"PANEL 1"); // Uncomment this line
//panel.setCollapsed(false); // Uncomment this line
//panel.setCollapsible(false); // Uncomment this line
//panel.setDraggable(false); // Uncomment this line
//panel.setOpaque(true); // Uncomment this line
button = new GButton(this, 15, 40, 60, 20);
button.setText("SETUP");
button.addEventHandler(this,"buttonHandler");
//panel.addControl(button); // Uncomment this line
}
public void draw() {
background(179,237,179);
}
public void buttonHandler (GButton source, GEvent event) {
makeChildWindow();
button.setEnabled(false);
}
public void makeChildWindow () {
window = GWindow.getWindow(this,"Child Window",20,40,400,200,JAVA2D);
window.setActionOnClose(G4P.CLOSE_WINDOW);
window.addDrawHandler(this,"windowDraw");
window.addOnCloseHandler(this,"windowClose");
dropList = new GDropList(window, 20, 20, 120, 100, 5);
dropList.addEventHandler(this, "dropListHandler");
dropList.setItems(dest,selected);
dropList.setEnabled(true);
}
public void windowDraw(PApplet app, GWinData data) {
app.background(179,237,179);
}
public void windowClose(GWindow window) {
button.setEnabled(true);
}
public void dropListHandler (GDropList source, GEvent event) {
println("selected text = "+source.getSelectedText());
selected = source.getSelectedIndex();
dropList.setItems(dest,selected);
}
If you’re wondering where I’m going with all this, I want to develop a graphical front-end for an audio application written in Pure Data (see http://puredata.info/). Attached is a screen print of a non-functional mock-up of the final product.