Skip to content

Commit

Permalink
Implement timeline.filterDisplay method.
Browse files Browse the repository at this point in the history
Closes #25 (and partly addresses #26)
  • Loading branch information
oaubert committed Feb 23, 2012
1 parent 4db531c commit a8a710b
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions src/com/ithaca/timeline/Timeline.as
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ package com.ithaca.timeline
/*
* Try to apply the given stylesheet to the TraceLine and its descendants.
*/
public function applyStylesheetToTraceline(applicator: IApplicator, stylesheet: IStyleSheet, traceline: TraceLine): void
public function applyStylesheetToTraceline(applicator: IApplicator, stylesheet: IStyleSheet, traceline: TraceLine, selector: ISelector = null): void
{
if (traceline === null)
{
Expand All @@ -588,8 +588,15 @@ package com.ithaca.timeline
if (os.skin !== null)
{
this.debug['os'] = os;

applicator.applyStyle(os,
stylesheet.getStyle("Obsel", os.obsel.type, traceline.name + ".Obsels"));
if (selector !== null) {
if (selector.isObselMatching(os.obsel))
applicator.applyStyle(os, stylesheet.getStyle("Obsel:match", os.obsel.type + ":match"))
else
applicator.applyStyle(os, stylesheet.getStyle("Obsel:nonmatch", os.obsel.type + ":nonmatch"));
}
}
}
}
Expand All @@ -598,7 +605,7 @@ package com.ithaca.timeline
for (var tlIndex: uint = 0; tlIndex < traceline.numElements; tlIndex++)
{
var tl: TraceLine = traceline.getElementAt(tlIndex) as TraceLine;
applyStylesheetToTraceline(applicator, stylesheet, tl);
applyStylesheetToTraceline(applicator, stylesheet, tl, selector);
}
}

Expand All @@ -608,8 +615,16 @@ package com.ithaca.timeline
* FIXME: properly register the new styles in the Flex
* stylemanager, so that new created elements get the
* appropriate styles too.
*
* If selector is not null, it must define a selector that will be applied to obsels.
* If the obsel matches, then the Obsel:match rule from stylesheet is applied.
* It the obsel does not match, the Obsel:nonmatch rule from stylesheet is applied.
*
* A typical use is to provide the following CSS:
* Obsel:nonmatch { visible: false; }
* to hide obsels that do not match the selector.
*/
public function applyCSS(cssData: String): void
public function applyCSS(cssData: String, selector: ISelector = null): void
{
var stylesheet: IStyleSheet = new FStyleSheet();
var applicator: IApplicator = new TimelineStyleApplicator();
Expand All @@ -634,10 +649,37 @@ package com.ithaca.timeline
for (var tlIndex: uint = 0; tlIndex < tlg.numElements; tlIndex++)
{
var tl: TraceLine = tlg.getElementAt(tlIndex) as TraceLine;
applyStylesheetToTraceline(applicator, stylesheet, tl);
applyStylesheetToTraceline(applicator, stylesheet, tl, selector);
}
}
}

/*
* Filter the display of obsels.
*
* Display only obsels matching a given string. If the string is in the form
* key,regexp (cf SelectorRegexp parameter syntax)
* then the "key" property will be matched against regexp.
* If the string contains no comma, then the whole TTL representation is matched (fulltext search).
*
* Calling with no parameter resets the filter (all obsels are shown).
*/
public function filterDisplay(expr: String = null): void
{
var selector: ISelector = null;

if (expr == null)
{
this.applyCSS('Obsel { visible: true; }');
}
else
{
if (expr.indexOf(',') > -1)
selector = new SelectorRegexp(expr)
else
selector = new SelectorRegexp("rdf," + expr);
this.applyCSS('Obsel:nonmatch { visible: false; }', selector);
}
}
}
}

0 comments on commit a8a710b

Please sign in to comment.