Search in sources :

Example 1 with ModpackWidget

use of net.technicpack.launcher.ui.controls.modpacks.ModpackWidget in project LauncherV3 by TechnicPack.

the class ModpackSelector method selectWidget.

protected void selectWidget(ModpackWidget widget) {
    if (selectedWidget != null)
        selectedWidget.setIsSelected(false);
    selectedWidget = widget;
    selectedWidget.setIsSelected(true);
    selectedWidget.getModpack().select();
    selectedWidget.scrollRectToVisible(new Rectangle(selectedWidget.getSize()));
    if (modpackInfoPanel != null)
        modpackInfoPanel.setModpack(widget.getModpack());
    final ModpackWidget refreshWidget = selectedWidget;
    Thread thread = new Thread("Modpack redownload " + selectedWidget.getModpack().getDisplayName()) {

        @Override
        public void run() {
            try {
                PlatformPackInfo updatedInfo = platformApi.getPlatformPackInfo(refreshWidget.getModpack().getName());
                PackInfo infoToUse = updatedInfo;
                if (updatedInfo != null && updatedInfo.hasSolder()) {
                    try {
                        ISolderPackApi solderPack = solderApi.getSolderPack(updatedInfo.getSolder(), updatedInfo.getName(), solderApi.getMirrorUrl(updatedInfo.getSolder()));
                        infoToUse = new CombinedPackInfo(solderPack.getPackInfo(), updatedInfo);
                    } catch (RestfulAPIException ex) {
                    }
                }
                if (infoToUse != null)
                    refreshWidget.getModpack().setPackInfo(infoToUse);
                EventQueue.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        if (modpackInfoPanel != null)
                            modpackInfoPanel.setModpackIfSame(refreshWidget.getModpack());
                        if (refreshWidget.getModpack().hasRecommendedUpdate()) {
                            refreshWidget.setToolTipText(resources.getString("launcher.packselector.updatetip"));
                        } else {
                            refreshWidget.setToolTipText(null);
                        }
                        iconRepo.refreshRetry(refreshWidget.getModpack());
                        refreshWidget.updateFromPack(iconRepo.startImageJob(refreshWidget.getModpack()));
                        EventQueue.invokeLater(new Runnable() {

                            @Override
                            public void run() {
                                revalidate();
                                repaint();
                            }
                        });
                    }
                });
            } catch (RestfulAPIException ex) {
                ex.printStackTrace();
                return;
            }
        }
    };
    thread.start();
}
Also used : RestfulAPIException(net.technicpack.rest.RestfulAPIException) PlatformPackInfo(net.technicpack.platform.io.PlatformPackInfo) CombinedPackInfo(net.technicpack.launchercore.modpacks.packinfo.CombinedPackInfo) CombinedPackInfo(net.technicpack.launchercore.modpacks.packinfo.CombinedPackInfo) PlatformPackInfo(net.technicpack.platform.io.PlatformPackInfo) PackInfo(net.technicpack.rest.io.PackInfo) ISolderPackApi(net.technicpack.solder.ISolderPackApi) ModpackWidget(net.technicpack.launcher.ui.controls.modpacks.ModpackWidget)

Example 2 with ModpackWidget

use of net.technicpack.launcher.ui.controls.modpacks.ModpackWidget in project LauncherV3 by TechnicPack.

the class ModpackSelector method refreshComplete.

@Override
public void refreshComplete() {
    setTintActive(false);
    if (findMoreWidget.getWidgetData().equals(resources.getString("launcher.packselector.api"))) {
        if (allModpacks.size() == 0) {
            findMoreWidget.setWidgetData(resources.getString("launcher.packselector.badapi"));
            findMoreUrl = "https://www.technicpack.net/";
        } else {
            for (ModpackWidget widget : allModpacks.values()) {
                findMoreUrl = widget.getModpack().getWebSite();
                break;
            }
        }
    }
    if (selectedWidget == null || selectedWidget.getModpack() == null || !allModpacks.containsKey(selectedWidget.getModpack().getName())) {
        java.util.List<ModpackWidget> sortedPacks = new LinkedList<ModpackWidget>();
        sortedPacks.addAll(allModpacks.values());
        Collections.sort(sortedPacks, new Comparator<ModpackWidget>() {

            @Override
            public int compare(ModpackWidget o1, ModpackWidget o2) {
                int priorityCompare = (new Integer(o2.getModpack().getPriority())).compareTo(new Integer(o1.getModpack().getPriority()));
                if (priorityCompare != 0)
                    return priorityCompare;
                else if (o1.getModpack().getDisplayName() == null && o2.getModpack().getDisplayName() == null)
                    return 0;
                else if (o1.getModpack().getDisplayName() == null)
                    return -1;
                else if (o2.getModpack().getDisplayName() == null)
                    return 1;
                else
                    return o1.getModpack().getDisplayName().compareToIgnoreCase(o2.getModpack().getDisplayName());
            }
        });
        if (sortedPacks.size() > 0) {
            selectWidget(sortedPacks.get(0));
        }
    }
}
Also used : java.util(java.util) ModpackWidget(net.technicpack.launcher.ui.controls.modpacks.ModpackWidget)

Example 3 with ModpackWidget

use of net.technicpack.launcher.ui.controls.modpacks.ModpackWidget in project LauncherV3 by TechnicPack.

the class ModpackSelector method addModpackInternal.

protected void addModpackInternal(ModpackModel modpack) {
    final ModpackWidget widget = new ModpackWidget(resources, modpack, iconRepo.startImageJob(modpack));
    if (modpack.hasRecommendedUpdate()) {
        widget.setToolTipText(resources.getString("launcher.packselector.updatetip"));
    }
    widget.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof ModpackWidget)
                selectWidget((ModpackWidget) e.getSource());
        }
    });
    if (widget.getModpack().isSelected()) {
        selectedWidget = widget;
    }
    if (allModpacks.containsKey(modpack.getName()) && allModpacks.get(modpack.getName()).isSelected())
        selectedWidget = widget;
    allModpacks.put(modpack.getName(), widget);
    rebuildUI();
    if (selectedWidget != null) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                if (widget == selectedWidget)
                    selectWidget(widget);
                else
                    selectedWidget.scrollRectToVisible(new Rectangle(selectedWidget.getSize()));
            }
        });
    }
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ModpackWidget(net.technicpack.launcher.ui.controls.modpacks.ModpackWidget)

Example 4 with ModpackWidget

use of net.technicpack.launcher.ui.controls.modpacks.ModpackWidget in project LauncherV3 by TechnicPack.

the class ModpackSelector method rebuildUI.

protected void rebuildUI() {
    if (!EventQueue.isDispatchThread()) {
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                rebuildUI();
            }
        });
        return;
    }
    GridBagConstraints constraints = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0);
    java.util.List<ModpackWidget> sortedPacks = new LinkedList<ModpackWidget>();
    sortedPacks.addAll(allModpacks.values());
    Collections.sort(sortedPacks, new Comparator<ModpackWidget>() {

        @Override
        public int compare(ModpackWidget o1, ModpackWidget o2) {
            int priorityCompare = (new Integer(o2.getModpack().getPriority())).compareTo(new Integer(o1.getModpack().getPriority()));
            if (priorityCompare != 0)
                return priorityCompare;
            else if (o1.getModpack().getDisplayName() == null && o2.getModpack().getDisplayName() == null)
                return 0;
            else if (o1.getModpack().getDisplayName() == null)
                return -1;
            else if (o2.getModpack().getDisplayName() == null)
                return 1;
            else
                return o1.getModpack().getDisplayName().compareToIgnoreCase(o2.getModpack().getDisplayName());
        }
    });
    widgetList.removeAll();
    for (ModpackWidget sortedPack : sortedPacks) {
        widgetList.add(sortedPack, constraints);
        constraints.gridy++;
    }
    if (filterContents.getText().length() >= 3) {
        widgetList.add(findMoreWidget, constraints);
    }
    widgetList.add(Box.createHorizontalStrut(294), constraints);
    constraints.gridy++;
    constraints.weighty = 1.0;
    widgetList.add(Box.createGlue(), constraints);
    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            revalidate();
            repaint();
        }
    });
}
Also used : java.util(java.util) ModpackWidget(net.technicpack.launcher.ui.controls.modpacks.ModpackWidget)

Aggregations

ModpackWidget (net.technicpack.launcher.ui.controls.modpacks.ModpackWidget)4 java.util (java.util)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 CombinedPackInfo (net.technicpack.launchercore.modpacks.packinfo.CombinedPackInfo)1 PlatformPackInfo (net.technicpack.platform.io.PlatformPackInfo)1 RestfulAPIException (net.technicpack.rest.RestfulAPIException)1 PackInfo (net.technicpack.rest.io.PackInfo)1 ISolderPackApi (net.technicpack.solder.ISolderPackApi)1