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

📄 statusbar.java

📁 用java 编写的源码开放的文本编辑器。有很多有用的特性
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			return;		}		messageComp = comp;		panel.add(BorderLayout.CENTER, messageComp);	} //}}}	//{{{ updateCaretStatus() method	public void updateCaretStatus()	{		//if(!isShowing())		//	return;		if (showCaretStatus)		{			Buffer buffer = view.getBuffer();			if(!buffer.isLoaded() ||				/* can happen when switching buffers sometimes */				buffer != view.getTextArea().getBuffer())			{				caretStatus.setText(" ");				return;			}			JEditTextArea textArea = view.getTextArea();			int currLine = textArea.getCaretLine();			// there must be a better way of fixing this...			// the problem is that this method can sometimes			// be called as a result of a text area scroll			// event, in which case the caret position has			// not been updated yet.			if(currLine >= buffer.getLineCount())				return; // hopefully another caret update will come?			int start = textArea.getLineStartOffset(currLine);			int dot = textArea.getCaretPosition() - start;			buffer.getText(start,dot,seg);			int virtualPosition = MiscUtilities.getVirtualWidth(seg,				buffer.getTabSize());			buf.setLength(0);			buf.append(Integer.toString(currLine + 1));			buf.append(',');			buf.append(Integer.toString(dot + 1));			if (virtualPosition != dot)			{				buf.append('-');				buf.append(Integer.toString(virtualPosition + 1));			}			buf.append(' ');			int firstLine = textArea.getFirstLine();			int visible = textArea.getVisibleLines();			int lineCount = textArea.getVirtualLineCount();			if (visible >= lineCount)			{				buf.append("All");			}			else if (firstLine == 0)			{				buf.append("Top");			}			else if (firstLine + visible >= lineCount)			{				buf.append("Bot");			}			else			{				float percent = (float)firstLine / (float)lineCount					* 100.0f;				buf.append(Integer.toString((int)percent));				buf.append('%');			}			caretStatus.setText(buf.toString());		}	} //}}}	//{{{ updateBufferStatus() method	public void updateBufferStatus()	{		//if(!isShowing())		//	return;		Buffer buffer = view.getBuffer();		if (showWrap)		{			String wrap = buffer.getStringProperty("wrap");			if(wrap.equals("none"))				this.wrap.setText("-");			else if(wrap.equals("hard"))				this.wrap.setText("H");			else if(wrap.equals("soft"))				this.wrap.setText("S");		}		if (showLineSeperator)		{			String lineSep = buffer.getStringProperty("lineSeparator");			if("\n".equals(lineSep))				this.lineSep.setText("U");			else if("\r\n".equals(lineSep))				this.lineSep.setText("W");			else if("\r".equals(lineSep))				this.lineSep.setText("M");		}		if (showEditMode || showFoldMode || showEncoding)		{			/* This doesn't look pretty and mode line should			 * probably be split up into seperate			 * components/strings			 */			buf.setLength(0);			if (showEditMode)				buf.append(buffer.getMode().getName());			if (showFoldMode)			{				if (showEditMode)					buf.append(",");				buf.append((String)view.getBuffer().getProperty("folding"));			}			if (showEncoding)			{				if (showEditMode || showFoldMode)					buf.append(",");				buf.append(buffer.getStringProperty("encoding"));			}			mode.setText("(" + buf.toString() + ")");		}	} //}}}	//{{{ updateMiscStatus() method	public void updateMiscStatus()	{		//if(!isShowing())		//	return;		JEditTextArea textArea = view.getTextArea();		if (showMultiSelect)			multiSelect.setText(textArea.isMultipleSelectionEnabled()				? "M" : "-");		if (showOverwrite)			overwrite.setText(textArea.isOverwriteEnabled()				? "O" : "-");	} //}}}	//{{{ Private members	private View view;	private JPanel panel;	private Box box;	private ToolTipLabel caretStatus;	private Component messageComp;	private JLabel message;	private JLabel mode;	private JLabel wrap;	private JLabel multiSelect;	private JLabel overwrite;	private JLabel lineSep;	private MemoryStatus memory;	/* package-private for speed */ StringBuffer buf = new StringBuffer();	private Timer tempTimer;	private boolean currentMessageIsIO;	private Segment seg = new Segment();	private boolean showCaretStatus = jEdit.getBooleanProperty("view.status.show-caret-status");	private boolean showEditMode = jEdit.getBooleanProperty("view.status.show-edit-mode");	private boolean showFoldMode = jEdit.getBooleanProperty("view.status.show-fold-mode");	private boolean showEncoding = jEdit.getBooleanProperty("view.status.show-encoding");	private boolean showWrap = jEdit.getBooleanProperty("view.status.show-wrap");	private boolean showMultiSelect = jEdit.getBooleanProperty("view.status.show-multi-select");	private boolean showOverwrite = jEdit.getBooleanProperty("view.status.show-overwrite");	private boolean showLineSeperator = jEdit.getBooleanProperty("view.status.show-line-seperator");	private boolean showMemory = jEdit.getBooleanProperty("view.status.show-memory");	//}}}	static final String caretTestStr = "9999,999-999 99%";	static final String memoryTestStr = "999/999Mb";	//{{{ MouseHandler class	class MouseHandler extends MouseAdapter	{		public void mouseClicked(MouseEvent evt)		{			Buffer buffer = view.getBuffer();			Object source = evt.getSource();			if(source == caretStatus)			{				if(evt.getClickCount() == 2)					view.getTextArea().showGoToLineDialog();			}			else if(source == mode)			{				if(evt.getClickCount() == 2)					new BufferOptions(view,view.getBuffer());			}			else if(source == wrap)				buffer.toggleWordWrap(view);			else if(source == multiSelect)				view.getTextArea().toggleMultipleSelectionEnabled();			else if(source == overwrite)				view.getTextArea().toggleOverwriteEnabled();			else if(source == lineSep)				buffer.toggleLineSeparator(view);			else if(source == memory)			{				if(evt.getClickCount() == 2)				{					jEdit.showMemoryDialog(view);					memory.repaint();				}			}		}	} //}}}	//{{{ ToolTipLabel class	class ToolTipLabel extends JLabel	{		//{{{ getToolTipLocation() method		public Point getToolTipLocation(MouseEvent event)		{			return new Point(event.getX(),-20);		} //}}}	} //}}}	//{{{ MemoryStatus class	class MemoryStatus extends JComponent implements ActionListener	{		//{{{ MemoryStatus constructor		public MemoryStatus()		{			MemoryStatus.this.setDoubleBuffered(true);			MemoryStatus.this.setForeground(UIManager.getColor("Label.foreground"));			MemoryStatus.this.setBackground(UIManager.getColor("Label.background"));			MemoryStatus.this.setFont(UIManager.getFont("Label.font"));		} //}}}		//{{{ addNotify() method		public void addNotify()		{			super.addNotify();			timer = new Timer(2000,this);			timer.start();			ToolTipManager.sharedInstance().registerComponent(this);		} //}}}		//{{{ removeNotify() method		public void removeNotify()		{			timer.stop();			ToolTipManager.sharedInstance().unregisterComponent(this);			super.removeNotify();		} //}}}		//{{{ getToolTipText() method		public String getToolTipText()		{			Runtime runtime = Runtime.getRuntime();			int freeMemory = (int)(runtime.freeMemory() / 1024);			int totalMemory = (int)(runtime.totalMemory() / 1024);			int usedMemory = (totalMemory - freeMemory);			Integer[] args = { new Integer(usedMemory),				new Integer(totalMemory) };			return jEdit.getProperty("view.status.memory-tooltip",args);		} //}}}		//{{{ getToolTipLocation() method		public Point getToolTipLocation(MouseEvent event)		{			return new Point(event.getX(),-20);		} //}}}		//{{{ actionPerformed() method		public void actionPerformed(ActionEvent evt)		{			MemoryStatus.this.repaint();		} //}}}		/* package-private */ LineMetrics lm;		/* package-private */ Color progressForeground;		/* package-private */ Color progressBackground;		//{{{ paintComponent() method		public void paintComponent(Graphics g)		{			Insets insets = new Insets(0,0,0,0);//MemoryStatus.this.getBorder().getBorderInsets(this);			Runtime runtime = Runtime.getRuntime();			int freeMemory = (int)(runtime.freeMemory() / 1024);			int totalMemory = (int)(runtime.totalMemory() / 1024);			int usedMemory = (totalMemory - freeMemory);			int width = MemoryStatus.this.getWidth()				- insets.left - insets.right;			int height = MemoryStatus.this.getHeight()				- insets.top - insets.bottom - 1;			float fraction = ((float)usedMemory) / totalMemory;			g.setColor(progressBackground);			g.fillRect(insets.left,insets.top,				(int)(width * fraction),				height);			String str = (usedMemory / 1024) + "/"				+ (totalMemory / 1024) + "Mb";			FontRenderContext frc = new FontRenderContext(null,false,false);			Rectangle2D bounds = g.getFont().getStringBounds(str,frc);					Graphics g2 = g.create();			g2.setClip(insets.left,insets.top,				(int)(width * fraction),				height);			g2.setColor(progressForeground);			g2.drawString(str,				insets.left + (int)(width - bounds.getWidth()) / 2,				(int)(insets.top + lm.getAscent()));			g2.dispose();			g2 = g.create();			g2.setClip(insets.left + (int)(width * fraction),				insets.top,MemoryStatus.this.getWidth()				- insets.left - (int)(width * fraction),				height);			g2.setColor(MemoryStatus.this.getForeground());			g2.drawString(str,				insets.left + (int)(width - bounds.getWidth()) / 2,				(int)(insets.top + lm.getAscent()));			g2.dispose();		} //}}}		private Timer timer;	} //}}}}

⌨️ 快捷键说明

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