Quantcast
Viewing all articles
Browse latest Browse all 115

Highlighting in IMessageEditor

Hello, I am trying to create an extension in which you can highlight single or multiple lines of text in the request or response tabs. I am having an issue when you add a “Graphic” to the IMessageEditor text area that it disappears when it is either selected or you highlight a new line of text. Highlight Method: /* * Graphics g: Takes components graphics object. * IMessageEditor req: Request Text Area * IMessageEditor res: Response Text Area * String text: Selected line to highlight * Int x,y,width,height: Dimensions */ public Graphics highlight(Graphics g, IMessageEditor req, IMessageEditor res, String text, int x, int y, int width, int height) { Graphics2D gr = (Graphics2D) g; FontRenderContext context = gr.getFontRenderContext(); Font font = gr.getFont(); int textWidth = (int) font.getStringBounds(text, context).getWidth(); LineMetrics ln = font.getLineMetrics(text, context); int textHeight = (int)(ln.getAscent() + ln.getDescent()); int x1 = x + (width - textWidth)/2; int y1 = (int)(y + (height + textHeight)/2 - ln.getDescent()); gr.setComposite(alphaComp); gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); gr.setColor(Color.YELLOW); gr.setBackground(Color.YELLOW); gr.fillRect(x, y, width, height); return g; } I am accessing the text area component with the following methods: IMessageEditor requestViewer = messageEditor.getRequestViewer(); JTabbedPane requestViewerPane = (JTabbedPane) requestViewer.getComponent(); //Request Tab JPanel jCompPanel = (JPanel) requestViewerPane.getComponent(0); //Get Request’s Raw Tab JComponent jComp2 = (JComponent) jCompPanel.getComponent(1); //Get Layout JComponent txtArea = (JComponent) jComp2.getComponent(0); //Request text area Highlight Call: highlightUtils.highlight(txtArea.getGraphics(), requestViewer, responseViewer, "Cookie: 12345", e.getX(), e.getY(), strw, strh); How would I got about fixing this issue and is there a better way to implement this type of highlighting?

Viewing all articles
Browse latest Browse all 115

Trending Articles