📄 editwindow.java
字号:
// this.wf = new WeakReference(wf); } public void adjustmentValueChanged(AdjustmentEvent e) { if (e.getSource() == wnd.getBottomScrollBar() && wnd.getCell() != null) wnd.bottomScrollChanged(e.getValue()); if (e.getSource() == wnd.getRightScrollBar() && wnd.getCell() != null) wnd.rightScrollChanged(e.getValue()); } } /** * Method to return the horizontal scroll bar at the bottom of the edit window. * @return the horizontal scroll bar at the bottom of the edit window. */ public JScrollBar getBottomScrollBar() { return bottomScrollBar; } /** * Method to return the vertical scroll bar at the right side of the edit window. * @return the vertical scroll bar at the right side of the edit window. */ public JScrollBar getRightScrollBar() { return rightScrollBar; } // ************************************* REPAINT ************************************* /** * Method to repaint this EditWindow. * Composites the image (taken from the PixelDrawing object) * with the grid, highlight, and any dragging rectangle. */ public void paintComponent(Graphics graphics) { // to enable keys to be received if (wf == null) return;// if (wf == WindowFrame.getCurrentWindowFrame())// requestFocusInWindow(); Graphics2D g = (Graphics2D)graphics; if (cell == null) { g.setColor(new Color(User.getColor(User.ColorPrefType.BACKGROUND))); g.fillRect(0, 0, getWidth(), getHeight()); String msg = "No cell in this window"; Font f = new Font(User.getDefaultFont(), Font.BOLD, 18); g.setFont(f); g.setColor(new Color(User.getColor(User.ColorPrefType.TEXT))); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.drawString(msg, (getWidth() - g.getFontMetrics(f).stringWidth(msg))/2, getHeight()/2); return; } logger.entering(CLASS_NAME, "paintComponent", this); if (!drawing.paintComponent(g, getSize())) { fullRepaint(); g.setColor(new Color(User.getColor(User.ColorPrefType.BACKGROUND))); g.fillRect(0, 0, getWidth(), getHeight()); logger.exiting(CLASS_NAME, "paintComponent", "resize and repaint"); return; } logger.logp(Level.FINER, CLASS_NAME, "paintComponent", "offscreen is drawn"); sz = getSize(); szHalfWidth = sz.width / 2; szHalfHeight = sz.height / 2; if (scale != drawing.da.scale || offx != drawing.da.offX || offy != drawing.da.offY) textInCell = null; scale = drawing.da.scale; offx = drawing.da.offX; offy = drawing.da.offY; setScrollPosition(); // redraw scroll bars // set the default text size (for highlighting, etc) Font f = new Font(User.getDefaultFont(), Font.PLAIN, (int)(10*globalTextScale)); g.setFont(f); // add cross-probed level display showCrossProbeLevels(g); if (Job.getDebug()) { // add in highlighting if (Job.acquireExamineLock(false)) { try { // add in the frame if present drawCellFrame(g); //long start = System.currentTimeMillis(); rulerHighlighter.showHighlights(this, g); mouseOverHighlighter.showHighlights(this, g); highlighter.showHighlights(this, g); //long end = System.currentTimeMillis(); //System.out.println("drawing highlights took "+TextUtils.getElapsedTime(end-start)); Job.releaseExamineLock(); } catch (Error e) { Job.releaseExamineLock(); throw e; } } } else { // unsafe try { // add in the frame if present drawCellFrame(g); //long start = System.currentTimeMillis(); rulerHighlighter.showHighlights(this, g); mouseOverHighlighter.showHighlights(this, g); highlighter.showHighlights(this, g); //long end = System.currentTimeMillis(); //System.out.println("drawing highlights took "+TextUtils.getElapsedTime(end-start)); } catch (Exception e) { } } // add in drag area if (doingAreaDrag) showDragBox(g); // add in popup cloud if (showPopupCloud) drawPopupCloud(g); // add in shadow if doing in-place editing if (inPlaceDisplay) { Rectangle2D bounds = cell.getBounds(); Point i1 = databaseToScreen(bounds.getMinX(), bounds.getMinY()); Point i2 = databaseToScreen(bounds.getMinX(), bounds.getMaxY()); Point i3 = databaseToScreen(bounds.getMaxX(), bounds.getMaxY()); Point i4 = databaseToScreen(bounds.getMaxX(), bounds.getMinY()); // shade everything else except for the cell being edited if (User.isDimUpperLevelWhenDownInPlace()) { Polygon innerPoly = new Polygon(); innerPoly.addPoint(i1.x, i1.y); innerPoly.addPoint(i2.x, i2.y); innerPoly.addPoint(i3.x, i3.y); innerPoly.addPoint(i4.x, i4.y); Area outerArea = new Area(new Rectangle(0, 0, sz.width, sz.height)); Area innerArea = new Area(innerPoly); outerArea.subtract(innerArea); g.setColor(new Color(128, 128, 128, 128)); g.fill(outerArea); } // draw a red box around the cell being edited g.setStroke(inPlaceMarker); g.setColor(new Color(User.getColor(User.ColorPrefType.DOWNINPLACEBORDER))); int lX = Math.min(Math.min(i1.x, i2.x), Math.min(i3.x, i4.x)); int hX = Math.max(Math.max(i1.x, i2.x), Math.max(i3.x, i4.x)); int lY = Math.min(Math.min(i1.y, i2.y), Math.min(i3.y, i4.y)); int hY = Math.max(Math.max(i1.y, i2.y), Math.max(i3.y, i4.y)); g.drawLine(lX-1, lY-1, lX-1, hY+1); g.drawLine(lX-1, hY+1, hX+1, hY+1); g.drawLine(hX+1, hY+1, hX+1, lY-1); g.drawLine(hX+1, lY-1, lX-1, lY-1); } logger.logp(Level.FINER, CLASS_NAME, "paintComponent", "overlays are drawn"); // see if anything else is queued if (scale != scaleRequested || offx != offxRequested || offy != offyRequested || !getSize().equals(sz)) { textInCell = null; fullRepaint(); } logger.exiting(CLASS_NAME, "paintComponent"); } /** * Method to store a new "in-place" text editing object on this EditWindow. * @param tl the Listener that is now sitting on top of this EditWindow. */ public void addInPlaceTextObject(GetInfoText.EditInPlaceListener tl) { inPlaceTextObjects.add(tl); add(tl.getTextComponent()); } /** * Method to return the current "in-place" text editing object on this EditWindow. * @return the current "in-place" text editing object on this EditWindow. */ public GetInfoText.EditInPlaceListener getInPlaceTextObject() { if (inPlaceTextObjects.size() == 0) return null; return inPlaceTextObjects.get(inPlaceTextObjects.size()-1); } /** * Method to remove a "in-place" text editing object from this EditWindow. * @param tl the Listener that is no longer sitting on top of this EditWindow. */ public void removeInPlaceTextObject(GetInfoText.EditInPlaceListener tl) { inPlaceTextObjects.remove(tl); remove(tl.getTextComponent()); } /** * Method to remove all in-place text objects in this window. * Called when the window pans or zooms and the text objects are no longer in the proper place. */ public void removeAllInPlaceTextObjects() { List<GetInfoText.EditInPlaceListener> allTextObjects = new ArrayList<GetInfoText.EditInPlaceListener>(); for(GetInfoText.EditInPlaceListener eip : inPlaceTextObjects) allTextObjects.add(eip); for(GetInfoText.EditInPlaceListener tl : allTextObjects) { tl.closeEditInPlace(); } } /** * Method requests that every EditWindow be redrawn, including a change of display algorithm. */ public static void displayAlgorithmChanged() { for(Iterator<WindowFrame> it = WindowFrame.getWindows(); it.hasNext(); ) { WindowFrame wf = it.next(); WindowContent content = wf.getContent(); if (!(content instanceof EditWindow)) continue; EditWindow wnd = (EditWindow)content; wnd.setDrawingAlgorithm(); wnd.fullRepaint(); } } /** * Method requests that every EditWindow be redrawn, including a rerendering of its contents. */ public static void repaintAllContents() { for(Iterator<WindowFrame> it = WindowFrame.getWindows(); it.hasNext(); ) { WindowFrame wf = it.next(); WindowContent content = wf.getContent(); if (!(content instanceof EditWindow)) continue; EditWindow wnd = (EditWindow)content; wnd.fullRepaint(); } } /** * Method requests that every EditWindow be redrawn, without rerendering the offscreen contents. */ public static void repaintAll() { for(Iterator<WindowFrame> it = WindowFrame.getWindows(); it.hasNext(); ) { WindowFrame wf = it.next(); WindowContent content = wf.getContent(); if (!(content instanceof EditWindow)) continue; EditWindow wnd = (EditWindow)content; wnd.repaint(); } } /** * Method requests that this EditWindow be redrawn, including a rerendering of the contents. */ public void fullRepaint() { repaintContents(null, false); } /** * Method requests that this EditWindow be redrawn, including a rerendering of the contents. * @param bounds the area to redraw (null to draw everything). * @param fullInstantiate true to display to the bottom of the hierarchy (for peeking). */ public void repaintContents(Rectangle2D bounds, boolean fullInstantiate) { // start rendering thread if (wf == null) return; if (cell == null) { repaint(); return; } if (runningNow != null && repaintRequest && !fullInstantiate) return; logger.entering(CLASS_NAME, "repaintContents", bounds); // do the redraw in a separate thread if (fullInstantiate) { fullInstantiateBounds = bounds.getBounds2D(); DBMath.transformRect(fullInstantiateBounds, outofCell); } invokeRenderJob(this); logger.exiting(CLASS_NAME, "repaintContents"); } public static void invokeRenderJob() { invokeRenderJob(null); } private static void invokeRenderJob(EditWindow wnd) { logger.entering(CLASS_NAME, "invokeRenderJob", wnd); synchronized(lock) { if (wnd != null) { wnd.drawing.abortRendering(); wnd.repaintRequest = true; } if (runningNow != null) { runningNow.hasTasks = true; logger.exiting(CLASS_NAME, "invokeRenderJob running now"); return; } runningNow = new RenderJob(); } runningNow.startJob(); logger.exiting(CLASS_NAME, "invokeRenderJob starting job"); } private final static String RENDER_JOB_CLASS_NAME = CLASS_NAME + ".RenderJob"; /** * This class queues requests to rerender a window. */ private static class RenderJob extends Job { private static Snapshot oldSnapshot = EDatabase.clientDatabase().getInitialSnapshot(); volatile boolean hasTasks; protected RenderJob() { super("Display", User.getUserTool(), Job.Type.EXAMINE, null, null, Job.Priority.USER); } public boolean doIt() throws JobException { logger.entering(RENDER_JOB_CLASS_NAME, "doIt"); try { for (;;) { hasTasks = false; Snapshot snapshot = EDatabase.clientDatabase().backup(); if (snapshot != oldSnapshot) { endBatch(oldSnapshot, snapshot); oldSnapshot = snapshot; } EditWindow wnd = null; for (Iterator<WindowFrame> it = WindowFrame.getWindows(); it.hasNext();) { WindowFrame wf = it.next(); WindowContent wc = wf.getContent(); if (wc instanceof EditWindow && ((EditWindow) wc).repaintRequest) { wnd = (EditWindow) wc; break; } } if (wnd == null) { break; } wnd.repaintRequest = false; render(wnd); } } finally { RenderJob j = null; synchronized (lock) { if (hasTasks) { runningNow = j = new RenderJob(); } else { runningNow = null; } } if (j != null) { assert j == runningNow; j.startJob(); } } logger.exiting(RENDER_JOB_CLASS_NAME, "doIt"); return true; } private void render(EditWindow wnd) throws JobException { logger.entering(RENDER_JOB_CLASS_NAME, "render"); // do the hard work of re-rendering the image Rectangle2D bounds = null; boolean fullInstantiate = false; if (wnd.fullInstantiateBounds != null) { fullInstantiate = true; bounds = wnd.fullInstantiateBounds; wnd.fullInstantiateBounds = null; } else if (bounds == null) { // see if a real bounds is defined in the cell bounds = User.getChangedInWindow(wnd); } if (bounds != null) { User.clearChangedInWindow(wnd); } WindowFrame.DisplayAttributes da = new WindowFrame.DisplayAttributes(wnd.scaleRequested, wnd.offxRequested, wnd.offyRequested, wnd.inPlaceDescent); wnd.drawing.render(wnd.getSize(), da, fullInstantiate, bounds); wnd.repaint(); logger.exiting(RENDER_JOB_CLASS_NAME, "render"); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -