ソースを参照

stupid bug fixed since hashMap was the reason
also: small refactor in the class names of the IZPl-Core

LH 10 年 前
コミット
7f6de000d4

+ 1 - 0
iZpl/build.gradle

@@ -85,6 +85,7 @@ dependencies{
 	compile group: 'org.apache.logging.log4j', name: 'log4j-iostreams', version: '2.1'
     compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.1'
     compile 'org.fusesource.jansi:jansi:1.11'
+    compile 'org.jgrapht:jgrapht-core:0.9.0'
     compile(project(':ToolKit')) {
         transitive = false
     }

+ 2 - 2
iZpl/src/main/java/de/nplusc/izc/iZpl/API/IZPLApi.java

@@ -7,7 +7,7 @@
 package de.nplusc.izc.iZpl.API;
 
 import de.nplusc.izc.iZpl.Main;
-import de.nplusc.izc.iZpl.Utils.PLReader2;
+import de.nplusc.izc.iZpl.Utils.PLFileIO;
 import java.awt.Image;
 import java.io.File;
 import java.util.List;
@@ -156,7 +156,7 @@ public class IZPLApi
    
     public static List<SinglePlayListItem> readPlayList(String path) throws InvalidPlayListFileException
     {
-        return PLReader2.readSingleList(path);
+        return PLFileIO.readSingleList(path);
     }
     
     

+ 2 - 2
iZpl/src/main/java/de/nplusc/izc/iZpl/PlProcessorV2.java

@@ -8,7 +8,7 @@ import de.nplusc.izc.iZpl.API.PlayListItem;
 import com.sun.net.httpserver.Headers;
 import com.sun.net.httpserver.HttpExchange;
 import com.sun.net.httpserver.HttpHandler;
-import de.nplusc.izc.iZpl.Utils.PLReader2;
+import de.nplusc.izc.iZpl.Utils.PLFileIO;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
@@ -108,7 +108,7 @@ public class PlProcessorV2 implements HttpHandler
     public void reloadLists(boolean reload)
     {
         availEtrs = new ArrayList<>();//cache flush and reinit...
-        List<PlayListItem> inp = PLReader2.parseFullList(path);
+        List<PlayListItem> inp = PLFileIO.parseFullList(path);
         if(!reload)
         {
             pool=new HashMap<>();

+ 2 - 2
iZpl/src/main/java/de/nplusc/izc/iZpl/Utils/PLReader2.java → iZpl/src/main/java/de/nplusc/izc/iZpl/Utils/PLFileIO.java

@@ -27,7 +27,7 @@ import org.yaml.snakeyaml.Yaml;
  *
  * @author iZc <nplusc.de>
  */
-public class PLReader2
+public class PLFileIO
 {
     //Formatdefinition //basiert aufne verpackte #extm3u
     /*
@@ -291,7 +291,7 @@ public class PLReader2
         return mi;
     }
 
-    private PLReader2()
+    private PLFileIO()
     {
     }
     

+ 7 - 0
iZplPlugins/Editor/build.gradle

@@ -2,11 +2,18 @@ apply plugin:'java'
 task distZip(dependsOn: 'jar') {
 	//NO-OPtask als redirect
 }
+
+
+
+
+
 compileJava.options.encoding = 'UTF-8'
 dependencies
 {
 	compile fileTree(dir: 'lib', include: '*.jar')
 	compile project(':iZpl')
+   
+
 }
 
 

+ 0 - 16
iZplPlugins/Editor/src/main/java/de/nplusc/izc/izpl/plugins/editor/DupeAddException.java

@@ -1,16 +0,0 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package de.nplusc.izc.izpl.plugins.editor;
-
-/**
- *
- * @author iZc <nplusc.de>
- */
-public class DupeAddException extends GraphException
-{
-    
-}

+ 99 - 14
iZplPlugins/Editor/src/main/java/de/nplusc/izc/izpl/plugins/editor/Editor.java

@@ -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()
+    {
+        
+    }
 }

+ 3 - 0
iZplPlugins/Editor/src/main/java/de/nplusc/izc/izpl/plugins/editor/EditorUICommon.form

@@ -62,6 +62,9 @@
       <Properties>
         <Property name="text" type="java.lang.String" value="Load"/>
       </Properties>
+      <Events>
+        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnLoadActionPerformed"/>
+      </Events>
     </Component>
     <Container class="javax.swing.JTabbedPane" name="tpMain">
 

+ 19 - 8
iZplPlugins/Editor/src/main/java/de/nplusc/izc/izpl/plugins/editor/EditorUICommon.java

@@ -20,8 +20,7 @@ public class EditorUICommon extends javax.swing.JFrame
 {
     private HashMap<PlayListFile,EditorUIFileWise> tabRemapping = new HashMap<>();
     private HashMap<String,PlayListFile> lookupCache;
-    private ListIncludeGraph parseGraph;
-    
+    private Editor e;
     /**
      * Creates new form EditorUICommon
      * @param r00t
@@ -31,10 +30,10 @@ public class EditorUICommon extends javax.swing.JFrame
     
     
     
-    public EditorUICommon(PlayListFile r00t,ListIncludeGraph pParseGraph)
+    public EditorUICommon(PlayListFile r00t,Editor e)
     {
-        parseGraph = pParseGraph;
-        lookupCache=parseGraph.getLookupCache();
+        lookupCache=e.getLookupCache();
+        this.e=e;
         initComponents();
         openFileTab(r00t);
     }
@@ -71,7 +70,7 @@ public class EditorUICommon extends javax.swing.JFrame
     
     public void recalculatePriorities(PlayListFile f)
     {
-        parseGraph.recalcPriorities(f);
+        e.recalculatePriorities(f);
         for (PlayListFile playListFile : tabRemapping.keySet())
         {
             tabRemapping.get(playListFile).resyncPriority();
@@ -81,7 +80,7 @@ public class EditorUICommon extends javax.swing.JFrame
     public void zapFile(SinglePlayListItem i,PlayListFile fromFile)
     {
         PlayListFile f = lookupCache.get(i.getPath());
-        parseGraph.zapElement(f);
+        e.zapFile(f, fromFile);
         Collection<PlayListFile> lcv = lookupCache.values();
         
         for (PlayListFile plf : new HashSet<>(tabRemapping.keySet()))
@@ -93,7 +92,7 @@ public class EditorUICommon extends javax.swing.JFrame
                 
             }
         }
-        parseGraph.refreshElement(fromFile);
+        e.revalidateElement(fromFile);
     }
     
     /**
@@ -116,6 +115,13 @@ public class EditorUICommon extends javax.swing.JFrame
         btnSave.setText("Save");
 
         btnLoad.setText("Load");
+        btnLoad.addActionListener(new java.awt.event.ActionListener()
+        {
+            public void actionPerformed(java.awt.event.ActionEvent evt)
+            {
+                btnLoadActionPerformed(evt);
+            }
+        });
 
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
         getContentPane().setLayout(layout);
@@ -147,6 +153,11 @@ public class EditorUICommon extends javax.swing.JFrame
         pack();
     }// </editor-fold>//GEN-END:initComponents
 
+    private void btnLoadActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnLoadActionPerformed
+    {//GEN-HEADEREND:event_btnLoadActionPerformed
+        // TODO add your handling code here:
+    }//GEN-LAST:event_btnLoadActionPerformed
+
     
     
     

+ 3 - 0
iZplPlugins/Editor/src/main/java/de/nplusc/izc/izpl/plugins/editor/EditorUIFileWise.java

@@ -15,6 +15,7 @@ import java.io.File;
 import java.util.Collections;
 import java.util.List;
 import javax.swing.DefaultListModel;
+import javax.swing.SpinnerNumberModel;
 import javax.swing.event.ListSelectionEvent;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
@@ -52,6 +53,8 @@ public class EditorUIFileWise extends javax.swing.JPanel
            
         });
         lstElements.setSelectedIndex(0);
+        iGroupNumber.setModel(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1));
+        iPriority.setModel(new SpinnerNumberModel(1, 1, Integer.MAX_VALUE, 1));
         recheckUIState();
     }
 

+ 0 - 16
iZplPlugins/Editor/src/main/java/de/nplusc/izc/izpl/plugins/editor/GraphException.java

@@ -1,16 +0,0 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package de.nplusc.izc.izpl.plugins.editor;
-
-/**
- *
- * @author iZc <nplusc.de>
- */
-public class GraphException extends Exception
-{
-    
-}

+ 0 - 16
iZplPlugins/Editor/src/main/java/de/nplusc/izc/izpl/plugins/editor/InvalidGraphReferenceException.java

@@ -1,16 +0,0 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package de.nplusc.izc.izpl.plugins.editor;
-
-/**
- *
- * @author iZc <nplusc.de>
- */
-public class InvalidGraphReferenceException extends GraphException
-{
-    
-}

+ 0 - 187
iZplPlugins/Editor/src/main/java/de/nplusc/izc/izpl/plugins/editor/ListIncludeGraph.java

@@ -1,187 +0,0 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package de.nplusc.izc.izpl.plugins.editor;
-
-import de.nplusc.izc.iZpl.API.SinglePlayListItem;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-/**
- *
- * @author iZc <nplusc.de>
- */
-public class ListIncludeGraph
-{
-    
-    private static final Logger l = LogManager.getLogger();
-    private HashMap<PlayListFile,Integer> refcount = new HashMap<>();
-    private HashMap<PlayListFile,List<PlayListFile>> downMap = new HashMap<>();
-    private HashMap<String, PlayListFile> lookupCache  = new HashMap<>();
-
-    public HashMap<String, PlayListFile> getLookupCache()
-    {
-        return lookupCache;
-    }
-
-    public HashMap<PlayListFile, List<PlayListFile>> getDownMap()
-    {
-        return downMap;
-    }
-
-    public void setDownMap(HashMap<PlayListFile, List<PlayListFile>> downMap)
-    {
-        this.downMap = downMap;
-    }
-
-    public HashMap<PlayListFile, Integer> getRefcount()
-    {
-        return refcount;
-    }
-
-    public void setRefcount(HashMap<PlayListFile, Integer> refcount)
-    {
-        this.refcount = refcount;
-    }
-
-    public void setLookupCache(HashMap<String, PlayListFile> lookupCache)
-    {
-        this.lookupCache = lookupCache;
-    }
-    
-    
-    
-    
-    public List<PlayListFile> getIncludedLists(PlayListFile reference)
-    {
-        if(downMap.containsKey(reference))
-        {
-            return downMap.get(reference);
-        }
-        return new ArrayList<>();
-    }
-    
-    
-   /* public PlayListFile getParentList(PlayListFile reference)
-    {
-        if(upMap.containsKey(reference))
-        {
-            return upMap.get(reference);
-        }
-        return null;
-    }
-    */
-    public void addListLink(PlayListFile parent,PlayListFile newList) throws InvalidGraphReferenceException, DupeAddException
-    {
-        //parent=null ist für die rootListe notwendig um die zu registrieren
-        if(parent==null)
-        {
-            downMap.put(newList,new ArrayList<>());
-            lookupCache.put(newList.getPath(), newList);
-            refcount.put(newList, 1);
-        }
-        else
-        {
-            if(lookupCache.containsKey(newList.getPath()))
-            {
-                refcount.put(newList, refcount.get(newList)+1);
-            }
-            else
-            {
-                refcount.put(newList, 1);
-                lookupCache.put(newList.getPath(), newList);
-            }
-            if(downMap.containsKey(parent))
-            {
-                downMap.get(parent).add(newList);
-            }
-            else
-            {
-                downMap.put(parent, new ArrayList<>());
-                downMap.get(parent).add(newList);
-            }
-        }
-    }
-    
-    
-    public void recalcPriorities(PlayListFile f)
-    {
-        int basePriority = f.getCalculatedBasePriority();
-        for (SinglePlayListItem pi : f.getEntries())
-        {
-            if(pi.isIncludeElement())
-            {
-                int intPrio=pi.getTargetPlaycount()*basePriority;
-                l.trace(pi.getPath());
-                lookupCache.get(pi.getPath()).setCalculatedBasePriority(intPrio);
-                recalcPriorities(lookupCache.get(pi.getPath()));
-            }
-        }
-    }
-    
-    public void refreshElement(PlayListFile f)
-    {
-        List<SinglePlayListItem> entries =  f.getEntries();
-        List<String> plfpaths = new ArrayList<>();
-        List<PlayListFile> trg = downMap.get(f);
-        for (SinglePlayListItem spli : entries)
-        {
-            plfpaths.add(spli.getPath());
-        }
-        for (PlayListFile plf : trg)
-        {
-            if(!plfpaths.contains(plf.getPath()))
-            {
-                trg.remove(plf);
-            }
-        }
-    }
-    
-    public void zapElement(PlayListFile f)
-    {
-        
-        if(refcount.get(f)>1)
-        {
-            return;
-        }
-        else
-        {
-            lookupCache.remove(f.getPath());
-            refcount.remove(f);
-            List<PlayListFile> lstElements = downMap.get(f);
-            if(lstElements!=null)
-            {
-                for (PlayListFile playListFile : lstElements)
-                {
-                    zapElement(playListFile);
-                    //upMap.remove(playListFile);
-                }
-            }
-            downMap.remove(f);
-        }
-        
-        /*
-        if(refcount.get(f)==1)
-        {
-            List<PlayListFile> lstElements = downMap.get(f);
-            if(lstElements!=null)
-            {
-                for (PlayListFile playListFile : lstElements)
-                {
-                    zapElement(playListFile);
-                    //upMap.remove(playListFile);
-                }
-
-                downMap.remove(f);
-            }
-        }
-        upMap.remove(f);
-        */
-    }
-}

+ 7 - 3
iZplPlugins/Editor/src/main/java/de/nplusc/izc/izpl/plugins/editor/PlayListFile.java

@@ -32,7 +32,6 @@ public class PlayListFile
     }
     
     
-    
     public List<SinglePlayListItem> getEntries()
     {
         return entries;
@@ -58,7 +57,7 @@ public class PlayListFile
     public int hashCode()
     {
         int hash = 3;
-        hash = 41 * hash + Objects.hashCode(this.entries);
+        //hash = 41 * hash + Objects.hashCode(this.entries);// fickdich, du funkst beim rumfuhrwerken an den daten beim edit rein
         hash = 41 * hash + Objects.hashCode(this.path);
         return hash;
     }
@@ -85,7 +84,12 @@ public class PlayListFile
         }
         return true;
     }
-    
+
+    @Override
+    public String toString()
+    {
+        return "PlayListFile{" + "calculatedBasePriority=" + calculatedBasePriority + ", path=" + path + '}';
+    }
     
     
     

+ 2 - 3
iZplPlugins/WMP/build.gradle

@@ -5,9 +5,8 @@ task distZip(dependsOn: 'fatJar') {
 
 task fatJar(type: Jar) {
 		manifest{
-		attributes 'Implementation-Title': 'iZSetup',
-					'Implementation-Version': 'SNAPSHOT',
-					'Main-Class': 'de.nplusc.izc.InstallPak.Main'
+		attributes 'Implementation-Title': 'iZPlaylist-WMP',
+					'Implementation-Version': 'SNAPSHOT'
 					
 	}
     baseName = project.name + '-all'