public void updatePanelSize() { // Set panel size. if (stmt != null && stmt.getWidth() > 0 && stmt.getHeight() > 0) { int width, height; switch (panel.getFitMode()) { case FIT_VERTICAL: height = getViewport().getHeight(); width = stmt.getWidth() * height / stmt.getHeight(); break; case FIT_HORIZONTAL: width = getViewport().getWidth(); height = stmt.getHeight() * width / stmt.getWidth(); break; case FIT_BOTH: width = getViewport().getWidth(); height = getViewport().getHeight(); break; case ORIGINAL: default: width = stmt.getWidth(); height = stmt.getHeight(); break; } panel.setPreferredSize(new Dimension(width, height)); panel.setSize(new Dimension(width, height)); } }
public int imageToViewY(int y) { switch (panel.getFitMode()) { case FIT_BOTH: case FIT_VERTICAL: return y * panel.getHeight() / stmt.getHeight(); case FIT_HORIZONTAL: return y * panel.getWidth() / stmt.getWidth(); default: return y; } }
public int viewToImageX(int x) { switch (panel.getFitMode()) { case FIT_BOTH: case FIT_HORIZONTAL: return x * stmt.getWidth() / panel.getWidth(); case FIT_VERTICAL: return x * stmt.getHeight() / panel.getHeight(); default: return x; } }