public Dimension requestResize( final Dimension newSize, final RequestOrigin origin, int cursorY, JediTerminal.ResizeHandler resizeHandler) { if (!newSize.equals(myTermSize)) { myTerminalTextBuffer.lock(); try { myTerminalTextBuffer.resize(newSize, origin, cursorY, resizeHandler, mySelection); myTermSize = (Dimension) newSize.clone(); final Dimension pixelDimension = new Dimension(getPixelWidth(), getPixelHeight()); setPreferredSize(pixelDimension); if (myTerminalPanelListener != null) { myTerminalPanelListener.onPanelResize(pixelDimension, origin); } SwingUtilities.invokeLater( new Runnable() { @Override public void run() { updateScrolling(); } }); } finally { myTerminalTextBuffer.unlock(); } } return new Dimension(getPixelWidth(), getPixelHeight()); }
/** The field view component needs to be redisplayed. Copy the internal image to screen. */ public void paintComponent(Graphics g) { if (fieldImage != null) { Dimension currentSize = getSize(); if (size.equals(currentSize)) { g.drawImage(fieldImage, 0, 0, null); } else { // Rescale the previous image. g.drawImage(fieldImage, 0, 0, currentSize.width, currentSize.height, null); } } }
/** * Prepare a buffer for the image, return if the canvas is ready Only need to call this when the * size of the canvas is changed, Since we automatically detect the size change in paint() only * call this on start */ public boolean newImgBuf() { Dimension sz = getSize(); if (sz.width == 0 || sz.height == 0) return false; // quit if the current image already has the right size if (img != null && imgG != null && sz.equals(imgSize)) return true; img = createImage(sz.width, sz.height); if (imgG != null) imgG.dispose(); imgG = img.getGraphics(); imgSize = sz; return true; }
/** * Prepare for a new round of painting. Since the component may be resized, compute the scaling * factor again. */ public void preparePaint() { if (!size.equals(getSize())) { // if the size has changed... size = getSize(); fieldImage = fieldView.createImage(size.width, size.height); g = fieldImage.getGraphics(); xScale = size.width / gridWidth; if (xScale < 1) { xScale = GRID_VIEW_SCALING_FACTOR; } yScale = size.height / gridHeight; if (yScale < 1) { yScale = GRID_VIEW_SCALING_FACTOR; } } }
private void invalidateIfNeeded() { if (myLabel.getRootPane() == null) return; Dimension d = myLabel.getSize(); Dimension pref = myLabel.getPreferredSize(); if (d != null && d.equals(pref)) { return; } setInactiveStateImage(null); myLabel.invalidate(); if (myActionPanel != null) { myActionPanel.invalidate(); } myTabs.revalidateAndRepaint(false); }