/** * Remove a message from the table. * @param message The message to remove. * @return <code>true</code> if success */ public boolean removeMessage(Message message) { int row = messages.indexOf(message); messages.remove(message); fireTableRowsDeleted(row, row); return true; }
/** * Return the message for a given x- and y-coordinate. * * @param x The x-coordinate. * @param y The y-coordinate. * @return The message or <code>null</code> if there is no message at the given point. */ public Message getMessage(int x, int y) { int msgnr = 0; for(Iterator iter = panelcan.visible_messages.keySet().iterator(); iter.hasNext();) { Message message = (Message)iter.next(); // get the x- and y-coordinates for the message Component sender = (Component)((Pair)panelcan.visible_messages.get(message)).getFirst(); Component receiver = (Component)((Pair)panelcan.visible_messages.get(message)).getSecond(); int posSource = panelcan.visible_components.indexOf(sender); int posDest = panelcan.visible_components.indexOf(receiver); int x1 = DiagramConstants.getTimelineX(posSource); int x2 = DiagramConstants.getTimelineX(posDest); int yt = DiagramConstants.getTimelineY(msgnr++); boolean inRangeX = x1 < x2 ? (x >= x1 - H_TOL) && (x <= x2 + H_TOL) : (x >= x2 - H_TOL) && (x <= x1 + H_TOL); boolean inRangeY = (y >= yt - V_TOL) && (y <= yt + V_TOL); if(inRangeX && inRangeY) { return message; } } return null; }