reset component selection when switching tabs

This commit is contained in:
bancika
2011-01-29 22:00:01 +00:00
parent c2051fcea2
commit e5113e110e
2 changed files with 28 additions and 10 deletions
@@ -11,9 +11,9 @@ import java.util.Map;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.diylc.common.ComponentType;
import org.diylc.common.IPlugInPort;
@@ -42,6 +42,13 @@ class ComponentTabbedPane extends JTabbedPane {
JPanel panel = createTab((componentTypes.get(category)));
addTab(category, panel);
}
addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
ComponentTabbedPane.this.plugInPort.setNewComponentTypeSlot(null);
}
});
}
private JPanel createTab(List<ComponentType> componentTypes) {
@@ -87,13 +94,13 @@ class ComponentTabbedPane extends JTabbedPane {
return panel;
}
private JScrollPane createComponentScrollBar(List<ComponentType> componentTypes) {
JScrollPane scrollPane = new JScrollPane(createComponentPanel(componentTypes));
scrollPane.setOpaque(false);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
return scrollPane;
}
// private JScrollPane createComponentScrollBar(List<ComponentType> componentTypes) {
// JScrollPane scrollPane = new JScrollPane(createComponentPanel(componentTypes));
// scrollPane.setOpaque(false);
// scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
// scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
// return scrollPane;
// }
private Component createComponentPanel(List<ComponentType> componentTypes) {
Container toolbar = new Container();
@@ -18,6 +18,9 @@ public class ToolBox implements IPlugIn {
private static final Logger LOG = Logger.getLogger(StatusBar.class);
private ISwingUI swingUI;
private IPlugInPort plugInPort;
private ComponentTabbedPane componentTabbedPane;
public ToolBox(ISwingUI swingUI) {
this.swingUI = swingUI;
@@ -25,12 +28,20 @@ public class ToolBox implements IPlugIn {
@Override
public void connect(IPlugInPort plugInPort) {
this.plugInPort = plugInPort;
try {
swingUI.injectGUIComponent(new ComponentTabbedPane(plugInPort), SwingConstants.TOP);
swingUI.injectGUIComponent(getComponentTabbedPane(), SwingConstants.TOP);
} catch (BadPositionException e) {
LOG.error("Could not install the toolbox", e);
}
}
public ComponentTabbedPane getComponentTabbedPane() {
if (componentTabbedPane == null) {
componentTabbedPane = new ComponentTabbedPane(plugInPort);
}
return componentTabbedPane;
}
@Override
public EnumSet<EventType> getSubscribedEventTypes() {