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

📄 textlist.java.svn-base

📁 类似QQ的功能
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
	public void selectFirstTextIndex()	{		int size = lines.size();		TextLine line;		for (int i = 0; i < size; i++)		{			line = getLine(i);			if (line.bigTextIndex == -1) continue;			setCurrentItem(i);			break;		}		line = null;	}		public String getTextByIndex(int offset, boolean wholeText, int textIndex)	{		StringBuffer result = new StringBuffer();				// Fills the lines		int size = lines.size();		TextLine line;		for (int i = 0; i < size; i++)		{			line = getLine(i);			if (wholeText || (textIndex == -1) || (line.bigTextIndex == textIndex))			{				line.readText(result);				if (line.last_charaster != '\0')				{					if (line.last_charaster == '\n') result.append("\n");					else result.append(line.last_charaster);				}			}		}		line = null;				if (result.length() == 0) return null;		String resultText = result.toString();		int len = resultText.length();		if (offset > len) return null;		return resultText.substring(offset, len);	}		public void selectTextByIndex(int textIndex)	{		if (textIndex == -1) return;		int size = lines.size();		for (int i = 0; i < size; i++)		{			if (getLine(i).bigTextIndex == textIndex)			{				setCurrentItem(i);				break;			}		}	}	// Returns lines of text which were added by 	// methon addBigText in current selection	public String getCurrText(int offset, boolean wholeText)	{		return getTextByIndex(offset, wholeText, getCurrTextIndex());	}	public int getCurrTextIndex()	{		int currItemIndex = getCurrIndex();		if ((currItemIndex < 0) || (currItemIndex >= lines.size())) return -1;		return getLine(currItemIndex).bigTextIndex;	}	public void setColors(int capTxt, int capbk, int bkgrnd, int cursor, int text, int crsFrame, int cursorAlpha, int menuAlpha)	{		if (getTextColor() != text)		{			Enumeration allLines = lines.elements();			while (allLines.hasMoreElements())				((TextLine) allLines.nextElement()).setItemColor(text);		}		super.setColors(capTxt, capbk, bkgrnd, cursor, text, crsFrame, cursorAlpha, menuAlpha);	}	public TextList doCRLF(int blockTextIndex)	{		if (lines.size() != 0) ((TextLine) lines.lastElement()).last_charaster = '\n';		TextLine newLine = new TextLine();		newLine.bigTextIndex = blockTextIndex;		lines.addElement(newLine);		return this;	}		public TextList addAniImage(Image[] image, byte[] imgNumsAndTimes, String altarnateText, int blockTextIndex)	{		if (lines.isEmpty()) lines.addElement(new TextLine());		TextLine textLine = (TextLine) lines.lastElement();		textLine.bigTextIndex = blockTextIndex;				if ((textLine.getWidth(getFontSize()) + image[0].getWidth()) > getTextAreaWidth())		{			doCRLF(blockTextIndex);			textLine = (TextLine) lines.lastElement();		}		TextItem newItem = new TextItem();		newItem.image = image;		newItem.imgNumsAndTimes = imgNumsAndTimes;		newItem.text = altarnateText;		textLine.add(newItem);				boolean lastAnimated = animated; 		animated |= (image.length > 1);		if (lastAnimated != animated) startAnimationTask();				return this;	}	public TextList addImage(Image image, String altarnateText, int blockTextIndex)	{		return addAniImage(new Image[] {image}, null, altarnateText, blockTextIndex);	}	public TextList insertAniImage(Image[] image, byte[] imgNumsAndTimes, String altarnateText, int blockTextIndex, int textLineIndex)	{		if (lines.isEmpty())		{			lines.addElement(new TextLine());			textLineIndex = 0;		}		else		{			lines.insertElementAt(new TextLine(), textLineIndex);		}		TextLine textLine = (TextLine) lines.elementAt(textLineIndex);		textLine.bigTextIndex = blockTextIndex;				if ((textLine.getWidth(getFontSize()) + image[0].getWidth()) > getTextAreaWidth())		{			doCRLF(blockTextIndex);			textLine = (TextLine) lines.lastElement();		}		TextItem newItem = new TextItem();		newItem.image = image;		newItem.imgNumsAndTimes = imgNumsAndTimes;		newItem.text = altarnateText;		textLine.add(newItem);				boolean lastAnimated = animated; 		animated |= (image.length > 1);		if (lastAnimated != animated) startAnimationTask();				return this;	}	public TextList insertImage(Image image, String altarnateText, int blockTextIndex, int textLineIndex)	{		return insertAniImage(new Image[] {image}, null, altarnateText, blockTextIndex, textLineIndex);	}	private int getTextAreaWidth()	{		return getWidthInternal() - scrollerWidth - borderWidth*2;	}	private static String replace(String text, String from, String to)	{		int fromSize = from.length();		int pos;		for (;;)		{			pos = text.indexOf(from);			if (pos == -1) break;			text = text.substring(0, pos) + to + text.substring(pos + fromSize, text.length());		}		return text;	}	private void addBigTextInternal(String text, int color, int fontStyle, int textIndex, int trueWidth)	{		Font font;		int textLen, curPos, lastWordEnd, startPos, width, testStringWidth = 0;		char curChar;		boolean lineBreak, wordEnd, textEnd, divideLineToWords;		String testString = null;				if (text == null)			return;				if (color == -1) color = getTextColor();		else if ((color&0xFF000000) != 0)		{			Integer indexedColor = (Integer)indexedColors.get(new Integer(color));			if (indexedColor != null) color = (0xFF000000&color)|indexedColor.intValue(); 		}				// Replace '\r\n' charasters with '\n'		text = replace(text, "\r\n", "\n");		// Replace '\r' charasters with '\n'		text = replace(text, "\r", "\n");		font = getQuickFont(fontStyle);		// Width of free space in last line 		width = lines.isEmpty() ? trueWidth : trueWidth - ((TextLine) lines.lastElement()).getWidth(getFontSize());		// Start pos of new line		startPos = 0;		// Pos of last word end		lastWordEnd = -1;		textLen = text.length();		String insString;		for (curPos = 0; curPos < textLen;)		{			curChar = text.charAt(curPos);			wordEnd = (curChar == ' ');			lineBreak = (curChar == '\n');			textEnd = (curPos == (textLen - 1));			divideLineToWords = false;			if (textEnd && (!lineBreak)) curPos++;			if (lineBreak || textEnd || wordEnd)			{				testString = text.substring(startPos, curPos);				testStringWidth = font.stringWidth(testString);			}			// simply add line			if ((lineBreak || textEnd) && (testStringWidth <= width))			{				internAdd(testString, color, -1, fontStyle, textIndex, lineBreak, lineBreak ? '\n' : ' ');				width = trueWidth;				curPos++;				startPos = curPos;				lastWordEnd = -1;				continue;			}			if ((lineBreak || textEnd || wordEnd) && (testStringWidth > width))			{				if ((testStringWidth < trueWidth) && (lastWordEnd != -1))				{					divideLineToWords = true;				}				// Insert new line and try again				else if ((trueWidth != width) && (lastWordEnd == -1))				{					doCRLF(textIndex);					curPos = startPos;					width = trueWidth;					lastWordEnd = -1;					continue;				}			}			if ((lineBreak || textEnd || wordEnd) && (testStringWidth > trueWidth) && (!divideLineToWords))			{				// divide big word to several lines				if (lastWordEnd == -1)				{					for (; curPos >= 1; curPos--)					{						testString = text.substring(startPos, curPos);						if (font.stringWidth(testString) <= width) break;					}					internAdd(testString, color, -1, fontStyle, textIndex, true, '\0');					width = trueWidth;					startPos = curPos;					lastWordEnd = -1;					continue;				}				// several words in line				else				{					divideLineToWords = true;				}			}			if (divideLineToWords)			{				insString = text.substring(startPos, lastWordEnd);				internAdd(insString, color, -1, fontStyle, textIndex, true, ' ');				curPos = lastWordEnd + 1;				startPos = curPos;				width = trueWidth;				lastWordEnd = -1;				continue;			}			if (wordEnd) lastWordEnd = curPos;			curPos++;		}	}	//! Add big multiline text. 	/*! Text visial width can be larger then screen width.	 Method addBigText automatically divides text to short lines 	 and adds lines to text list */	public TextList addBigText(String text, //!< Text to add		int color, //!< Text color		int fontStyle, //!< Text font style. See MID profile for details		int textIndex //!< Whole text index	)	{		addBigTextInternal(text, color, fontStyle, textIndex, getTextAreaWidth());		invalidate();		return this;	}		public boolean replaceImages(int textIndex, Image from, Image to)	{		boolean replaced = false;		TextLine textLine;		for (int i = getSize()-1; i >= 0; i--)		{			textLine = (TextLine) lines.elementAt(i);			if (textLine.bigTextIndex != textIndex) continue;			replaced |= textLine.replaceImages(from, to);		}		textLine = null;		return replaced;	}	// TODO: full rewrite code below!	static public int getLineNumbers(String s, int width, int fontSize, int fontStyle, int textColor)	{		TextList paintList = new TextList(null);		paintList.setFontSize(fontSize);		paintList.addBigTextInternal(s, textColor, fontStyle, -1, width);		return (paintList.getSize());	}	static public void showText(Graphics g, String s, int x, int y, int width, int height, int fontSize, int fontStyle, int textColor)	{		TextList paintList = new TextList(null);		paintList.setFontSize(fontSize);		paintList.addBigTextInternal(s, textColor, fontStyle, -1, width);		int line, textHeight = 0;		int linesCount = paintList.getSize();		for (line = 0; line < linesCount; line++)			textHeight += paintList.getLine(line).getHeight(fontSize);		int top = y + (height - textHeight) / 2;		for (line = 0; line < linesCount; line++)		{			paintList.getLine(line).paint(x, top, g, fontSize, paintList, false);			top += paintList.getLine(line).getHeight(fontSize);		}	}		protected void onShow() 	{		if (animated)		{			startAnimationTask();		}		else if (!animated && (aniTimerTask != null))		{			aniTimerTask.cancel();			aniTimerTask = null;		}	}		public void run()	{		int menuBarHeight;//#sijapp cond.if target="RIM" | target="DEFAULT"#		menuBarHeight = 0;//#sijapp cond.else#				menuBarHeight = getMenuBarHeight();//#sijapp cond.end#				drawItems(null, getCapHeight(), menuBarHeight, DMS_CUSTOM, -1, -1, -1, -1);	}		protected void onHide() 	{		resetAnimationTask();	}		private void startAnimationTask()	{		if (aniTimerTask != null) aniTimerTask.cancel();				aniTimerTask = new TimerTask() 		{			public void run()			{				getDisplay().callSerially(TextList.this);			}		};				aniTimer.schedule(aniTimerTask, 100, 100);				//System.out.println("startAnimationTask");	}		private void resetAnimationTask()	{		if (aniTimerTask != null)		{			aniTimerTask.cancel();			aniTimerTask = null;			//System.out.println("resetAnimationTask");		}	}		public void addTextItem(String string, Image image, int index, int fontStyle)	{		if (fontStyle == -1) fontStyle = Font.STYLE_PLAIN;		if (image != null)		{			addImage(image, null, index);			addBigText(" ", getTextColor(), fontStyle, index);		}		addBigText(string, getTextColor(), fontStyle, index);		doCRLF(index);	}		public int getLastTextIndex()	{		int size = getSize();		if (size == 0) return -1;		return getLine(size-1).bigTextIndex; 	}		public void setIndexedColor(int color, int value)	{		Integer colorInt = new Integer(color);		Integer lastValueInt = (Integer)indexedColors.get(colorInt);		int lastValue = (lastValueInt == null) ? -1 : lastValueInt.intValue();		if (value != lastValue)		{			for (int i = getSize()-1; i >= 0; i--) getLine(i).setIndexedColor(color, value);			indexedColors.put(colorInt, new Integer(value));		}	}	}

⌨️ 快捷键说明

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