Skip to content

Commit

Permalink
separated code for ProMList away from controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamBanham committed Jul 12, 2022
1 parent 9251a73 commit 8ec86f1
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 288 deletions.
267 changes: 14 additions & 253 deletions src/org/processmining/qut/exogenousaware/gui/ExogenousTraceView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -25,7 +22,6 @@
import org.deckfour.xes.model.XAttributeTimestamp;
import org.deckfour.xes.model.XEvent;
import org.deckfour.xes.model.XTrace;
import org.deckfour.xes.model.impl.XAttributeLiteralImpl;
import org.jfree.chart.ChartPanel;
import org.processmining.contexts.uitopia.UIPluginContext;
import org.processmining.contexts.uitopia.annotations.Visualizer;
Expand All @@ -34,13 +30,11 @@
import org.processmining.framework.util.ui.widgets.ProMSplitPane;
import org.processmining.framework.util.ui.widgets.traceview.ProMTraceList;
import org.processmining.framework.util.ui.widgets.traceview.ProMTraceList.ClickListener;
import org.processmining.framework.util.ui.widgets.traceview.ProMTraceList.TraceBuilder;
import org.processmining.framework.util.ui.widgets.traceview.ProMTraceView.Event;
import org.processmining.framework.util.ui.widgets.traceview.ProMTraceView.Trace;
import org.processmining.qut.exogenousaware.data.ExogenousAnnotatedLog;
import org.processmining.qut.exogenousaware.gui.listeners.EndoTraceListener;
import org.processmining.qut.exogenousaware.gui.panels.ExogenousTraceViewJChartFilterPanel;
import org.processmining.qut.exogenousaware.gui.panels.ExogenousTraceViewJChartFilterPanel.EventFilter;
import org.processmining.qut.exogenousaware.gui.promlist.ProMListComponents.exoTraceBuilder;
import org.processmining.qut.exogenousaware.gui.workers.TraceVisEventChart;
import org.processmining.qut.exogenousaware.gui.workers.TraceVisOverviewChart;
import org.processmining.qut.exogenousaware.gui.workers.TraceVisTraceBreakdownCharts;
Expand Down Expand Up @@ -299,7 +293,6 @@ public void highlightEventSlice(XTrace trace, int eventIndex) {
}
}


public boolean setSelectEndogenous(XTrace select, EndoTraceListener listener) {
if (this.selectedEndogenous == null) {
this.selectedEndogenous = select;
Expand Down Expand Up @@ -344,7 +337,7 @@ public boolean setSelectEndogenous(XTrace select) {
}

public double getEventTimestampMillis(XEvent ev) {
return (double) ((XAttributeTimestamp) ev.getAttributes().get("time:timestamp")).getValueMillis();
return ((XAttributeTimestamp) ev.getAttributes().get("time:timestamp")).getValueMillis();
}

public double getExoEventValue(XEvent ev) {
Expand All @@ -369,8 +362,7 @@ public void updateTraceBreakdownEvent(XEvent ev, int eventIndex) {
this.traceBreakdownView.removeFilter(this.eventfilter);
this.eventfilter = null;
}
// this.traceBreakdownView.validate();
// this.traceBreakdownView.getParent().validate();

this.rightTopBottom.validate();
}

Expand All @@ -385,6 +377,17 @@ public JPanel buildIndividualEventBreakdown(XEvent ev) {
return chartbuilder.getView();
}

public static JLabel createLeftAlignedLabel(String text, Boolean bold, int fontSize) {
JLabel label = new JLabel(text, SwingConstants.LEADING);
label.setFont(new Font("Times new Roman", bold ? Font.BOLD : null, fontSize));
label.setBackground(Color.DARK_GRAY);
label.setHorizontalAlignment(JLabel.LEFT);
label.setAlignmentX(JPanel.RIGHT_ALIGNMENT);
return label;
}


// interfaces
public static class endoClickListener implements ClickListener<XTrace> {

private ExogenousTraceView source;
Expand All @@ -395,257 +398,15 @@ public endoClickListener(ExogenousTraceView source) {

@Override
public void traceMouseDoubleClicked(XTrace trace, int traceIndex, int eventIndex, MouseEvent e) {
// TODO Auto-generated method stub
this.source.setSelectEndogenous(trace);
}

@Override
public void traceMouseClicked(XTrace trace, int traceIndex, int eventIndex, MouseEvent e) {
// TODO Auto-generated method stub
this.source.setSelectEndogenous(trace);
}

}

public static JLabel createLeftAlignedLabel(String text, Boolean bold, int fontSize) {
JLabel label = new JLabel(text, SwingConstants.LEADING);
label.setFont(new Font("Times new Roman", bold ? Font.BOLD : null, fontSize));
label.setBackground(Color.DARK_GRAY);
label.setHorizontalAlignment(JLabel.LEFT);
label.setAlignmentX(JPanel.RIGHT_ALIGNMENT);
return label;
}

// Usage
// #TODO colors for events with exogenous linked subseries
// ProMTraceList<XTrace> traceView = new ProMTraceList<XTrace>(
// new exoTraceBuilder()
// );
// traceView.addAll(this.source.getEndogenousLog());
public static class exoTraceBuilder implements TraceBuilder<XTrace> {

private Set<String> exoEvents;
private boolean highlight = false;
private int eventid = -1;

public exoTraceBuilder(Set<String> exoEvents) {
this.exoEvents = exoEvents;
}


@Override
public Trace<? extends Event> build(XTrace element) {
// TODO Auto-generated method stub
Boolean hasExo = false;
if (element.getAttributes().keySet().contains("exogenous:exist")) {
hasExo = ((XAttributeLiteralImpl) element.getAttributes().get("exogenous:exist") ).getValue().contentEquals("True");
}
if (this.highlight) {
return new exoTrace(element,
hasExo,
exoEvents,
this.eventid
);
} else {
return new exoTrace(element,
hasExo,
exoEvents
);
}
}

public void setHighlight(int eventid) {
this.highlight = true;
this.eventid = eventid;
}

public void dehighlight() {
this.highlight = false;
this.eventid = -1;
}


public static class exoTrace implements Trace<Event> {

private XTrace source;
private Boolean hasExo;
private Set<String> exoEvents;
private int highlightevent = -1;

public exoTrace(XTrace source, Boolean hasExo, Set<String> exoEvents) {
this(source,hasExo,exoEvents,-1);
}

public exoTrace(XTrace source, Boolean hasExo, Set<String> exoEvents, int highlightevent) {
this.source = source;
this.hasExo = hasExo;
this.exoEvents = exoEvents;
this.highlightevent = highlightevent;
}

@Override
public Iterator<Event> iterator() {

List<String> evSet = this.source.stream().map(ev -> ev.getID().toString()).collect(Collectors.toList());
return new exoIterator(
this.source.iterator(),
this.hasExo ? this.exoEvents.stream().filter(s -> evSet.contains(s)).collect(Collectors.toSet()) : new HashSet<String>(),
this.highlightevent
);
}

@Override
public String getName() {
return this.source.getAttributes().get("concept:name").toString();
}

@Override
public Color getNameColor() {
return this.hasExo ? new Color(65,150,98) : Color.red;
}

@Override
public String getInfo() {
// TODO Auto-generated method stub
String info = "";
for(String key: this.source.getAttributes().keySet()) {
info += String.format("%s : %s \n",
key, this.source.getAttributes().get(key)
);
}
return info;
}

@Override
public Color getInfoColor() {
// TODO Auto-generated method stub
return Color.black;
}

}

public static class exoIterator implements Iterator<Event> {

Iterator<XEvent> source;
private Set<String> exoEvents;
private int highlightevent = -1;
private int counter = -1;

public exoIterator(Iterator<XEvent> source, Set<String> exoEvents, int highlightevent) {
this.source = source;
this.exoEvents = exoEvents;
this.highlightevent = highlightevent;
}

@Override
public boolean hasNext() {
// TODO Auto-generated method stub
return this.source.hasNext();
}

@Override
public Event next() {
// TODO Auto-generated method stub
this.counter++;
XEvent ev = this.source.next();
return new exoEvent(
ev,
counter,
ev.getAttributes().keySet().stream().anyMatch(s -> s.contains("exogenous:dataset")),
this.counter == this.highlightevent
);
}

}

public static class exoEvent implements Event {

private XEvent source;
private boolean hasExo;
private boolean highlight;
public int eventID;

public exoEvent(XEvent source, int eventID, boolean hasExo) {
this(source, eventID, hasExo, false);
}

public exoEvent(XEvent source, int eventID, boolean hasExo, boolean highlight) {
this.source = source;
this.hasExo = hasExo;
this.highlight = highlight;
this.eventID = eventID;
}

public void setHighlight(boolean highlight) {
this.highlight = highlight;
}

@Override
public Color getWedgeColor() {
if (this.highlight) {
return Color.orange;
}
else if (this.hasExo) {
return new Color(65,150,98);
} else {
return Color.red;
}
}

@Override
public Color getBorderColor() {
// TODO Auto-generated method stub
return null;
}

@Override
public String getLabel() {
return this.source.getAttributes().get("concept:name").toString();
}

@Override
public Color getLabelColor() {
// TODO Auto-generated method stub
return null;
}

@Override
public String getTopLabel() {
// TODO Auto-generated method stub
return null;
}

@Override
public Color getTopLabelColor() {
// TODO Auto-generated method stub
return null;
}

@Override
public String getBottomLabel() {
// TODO Auto-generated method stub
return null;
}

@Override
public Color getBottomLabelColor() {
// TODO Auto-generated method stub
return null;
}

@Override
public String getBottomLabel2() {
// TODO Auto-generated method stub
return null;
}

@Override
public Color getBottomLabel2Color() {
// TODO Auto-generated method stub
return null;
}

}
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package org.processmining.qut.exogenousaware.gui.listeners;

import java.awt.Color;
import java.awt.event.MouseEvent;

import org.deckfour.xes.model.XEvent;
import org.deckfour.xes.model.XTrace;
import org.processmining.framework.util.ui.widgets.traceview.ProMTraceList;
import org.processmining.framework.util.ui.widgets.traceview.ProMTraceList.ClickListener;
import org.processmining.framework.util.ui.widgets.traceview.ProMTraceList.DefaultWedgeBuilder;
import org.processmining.framework.util.ui.widgets.traceview.ProMTraceView.Event;
import org.processmining.framework.util.ui.widgets.traceview.ProMTraceView.Trace;
import org.processmining.qut.exogenousaware.gui.ExogenousTraceView;
import org.processmining.qut.exogenousaware.gui.ExogenousTraceView.exoTraceBuilder;
import org.processmining.qut.exogenousaware.gui.ExogenousTraceView.exoTraceBuilder.exoEvent;
import org.processmining.qut.exogenousaware.gui.promlist.ProMListComponents.exoTraceBuilder;
import org.processmining.qut.exogenousaware.gui.promlist.WedgeBuilderFactory;

import lombok.Builder;
import lombok.NonNull;
Expand Down Expand Up @@ -43,37 +39,10 @@ public void traceMouseClicked(XTrace trace, int traceIndex, int eventIndex, Mous
// highlight this event slice in the overview chart
this.source.highlightEventSlice(trace, eventIndex);
// highlight wedge that was clicked
this.controller.setWedgeBuilder(new AdjustedWedgeBuilder(previousEvent != eventIndex ? eventIndex : -2));
this.controller.setWedgeBuilder(WedgeBuilderFactory.createEventHighlight(previousEvent != eventIndex ? eventIndex : -2));
this.controller.updateUI();
this.previousEvent = previousEvent == eventIndex ? -1 : eventIndex;
}
}

public class AdjustedWedgeBuilder extends DefaultWedgeBuilder {

private int highlight = -1;

public AdjustedWedgeBuilder(int highlight) {
this.highlight = highlight;
}

@Override
public Color buildWedgeColor(Trace<? extends Event> trace, Event event) {
exoEvent neweventype = (exoEvent) event;
neweventype.setHighlight(neweventype.eventID == this.highlight);
return event.getWedgeColor();

}

@Override
public Integer assignWedgeGap(Trace<? extends Event> trace, Event event) {
exoEvent neweventype = (exoEvent) event;
if ((neweventype.eventID == this.highlight)||(neweventype.eventID==(this.highlight-1))) {
return 10;
}
return null;
}

}

}
Loading

0 comments on commit 8ec86f1

Please sign in to comment.