Create an ArcFilter factory.
This commit is contained in:
parent
dc3a9b9860
commit
7e06e1c4bf
55
src/main/org/insa/algo/ArcFilterFactory.java
Normal file
55
src/main/org/insa/algo/ArcFilterFactory.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package org.insa.algo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.insa.algo.AbstractInputData.ArcFilter;
|
||||||
|
import org.insa.graph.AccessRestrictions.AccessMode;
|
||||||
|
import org.insa.graph.AccessRestrictions.AccessRestriction;
|
||||||
|
import org.insa.graph.Arc;
|
||||||
|
|
||||||
|
public class ArcFilterFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return List of all arc filters in this factory.
|
||||||
|
*/
|
||||||
|
public static List<ArcFilter> getAllFilters() {
|
||||||
|
List<ArcFilter> filters = new ArrayList<>();
|
||||||
|
|
||||||
|
// Common filters:
|
||||||
|
|
||||||
|
// 1. No filter (all arcs allowed):
|
||||||
|
filters.add(new ArcFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean isAllowed(Arc arc) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "All roads are allowed.";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. Only road allowed for cars:
|
||||||
|
filters.add(new ArcFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean isAllowed(Arc arc) {
|
||||||
|
return arc.getRoadInformation().getAccessRestrictions().isAllowedForAny(AccessMode.MOTORCAR,
|
||||||
|
EnumSet.complementOf(EnumSet.of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Only roads open for cars.";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 3. Add your own filters here (do not forget to implement toString() to get an
|
||||||
|
// understandable output!):
|
||||||
|
|
||||||
|
return filters;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -10,7 +10,6 @@ import java.awt.event.ActionListener;
|
|||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.Box;
|
import javax.swing.Box;
|
||||||
@ -30,10 +29,7 @@ import org.insa.algo.AbstractInputData;
|
|||||||
import org.insa.algo.AbstractInputData.ArcFilter;
|
import org.insa.algo.AbstractInputData.ArcFilter;
|
||||||
import org.insa.algo.AbstractInputData.Mode;
|
import org.insa.algo.AbstractInputData.Mode;
|
||||||
import org.insa.algo.AlgorithmFactory;
|
import org.insa.algo.AlgorithmFactory;
|
||||||
import org.insa.graph.AccessRestrictions;
|
import org.insa.algo.ArcFilterFactory;
|
||||||
import org.insa.graph.AccessRestrictions.AccessMode;
|
|
||||||
import org.insa.graph.AccessRestrictions.AccessRestriction;
|
|
||||||
import org.insa.graph.Arc;
|
|
||||||
import org.insa.graph.Node;
|
import org.insa.graph.Node;
|
||||||
import org.insa.graphics.NodesInputPanel.InputChangedEvent;
|
import org.insa.graphics.NodesInputPanel.InputChangedEvent;
|
||||||
|
|
||||||
@ -171,30 +167,8 @@ public class AlgorithmPanel extends JPanel {
|
|||||||
add(this.nodesInputPanel);
|
add(this.nodesInputPanel);
|
||||||
components.add(this.nodesInputPanel);
|
components.add(this.nodesInputPanel);
|
||||||
|
|
||||||
JComboBox<AbstractInputData.ArcFilter> arcFilterSelect = new JComboBox<>(
|
JComboBox<ArcFilter> arcFilterSelect = new JComboBox<>(
|
||||||
new AbstractInputData.ArcFilter[] { new AbstractInputData.ArcFilter() {
|
ArcFilterFactory.getAllFilters().toArray(new ArcFilter[0]));
|
||||||
@Override
|
|
||||||
public boolean isAllowed(Arc arc) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "All arcs are allowed";
|
|
||||||
}
|
|
||||||
}, new AbstractInputData.ArcFilter() {
|
|
||||||
@Override
|
|
||||||
public boolean isAllowed(Arc arc) {
|
|
||||||
AccessRestrictions restrictions = arc.getRoadInformation().getAccessRestrictions();
|
|
||||||
return restrictions.isAllowedForAny(AccessMode.MOTORCAR, EnumSet
|
|
||||||
.complementOf(EnumSet.of(AccessRestriction.PRIVATE, AccessRestriction.FORBIDDEN)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Only non-private roads allowed for motorcars";
|
|
||||||
}
|
|
||||||
} });
|
|
||||||
arcFilterSelect.setBackground(Color.WHITE);
|
arcFilterSelect.setBackground(Color.WHITE);
|
||||||
|
|
||||||
// Add mode selection
|
// Add mode selection
|
||||||
|
Loading…
Reference in New Issue
Block a user