Example usage for javax.swing JScrollPane getInsets

List of usage examples for javax.swing JScrollPane getInsets

Introduction

In this page you can find the example usage for javax.swing JScrollPane getInsets.

Prototype

@BeanProperty(expert = true)
public Insets getInsets() 

Source Link

Document

If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets.

Usage

From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java

/**
 * Creates the menu hosting the users belonging to the specified group.
 * Returns <code>true</code> if the group is selected, <code>false</code>
 * otherwise./*w  ww . ja v  a  2s  . c  o m*/
 * 
 * @param groupItem The item hosting the group.
 * @param size The number of groups.
 * @return See above.
 */
private boolean createGroupMenu(GroupItem groupItem, int size) {
    long loggedUserID = model.getUserDetails().getId();
    GroupData group = groupItem.getGroup();
    //Determine the user already added to the display
    Browser browser = model.getBrowser(Browser.PROJECTS_EXPLORER);
    TreeImageDisplay refNode = null;
    List<TreeImageDisplay> nodes;
    ExperimenterVisitor visitor;
    List<Long> users = new ArrayList<Long>();
    //Find the group already displayed
    if (group != null && size > 0) {
        visitor = new ExperimenterVisitor(browser, group.getId());
        browser.accept(visitor);
        nodes = visitor.getNodes();
        if (nodes.size() == 1) {
            refNode = nodes.get(0);
        }
        visitor = new ExperimenterVisitor(browser, -1, -1);
        if (refNode != null)
            refNode.accept(visitor);
        else if (size == 1)
            browser.accept(visitor);
        nodes = visitor.getNodes();

        TreeImageDisplay n;
        if (CollectionUtils.isNotEmpty(nodes)) {
            Iterator<TreeImageDisplay> j = nodes.iterator();
            while (j.hasNext()) {
                n = j.next();
                if (n.getUserObject() instanceof ExperimenterData) {
                    users.add(((ExperimenterData) n.getUserObject()).getId());
                }
            }
            if (size == 1) {
                groupItem.setMenuSelected(true, false);
            }
        }
    }

    //now add the users
    List<DataMenuItem> items = new ArrayList<DataMenuItem>();
    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
    List l = null;
    if (group != null)
        l = sorter.sort(group.getLeaders());
    Iterator i;
    ExperimenterData exp;

    DataMenuItem item, allUser;
    JPanel list;

    boolean view = true;
    if (group != null) {
        int level = group.getPermissions().getPermissionsLevel();
        if (level == GroupData.PERMISSIONS_PRIVATE) {
            view = model.isAdministrator() || model.isGroupOwner(group);
        }
    }

    list = new JPanel();
    list.setLayout(new BoxLayout(list, BoxLayout.Y_AXIS));
    allUser = new DataMenuItem(DataMenuItem.ALL_USERS_TEXT, true);
    items.add(allUser);
    if (view)
        list.add(allUser);
    p.add(UIUtilities.buildComponentPanel(list));
    int count = 0;
    int total = 0;
    if (CollectionUtils.isNotEmpty(l)) {
        total += l.size();
        i = l.iterator();
        list = new JPanel();
        list.setLayout(new BoxLayout(list, BoxLayout.Y_AXIS));
        while (i.hasNext()) {
            exp = (ExperimenterData) i.next();
            if (view || exp.getId() == loggedUserID) {
                item = new DataMenuItem(exp, true);
                item.setSelected(users.contains(exp.getId()));
                if (item.isSelected())
                    count++;
                item.addPropertyChangeListener(groupItem);
                items.add(item);
                list.add(item);
            }
        }
        if (list.getComponentCount() > 0) {
            p.add(formatHeader("Group owners"));
            p.add(UIUtilities.buildComponentPanel(list));
        }
    }

    if (group != null)
        l = sorter.sort(group.getMembersOnly());
    if (CollectionUtils.isNotEmpty(l)) {
        total += l.size();
        i = l.iterator();
        list = new JPanel();
        list.setLayout(new BoxLayout(list, BoxLayout.Y_AXIS));
        while (i.hasNext()) {
            exp = (ExperimenterData) i.next();
            if (view || exp.getId() == loggedUserID) {
                item = new DataMenuItem(exp, true);
                item.setSelected(users.contains(exp.getId()));
                if (item.isSelected())
                    count++;
                item.addPropertyChangeListener(groupItem);
                items.add(item);
                list.add(item);
            }
        }
        if (list.getComponentCount() > 0) {
            p.add(formatHeader("Members"));
            p.add(UIUtilities.buildComponentPanel(list));
        }
    }
    allUser.setSelected(total != 0 && total == count);
    allUser.addPropertyChangeListener(groupItem);
    JScrollPane pane = new JScrollPane(p);
    Dimension d = p.getPreferredSize();
    int max = 500;
    if (d.height > max) {
        Insets insets = pane.getInsets();
        pane.setPreferredSize(new Dimension(d.width + insets.left + insets.right + 20, max));
    }

    groupItem.add(pane);
    groupItem.setUsersItem(items);
    groupItem.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (GroupItem.USER_SELECTION_PROPERTY.equals(name))
                handleSelection();
            else if (GroupItem.ALL_GROUPS_SELECTION_PROPERTY.equals(name))
                handleAllGroupsSelection(true);
            else if (GroupItem.ALL_GROUPS_DESELECTION_PROPERTY.equals(name))
                handleAllGroupsSelection(false);
            else if (GroupItem.ALL_USERS_SELECTION_PROPERTY.equals(name))
                handleAllUsersSelection((Boolean) evt.getNewValue());
        }
    });
    return groupItem.isMenuSelected();
}