Permalink
Browse files

moar little improvements

  • Loading branch information...
1 parent f8a8de2 commit 01e6877012796600d8e99a608abadc43f89f134c Acerbic committed Oct 21, 2012
Showing with 41 additions and 15 deletions.
  1. +4 −0 src/dloader/Main.java
  2. +24 −7 src/dloader/gui/GUI.java
  3. +12 −7 src/dloader/gui/TreeNodePageWrapper.java
  4. +1 −1 src/dloader/page/Track.java
View
4 src/dloader/Main.java
@@ -9,6 +9,10 @@
import dloader.gui.GUI;
+/**
+ * Starting thread. May continue in a single console thread or spawn GUI.
+ * @author Acerbic
+ */
public class Main {
// public static final String nl = System.getProperty ( "line.separator" );
View
31 src/dloader/gui/GUI.java
@@ -22,6 +22,11 @@
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
+/**
+ * well. GUI, duh.
+ * @author Acerbic
+ *
+ */
public class GUI extends JFrame {
/**
@@ -341,16 +346,18 @@ else if (!p.getParent().childPages.contains(p))
if (parentNode.getChildCount() > 0) {
// some children are present, but not all of them.
- // normally one would compare parenNode's children to parentPage's children, and insert the new one to proper place, but
- // for the sake of efficiency it is faster to just drop all existing children nodes and add new ones instead as a bunch
+ // remove all old children then add all new ones
parentNode.removeAllChildren();
+ // we don't need to worry about removed pages' jobs because
+ // PageJob algorithms operates on updated data, it is GUI tree that lags behind
}
-
- // add new items under this parent
+ // add new items under current parent
+ // we are assuming that if one (this) child is present, then all of them are already present,
+ // as children list is initiated / updated as a whole at the same time.
childNode = addChildrenNodes(parentNode, childPage);
- assert (childNode != null); // can happen if ghost sneaked in - other thread compromised AbstractPage tree
+ assert (childNode != null); // can happen only if ghost sneaked in - other thread compromised AbstractPage tree
// new item's children if any
if (childPage.childPages.size() > 0)
@@ -361,12 +368,15 @@ else if (!p.getParent().childPages.contains(p))
parentNode = childNode; // advance to search next element in our pathToPage
}
- // after search is complete, parent points to a TreeNodePageWrapper containing original p (but now p is different)
+ // after search is complete, parentNode points to a TreeNodePageWrapper containing original p (but now p is different)
// usually unfolding happens only after job is finished (for performance), but in
// case of new page downloads it is visually more pleasing to see what is going on asap
- if (parentNode.page.equals(pathToPage.getFirst()))
+ if (parentNode.page.equals(pathToPage.getFirst())) {
+ if (parentNode.page.childPages.size() > 0 && parentNode.getChildCount() == 0)
+ addChildrenNodes(parentNode, parentNode.page.childPages.get(0)); // bit awkward code reuse
unfoldFirst();
+ }
// pass message to the user object and refresh its visual if needed
parentNode.update(message, value);
@@ -535,6 +545,7 @@ private void unfoldFirst() {
target = (TreeNodePageWrapper) target.getFirstChild();
tree.expandPath(new TreePath(target.getPath()));
} catch (NoSuchElementException e) {
+ e.printStackTrace();
}
}
@@ -570,6 +581,12 @@ private TreeNodePageWrapper getNodeOfPage (TreeNodePageWrapper parentNode, Abstr
return null;
}
+ /**
+ * Adds to a given tree node children nodes, which are all wrappers of siblings of given childPage (including the very childPage)
+ * @param parentNode - parent tree node where children will be added
+ * @param childPage - a page whose siblings will be add.
+ * @return a new node created for a given child page.
+ */
private TreeNodePageWrapper addChildrenNodes (TreeNodePageWrapper parentNode, AbstractPage childPage) {
TreeNodePageWrapper returnedChildNode = null;
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
View
19 src/dloader/gui/TreeNodePageWrapper.java
@@ -29,6 +29,8 @@
public final AbstractPage page; //wrapped object
public final DefaultTreeModel model; //backref to model
+ private String titleCache;
+
boolean readFromCache = false;
boolean downloadPageQ = false;
@@ -56,9 +58,8 @@ public TreeNodePageWrapper(AbstractPage page, TreeModel treeModel) {
* Update flags and states of this node visual representation
* @param message
* @param value
- * @return true if node must be repainted
*/
- public boolean update(String message, long value) {
+ public void update(String message, long value) {
boolean updateVisuals = false;
boolean updateParent = false;
switch (message) {
@@ -147,17 +148,20 @@ public boolean update(String message, long value) {
}
if (updateVisuals)
model.nodeChanged(this);
- return updateVisuals;
+
+ titleCache = page.getTitle();
}
@Override
public String toString() {
if (page == null) return null;
+ if (titleCache == null)
+ titleCache = page.getTitle();
String header = "<html>";
String bottom = "</html>";
String styleCompilation = "";
- String title = page.getTitle();
+ String title = titleCache;
if (title == null || title.isEmpty())
title = "????";
String saveDecorator = "";
@@ -182,10 +186,11 @@ else if (kidsToSave > 0)
// title formatters;
int childrenCount = (kidsInScanning > 0)? kidsInScanning: kidsToSave;
- String strChildrenCount = (page.childPages.size() <= 0)? "":
+ int childrenSize = page.childPages.size();
+ String strChildrenCount = (childrenSize <= 0)? "":
"<span id='children'>[" +
- (childrenCount <= 0 ? "": (page.childPages.size()-childrenCount) +"/") +
- page.childPages.size()+"]</span>";
+ (childrenCount <= 0 ? "": (childrenSize-childrenCount) +"/") +
+ childrenSize+"]</span>";
if (downloading) {
title = title + " (Scanning...)";
View
2 src/dloader/page/Track.java
@@ -107,7 +107,7 @@ boolean saveResult(ProgressReporter reporter) throws IOException, InterruptedExc
String statusReport = null; // defaults to "skipped"
// tagging does not require synchronization as it is operating with Properties object which is thread-safe.
- //XXX: this is not strictly true, but as properties are read much later than written, we may assume those operations do not overlap.
+ //XXX: this is not strictly true, but as properties are read much later than written in different PageJobs, we may assume those operations do not overlap.
if (tagAudioFile(Main.forceTagging))
statusReport = "file updated";
if (wasDownloaded)

0 comments on commit 01e6877

Please sign in to comment.