@Override
    public void alert(LayerEvent l) {
        if (l.type == LayerEvent.LAYER_CREATED) {
            layerCount++;
            displayed.add(true);
            selected = displayed.size() - 1;
        }
        if (l.type == LayerEvent.LAYER_SELECTED) {
            displayed.set(l.layer, true);
            selected = l.layer;
        }
        if (l.type == LayerEvent.LAYER_DESELECTED) {
            displayed.set(l.layer, false);
            if (l.layer == selected) {
                selected = -1;
                for (int i = displayed.size() - 1; i >= 0; i--) {
                    if (displayed.get(i)) {
                        selected = i;
                        break;
                    }
                }
            }
        }
        if (l.type == LayerEvent.LAYER_DELETED) {
            layerCount--;
        }
        repaint();
    }