Menu

#85 Content selection not working with MultiSplitLayout

open
None
5
2010-10-30
2010-10-07
No

Hello Angelo,
For this one, I don't have any solution yet. Can you help me?
With the MultiSplitLayout, if I have two content views in two different nodes (i.e. two different tabbed panes with one tab in each), then I don't get any selection event when I click on the tabs. The selected content does not change. And there is no visual hint either on which content is currently selected. It's really painful because my tool windows an my application state depend on the selected content.

Along the same lines, if I have two content views in each node (i.e. two tabs in each tabbed pane), the restore mechanism does not restore the "active" tab in each node.

Can you suggest anything I can do to fix these?
Thanks,
Pierre

Discussion

  • Pierre Auslaender

    Fix 1: TabbedContentPane.MouseOverTabListener.mousePressed(MouseEvent), line 618:

    public void mousePressed(MouseEvent e) {
    if (mouseOverTab >= 0 && mouseOverTab < getTabCount()) {
    selectionOnPressed = (aggregateIcon.getIndex() == mouseOverTab);
    }
    mouseOverTabWhenPressed = mouseOverTab;
    // PAMFOLIO-2469 mydoggy: fix selected content when clicking on "active" tab in
    Content newSelected = getContentAt(mouseOverTab);
    if (newSelected != null && !newSelected.isMaximized()) {
    Content oldSelected = toolWindowManager.getContentManager().getSelectedContent();
    if (newSelected != oldSelected) {
    newSelected.setSelected(true);
    }
    }
    }

     
  • Pierre Auslaender

    Fix 2: Paint the selected content tab background with a different color than other active tabs in other nodes.
    a/ In TabbedContentPane, add a variable for the selected content color (plus accessors):
    // PAMFOLIO-2413 mydoggy: highlight selected content tab in multi-split layout
    // TODO factor out to proper mydoggy-style UI
    // TODO add property change listeners
    protected static final Color DEFAULT_SELECTED_CONTENT_COLOR = new Color(255, 255, 196);
    protected Color selectedContentColor = DEFAULT_SELECTED_CONTENT_COLOR;

    b/ Create a subclass of BasicTabbedPaneUI that paints the tab background with the "selectedContentColor" if the tab represents the currrently selected dockable:

    public class MetalTabbedContentPaneUI extends MetalTabbedPaneUI {

    /**
    *
    */
    public MetalTabbedContentPaneUI() {
    super();
    }

    /**
    * @see javax.swing.plaf.metal.MetalTabbedPaneUI#paintTabBackground(java.awt.Graphics, int, int, int, int, int, int,
    * boolean)
    */
    @Override
    protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h,
    boolean isSelected) {
    if (isSelected) {
    Color color = selectColor;
    if (tabPane instanceof TabbedContentPane) {
    TabbedContentPane tabbedContentPane = (TabbedContentPane) tabPane;
    Dockable<?> dockable = tabbedContentPane.getDockable(tabIndex);
    if (dockable != null && dockable.isSelected()) {
    color = tabbedContentPane.getSelectedContentColor();
    }
    }
    g.setColor(color);
    } else {
    g.setColor(getUnselectedBackgroundAt(tabIndex));
    }

    if (tabPane.getComponentOrientation().isLeftToRight()) {
    switch (tabPlacement) {
    case LEFT:
    g.fillRect(x + 5, y + 1, w - 5, h - 1);
    g.fillRect(x + 2, y + 4, 3, h - 4);
    break;
    case BOTTOM:
    g.fillRect(x + 2, y, w - 2, h - 4);
    g.fillRect(x + 5, y + (h - 1) - 3, w - 5, 3);
    break;
    case RIGHT:
    g.fillRect(x, y + 1, w - 4, h - 1);
    g.fillRect(x + (w - 1) - 3, y + 5, 3, h - 5);
    break;
    case TOP:
    default:
    g.fillRect(x + 4, y + 2, (w - 1) - 3, (h - 1) - 1);
    g.fillRect(x + 2, y + 5, 2, h - 5);
    }
    } else {
    switch (tabPlacement) {
    case LEFT:
    g.fillRect(x + 5, y + 1, w - 5, h - 1);
    g.fillRect(x + 2, y + 4, 3, h - 4);
    break;
    case BOTTOM:
    g.fillRect(x, y, w - 5, h - 1);
    g.fillRect(x + (w - 1) - 4, y, 4, h - 5);
    g.fillRect(x + (w - 1) - 4, y + (h - 1) - 4, 2, 2);
    break;
    case RIGHT:
    g.fillRect(x + 1, y + 1, w - 5, h - 1);
    g.fillRect(x + (w - 1) - 3, y + 5, 3, h - 5);
    break;
    case TOP:
    default:
    g.fillRect(x, y + 2, (w - 1) - 3, (h - 1) - 1);
    g.fillRect(x + (w - 1) - 3, y + 4, 3, h - 4);
    }
    }
    }

    /**
    * Returns the color to use for the specified tab.
    */
    private Color getUnselectedBackgroundAt(int index) {
    Color color = tabPane.getBackgroundAt(index);
    // if (color instanceof UIResource) {
    // if (unselectedBackground != null) {
    // return unselectedBackground;
    // }
    // }
    return color;
    }

    }

    c/ In TabbedContentPane, call "setUI" with an instance of the new TabbedPaneUI:

    // PAMFOLIO-2413 mydoggy: highlight selected content tab in multi-split layout
    // TODO factor out to proper mydoggy-style UI
    // TODO add property change listeners
    setUI(new MetalTabbedContentPaneUI());

     
  • Angelo De Caro

    Angelo De Caro - 2010-10-30
    • assigned_to: nobody --> adecaro
     
  • Angelo De Caro

    Angelo De Caro - 2010-10-30

    The first Fix seems ok, for the second I'm not sure.

     
  • Angelo De Caro

    Angelo De Caro - 2010-10-30

    Fix 1 has been integrated.