⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 highlighter.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        {            List<Network> sortedNets = new ArrayList<Network>(nets);            Collections.sort(sortedNets, new TextUtils.NetworksByName());            for (Network net : sortedNets) {                System.out.println("Highlighting "+net);            }            clear();        }        int count = 0;        List<Highlight2> highlights = NetworkHighlighter.getHighlights(cell, netlist, nets,                showNetworkLevel, showNetworkLevel);        for (Highlight2 h : highlights) {            addHighlight(h);            count++;        }        synchronized(this) {            this.showNetworkLevel = showNetworkLevel+1;        }        if (count == 0) {            System.out.println("Nothing more in hierarchy on network(s) to show");        }    }    /**     * Add a Highlight     */    public synchronized void addHighlight(Highlight2 h) {        if (h == null) return;        highlightList.add(h);        changed = true;    }    /**	 * Method to clear the list of all highlighted objects in	 */	public void clear()	{        clear(true);    }    private synchronized void clear(boolean resetLastHighlightListEndObj) {        highOffX = highOffY = 0;        showNetworkLevel = 0;        if (highlightList.size() == 0) return;        // save last selected        if (resetLastHighlightListEndObj)            lastHighlightListEndObj = highlightList.get(highlightList.size()-1);        // clear        highlightList.clear();        changed = true;	}    /**	 * Method to indicate that changes to highlighting are finished.	 * Call this after any change to highlighting.	 */	public void finished()	{        // only do something if highlights changed        synchronized(this)        {            // check to see if any highlights are now invalid            for (Highlight2 h : getHighlights())            {                if (!h.isValid())                {                    // remove                    remove(h); // we can do this because iterator is iterating over copy                    changed = true;                }            }            if (!changed) return;        }		// see if arcs of a single type were selected		boolean mixedArc = false;		ArcProto foundArcProto = null;		for(Highlight2 h : getHighlights())		{            if (h instanceof HighlightEOBJ)			{				ElectricObject eobj = ((HighlightEOBJ)h).eobj;				if (eobj instanceof ArcInst)				{					ArcProto ap = ((ArcInst)eobj).getProto();					if (foundArcProto == null)					{						foundArcProto = ap;					} else					{						if (foundArcProto != ap) mixedArc = true;					}				}			}		}        if (type == SELECT_HIGHLIGHTER)		    if (foundArcProto != null && !mixedArc) User.getUserTool().setCurrentArcProto(foundArcProto);        // notify all listeners that highlights have changed (changes committed).        if (!SwingUtilities.isEventDispatchThread())        {            SwingUtilities.invokeLater(new Runnable()            {                public void run() { fireHighlightChanged(); }            });        } else        {            fireHighlightChanged();        }	}	/**	 * Method to ensure that the highlighting is visible.	 * If the highlighting is offscreen, flash an arrow towards it.	 * If the highlighting is small, flash lines around it.	 */	public void ensureHighlightingSeen()	{		// must be drawing in an edit window	    if (wf == null || !(wf.getContent() instanceof EditWindow)) return;		EditWindow wnd = (EditWindow)wf.getContent();		// must have something highlighted		Rectangle2D bounds = getHighlightedArea(wnd);		if (bounds == null) return;		// determine the area being highlighted		double boundsArea = bounds.getWidth() * bounds.getHeight();		Rectangle2D displayBounds = wnd.displayableBounds();		double displayArea = displayBounds.getWidth() * displayBounds.getHeight();		Highlight2 line1 = null, line2 = null, line3 = null, line4 = null;		// if objects are offscreen, point the way		if (bounds.getMinX() >= displayBounds.getMaxX() ||			bounds.getMaxX() <= displayBounds.getMinX() ||			bounds.getMinY() >= displayBounds.getMaxY() ||			bounds.getMaxY() <= displayBounds.getMinY())		{			Point2D fromPt = new Point2D.Double(displayBounds.getCenterX(), displayBounds.getCenterY());			Point2D toPt = new Point2D.Double(bounds.getCenterX(), bounds.getCenterY());			GenMath.clipLine(fromPt, toPt, displayBounds.getMinX(), displayBounds.getMaxX(),					displayBounds.getMinY(), displayBounds.getMaxY());			if (fromPt.getX() != displayBounds.getCenterX() || fromPt.getY() != displayBounds.getCenterY())			{				// clipLine may swap points: swap them back				Point2D swap = fromPt;				fromPt = toPt;				toPt = swap;			}			line1 = addLine(fromPt, toPt, wnd.getCell());			int angle = GenMath.figureAngle(fromPt, toPt);			double headLength = fromPt.distance(toPt) / 10;			double xLeft = toPt.getX() - headLength * DBMath.cos(angle+150);			double yLeft = toPt.getY() - headLength * DBMath.sin(angle+150);			double xRight = toPt.getX() - headLength * DBMath.cos(angle-150);			double yRight = toPt.getY() - headLength * DBMath.sin(angle-150);			line2 = addLine(new Point2D.Double(xLeft, yLeft), toPt, wnd.getCell());			line3 = addLine(new Point2D.Double(xRight, yRight), toPt, wnd.getCell());		} else		{			// if displayed objects are very small, point them out			if (boundsArea * 500 <  displayArea)			{				if (bounds.getMinX() > displayBounds.getMinX() && bounds.getMinY() > displayBounds.getMinY())					line1 = addLine(new Point2D.Double(displayBounds.getMinX(), displayBounds.getMinY()),						new Point2D.Double(bounds.getMinX(), bounds.getMinY()), wnd.getCell());				if (bounds.getMinX() > displayBounds.getMinX() && bounds.getMaxY() < displayBounds.getMaxY())					line2 = addLine(new Point2D.Double(displayBounds.getMinX(), displayBounds.getMaxY()),						new Point2D.Double(bounds.getMinX(), bounds.getMaxY()), wnd.getCell());				if (bounds.getMaxX() < displayBounds.getMaxX() && bounds.getMinY() > displayBounds.getMinY())					line3 = addLine(new Point2D.Double(displayBounds.getMaxX(), displayBounds.getMinY()),						new Point2D.Double(bounds.getMaxX(), bounds.getMinY()), wnd.getCell());				if (bounds.getMaxX() < displayBounds.getMaxX() && bounds.getMaxY() < displayBounds.getMaxY())					line4 = addLine(new Point2D.Double(displayBounds.getMaxX(), displayBounds.getMaxY()),						new Point2D.Double(bounds.getMaxX(), bounds.getMaxY()), wnd.getCell());			}		}		// if there was temporary identification, queue a timer to turn it off		if (line1 != null || line2 != null || line3 != null || line4 != null)		{			Timer timer = new Timer(500, new FlashActionListener(this, line1, line2, line3, line4));			timer.setRepeats(false);			timer.start();		}	}	/**	 * Class to temporarily "flash" a selection that is otherwise hard to see.	 */	private static class FlashActionListener implements ActionListener	{		private Highlighter hl;		private Highlight2 line1, line2, line3, line4;		FlashActionListener(Highlighter hl, Highlight2 line1, Highlight2 line2, Highlight2 line3, Highlight2 line4)		{			this.hl = hl;			this.line1 = line1;			this.line2 = line2;			this.line3 = line3;			this.line4 = line4;		}	    public void actionPerformed(ActionEvent evt)		{			if (line1 != null) hl.remove(line1);			if (line2 != null) hl.remove(line2);			if (line3 != null) hl.remove(line3);			if (line4 != null) hl.remove(line4);			hl.finished();			hl.getWindowFrame().getContent().repaint();		}	}    /**     * Get the last object that was selected. If underCursor is not null,     * if any of the Highlights in underCursor are currently highlighted, then     * the last thing highlighted will be the last thing selected before the last     * clear(). This is to be able to properly cycle through objects under the cursor.     * @param underCursor a list of Highlights underCursor.     * @return the last object that was selected     */    private synchronized Highlight2 getLastSelected(List<Highlight2> underCursor)    {        List<Highlight2> currentHighlights = getHighlights();	// not that this is a copy        // check underCursor list        for (Highlight2 h : underCursor) {            for (Highlight2 curHigh : currentHighlights) {                if (h.sameThing(curHigh)) {                    return lastHighlightListEndObj;                }            }        }        if (currentHighlights.size() > 0)            return currentHighlights.get(currentHighlights.size()-1);        return lastHighlightListEndObj;    }    /**     * Inherits the last selected object from the specified highlighter.     * This is a hack, don't use it.     * @param highlighter     */    public synchronized void copyState(Highlighter highlighter) {        clear();        lastHighlightListEndObj = highlighter.lastHighlightListEndObj;        for (Highlight2 h : highlighter.getHighlights()) {            Highlight2 copy = (Highlight2)h.clone();            addHighlight(copy);        }        // don't inherit offset, messes up mouse over highlighter        //highOffX = highlighter.highOffX;        //highOffY = highlighter.highOffY;    }    /**     * Shows highlights for the current EditWindow     * @param wnd     * @param g     */    public void showHighlights(EditWindow wnd, Graphics g) {        int num = getNumHighlights();        int highOffX, highOffY;        synchronized(this) {            highOffX = this.highOffX;            highOffY = this.highOffY;        }        List<Highlight2> list = highlightList; //getHighlights();        Color colorH = new Color(User.getColor(User.ColorPrefType.HIGHLIGHT));        Color colorM = new Color(User.getColor(User.ColorPrefType.MOUSEOVER_HIGHLIGHT));        Stroke stroke = Highlight2.solidLine;        for (Highlight2 h : list)        {            // only show highlights for the current cell            if (h.getCell() == wnd.getCell())            {                boolean setConnected = User.isHighlightConnectedObjects();                Color color = colorH;                if (type == MOUSEOVER_HIGHLIGHTER)                {                    color = colorM;                    setConnected = false;                }                h.showHighlight(wnd, g, highOffX, highOffY, (num == 1), color, stroke, setConnected);            }        }    }	/**	 * Method to return the WindowFrame associated with this Highlighter.	 * @return the WindowFrame associated with this Highlighter.	 * Returns null if no WindowFrame is associated.	 */	public WindowFrame getWindowFrame() { return wf; }    /** Add a Highlight listener */    public static synchronized void addHighlightListener(HighlightListener l)    {        highlightListeners.add(l);    }    /** Remove a Highlight listener */    public static synchronized void removeHighlightListener(HighlightListener l)    {        highlightListeners.remove(l);    }    /** Notify listeners that highlights have changed */    private void fireHighlightChanged()    {    	if (type == SELECT_HIGHLIGHTER)    	{	        List<HighlightListener> listenersCopy;	        synchronized(this) {	            listenersCopy = new ArrayList<HighlightListener>(highlightListeners);	        }	        for (HighlightListener l : listenersCopy) {	            l.highlightChanged(this);	        }    	}        synchronized(this) {            changed = false;        }    }    /** Notify listeners that the current Highlighter has changed */    private synchronized void fireHighlighterLostFocus(Highlighter highlighterGainedFocus)    {    	if (type == SELECT_HIGHLIGHTER)    	{	        List<HighlightListener> listenersCopy;	        synchronized(this) {	            listenersCopy = new ArrayList<HighlightListener>(highlightListeners);	        }	        for (HighlightListener l : listenersCopy) {	            l.highlighterLostFocus(highlighterGainedFocus);	        }    	}    }    /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -