Java Code Examples for javax.swing.SingleSelectionModel

The following examples show how to use javax.swing.SingleSelectionModel. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: netbeans   Source File: AbstractViewTabDisplayerUI.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void mousePressed(MouseEvent e) {
    Point p = e.getPoint();
    int i = getLayoutModel().indexOfPoint(p.x, p.y);
    tabState.setPressed(i);
    SingleSelectionModel sel = getSelectionModel();
    selectionChanged = i != sel.getSelectedIndex();
    // invoke possible selection change
    if ((i != -1) || !selectionChanged) {
        boolean change = shouldPerformAction(TabDisplayer.COMMAND_SELECT,
            i, e);
        if (change) {
            getSelectionModel().setSelectedIndex(i);
            tabState.setSelected(i);
            Component tc = i >= 0 ? getDataModel().getTab(i).getComponent() : null;
            if( null != tc && tc instanceof TopComponent
                && !((TopComponent)tc).isAncestorOf( KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner() ) ) {
                ((TopComponent)tc).requestActive();
            }
        }
    } 
    if (e.isPopupTrigger()) {
        //Post a popup menu show request
        shouldPerformAction(TabDisplayer.COMMAND_POPUP_REQUEST, i, e);
    }
}
 
Example 2
Source Project: netbeans   Source File: NBTabbedPaneController.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void mousePressed( MouseEvent e ) {

    Point p = e.getPoint();
    p = SwingUtilities.convertPoint( e.getComponent(), p, container );
    int tabIndex = container.indexAtLocation( p.x, p.y );

    SingleSelectionModel sel = container.getModel();
    //invoke possible selection change
    if( tabIndex >= 0 && e.getComponent() != container ) {
        CloseableTabComponent tab = ( CloseableTabComponent ) container.getTabComponentAt( tabIndex );
        if( tab.isInCloseButton( e ) ) {
            return;
        }
        tabIndex = container.indexOf( container.getComponentAt( tabIndex ) );
        boolean change = shouldPerformAction( TabDisplayer.COMMAND_SELECT,
                tabIndex, e );
        if( change ) {

            sel.setSelectedIndex( tabIndex );
            Component tc = container.getDataModel().getTab( tabIndex ).getComponent();
            if( null != tc && tc instanceof TopComponent && !(( TopComponent ) tc).isAncestorOf( KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner() ) ) {
                (( TopComponent ) tc).requestActive();
            }
        }
    }
    if( e.isPopupTrigger() ) {
        //Post a popup menu show request

        shouldPerformAction( TabDisplayer.COMMAND_POPUP_REQUEST, tabIndex, e );
    }
}
 
Example 3
/**
 * Maps {@code JTabbedPane.getModel()} through queue
 */
public SingleSelectionModel getModel() {
    return (runMapping(new MapAction<SingleSelectionModel>("getModel") {
        @Override
        public SingleSelectionModel map() {
            return ((JTabbedPane) getSource()).getModel();
        }
    }));
}
 
Example 4
/**
 * Maps {@code JTabbedPane.setModel(SingleSelectionModel)} through queue
 */
public void setModel(final SingleSelectionModel singleSelectionModel) {
    runMapping(new MapVoidAction("setModel") {
        @Override
        public void map() {
            ((JTabbedPane) getSource()).setModel(singleSelectionModel);
        }
    });
}
 
Example 5
/**
 * Maps {@code JMenuBar.getSelectionModel()} through queue
 */
public SingleSelectionModel getSelectionModel() {
    return (runMapping(new MapAction<SingleSelectionModel>("getSelectionModel") {
        @Override
        public SingleSelectionModel map() {
            return ((JMenuBar) getSource()).getSelectionModel();
        }
    }));
}
 
Example 6
/**
 * Maps {@code JMenuBar.setSelectionModel(SingleSelectionModel)}
 * through queue
 */
public void setSelectionModel(final SingleSelectionModel singleSelectionModel) {
    runMapping(new MapVoidAction("setSelectionModel") {
        @Override
        public void map() {
            ((JMenuBar) getSource()).setSelectionModel(singleSelectionModel);
        }
    });
}
 
Example 7
/**
 * Maps {@code JPopupMenu.getSelectionModel()} through queue
 */
public SingleSelectionModel getSelectionModel() {
    return (runMapping(new MapAction<SingleSelectionModel>("getSelectionModel") {
        @Override
        public SingleSelectionModel map() {
            return ((JPopupMenu) getSource()).getSelectionModel();
        }
    }));
}
 
Example 8
/**
 * Maps {@code JPopupMenu.setSelectionModel(SingleSelectionModel)}
 * through queue
 */
public void setSelectionModel(final SingleSelectionModel singleSelectionModel) {
    runMapping(new MapVoidAction("setSelectionModel") {
        @Override
        public void map() {
            ((JPopupMenu) getSource()).setSelectionModel(singleSelectionModel);
        }
    });
}
 
Example 9
Source Project: beautyeye   Source File: ButtonDemo.java    License: Apache License 2.0 5 votes vote down vote up
public void stateChanged(ChangeEvent e) {
SingleSelectionModel model = (SingleSelectionModel) e.getSource();
if(model.getSelectedIndex() == 0) {
    currentControls = buttons;
} else if(model.getSelectedIndex() == 1) {
    currentControls = radiobuttons;
} else if(model.getSelectedIndex() == 2) {
    currentControls = checkboxes;
} else {
    currentControls = togglebuttons;
}
   }
 
Example 10
Source Project: beautyeye   Source File: SwingSet2.java    License: Apache License 2.0 5 votes vote down vote up
public void stateChanged(ChangeEvent e) {
	SingleSelectionModel model = (SingleSelectionModel) e.getSource();
	boolean srcSelected = model.getSelectedIndex() == 1;
	if(currentTabDemo != currentDemo && demoSrcPane != null && srcSelected) {
		demoSrcPane.setText(getString("SourceCode.loading"));
		repaint();
	}
	if(currentTabDemo != currentDemo && srcSelected) {
		currentTabDemo = currentDemo;
		setSourceCode(currentDemo);
	} 
}
 
Example 11
Source Project: pcgen   Source File: SharedTabPane.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
protected SharedTabPane()
{
	final SingleSelectionModel selectionModel = getModel();
	selectionModel.addChangeListener(e -> {
           int index = selectionModel.getSelectedIndex();
           if (index != -1)
           {
               setSharedComponentParent(index);
           }
       });

}
 
Example 12
Source Project: pcgen   Source File: SharedTabPane.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
protected SharedTabPane()
{
	final SingleSelectionModel selectionModel = getModel();
	selectionModel.addChangeListener(e -> {
           int index = selectionModel.getSelectedIndex();
           if (index != -1)
           {
               setSharedComponentParent(index);
           }
       });

}
 
Example 13
Source Project: netbeans   Source File: DefaultTabbedContainerUI.java    License: Apache License 2.0 4 votes vote down vote up
public SingleSelectionModel getSelectionModel() {
    return tabDisplayer.getSelectionModel();
}
 
Example 14
Source Project: netbeans   Source File: AbstractViewTabDisplayerUI.java    License: Apache License 2.0 4 votes vote down vote up
protected final SingleSelectionModel getSelectionModel() {
    return selectionModel;
}
 
Example 15
Source Project: netbeans   Source File: AbstractViewTabDisplayerUI.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected final SingleSelectionModel createSelectionModel() {
    return new DefaultTabSelectionModel (displayer.getModel());
}
 
Example 16
Source Project: netbeans   Source File: JTabbedPaneAdapter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected SingleSelectionModel getSelectionModel() {
    return JTabbedPaneAdapter.this.getModel();
}
 
Example 17
Source Project: netbeans   Source File: Controller.java    License: Apache License 2.0 4 votes vote down vote up
SingleSelectionModel getSelectionModel() {
    return selectionModel;
}
 
Example 18
Source Project: netbeans   Source File: TabbedImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected final SingleSelectionModel getSelectionModel() {
    return controller.getSelectionModel();
}
 
Example 19
Source Project: netbeans   Source File: TabDisplayerUI.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Create the selection model which will handle selection for the
 * TabDisplayer.  SPI method located here because TabDisplayer.setSelectionModel
 * is package private.
 */
protected abstract SingleSelectionModel createSelectionModel();