final HashMap<Balloon, RelativePoint> balloonPointHashMap = new HashMap<Balloon, RelativePoint>();
for (int i = start; i < end; i++) {
int textOffset = results.get(i);
RelativePoint point = getPointFromVisualPosition(editor, editor.offsetToVisualPosition(textOffset));
Point originalPoint = point.getOriginalPoint();
originalPoint.translate(0, -editor.getLineHeight() / 2);
// System.out.println(originalPoint.getX() + " " + originalPoint.getY());
JPanel jPanel = new JPanel(new GridLayout());
jPanel.setBackground(new Color(255, 255, 255));
int mnemoicNumber = i % ALLOWED_RESULTS;
String text = String.valueOf(mnemoicNumber);
if (i % ALLOWED_RESULTS == 0) {
text = "Enter";
}
JLabel jLabel = new JLabel(text);
// Font jLabelFont = new Font(jLabel.getFont().getName(), Font.BOLD, 11);
jLabel.setFont(font);
jLabel.setBackground(new Color(192, 192, 192));
jLabel.setHorizontalAlignment(CENTER);
jLabel.setFocusable(false);
jLabel.setSize(jLabel.getWidth(), 5);
jPanel.setFocusable(false);
jPanel.add(jLabel);
if (text.equals("Enter")) {
jPanel.setPreferredSize(new Dimension(45, 13));
} else {
jPanel.setPreferredSize(new Dimension(19, 13));
}
BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createBalloonBuilder(jPanel);
balloonBuilder.setFadeoutTime(0);
balloonBuilder.setAnimationCycle(0);
balloonBuilder.setHideOnClickOutside(true);
balloonBuilder.setHideOnKeyOutside(true);
balloonBuilder.setHideOnAction(true);
balloonBuilder.setFillColor(new Color(221, 221, 221));
balloonBuilder.setBorderColor(new Color(136, 136, 136));
Balloon balloon = balloonBuilder.createBalloon();
balloonPointHashMap.put(balloon, point);
balloons.add(balloon);
hashMap.put(mnemoicNumber, textOffset);
}
Collections.sort(balloons, new Comparator<Balloon>() {
@Override
public int compare(Balloon o1, Balloon o2) {
RelativePoint point1 = balloonPointHashMap.get(o1);
RelativePoint point2 = balloonPointHashMap.get(o2);
if (point1.getOriginalPoint().y < point2.getOriginalPoint().y) {
return 1;
} else if (point1.getOriginalPoint().y == point2.getOriginalPoint().y) {
return 0;
} else {
return -1;
}
}
});
for (int i = 0, balloonsSize = balloons.size(); i < balloonsSize; i++) {
Balloon balloon = balloons.get(i);
RelativePoint point = balloonPointHashMap.get(balloon);
balloon.show(point, Balloon.Position.above);
}
}