public void zoom(double scale) {
    double oldScale = _panel.getScale();

    // Get the top left coordinates of the viewport
    Point point = getViewport().getViewPosition();

    // Zoom the JPanel containing the graphics
    _panel.zoom(scale);

    double w = getViewport().getWidth();
    double h = getViewport().getHeight();

    // Turn the top left coordinates into the center coordinates of the viewport
    int halfW = (int) (w/2.0);
    int halfH = (int) (h/2.0);
    point.translate(halfW, halfH);

    // Calculate the scaling factor relative to the old one
    double relScale = scale / oldScale;

    // Calculate the new center of the viewport
    point.move((int) (point.getX() * relScale), (int) (point.getY() * relScale));

    // Move back to top left
    point.translate(-halfW, -halfH);

    // Set this to be the new top left coordinates of the viewport
    getViewport().setViewPosition(point);
  }