buttonsPanel.setButtonGap(0);
final ButtonGroup group = new ButtonGroup();
for (int i = 0; i < _pageList.getPageCount(); i++) {
final AbstractDialogPage optionsPanel = _pageList.getPage(i);
final JideButton button = createIconButton(optionsPanel.getTitle(), optionsPanel.getIcon());
button.setToolTipText(optionsPanel.getDescription());
button.setEnabled(optionsPanel.isPageEnabled());
button.addActionListener(new AbstractAction() {
private static final long serialVersionUID = 4451059166068761678L;
public void actionPerformed(ActionEvent e) {
setCurrentPage(optionsPanel, buttonsPanel);
if (getCurrentPage() == optionsPanel) {
group.setSelected(button.getModel(), true);
}
}
});
optionsPanel.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (AbstractDialogPage.PROPERTY_PAGE_ENABLED.equals(evt.getPropertyName())) {
button.setEnabled(Boolean.TRUE.equals(evt.getNewValue()));
}
else if (AbstractDialogPage.ICON_PROPERTY.equals(evt.getPropertyName())) {
button.setIcon((Icon) evt.getNewValue());
}
else if (AbstractDialogPage.TITLE_PROPERTY.equals(evt.getPropertyName())) {
button.setText((String) evt.getNewValue());
}
else if (AbstractDialogPage.DESCRIPTION_PROPERTY.equals(evt.getPropertyName())) {
button.setToolTipText((String) evt.getNewValue());
}
}
});
buttonsPanel.addButton(button);
group.add(button);
if (_pageList.getPageCount() > 0) {
if (getInitialPageTitle() != null && getInitialPageTitle().equals(optionsPanel.getFullTitle())) {
group.setSelected(button.getModel(), true);
}
else if (getInitialPageTitle() == null && i == 0) {
group.setSelected(button.getModel(), true);
}
}
}
buttonsPanel.setOpaque(false);
buttonsPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
final JScrollPane pane = new JScrollPane(buttonsPanel) {
@Override
public Dimension getPreferredSize() {
if (buttonsPanel.getAlignment() == SwingConstants.TOP || buttonsPanel.getAlignment() == SwingConstants.BOTTOM)
return new Dimension(buttonsPanel.getPreferredSize().width + getVerticalScrollBar().getPreferredSize().width, 5);
else
return new Dimension(5, buttonsPanel.getPreferredSize().height + getHorizontalScrollBar().getPreferredSize().height);
}
@Override
public Dimension getMinimumSize() {
return getPreferredSize();
}
};
if (buttonsPanel.getAlignment() == SwingConstants.TOP || buttonsPanel.getAlignment() == SwingConstants.BOTTOM)
pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
else
pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
buttonsPanel.setOpaque(false);
_pageList.addListDataListener(new ListDataListener() {
public void intervalAdded(ListDataEvent e) {
for (int i = e.getIndex0(); i <= e.getIndex1(); i++) {
addPage(i, group, buttonsPanel);
}
buttonsPanel.invalidate();
buttonsPanel.doLayout();
}
public void intervalRemoved(ListDataEvent e) {
for (int i = e.getIndex1(); i >= e.getIndex0(); i--) {
AbstractButton button = (AbstractButton) buttonsPanel.getComponent(i);
buttonsPanel.remove(button);
group.remove(button);
}
buttonsPanel.invalidate();
buttonsPanel.doLayout();
}
public void contentsChanged(ListDataEvent e) {
if (e.getIndex0() == -1 && e.getIndex1() == -1 && e.getType() == ListDataEvent.CONTENTS_CHANGED) {
AbstractButton button = (AbstractButton) buttonsPanel.getButtonByName(_pageList.getCurrentPage().getTitle());
if (button != null) {
group.setSelected(button.getModel(), true);
}
}
}
});