//pencilTool.enable();
selectButtonForTool(pencilTool);
fg = new SwatchColorPicker();
fg.onColorSelected(new Callback<ChangedEvent>() {
public void call(ChangedEvent event) throws Exception {
getDocument().setForegroundColor(fg.getSelectedColor());
}
});
toolbar.add(fg);
final SwatchColorPicker bg = new SwatchColorPicker();
bg.onColorSelected(new Callback<ChangedEvent>() {
public void call(ChangedEvent event) throws Exception {
getDocument().setBackgroundColor(bg.getSelectedColor());
}
});
toolbar.add(bg);
EventBus.getSystem().addListener(ChangedEvent.ColorChanged, new Callback<ChangedEvent>() {
public void call(ChangedEvent event) throws Exception {
if(event.getSource() == getDocument()) {
fg.setSelectedColor(getDocument().getForegroundColor());
bg.setSelectedColor(getDocument().getBackgroundColor());
}
}
});
//swap fg and bg
EventBus.getSystem().addListener(getCanvas(), KeyEvent.KeyTyped, new Callback<KeyEvent>() {
public void call(KeyEvent keyEvent) throws Exception {
if('x' == keyEvent.getKeyChar()) {
FlatColor c1 = fg.getSelectedColor();
FlatColor c2 = bg.getSelectedColor();
fg.setSelectedColor(c2);
bg.setSelectedColor(c1);
}
}
});
}