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();
}
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));
}
}
}
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()));
}
});
}
}
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();
}
});
}
Aggregations