Skip to content

Commit

Permalink
cleaning up more of the maze inside contribs (fixes #613)
Browse files Browse the repository at this point in the history
  • Loading branch information
benfry committed Jan 12, 2023
1 parent ddfaaa3 commit 941283f
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 114 deletions.
25 changes: 12 additions & 13 deletions app/src/processing/app/contrib/ContributionListing.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public class ContributionListing {
Set<Contribution> allContributions;
boolean listDownloaded;
// boolean listDownloadFailed;
ReentrantLock downloadingListingLock;
ReentrantLock downloadingLock;


private ContributionListing() {
listPanels = new HashSet<>();
advertisedContributions = new ArrayList<>();
librariesByImportHeader = new HashMap<>();
allContributions = new LinkedHashSet<>();
downloadingListingLock = new ReentrantLock();
downloadingLock = new ReentrantLock();

listingFile = Base.getSettingsFile(LOCAL_FILENAME);
if (listingFile.exists()) {
Expand Down Expand Up @@ -102,7 +102,7 @@ private void setAdvertisedList(File file) {
* Adds the installed libraries to the listing of libraries, replacing
* any pre-existing libraries by the same name as one in the list.
*/
protected void updateInstalledList(List<Contribution> installed) {
protected void updateInstalledList(Set<Contribution> installed) {
for (Contribution contribution : installed) {
Contribution existingContribution = getContribution(contribution);
if (existingContribution != null) {
Expand Down Expand Up @@ -203,7 +203,7 @@ public void downloadAvailableList(final Base base,

// TODO: replace with SwingWorker [jv]
new Thread(() -> {
downloadingListingLock.lock();
downloadingLock.lock();

try {
URL url = new URL(LISTING_URL);
Expand Down Expand Up @@ -247,7 +247,7 @@ public void downloadAvailableList(final Base base,
progress.setException(e);
progress.finished();
} finally {
downloadingListingLock.unlock();
downloadingLock.unlock();
}
}, "Contribution List Downloader").start();
}
Expand Down Expand Up @@ -276,15 +276,14 @@ private byte[] makeContribsBlob(Base base) {


protected boolean hasUpdates(Contribution contrib) {
if (!contrib.isInstalled()) {
return false;
}
Contribution advertised = getAvailableContribution(contrib);
if (advertised == null) {
return false;
if (contrib.isInstalled()) {
Contribution advertised = getAvailableContribution(contrib);
if (advertised != null) {
return (advertised.getVersion() > contrib.getVersion() &&
advertised.isCompatible(Base.getRevision()));
}
}
return (advertised.getVersion() > contrib.getVersion() &&
advertised.isCompatible(Base.getRevision()));
return false;
}


Expand Down
40 changes: 24 additions & 16 deletions app/src/processing/app/contrib/ContributionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@


public class ContributionManager {
static ContributionListing listing;
static ManagerFrame managerFrame;
static ContributionListing contribListing;


/**
Expand Down Expand Up @@ -162,9 +163,9 @@ static void downloadAndInstall(final Base base,
try {
// TODO: run this in SwingWorker done() [jv]
EventQueue.invokeAndWait(() -> {
listing.replaceContribution(ad, contribution);
contribListing.replaceContribution(ad, contribution);
base.refreshContribs(contribution.getType());
base.setUpdatesAvailable(listing.countUpdates(base));
base.setUpdatesAvailable(contribListing.countUpdates(base));
});
} catch (InterruptedException e) {
e.printStackTrace();
Expand Down Expand Up @@ -245,9 +246,9 @@ static void downloadAndInstallOnStartup(final Base base, final URL url,
try {
// TODO: run this in SwingWorker done() [jv]
EventQueue.invokeAndWait(() -> {
listing.replaceContribution(ad, contribution);
contribListing.replaceContribution(ad, contribution);
base.refreshContribs(contribution.getType());
base.setUpdatesAvailable(listing.countUpdates(base));
base.setUpdatesAvailable(contribListing.countUpdates(base));
});
} catch (InterruptedException e) {
e.printStackTrace();
Expand Down Expand Up @@ -375,9 +376,9 @@ static public void downloadAndInstallOnImport(final Base base,
if (contribution != null) {
try {
EventQueue.invokeAndWait(() -> {
listing.replaceContribution(contrib, contribution);
contribListing.replaceContribution(contrib, contribution);
base.refreshContribs(contribution.getType());
base.setUpdatesAvailable(listing.countUpdates(base));
base.setUpdatesAvailable(contribListing.countUpdates(base));
});
} catch (InterruptedException e) {
e.printStackTrace();
Expand Down Expand Up @@ -428,7 +429,7 @@ static public void downloadAndInstallOnImport(final Base base,
*
* @return a file that does not exist yet
*/
public static File getUniqueName(File parentFolder, String fileName) {
static public File getUniqueName(File parentFolder, String fileName) {
File backupFolderForLib;
int i = 1;
do {
Expand Down Expand Up @@ -486,6 +487,7 @@ static private void cleanup(final Base base) throws Exception {
deleteFlagged(Base.getSketchbookToolsFolder());

installPreviouslyFailed(base, Base.getSketchbookModesFolder());

updateFlagged(base, Base.getSketchbookModesFolder());
updateFlagged(base, Base.getSketchbookToolsFolder());

Expand Down Expand Up @@ -549,11 +551,11 @@ static private void installPreviouslyFailed(Base base, File root) throws Excepti
// https://github.com/processing/processing/issues/5823
if (installList != null) {
for (File file : installList) {
for (AvailableContribution contrib : listing.advertisedContributions) {
for (AvailableContribution contrib : contribListing.advertisedContributions) {
if (file.getName().equals(contrib.getName())) {
file.delete();
installOnStartUp(base, contrib);
EventQueue.invokeAndWait(() -> listing.replaceContribution(contrib, contrib));
EventQueue.invokeAndWait(() -> contribListing.replaceContribution(contrib, contrib));
}
}
}
Expand Down Expand Up @@ -635,15 +637,15 @@ else if (contribType.equalsIgnoreCase("modes"))
}
}

for (AvailableContribution contrib : listing.advertisedContributions) {
for (AvailableContribution contrib : contribListing.advertisedContributions) {
if (updateContribsNames.contains(contrib.getName())) {
updateContribsList.add(contrib);
}
}

for (AvailableContribution contrib : updateContribsList) {
installOnStartUp(base, contrib);
listing.replaceContribution(contrib, contrib);
contribListing.replaceContribution(contrib, contrib);
}
}

Expand Down Expand Up @@ -680,12 +682,10 @@ static private void clearRestartFlags(File root) {
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .


static ManagerFrame managerFrame;


static public void init(Base base) throws Exception {
// long t1 = System.currentTimeMillis();
listing = ContributionListing.getInstance(); // Moved here to make sure it runs on EDT [jv 170121]
// Moved here to make sure it runs on EDT [jv 170121]
contribListing = ContributionListing.getInstance();
// long t2 = System.currentTimeMillis();
managerFrame = new ManagerFrame(base);
// long t3 = System.currentTimeMillis();
Expand All @@ -695,6 +695,14 @@ static public void init(Base base) throws Exception {
}


/*
static public void downloadAvailable() {
//ContributionListing cl = ContributionListing.getInstance();
contribListing.downloadAvailableList(base, new ContribProgress(null));
}
*/


static public void updateTheme() {
if (managerFrame != null) {
managerFrame.updateTheme();
Expand Down
61 changes: 44 additions & 17 deletions app/src/processing/app/contrib/ContributionTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ public class ContributionTab extends JPanel {
StatusPanel statusPanel;
FilterField filterField;

/*
JLabel loaderLabel;
JPanel errorPanel;
JTextPane errorMessage;
JButton tryAgainButton;
JButton closeButton;
*/

String category;

Expand All @@ -68,22 +70,24 @@ public ContributionTab(ManagerFrame dialog) {
this.managerFrame = dialog;
this.base = dialog.base;

/*
buildErrorPanel();
loaderLabel = new JLabel(Toolkit.getLibIcon("manager/loader.gif"));
loaderLabel.setOpaque(false);
*/
}


public ContributionTab(ManagerFrame frame, ContributionType type) {
this(frame);
this.contribType = type;

contribType = type;
filter = contrib -> contrib.getType() == contribType;

listPanel = new ListPanel(this, filter, false);
// TODO init is after listPanel is created because it calls updateTheme()
// which needs it, but yuck, too messy [fry 220504]
// TODO StatusPanel init is after listPanel is created because it calls
// updateTheme() which needs it, but yuck, too messy [fry 220504]
statusPanel = new StatusPanel(this);

ContributionListing.getInstance().addListPanel(listPanel);
Expand All @@ -100,18 +104,33 @@ protected void updateTheme() {
listPanel.updateTheme();
statusPanel.updateTheme();

closeButton.setIcon(Toolkit.renderIcon("manager/close", Theme.get("manager.error.close.icon.color"), 16));
//closeButton.setIcon(Toolkit.renderIcon("manager/close", Theme.get("manager.error.close.icon.color"), 16));
}


/*
protected void activate() {
System.out.println("activating " + contribType);
//updateContributionListing();
ContributionListing.getInstance().updateInstalledList(base.getInstalledContribs());
updateCategoryChooser();
//rebuildLayout(false, false);
rebuildLayout();
}
*/


public void rebuildLayout(boolean error, boolean loading) {
// public void rebuildLayout(boolean error, boolean loading) {
public void rebuildLayout() {
setLayout();

/*
listPanel.setVisible(!loading);
loaderLabel.setVisible(loading);
errorPanel.setVisible(error);
*/

listPanel.fireChange();
listPanel.fireChange(); // wtf, really? every time? [fry 230111]

validate();
repaint();
Expand Down Expand Up @@ -147,12 +166,14 @@ protected void setLayout() {
filterWidth, filterWidth, filterWidth)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED,
GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)
.addComponent(categoryChooser,
ManagerFrame.AUTHOR_WIDTH,
ManagerFrame.AUTHOR_WIDTH,
ManagerFrame.AUTHOR_WIDTH)
.addGap(scrollBarWidth)).addComponent(loaderLabel)
.addComponent(listPanel).addComponent(errorPanel)
.addComponent(categoryChooser,
ManagerFrame.AUTHOR_WIDTH,
ManagerFrame.AUTHOR_WIDTH,
ManagerFrame.AUTHOR_WIDTH)
.addGap(scrollBarWidth))
//.addComponent(loaderLabel)
.addComponent(listPanel)
//.addComponent(errorPanel)
.addComponent(statusPanel));

layout.setVerticalGroup(layout
Expand All @@ -164,11 +185,13 @@ protected void setLayout() {
// https://github.com/processing/processing4/issues/520
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(loaderLabel)
//.addComponent(loaderLabel)
.addComponent(listPanel))
.addComponent(errorPanel)
.addComponent(statusPanel, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE));
//.addComponent(errorPanel)
.addComponent(statusPanel,
GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE));
layout.linkSize(SwingConstants.VERTICAL, categoryChooser, filterField);

// these will occupy space even if not visible
Expand Down Expand Up @@ -201,6 +224,7 @@ private void createComponents() {
}


/*
protected void buildErrorPanel() {
errorPanel = new JPanel();
GroupLayout layout = new GroupLayout(errorPanel);
Expand Down Expand Up @@ -248,6 +272,7 @@ protected void buildErrorPanel() {
errorPanel.setBackground(Color.PINK);
errorPanel.validate();
}
*/


private Set<String> listCategories() {
Expand Down Expand Up @@ -298,6 +323,7 @@ protected void filterLibraries() {
}


/*
// TODO Why is this entire set of code only running when Editor
// is not null... And what's it doing anyway? Shouldn't it run
// on all editors? (The change to getActiveEditor() was made
Expand Down Expand Up @@ -339,6 +365,7 @@ protected void updateContributionListing() {
//listPanel.filterDummy(category);
}
}
*/


public void updateStatusDetail(StatusDetail detail) {
Expand All @@ -364,7 +391,7 @@ class FilterField extends JTextField {
// Color placeholderColor;
// Color backgroundColor;

FilterField () {
FilterField() {
// super(""); // necessary?

// a label that appears above the component when empty and not focused
Expand Down
Loading

0 comments on commit 941283f

Please sign in to comment.