Skip to content

Commit

Permalink
Merge pull request #67 from marc-outins/issue_38_multiselect
Browse files Browse the repository at this point in the history
Allows multiple selection of boxes and automatic mappings between them
  • Loading branch information
aguynamedryan committed Jun 2, 2015
2 parents c1325b6 + ff390b0 commit 9ae9a45
Show file tree
Hide file tree
Showing 5 changed files with 286 additions and 110 deletions.
55 changes: 40 additions & 15 deletions src/org/ohdsi/rabbitInAHat/Arrow.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,22 @@

public class Arrow implements MappingComponent {

public enum HighlightStatus {
BOTH_SELECTED (new Color(255, 255, 0, 192)),
SOURCE_SELECTED (new Color(255, 128, 0, 192)),
TARGET_SELECTED (new Color(0, 0, 255, 192)),
NONE_SELECTED (new Color(128, 128, 128, 128));

private final Color color;

HighlightStatus(Color color) {
this.color = color;
}
}

public static float thickness = 5;
public static int headThickness = 15;
public static Color color = new Color(128, 128, 128, 128);
public static Color sourceColor = new Color(255, 128, 0, 192);
public static Color targetColor = new Color(0, 0, 255, 192);
public static Color color = HighlightStatus.NONE_SELECTED.color;
private static BasicStroke dashed = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 10.f }, 0.0f);

private int x1;
Expand All @@ -46,7 +57,7 @@ public class Arrow implements MappingComponent {
private Polygon polygon;

private boolean isSelected = false;
private boolean isVisible = true; ;
private boolean isVisible = true;

public Arrow(LabeledRectangle source) {
this.source = source;
Expand Down Expand Up @@ -148,17 +159,15 @@ public void paint(Graphics g) {
}

public Color fillColor() {
if (source != null && source.isSelected()) {
return sourceColor;
} else if (target != null && target.isSelected()) {
return targetColor;
} else {
return color;
}
return getHighlightStatus().color;
}

public boolean isHighlighted() {
return (source != null && source.isSelected()) || (target != null && target.isSelected());

private boolean isTargetSelected() {
return target != null && target.isSelected();
}

private boolean isSourceSelected() {
return source != null && source.isSelected();
}

public static void drawArrowHead(Graphics2D g2d, int x, int y) {
Expand All @@ -183,10 +192,22 @@ public LabeledRectangle getTarget() {
return target;
}

public HighlightStatus getHighlightStatus() {
if (isSourceSelected() && isTargetSelected()) {
return HighlightStatus.BOTH_SELECTED;
} else if (isSourceSelected()) {
return HighlightStatus.SOURCE_SELECTED;
} else if (isTargetSelected()) {
return HighlightStatus.TARGET_SELECTED;
} else {
return HighlightStatus.NONE_SELECTED;
}
}

public boolean isSelected() {
return isSelected;
}

public void setSelected(boolean isSelected) {
this.isSelected = isSelected;
}
Expand All @@ -202,4 +223,8 @@ public void setVisible(boolean value) {
public boolean isSourceAndTargetVisible(){
return source.isVisible() && target.isVisible();
}

public boolean isConnected(){
return source != null && target != null;
}
}
11 changes: 8 additions & 3 deletions src/org/ohdsi/rabbitInAHat/FilterDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class FilterDialog extends JDialog implements ActionListener, ResizeListe

public FilterDialog(Window parentWindow){

super(parentWindow,"Filter Results",ModalityType.MODELESS);
super(parentWindow,"Filter",ModalityType.MODELESS);

this.setLocation(parentWindow.getX()+parentWindow.getWidth()/2, parentWindow.getY()+100);
this.setSize(700,120);
Expand Down Expand Up @@ -95,6 +95,8 @@ public void setFilterPanel(MappingPanel aFilterPanel){
if (filterPanel != null) {
aFilterPanel.addResizeListener(this);
}

setSearchFieldsToLastSearch();
}

public MappingPanel getFilterPanel(){
Expand Down Expand Up @@ -134,9 +136,12 @@ private void clearSourceFilter() {
doFilterPanel("","Source");
}

private void setSearchFieldsToLastSearch(){
sourceSearchField.setText(getFilterPanel().getLastSourceFilter());
targetSearchField.setText(getFilterPanel().getLastTargetFilter());
}
public void notifyResized(int height, boolean minimized, boolean maximized) {
clearSourceFilter();
clearTargetFilter();
setSearchFieldsToLastSearch();
}

class SearchListener implements KeyListener{
Expand Down
13 changes: 12 additions & 1 deletion src/org/ohdsi/rabbitInAHat/LabeledRectangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ public void setLocation(int x, int y) {
}

public void filter(String searchTerm){
if (this.getItem().getName().matches(".*" + searchTerm + ".*") || searchTerm.equals("") ){
if (this.getItem().getName().matches(".*(" + searchTerm + ").*") || searchTerm.equals("") ){
this.setVisible(true);
}else{
this.setVisible(false);
this.setSelected(false);
}
}

Expand Down Expand Up @@ -161,6 +162,11 @@ else if (index2 == -1)
public boolean contains(Point point) {
return (point.x >= x && point.x <= x + width && point.y >= y && point.y <= y + height);
}

public boolean contains(Point point, int xOffset, int yOffset) {
Point p = new Point(point.x + xOffset, point.y + yOffset);
return contains(p);
}

public int getX() {
return x;
Expand All @@ -181,6 +187,11 @@ public boolean isSelected() {
public void setSelected(boolean isSelected) {
this.isSelected = isSelected;
}

public boolean toggleSelected(){
this.isSelected = !this.isSelected;
return isSelected;
}

public void setVisible(boolean value) {
isVisible = value;
Expand Down

0 comments on commit 9ae9a45

Please sign in to comment.