Search in sources :

Example 71 with Comparator

use of java.util.Comparator in project gephi by gephi.

the class PartitionImpl method getSortedValues.

@Override
public Collection getSortedValues() {
    List values = new ArrayList(getValues());
    Collections.sort(values, new Comparator() {

        @Override
        public int compare(Object o1, Object o2) {
            float p1 = percentage(o1);
            float p2 = percentage(o2);
            return p1 > p2 ? -1 : p1 < p2 ? 1 : 0;
        }
    });
    return values;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Comparator(java.util.Comparator)

Example 72 with Comparator

use of java.util.Comparator in project gephi by gephi.

the class StatisticsPanel method refreshFrontEnd.

private void refreshFrontEnd() {
    squeezeBoxPanel.cleanPanels();
    for (StatisticsCategory category : categories) {
        //Find uis in this category
        List<UIFrontEnd> uis = new ArrayList<>();
        for (UIFrontEnd uife : frontEnds) {
            if (uife.getCategory().equals(category) && uife.isVisible()) {
                uis.add(uife);
            }
        }
        if (uis.size() > 0) {
            //Sort it by position
            Collections.sort(uis, new Comparator() {

                @Override
                public int compare(Object o1, Object o2) {
                    Integer p1 = ((UIFrontEnd) o1).getStatisticsUI().getPosition();
                    Integer p2 = ((UIFrontEnd) o2).getStatisticsUI().getPosition();
                    return p1.compareTo(p2);
                }
            });
            MigLayout migLayout = new MigLayout("insets 0");
            migLayout.setColumnConstraints("[grow,fill]");
            migLayout.setRowConstraints("[pref!]");
            JPanel innerPanel = new JPanel(migLayout);
            for (UIFrontEnd sui : uis) {
                innerPanel.add(sui.frontEnd, "wrap");
            }
            squeezeBoxPanel.addPanel(innerPanel, category.getName());
        }
    }
}
Also used : JPanel(javax.swing.JPanel) MigLayout(net.miginfocom.swing.MigLayout) ArrayList(java.util.ArrayList) Comparator(java.util.Comparator)

Example 73 with Comparator

use of java.util.Comparator in project gephi by gephi.

the class StatisticsPanel method initFrontEnds.

private void initFrontEnds() {
    StatisticsUI[] statisticsUIs = Lookup.getDefault().lookupAll(StatisticsUI.class).toArray(new StatisticsUI[0]);
    frontEnds = new ArrayList<>();
    for (StatisticsCategory category : categories) {
        //Find uis in this category
        List<StatisticsUI> uis = new ArrayList<>();
        for (StatisticsUI sui : statisticsUIs) {
            if (sui.getCategory().equals(category.getName())) {
                uis.add(sui);
            }
        }
        if (uis.size() > 0) {
            //Sort it by position
            Collections.sort(uis, new Comparator() {

                @Override
                public int compare(Object o1, Object o2) {
                    Integer p1 = ((StatisticsUI) o1).getPosition();
                    Integer p2 = ((StatisticsUI) o2).getPosition();
                    return p1.compareTo(p2);
                }
            });
            MigLayout migLayout = new MigLayout("insets 0");
            migLayout.setColumnConstraints("[grow,fill]");
            migLayout.setRowConstraints("[pref!]");
            JPanel innerPanel = new JPanel(migLayout);
            for (StatisticsUI sui : uis) {
                StatisticsFrontEnd frontEnd = new StatisticsFrontEnd(sui);
                UIFrontEnd uife = new UIFrontEnd(sui, frontEnd, category);
                frontEnds.add(uife);
                innerPanel.add(frontEnd, "wrap");
            }
            squeezeBoxPanel.addPanel(innerPanel, category.getName());
        }
    }
}
Also used : JPanel(javax.swing.JPanel) MigLayout(net.miginfocom.swing.MigLayout) ArrayList(java.util.ArrayList) Comparator(java.util.Comparator) StatisticsUI(org.gephi.statistics.spi.StatisticsUI)

Example 74 with Comparator

use of java.util.Comparator in project gephi by gephi.

the class DesktopToolController method getToolbar.

@Override
public JComponent getToolbar() {
    //Get tools ui
    HashMap<ToolUI, Tool> toolMap = new HashMap<>();
    List<ToolUI> toolsUI = new ArrayList<>();
    for (Tool tool : tools) {
        ToolUI ui = tool.getUI();
        if (ui != null) {
            toolsUI.add(ui);
            toolMap.put(ui, tool);
        }
    }
    //Sort by priority
    Collections.sort(toolsUI, new Comparator() {

        @Override
        public int compare(Object o1, Object o2) {
            Integer p1 = ((ToolUI) o1).getPosition();
            Integer p2 = ((ToolUI) o2).getPosition();
            return p1.compareTo(p2);
        }
    });
    //Create toolbar
    final Toolbar toolbar = new Toolbar();
    for (final ToolUI toolUI : toolsUI) {
        final Tool tool = toolMap.get(toolUI);
        JToggleButton btn;
        if (toolUI.getIcon() != null) {
            btn = new JToggleButton(toolUI.getIcon());
        } else {
            btn = new JToggleButton(new ImageIcon(getClass().getResource("/org/gephi/desktop/tools/tool.png")));
        }
        btn.setToolTipText(toolUI.getName() + " - " + toolUI.getDescription());
        btn.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                //Let the user unselect a tool (by clicking on it again) without having to select other tool:
                if (tool == currentTool) {
                    toolbar.clearSelection();
                    unselect();
                } else {
                    try {
                        select(tool);
                        propertiesBar.select(toolUI.getPropertiesBar(tool));
                    } catch (UnselectToolException unselectToolException) {
                        toolbar.clearSelection();
                        unselect();
                    }
                }
            }
        });
        toolbar.add(btn);
    }
    //SelectionManager events
    VizController.getInstance().getSelectionManager().addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            SelectionManager selectionManager = VizController.getInstance().getSelectionManager();
            if (selectionManager.isRectangleSelection() && currentTool != null) {
                toolbar.clearSelection();
                unselect();
            } else if (selectionManager.isSelectionEnabled() && currentTool != null && currentTool.getSelectionType() == ToolSelectionType.NONE) {
                toolbar.clearSelection();
                unselect();
            } else if (selectionManager.isDraggingEnabled() && currentTool != null) {
                toolbar.clearSelection();
                unselect();
            }
        }
    });
    return toolbar;
}
Also used : ImageIcon(javax.swing.ImageIcon) SelectionManager(org.gephi.visualization.api.selection.SelectionManager) HashMap(java.util.HashMap) UnselectToolException(org.gephi.tools.spi.UnselectToolException) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) ToolUI(org.gephi.tools.spi.ToolUI) Comparator(java.util.Comparator) JToggleButton(javax.swing.JToggleButton) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener) Tool(org.gephi.tools.spi.Tool)

Example 75 with Comparator

use of java.util.Comparator in project gitblit by gitblit.

the class MyDashboardPage method setup.

private void setup(PageParameters params) {
    setupPage("", "");
    // check to see if we should display a login message
    boolean authenticateView = app().settings().getBoolean(Keys.web.authenticateViewPages, true);
    if (authenticateView && !GitBlitWebSession.get().isLoggedIn()) {
        String messageSource = app().settings().getString(Keys.web.loginMessage, "gitblit");
        String message = readMarkdown(messageSource, "login.mkd");
        Component repositoriesMessage = new Label("repositoriesMessage", message);
        add(repositoriesMessage.setEscapeModelStrings(false));
        add(new Label("activity").setVisible(false));
        add(new Label("repositoryTabs").setVisible(false));
        return;
    }
    // Load the markdown welcome message
    String messageSource = app().settings().getString(Keys.web.repositoriesMessage, "gitblit");
    String message = readMarkdown(messageSource, "welcome.mkd");
    Component repositoriesMessage = new Label("repositoriesMessage", message).setEscapeModelStrings(false).setVisible(message.length() > 0);
    add(repositoriesMessage);
    UserModel user = GitBlitWebSession.get().getUser();
    if (user == null) {
        user = UserModel.ANONYMOUS;
    }
    // parameters
    int daysBack = params == null ? 0 : WicketUtils.getDaysBack(params);
    int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30);
    if (daysBack < 1) {
        daysBack = app().settings().getInteger(Keys.web.activityDuration, 7);
    }
    if (maxDaysBack > 0 && daysBack > maxDaysBack) {
        daysBack = maxDaysBack;
    }
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DATE, -1 * daysBack);
    Date minimumDate = c.getTime();
    // build repo lists
    List<RepositoryModel> starred = new ArrayList<RepositoryModel>();
    List<RepositoryModel> owned = new ArrayList<RepositoryModel>();
    List<RepositoryModel> active = new ArrayList<RepositoryModel>();
    for (RepositoryModel model : getRepositoryModels()) {
        if (model.isUsersPersonalRepository(user.username) || model.isOwner(user.username)) {
            owned.add(model);
        }
        if (user.getPreferences().isStarredRepository(model.name)) {
            starred.add(model);
        }
        if (model.isShowActivity() && model.lastChange.after(minimumDate)) {
            active.add(model);
        }
    }
    Comparator<RepositoryModel> lastUpdateSort = new Comparator<RepositoryModel>() {

        @Override
        public int compare(RepositoryModel o1, RepositoryModel o2) {
            return o2.lastChange.compareTo(o1.lastChange);
        }
    };
    Collections.sort(owned, lastUpdateSort);
    Collections.sort(starred, lastUpdateSort);
    Collections.sort(active, lastUpdateSort);
    String activityTitle;
    Set<RepositoryModel> feed = new HashSet<RepositoryModel>();
    feed.addAll(starred);
    feed.addAll(owned);
    if (feed.isEmpty()) {
        // no starred or owned, go with recent activity
        activityTitle = getString("gb.recentActivity");
        feed.addAll(active);
    } else if (starred.isEmpty()) {
        // no starred, owned repos feed
        activityTitle = getString("gb.owned");
    } else if (owned.isEmpty()) {
        // no owned, starred repos feed
        activityTitle = getString("gb.starred");
    } else {
        // starred and owned repositories
        activityTitle = getString("gb.starredAndOwned");
    }
    addActivity(user, feed, activityTitle, daysBack);
    Fragment repositoryTabs;
    if (UserModel.ANONYMOUS.equals(user)) {
        repositoryTabs = new Fragment("repositoryTabs", "anonymousTabsFragment", this);
    } else {
        repositoryTabs = new Fragment("repositoryTabs", "authenticatedTabsFragment", this);
    }
    add(repositoryTabs);
    // projects list
    List<ProjectModel> projects = app().projects().getProjectModels(getRepositoryModels(), false);
    repositoryTabs.add(new FilterableProjectList("projects", projects));
    // active repository list
    if (active.isEmpty()) {
        repositoryTabs.add(new Label("active").setVisible(false));
    } else {
        FilterableRepositoryList repoList = new FilterableRepositoryList("active", active);
        repoList.setTitle(getString("gb.activeRepositories"), "icon-time");
        repositoryTabs.add(repoList);
    }
    // starred repository list
    if (ArrayUtils.isEmpty(starred)) {
        repositoryTabs.add(new Label("starred").setVisible(false));
    } else {
        FilterableRepositoryList repoList = new FilterableRepositoryList("starred", starred);
        repoList.setTitle(getString("gb.starredRepositories"), "icon-star");
        repositoryTabs.add(repoList);
    }
    // owned repository list
    if (ArrayUtils.isEmpty(owned)) {
        repositoryTabs.add(new Label("owned").setVisible(false));
    } else {
        FilterableRepositoryList repoList = new FilterableRepositoryList("owned", owned);
        repoList.setTitle(getString("gb.myRepositories"), "icon-user");
        repoList.setAllowCreate(user.canCreate() || user.canAdmin());
        repositoryTabs.add(repoList);
    }
}
Also used : FilterableRepositoryList(com.gitblit.wicket.panels.FilterableRepositoryList) Calendar(java.util.Calendar) Label(org.apache.wicket.markup.html.basic.Label) ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel) Fragment(org.apache.wicket.markup.html.panel.Fragment) Date(java.util.Date) Comparator(java.util.Comparator) UserModel(com.gitblit.models.UserModel) FilterableProjectList(com.gitblit.wicket.panels.FilterableProjectList) Component(org.apache.wicket.Component) ProjectModel(com.gitblit.models.ProjectModel) HashSet(java.util.HashSet)

Aggregations

Comparator (java.util.Comparator)322 ArrayList (java.util.ArrayList)123 List (java.util.List)58 Test (org.junit.Test)58 HashMap (java.util.HashMap)50 IOException (java.io.IOException)36 Map (java.util.Map)35 File (java.io.File)24 HashSet (java.util.HashSet)23 TreeSet (java.util.TreeSet)20 Set (java.util.Set)18 Iterator (java.util.Iterator)15 Method (java.lang.reflect.Method)14 Collections (java.util.Collections)14 Date (java.util.Date)14 TreeMap (java.util.TreeMap)14 ArrayMap (android.util.ArrayMap)12 Collection (java.util.Collection)11 LinkedList (java.util.LinkedList)11 SimpleDateFormat (java.text.SimpleDateFormat)10