|
@@ -12,10 +12,16 @@ import de.nplusc.izc.iZpl.API.InvalidPlayListFileException;
|
|
|
import de.nplusc.izc.iZpl.API.SinglePlayListItem;
|
|
|
import de.schlichtherle.truezip.file.TFile;
|
|
|
import java.awt.EventQueue;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
import javax.swing.JOptionPane;
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
+import org.jgrapht.graph.DefaultDirectedGraph;
|
|
|
+import org.jgrapht.graph.DefaultEdge;
|
|
|
import org.yaml.snakeyaml.Yaml;
|
|
|
|
|
|
/**
|
|
@@ -24,8 +30,8 @@ import org.yaml.snakeyaml.Yaml;
|
|
|
*/
|
|
|
public class Editor implements FeaturePlugin
|
|
|
{
|
|
|
- private ListIncludeGraph parseGraph = new ListIncludeGraph();
|
|
|
-
|
|
|
+ private final DefaultDirectedGraph<PlayListFile,DefaultEdge> parseGraph = new DefaultDirectedGraph<>(DefaultEdge.class);
|
|
|
+ private HashMap<String,PlayListFile> lookupCache = new HashMap<>();
|
|
|
|
|
|
private PlayListFile rootFile=null;
|
|
|
|
|
@@ -57,12 +63,19 @@ public class Editor implements FeaturePlugin
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ public HashMap<String, PlayListFile> getLookupCache()
|
|
|
+ {
|
|
|
+ return lookupCache;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void openUserInterface()
|
|
|
{
|
|
|
EventQueue.invokeLater(()->
|
|
|
{
|
|
|
- new EditorUICommon(rootFile,parseGraph).setVisible(true);
|
|
|
+ EditorUICommon eu = new EditorUICommon(rootFile,this);
|
|
|
+ eu.setIconImage(IZPLApi.getProgramIcon());
|
|
|
+ eu.setVisible(true);
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -107,23 +120,30 @@ public class Editor implements FeaturePlugin
|
|
|
}
|
|
|
/*packageprotected*/ void loadPlayListIntoGraph(String path,int rd,PlayListFile fromFile) throws InvalidPlayListFileException
|
|
|
{
|
|
|
+ if(fromFile!=null&&lookupCache.containsKey(path))
|
|
|
+ {
|
|
|
+ l.trace("fromfilepath:"+fromFile.getPath());
|
|
|
+ l.trace("links:"+parseGraph.containsVertex(fromFile)+"|"+parseGraph.containsVertex(lookupCache.get(path)));
|
|
|
+ parseGraph.addEdge(fromFile, lookupCache.get(path));
|
|
|
+ l.trace("detected already existing target:"+path);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
List<SinglePlayListItem> data = IZPLApi.readPlayList(path);
|
|
|
PlayListFile f = new PlayListFile();
|
|
|
f.setPath(path);
|
|
|
f.setEntries(data);
|
|
|
- try
|
|
|
- {
|
|
|
- parseGraph.addListLink(fromFile, f);
|
|
|
- }
|
|
|
- catch(GraphException x)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
+ lookupCache.put(path, f);
|
|
|
+ parseGraph.addVertex(f);
|
|
|
if(fromFile==null)
|
|
|
{
|
|
|
rootFile=f;
|
|
|
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ parseGraph.addEdge(fromFile, f);
|
|
|
+ }
|
|
|
for (SinglePlayListItem spi : data)
|
|
|
{
|
|
|
if(spi.isIncludeElement())
|
|
@@ -134,15 +154,80 @@ public class Editor implements FeaturePlugin
|
|
|
}
|
|
|
if(fromFile==null)
|
|
|
{
|
|
|
- parseGraph.recalcPriorities(rootFile);
|
|
|
+ recalculatePriorities(rootFile);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*packageprotected*/ void recalculatePriorities(PlayListFile f)
|
|
|
+ {
|
|
|
+ Set<DefaultEdge> e = parseGraph.outgoingEdgesOf(f);
|
|
|
+ List<SinglePlayListItem> ir = f.getEntries();
|
|
|
+ HashMap<String,Integer> im = new HashMap<>();
|
|
|
+ for (SinglePlayListItem spli : ir)
|
|
|
+ {
|
|
|
+ if(spli.isIncludeElement())
|
|
|
+ {
|
|
|
+ im.put(spli.getPath(), spli.getTargetPlaycount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (DefaultEdge edg : e)
|
|
|
+ {
|
|
|
+ PlayListFile se = parseGraph.getEdgeTarget(edg);
|
|
|
+ se.setCalculatedBasePriority(im.get(se.getPath())*f.getCalculatedBasePriority());
|
|
|
+ recalculatePriorities(se);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /*packageprotected*/ void revalidateElement(PlayListFile f)
|
|
|
+ {
|
|
|
+ Set<DefaultEdge> e = parseGraph.outgoingEdgesOf(f);
|
|
|
+ List<SinglePlayListItem> ir = new ArrayList(f.getEntries());
|
|
|
+ List<String> is = new ArrayList<>();
|
|
|
+ for (DefaultEdge edg : e)
|
|
|
+ {
|
|
|
+ PlayListFile se = parseGraph.getEdgeTarget(edg);
|
|
|
+ is.add(se.getPath());
|
|
|
+ }
|
|
|
+
|
|
|
+ for (SinglePlayListItem spli : ir)
|
|
|
+ {
|
|
|
+ if(spli.isIncludeElement())
|
|
|
+ {
|
|
|
+ if(!is.contains(spli.getPath()))
|
|
|
+ {
|
|
|
+ f.getEntries().remove(spli);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- public ListIncludeGraph getParseGraph()
|
|
|
+ /*packageprotected*/ void zapFile(PlayListFile f,PlayListFile p)
|
|
|
{
|
|
|
- return parseGraph;
|
|
|
+ Set<DefaultEdge> ie = parseGraph.incomingEdgesOf(f);
|
|
|
+ if(ie.size()>1)
|
|
|
+ {
|
|
|
+ parseGraph.removeEdge(p, f); //incoming_edge zappen
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //parseGraph.removeEdge(p, f); //incoming_edge zappen
|
|
|
+ Set<DefaultEdge> oe = new HashSet<>(parseGraph.outgoingEdgesOf(f));
|
|
|
+ for (DefaultEdge defaultEdge : oe)
|
|
|
+ {
|
|
|
+ zapFile(parseGraph.getEdgeTarget(defaultEdge), f);
|
|
|
+ }
|
|
|
+ if(parseGraph.containsVertex(f))
|
|
|
+ {
|
|
|
+ parseGraph.removeVertex(f);
|
|
|
+ }
|
|
|
+ lookupCache.remove(f.getPath()); //zappen falls das die letzte instanz dieses files war
|
|
|
}
|
|
|
|
|
|
|
|
|
+ void saveAll()
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
}
|