if(markerMap.get(markString) != null){
Label lbl = markerMap.get(markString);
lbl.setVisible(true);
displayComponentPanel.setWidgetPosition(lbl, (int)x-lbl.getOffsetWidth()/2, (int)y-lbl.getOffsetHeight());
FlexTable tooltip = markerTooltipMap.get(markString);
tooltip.setVisible(true);
int posX = (int)x-lbl.getOffsetWidth()-10;
int posY = (int)y-tooltip.getOffsetHeight()-lbl.getOffsetHeight()-10;
//Check if right border is reached, if so, the move the tooltip left
if(posX+tooltip.getOffsetWidth() > displayComponentPanel.getOffsetWidth()) {
posX -= tooltip.getOffsetWidth()-50;
}
displayComponentPanel.setWidgetPosition(tooltip, posX, posY);
tooltip.setVisible(false);
} else {
String m[] = markString.split("_");
Long time = Long.parseLong(m[0]);
String caption = m[1];
String description = m[2];
Label lbl = new Label(caption);
lbl.setStyleName(CLASSNAME_MARKER);
lbl.addStyleName(CLASSNAME_MARKER+"-"+caption);
displayComponentPanel.add(lbl);
displayComponentPanel.setWidgetPosition(lbl, (int)x-lbl.getOffsetWidth()/2, (int)y-lbl.getOffsetHeight());
markerMap.put(markString, lbl);
DateTimeFormat formatter = DateTimeFormat.getFormat("MMM d, ''yy");
FlexTable tooltip = new FlexTable();
tooltip.setVisible(true);
tooltip.setStyleName(CLASSNAME_MARKERTOOLTIP);
tooltip.setBorderWidth(0);
tooltip.setCellSpacing(0);
tooltip.setCellPadding(0);
tooltip.getRowFormatter().setStyleName(0, "top");
tooltip.getCellFormatter().setStyleName(0, 0, "topLeft");
tooltip.getCellFormatter().setStyleName(0, 1, "topMiddle");
tooltip.getCellFormatter().setStyleName(0, 2, "topRight");
tooltip.getRowFormatter().setStyleName(1, "middle");
tooltip.getCellFormatter().setStyleName(1, 0, "middleLeft");
tooltip.getCellFormatter().setStyleName(1, 1, "content");
tooltip.getCellFormatter().setStyleName(1, 2, "middleRight");
tooltip.getRowFormatter().setStyleName(2, "bottom");
tooltip.getCellFormatter().setStyleName(2, 0, "bottomLeft");
tooltip.getCellFormatter().setStyleName(2, 1, "bottomMiddle");
tooltip.getCellFormatter().setStyleName(2, 2, "bottomRight");
HTML content = new HTML(
"<span class=date>"+formatter.format(new Date(time))+"</span> <br/>"+
"<span class=text>"+description+"</span>"
);
tooltip.setWidget(1, 1, content);
displayComponentPanel.add(tooltip);
markerTooltipMap.put(markString, tooltip);
int posX = (int)x-lbl.getOffsetWidth()-10;
int posY = (int)y-tooltip.getOffsetHeight()-lbl.getOffsetHeight()-10;
//Check if right border is reached, if so, the move the tooltip left
if(posX+tooltip.getOffsetWidth() > displayComponentPanel.getOffsetWidth()) {
posX -= tooltip.getOffsetWidth()-50;
}
displayComponentPanel.setWidgetPosition(tooltip, posX, posY);
tooltip.setVisible(false);
}
}