Overwriting Zoom Rectangle Issue

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
converge
Posts: 30
Joined: Wed Jun 16, 2004 3:00 pm

Overwriting Zoom Rectangle Issue

Post by converge » Thu Feb 19, 2015 5:04 pm

I'm trying to create my own zoom rectangle where the user is not forced to always move the mouse to the bottom-right. Ideally, I'd like to create a zoom rectangle using any of the other three starting orientations (bottom-left, top-right, top-left). To do this, I have to change code in ChartPanel.java to the following:

Code: Select all

@Override
    public void mouseDragged(final MouseEvent event) {
            ...
            double mouseX = event.getX();
            double mouseY = event.getY();
            double zoomX;
            double zoomY;
            double zoomWidth;
            double zoomHeight;
            if (mouseX > zoomPoint.getX()) {
                zoomX = this.zoomPoint.getX();
                zoomWidth = Math.min(mouseX, scaledDataArea.getMaxX()) - this.zoomPoint.getX();
            } else {
                mouseX = Math.max(mouseX, scaledDataArea.getMinX());
                zoomX = mouseX;
                zoomWidth = this.zoomPoint.getX() - mouseX;
            }
            if (mouseY > zoomPoint.getY()) {
                zoomY = this.zoomPoint.getY();
                zoomHeight = Math.min(mouseY, scaledDataArea.getMaxY()) - this.zoomPoint.getY();
            } else {
                mouseY = Math.max(mouseY, scaledDataArea.getMinY());
                zoomY = mouseY;
                zoomHeight = this.zoomPoint.getY() - mouseY;
            }
            this.zoomRectangle = new Rectangle2D.Double(zoomX, zoomY, zoomWidth, zoomHeight);
            ...
This works. However, my issue is that I don't want to change the JFreeChart source code. I would rather extend the ChartPanel class and use my own code. But when I do this (extend ChartPanel), the zoom rectangle does not have that nice translucent blue look.

Instead of looking like this (translucent blue):
Image

It looks like this (dark grey):
Image

The drawZoomRectangle() function is the same in my extended class. I think the problem may have to do with using setXORMode() in drawZoomRectangle() but I'm not sure. Any ideas?

Locked