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

📄 manualviewer.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
				indent++;			}			int titleStart = indent;			int titleEnd = line.indexOf('=', titleStart);			String fileName = null;			if (titleEnd < 0) titleEnd = line.length();			else				fileName = line.substring(titleEnd+1).trim();			String title = line.substring(titleStart, titleEnd).trim();			if (fileName == null)			{				if (indent == 0)				{					chapterNumber++;					chapterName = chapterNumber + ": " + title;				}				sectionNumbers[indent]++;				stack[indent+1] = new DefaultMutableTreeNode(sectionNumbers[indent] + ": " + title);				stack[indent].add(stack[indent+1]);				sectionNumbers[indent+1] = 0;				newAtLevel = true;			} else			{				PageInfo pi = new PageInfo();				pi.fileName = fileName;				pi.title = title;				pi.chapterName = chapterName;				pi.chapterNumber = chapterNumber;				pi.sectionNumber = ++sectionNumbers[indent];				pi.fullChapterNumber = "";				for(int i=0; i<indent; i++)				{					pi.fullChapterNumber += sectionNumbers[i] + "-";				}				pi.fullChapterNumber += sectionNumbers[indent];				pi.level = indent;				pi.newAtLevel = newAtLevel;				pi.url = htmlBaseClass.getResource(htmlDirectory + "/" + fileName + ".html");				if (pi.url == null)					System.out.println("NULL URL to "+fileName);				DefaultMutableTreeNode node = new DefaultMutableTreeNode(new Integer(pageSequence.size()));				if (preference != null && pi.fileName.equals(prefFileName))				{					currentIndex = pageSequence.size();					thisNode = node;				}				stack[indent].add(node);				pageSequence.add(pi);				pageNodeSequence.add(node);				newAtLevel = false;			}		}		try		{			stream.close();		} catch (IOException e)		{			System.out.println("Error closing file");		}		// No preference page given		if (preference == null || thisNode != null)		{			// pre-expand the tree			TreePath topPath = manualTree.getPathForRow(0);			manualTree.expandPath(topPath);			topPath = manualTree.getPathForRow(1);			manualTree.expandPath(topPath);			manualTree.setSelectionPath(topPath);		} else		{			TreePath tp = new TreePath(thisNode.getPath());			manualTree.scrollPathToVisible(tp);			manualTree.setSelectionPath(tp);		}		// load the title page of the manual		loadPage(currentIndex);		finishInitialization();	}	/**	 * Method to show the menu bar in the manual dialog.	 */	private void loadMenuBar()	{		if (menubarShown) return;		menubarShown = true;		JMenuBar helpMenuBar = new JMenuBar();		// convert menuBar to tree		TopLevel top = TopLevel.getCurrentJFrame();		EMenuBar menuBar = top.getEMenuBar();		for (EMenuItem menu: menuBar.getItems())		{			JMenu helpMenu = new JMenu(menu.getText());			helpMenuBar.add(helpMenu);			addMenu((EMenu)menu, helpMenu, menu.getText() + "/");		}		setJMenuBar(helpMenuBar);		pack();		ensureProperSize();		StringBuffer sb = new StringBuffer();		sb.append("<CENTER><H1>HELP MENU ENABLED</H1></CENTER>\n");		sb.append("The menu bar at the top of <I>this</I> window looks the same as the main menu bar in Electric.<BR><BR>\n");		sb.append("Use any entry in this menu bar to see the manual page that explains that menu entry.\n");		editorPane.setText(sb.toString());		editorPane.setCaretPosition(0);	}	/**	 * Method to examine the online manual and extract pointers to commands and preferences.	 */	private void loadPointers()	{		// stop if already done		if (keywordMap != null) return;		menuMap = new HashMap<String,String>();		HashMap<String,String> menuMapCheck = null;		keywordMap = new HashMap<String,String>();		if (Job.getDebug())		{			menuMapCheck = new HashMap<String,String>();		}		// scan all manual entries for menu associations		String indexName = htmlDirectory + "/toc.txt";		URL url = htmlBaseClass.getResource(indexName);		InputStream stream = TextUtils.getURLStream(url, null);		if (stream == null)		{			System.out.println("Can't open " + indexName + " in " + htmlBaseClass.getPackage());			return;		}		InputStreamReader is = new InputStreamReader(stream);		for(;;)		{			String line = getLine(is);			if (line == null) break;			if (line.length() == 0) continue;			int indent = 0;			for(;;)			{				if (indent >= line.length() || line.charAt(indent) != ' ') break;				indent++;			}			int titleStart = indent;			int titleEnd = line.indexOf('=', titleStart);			if (titleEnd < 0) continue;			String fileName = line.substring(titleEnd+1).trim();			URL pageURL = htmlBaseClass.getResource(htmlDirectory + "/" + fileName + ".html");			if (pageURL == null)			{				System.out.println("NULL URL to "+fileName);				continue;			}			InputStream pageStream = TextUtils.getURLStream(pageURL, null);			InputStreamReader pageIS = new InputStreamReader(pageStream);			for(;;)			{				String pageLine = getLine(pageIS);				if (pageLine == null) break;				if (pageLine.startsWith("<!-- COMMAND "))				{					int endPt = pageLine.indexOf("-->");					if (endPt < 0)					{						System.out.println("No end comment on line: "+pageLine);						continue;					}					String commandName = pageLine.substring(13, endPt).trim();					for(;;)					{						int backslashPos = commandName.indexOf('\\');						if (backslashPos < 0) break;						commandName = commandName.substring(0, backslashPos) + commandName.substring(backslashPos+1);					}					String already = menuMap.get(commandName);					if (already != null && Job.getDebug())					{						System.out.println("ERROR: command " + commandName + " is keyed to both " + already + " and " + fileName);					}					menuMap.put(commandName, fileName);					if (menuMapCheck != null) menuMapCheck.put(commandName, fileName);					continue;				}				if (pageLine.startsWith("<!-- PREFERENCE "))				{					int endPt = pageLine.indexOf("-->");					if (endPt < 0)					{						System.out.println("No end comment on line: "+pageLine);						continue;					}					String preferenceName = "PREF" + pageLine.substring(16, endPt).trim();					String already = keywordMap.get(preferenceName);					if (already != null && Job.getDebug())					{						System.out.println("ERROR: command " + preferenceName + " is keyed to both " + already + " and " + fileName);					}					keywordMap.put(preferenceName, fileName);					continue;				}				if (pageLine.startsWith("<!-- PROJECTSETTING "))				{					int endPt = pageLine.indexOf("-->");					if (endPt < 0)					{						System.out.println("No end comment on line: "+pageLine);						continue;					}					String projSettingName = "PROJ" + pageLine.substring(20, endPt).trim();					String already = keywordMap.get(projSettingName);					if (already != null && Job.getDebug())					{						System.out.println("ERROR: command " + projSettingName + " is keyed to both " + already + " and " + fileName);					}					keywordMap.put(projSettingName, fileName);					continue;				}			}			try			{				pageStream.close();			} catch (IOException e)			{				System.out.println("Error closing file");			}		}		if (menuMapCheck != null)		{			TopLevel top = TopLevel.getCurrentJFrame();			EMenuBar menuBar = top.getEMenuBar();			for (EMenuItem menu: menuBar.getItems())			{				if (Job.getDebug() && excludeMenu.contains(menu.getText())) continue;				checkMenu((EMenu)menu, menu.getText() + "/", menuMapCheck);			}			for(String commandName : menuMapCheck.keySet())			{				String fileName = menuMapCheck.get(commandName);				System.out.println("Command " + commandName + " was mentioned in file " + fileName + " but does not exist");			}			menuMapCheck = null;		}	}	private void checkMenu(EMenu menu, String cumulative, HashMap<String,String> menuMapCheck)	{		for (EMenuItem menuItem: menu.getItems())		{			if (menuItem == EMenuItem.SEPARATOR) continue;			if (menuItem instanceof EMenu)			{				EMenu subMenu = (EMenu)menuItem;				checkMenu(subMenu, cumulative + subMenu.getText() + "/", menuMapCheck);			} else			{				String commandName = cumulative + menuItem.getText();				String fileName = menuMap.get(commandName);				if (fileName == null && Job.getDebug())				{					System.out.println("No help for " + commandName);				} else				{					if (menuMapCheck != null) menuMapCheck.remove(commandName);				}			}		}	}	private void addMenu(EMenu menu, JMenu helpMenu, String cumulative)	{		for (EMenuItem menuItem: menu.getItems())		{			if (menuItem == EMenuItem.SEPARATOR)			{				helpMenu.addSeparator();				continue;			}			if (menuItem instanceof EMenu)			{				EMenu subMenu = (EMenu)menuItem;				JMenu helpSubMenu = new JMenu(subMenu.getText());				helpMenu.add(helpSubMenu);				addMenu(subMenu, helpSubMenu, cumulative + subMenu.getText() + "/");			} else			{				JMenuItem helpMenuItem = new JMenuItem(menuItem.getText());				helpMenu.add(helpMenuItem);				String commandName = cumulative + menuItem.getText();				String fileName = menuMap.get(commandName);				helpMenuItem.addActionListener(new HelpMenuActionListener(this, fileName));			}		}	}	private static class HelpMenuActionListener implements ActionListener	{		private ManualViewer dialog;		private String title;		HelpMenuActionListener(ManualViewer dialog, String title)		{			this.dialog = dialog;			this.title = title;		}		public void actionPerformed(ActionEvent e) { doHelpMenu(title); }		private void doHelpMenu(String fileName)		{			if (fileName == null)			{				System.out.println("No help for this command");				return;			}			for(int i=0; i<dialog.pageSequence.size(); i++)			{				PageInfo pi = dialog.pageSequence.get(i);				if (pi.fileName.equals(fileName))				{					dialog.loadPage(i);					return;				}			}		}	}	private String getLine(InputStreamReader is)	{		StringBuffer sb = new StringBuffer();		for(;;)		{			int ch = -1;			try			{				ch = is.read();			} catch (IOException e) {}			if (ch == -1) return null;			if (ch == '\n' || ch == '\r') break;			sb.append((char)ch);		}		return sb.toString();	}	private void loadPage(int index)	{		// add to browsing history		history.add(new Integer(index));		currentIndex = index;		lastPageVisited = index;		PageInfo pi = pageSequence.get(index);		if (pi.url == null) return; // error reading the html file		DefaultMutableTreeNode node = pageNodeSequence.get(index);		EDialog.recursivelyHighlight(manualTree, rootNode, node, manualTree.getPathForRow(0));		InputStream stream = TextUtils.getURLStream(pi.url, null);		InputStreamReader is;		try {			is = new InputStreamReader(stream, "UTF-8");		} catch (UnsupportedEncodingException e) {			System.out.println("UTF-8 is UnsupportedEncodingException");			return;		}		StringBuffer sb = new StringBuffer();		// emit header HTML		sb.append("<BASE href=\"" + pi.url.toString() + "\">");		int lastIndex = index - 1;		if (lastIndex < 0) lastIndex = pageSequence.size() - 1;		PageInfo lastPi = pageSequence.get(lastIndex);		String lastFileName = lastPi.fileName;		int nextIndex = index + 1;		if (nextIndex >= pageSequence.size()) nextIndex = 0;		PageInfo nextPi = pageSequence.get(nextIndex);		String nextFileName = nextPi.fileName;		boolean pageFound = false;		for(;;)		{			String line = getLine(is);			if (line == null) break;			if (line.startsWith("<!-- HEADER "))			{				int endPt = line.indexOf("-->");				if (endPt < 0)				{					System.out.println("No end comment on line: "+line);					continue;				}				String pageName = line.substring(12, endPt).trim();				setTitle(pageName + " - Electric Manual");				pageFound = true;				sb.append("<HTML><HEAD><TITLE>Using Electric " + pageName + "\"</TITLE></HEAD>\n");				sb.append("<BODY>\n");				sb.append("<CENTER><TABLE WIDTH=\"90%\" BORDER=0><TR>\n");				sb.append("<TD><CENTER><A HREF=\"" + lastFileName + ".html#" + lastFileName +					".html\"><IMG SRC=\"iconplug.png\" ALT=\"plug\" BORDER=0></A></CENTER></TD>\n");				sb.append("<TD><CENTER><H1>" + pageName + "</H1></CENTER></TD>\n");				sb.append("<TD><CENTER><A HREF=\"" + nextFileName + ".html#" + nextFileName +					".html\"><IMG SRC=\"iconplug.png\" ALT=\"plug\" BORDER=0></A></CENTER></TD></TR></TABLE></CENTER>\n");				sb.append("<HR>\n");				sb.append("<BR>\n");				continue;			}			if (line.equals("<!-- TRAILER -->"))			{				sb.append("</BODY>\n");				sb.append("</HTML>\n");				continue;			}			sb.append(line);			sb.append("\n");		}		try

⌨️ 快捷键说明

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