mirror of
https://github.com/processing/processing4.git
synced 2026-02-13 18:35:37 +01:00
Merge pull request #2746 from joelmoniz/compatibleContribs
Added option to allow the user to make the contributions listing dependent on the PDE version
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
@@ -49,11 +49,14 @@ class AvailableContribution extends Contribution {
|
||||
url = params.get("url");
|
||||
sentence = params.get("sentence");
|
||||
paragraph = params.get("paragraph");
|
||||
|
||||
String versionStr = params.get("version");
|
||||
if (versionStr != null) {
|
||||
version = PApplet.parseInt(versionStr, 0);
|
||||
}
|
||||
|
||||
prettyVersion = params.get("prettyVersion");
|
||||
|
||||
String lastUpdatedStr = params.get("lastUpdated");
|
||||
if (lastUpdatedStr != null)
|
||||
try {
|
||||
@@ -61,6 +64,16 @@ class AvailableContribution extends Contribution {
|
||||
} catch (NumberFormatException e) {
|
||||
lastUpdated = 0;
|
||||
}
|
||||
|
||||
String minRev = params.get("minRevision");
|
||||
if (minRev != null) {
|
||||
minRevision = PApplet.parseInt(minRev, 0);
|
||||
}
|
||||
|
||||
String maxRev = params.get("maxRevision");
|
||||
if (maxRev != null) {
|
||||
maxRevision = PApplet.parseInt(maxRev, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -288,6 +301,24 @@ class AvailableContribution extends Contribution {
|
||||
// .println("Please contact the author to fix it according to the guidelines.");
|
||||
}
|
||||
|
||||
int minRev;
|
||||
try {
|
||||
minRev = Integer.parseInt(properties.get("minRevision"));
|
||||
} catch (NumberFormatException e) {
|
||||
minRev = getMinRevision();
|
||||
System.err.println("The minimum compatible revision for the “" + name
|
||||
+ "” contribution is not set properly. Assuming minimum revision 0.");
|
||||
}
|
||||
|
||||
int maxRev;
|
||||
try {
|
||||
maxRev = Integer.parseInt(properties.get("maxRevision"));
|
||||
} catch (NumberFormatException e) {
|
||||
maxRev = getMaxRevision();
|
||||
System.err.println("The maximum compatible revision for the “" + name
|
||||
+ "” contribution is not set properly. Assuming maximum revision INF.");
|
||||
}
|
||||
|
||||
if (propFile.delete() && propFile.createNewFile() && propFile.setWritable(true)) {
|
||||
PrintWriter writer = PApplet.createWriter(propFile);
|
||||
|
||||
@@ -300,6 +331,8 @@ class AvailableContribution extends Contribution {
|
||||
writer.println("version=" + version);
|
||||
writer.println("prettyVersion=" + prettyVersion);
|
||||
writer.println("lastUpdated=" + lastUpdated);
|
||||
writer.println("minRevision=" + minRev);
|
||||
writer.println("maxRevision=" + maxRev);
|
||||
if (getType() == ContributionType.EXAMPLES_PACKAGE) {
|
||||
writer.println("compatibleModesList=" + compatibleContribsList);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ abstract public class Contribution {
|
||||
protected int version; // 102
|
||||
protected String prettyVersion; // "1.0.2"
|
||||
protected long lastUpdated; // 1402805757
|
||||
protected int minRevision; // 0
|
||||
protected int maxRevision; // 227
|
||||
|
||||
|
||||
// "Sound"
|
||||
@@ -129,6 +131,21 @@ abstract public class Contribution {
|
||||
return lastUpdated;
|
||||
}
|
||||
|
||||
// 0
|
||||
public int getMinRevision() {
|
||||
return minRevision;
|
||||
}
|
||||
|
||||
// 227
|
||||
public int getMaxRevision() {
|
||||
return maxRevision;
|
||||
}
|
||||
|
||||
|
||||
public boolean isCompatible(int versionNum) {
|
||||
return ((maxRevision == 0 || versionNum < maxRevision) && versionNum > minRevision);
|
||||
}
|
||||
|
||||
|
||||
abstract public ContributionType getType();
|
||||
|
||||
|
||||
@@ -308,6 +308,24 @@ public class ContributionListing {
|
||||
}
|
||||
|
||||
|
||||
protected List<Contribution> getCompatibleContributionList(List<Contribution> filteredLibraries, boolean filter) {
|
||||
ArrayList<Contribution> filteredList =
|
||||
new ArrayList<Contribution>(filteredLibraries);
|
||||
|
||||
if (!filter)
|
||||
return filteredList;
|
||||
|
||||
Iterator<Contribution> it = filteredList.iterator();
|
||||
while (it.hasNext()) {
|
||||
Contribution libInfo = it.next();
|
||||
if (!libInfo.isCompatible(Base.getRevision())) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
return filteredList;
|
||||
}
|
||||
|
||||
|
||||
private void notifyRemove(Contribution contribution) {
|
||||
for (ContributionChangeListener listener : listeners) {
|
||||
listener.contributionRemoved(contribution);
|
||||
|
||||
@@ -57,6 +57,8 @@ public class ContributionManagerDialog {
|
||||
// the calling editor, so updates can be applied
|
||||
Editor editor;
|
||||
String category;
|
||||
String compatibleContribType;
|
||||
boolean isCompatibilityFilter;
|
||||
ContributionListing contribListing;
|
||||
|
||||
|
||||
@@ -64,6 +66,7 @@ public class ContributionManagerDialog {
|
||||
if (type == null) {
|
||||
title = Language.text("contrib.manager_title.update");
|
||||
filter = ContributionType.createUpdateFilter();
|
||||
compatibleContribType = "Updates";
|
||||
} else {
|
||||
if (type == ContributionType.MODE)
|
||||
title = Language.text("contrib.manager_title.mode");
|
||||
@@ -73,6 +76,11 @@ public class ContributionManagerDialog {
|
||||
title = Language.text("contrib.manager_title.library");
|
||||
|
||||
filter = type.createFilter();
|
||||
|
||||
if (type == ContributionType.LIBRARY)
|
||||
compatibleContribType = "Libraries";
|
||||
else
|
||||
compatibleContribType = type.getTitle() + "s";
|
||||
}
|
||||
contribListing = ContributionListing.getInstance();
|
||||
contributionListPanel = new ContributionListPanel(this, filter);
|
||||
@@ -217,7 +225,7 @@ public class ContributionManagerDialog {
|
||||
if (ContributionManagerDialog.ANY_CATEGORY.equals(category)) {
|
||||
category = null;
|
||||
}
|
||||
filterLibraries(category, filterField.filters);
|
||||
filterLibraries(category, filterField.filters, isCompatibilityFilter);
|
||||
contributionListPanel.updateColors();
|
||||
}
|
||||
});
|
||||
@@ -226,6 +234,20 @@ public class ContributionManagerDialog {
|
||||
// filterPanel.add(Box.createHorizontalGlue());
|
||||
filterField = new FilterField();
|
||||
filterPanel.add(filterField);
|
||||
|
||||
filterPanel.add(Box.createHorizontalStrut(5));
|
||||
|
||||
final JCheckBox compatibleContrib = new JCheckBox("Show Only Compatible " + compatibleContribType);
|
||||
compatibleContrib.addItemListener(new ItemListener() {
|
||||
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent arg0) {
|
||||
isCompatibilityFilter = compatibleContrib.isSelected();
|
||||
filterLibraries(category, filterField.filters, isCompatibilityFilter);
|
||||
contributionListPanel.updateColors();
|
||||
}
|
||||
});
|
||||
filterPanel.add(compatibleContrib);
|
||||
// filterPanel.add(Box.createHorizontalGlue());
|
||||
// }
|
||||
//filterPanel.setBorder(new EmptyBorder(13, 13, 13, 13));
|
||||
@@ -387,6 +409,14 @@ public class ContributionManagerDialog {
|
||||
contributionListPanel.filterLibraries(filteredLibraries);
|
||||
}
|
||||
|
||||
|
||||
protected void filterLibraries(String category, List<String> filters, boolean isCompatibilityFilter) {
|
||||
List<Contribution> filteredLibraries =
|
||||
contribListing.getFilteredLibraryList(category, filters);
|
||||
filteredLibraries = contribListing.getCompatibleContributionList(filteredLibraries, isCompatibilityFilter);
|
||||
contributionListPanel.filterLibraries(filteredLibraries);
|
||||
}
|
||||
|
||||
|
||||
protected void updateContributionListing() {
|
||||
if (editor != null) {
|
||||
@@ -523,7 +553,7 @@ public class ContributionManagerDialog {
|
||||
// Replace anything but 0-9, a-z, or : with a space
|
||||
filter = filter.replaceAll("[^\\x30-\\x39^\\x61-\\x7a^\\x3a]", " ");
|
||||
filters = Arrays.asList(filter.split(" "));
|
||||
filterLibraries(category, filters);
|
||||
filterLibraries(category, filters, isCompatibilityFilter);
|
||||
|
||||
contributionListPanel.updateColors();
|
||||
}
|
||||
|
||||
@@ -63,6 +63,9 @@ class ContributionPanel extends JPanel {
|
||||
|
||||
static public final String BUTTON_CONSTRAINT = "Install/Remvoe Button Panel";
|
||||
|
||||
static public final String INCOMPATIBILITY_BLUR = "This contribution is not compatible with "
|
||||
+ "the current revision of Processing";
|
||||
|
||||
private final ContributionListPanel listPanel;
|
||||
private final ContributionListing contribListing = ContributionListing.getInstance();
|
||||
|
||||
@@ -230,7 +233,11 @@ class ContributionPanel extends JPanel {
|
||||
|
||||
setExpandListener(this, new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
listPanel.setSelectedPanel(ContributionPanel.this);
|
||||
if (contrib.isCompatible(Base.getRevision()))
|
||||
listPanel.setSelectedPanel(ContributionPanel.this);
|
||||
else
|
||||
listPanel.contribManager.status.setErrorMessage(contrib.getName()
|
||||
+ " is not compatible with this revision of Processing");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -513,6 +520,19 @@ class ContributionPanel extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void blurContributionPanel(Component component) {
|
||||
component.setFocusable(false);
|
||||
component.setEnabled(false);
|
||||
if (component instanceof JComponent)
|
||||
((JComponent) component).setToolTipText(INCOMPATIBILITY_BLUR);
|
||||
if (component instanceof Container) {
|
||||
for (Component child : ((Container) component).getComponents()) {
|
||||
blurContributionPanel(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setContribution(Contribution contrib) {
|
||||
this.contrib = contrib;
|
||||
@@ -681,6 +701,9 @@ class ContributionPanel extends JPanel {
|
||||
setComponentPopupMenu(null);
|
||||
}
|
||||
|
||||
if (!contrib.isCompatible(Base.getRevision())) {
|
||||
blurContributionPanel(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void installContribution(AvailableContribution info) {
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.util.zip.*;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import processing.app.*;
|
||||
import processing.core.PApplet;
|
||||
|
||||
|
||||
/**
|
||||
@@ -74,7 +75,9 @@ public abstract class LocalContribution extends Contribution {
|
||||
System.err.println("The version number for the “" + name + "” library is not set properly.");
|
||||
System.err.println("Please contact the library author to fix it according to the guidelines.");
|
||||
}
|
||||
|
||||
prettyVersion = properties.get("prettyVersion");
|
||||
|
||||
try {
|
||||
lastUpdated = Long.parseLong(properties.get("lastUpdated"));
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -84,6 +87,16 @@ public abstract class LocalContribution extends Contribution {
|
||||
// System.err.println("The last updated timestamp for the “" + name + "” library is not set properly.");
|
||||
// System.err.println("Please contact the library author to fix it according to the guidelines.");
|
||||
}
|
||||
|
||||
String minRev = properties.get("minRevision");
|
||||
if (minRev != null) {
|
||||
minRevision = PApplet.parseInt(minRev, 0);
|
||||
}
|
||||
|
||||
String maxRev = properties.get("maxRevision");
|
||||
if (maxRev != null) {
|
||||
maxRevision = PApplet.parseInt(maxRev, 0);
|
||||
}
|
||||
|
||||
} else {
|
||||
Base.log("No properties file at " + propertiesFile.getAbsolutePath());
|
||||
|
||||
Reference in New Issue
Block a user