📄 emotions.java.svn-base
字号:
findedEmotions.addElement(new int[] { findedIndex, len, index }); } static public void addTextWithEmotions(TextList textList, String text, int fontStyle, int textColor, int bigTextIndex) { if (!used || !Options.getBoolean(Options.OPTION_USE_SMILES)) { textList.addBigText(text, textColor, fontStyle, bigTextIndex); return; } String loweredText = text.toLowerCase(); for (int i = emoFinded.length - 1; i >= 0; i--) emoFinded[i] = true; int startIndex = 0; int size; int count; int imgIndex; Image[] imgSeq; byte[] timeSeq; for (;;) { findedEmotions.removeAllElements(); size = textCorrWords.length; for (int i = 0; i < size; i++) findEmotionInText(loweredText, textCorrWords[i], textCorrIndexes[i], startIndex, i); if (findedEmotions.isEmpty()) break; count = findedEmotions.size(); int minIndex = 100000, data[] = null, minArray[] = null; for (int i = 0; i < count; i++) { data = (int[]) findedEmotions.elementAt(i); if (data[0] < minIndex) { minIndex = data[0]; minArray = data; } } if (startIndex != minIndex) textList.addBigText(text.substring(startIndex, minIndex), textColor, fontStyle, bigTextIndex); imgIndex = minArray[2]; imgSeq = (Image[])imagesData.elementAt(imgIndex); timeSeq = (byte[])timeData.elementAt(imgIndex); textList.addAniImage(imgSeq, timeSeq, text.substring(minIndex, minIndex + minArray[1]), bigTextIndex); startIndex = minIndex + minArray[1]; } imgSeq = null; timeSeq = null; int lastIndex = text.length(); if (lastIndex != startIndex) textList.addBigText(text.substring(startIndex, lastIndex), textColor, fontStyle, bigTextIndex); } /////////////////////////////////// // // // UI for emotion selection // // // /////////////////////////////////// private static Command cmdOk = new Command(ResourceBundle.getString("select"), Command.OK, 1); private static Command cmdCancel = new Command(ResourceBundle.getString("cancel"), Jimm.cmdBack, 2); private static String emotionText; private static Selector selector; private static int caretPos; private static TextBox textBox; private static TimerTask aniTask; static public void aniEmoTimer() { if (selector == null) return; Selector.counter += 2; Selector._this.repaint(); } static public void selectEmotion(TextBox textBox) { Emotions.caretPos = textBox.getCaretPosition(); Emotions.textBox = textBox; selector = new Selector(); JimmUI.setColorScheme(selector, false, -1, true); selector.addCommandEx(cmdOk, VirtualList.MENU_TYPE_RIGHT_BAR); selector.addCommandEx(cmdCancel, VirtualList.MENU_TYPE_LEFT_BAR); selector.setCommandListener(_this); selector.activate(Jimm.display); if (animated) { aniTask = new TimerTasks(TimerTasks.TYPE_SMILES_SEL_ANI); new Timer().schedule(aniTask, 200, 200); } } public void commandAction(Command c, Displayable d) { Jimm.aaUserActivity(); if (c == cmdOk) select(); else if (c == cmdCancel) { Jimm.display.setCurrent(textBox); Jimm.setBkltOn(true); } } public void vlKeyPress(VirtualList sender, int keyCode, int type) { } public void vlCursorMoved(VirtualList sender) { } public void vlItemClicked(VirtualList sender) { select(); } static private void select() { textBox.insert(" " + Emotions.getSelectedEmotion() + " ", caretPos); Jimm.display.setCurrent(textBox); Jimm.setBkltOn(true); } static public String getSelectedEmotion() { return emotionText; } static public boolean isMyOkCommand(Command command) { return (command == cmdOk); } ///////////////////////// // // // class Selector // // // ///////////////////////// static class Selector extends VirtualList implements VirtualListCommands { static private int cols, rows, itemHeight, itemWidth, curCol, lastRow; static int counter; static Selector _this; static { curCol = 0; lastRow = 0; } Selector() { super(null); _this = this; setVLCommands(this); int drawWidth = getWidth()-2*borderWidth-scrollerWidth; setMode(CURSOR_MODE_ENABLED); itemWidth = itemHeight = 0; Image[] images; int w; int h; for (int i = 0; i < imagesData.size(); i++) { images = (Image[])imagesData.elementAt(i); if (images == null) continue; w = images[0].getWidth(); h = images[0].getHeight(); if (w > itemWidth) itemWidth = w; if (h > itemHeight) itemHeight = h; } images = null; int layer = (itemWidth < 30) ? 5 : 0; itemWidth += layer; itemHeight += layer; cols = drawWidth / itemWidth; rows = (selEmotionsIndexes.length + cols - 1) / cols; setCurrentItem(lastRow); showCurrSmileName(); } protected void getCurXVals(int[] values) { values[0] = borderWidth+curCol*itemWidth; values[1] = borderWidth+(curCol+1)*itemWidth; } //#sijapp cond.if target is "MIDP2"# protected boolean pointerPressedOnUtem(int index, int x, int y, int mode) { int lastCol = curCol; curCol = x / itemHeight; if (curCol < 0) curCol = 0; if (curCol >= cols) curCol = cols - 1; if (lastCol != curCol) { showCurrSmileName(); invalidate(); } return false; } //#sijapp cond.end# protected void drawItemData(Graphics g, int index, int x1, int y1, int x2, int y2, int paintMode) { int xa, xb; int startIdx = cols * index; int imagesCount = imagesData.size(); int smileIdx; int imgIndex; byte[] timeSeq; Image img; xa = x1; for (int i = 0; i < cols; i++, startIdx++) { if (startIdx >= selEmotionsIndexes.length) break; smileIdx = selEmotionsIndexes[startIdx]; xb = xa + itemWidth; if (smileIdx < imagesCount) { if (animated) { timeSeq = (byte[])timeData.elementAt(smileIdx); imgIndex = (timeSeq == null) ? 0 : 0xFF&(int)timeSeq[counter%timeSeq.length]; } else imgIndex = 0; img = ((Image[])imagesData.elementAt(smileIdx))[imgIndex]; g.drawImage(img, (xa+xb-img.getWidth()+1)/2, (y1+y2-img.getHeight()+1)/2, Graphics.TOP | Graphics.LEFT); } xa = xb; } img = null; } protected void onHide() { System.out.println("Emotions.onHide()"); if (aniTask != null) { aniTask.cancel(); aniTask = null; } selector = null; } static private void showCurrSmileName() { lastRow = _this.getCurrIndex(); int selIdx = lastRow * cols + curCol; if (selIdx >= selEmotionsSmileNames.length) return; emotionText = selEmotionsWord[selIdx]; String emoName = selEmotionsSmileNames[selIdx]; _this.setCaption(setName != null ? emoName+" ["+setName+"]" : emoName); } public int getItemHeight(int itemIndex) { return itemHeight; } protected int getSize() { return rows; } protected void get(int index, ListItem item) { } public void vlKeyPress(VirtualList sender, int keyCode, int type) { if (type == VirtualList.KEY_PRESSED) { int lastCol = curCol; int curRow = getCurrIndex(); int rowCount = getSize(); switch (getGameAction(keyCode)) { case Canvas.LEFT: if (curCol != 0) curCol--; else if (curRow != 0) { curCol = cols - 1; curRow--; } else { curCol = (selEmotionsIndexes.length - 1) % cols; curRow = rowCount - 1; } break; case Canvas.RIGHT: if (curCol < (cols - 1)) curCol++; else if (curRow < rowCount-1) { curCol = 0; curRow++; } else { curCol = 0; curRow = 0; } break; } setCurrentItem(curRow); int index = curCol + getCurrIndex() * cols; if (index >= selEmotionsIndexes.length-1) curCol = (selEmotionsIndexes.length - 1) % cols; if (lastCol != curCol) { invalidate(); showCurrSmileName(); } } } public void vlCursorMoved(VirtualList sender) { showCurrSmileName(); } public void vlItemClicked(VirtualList sender) { select(); } }}//#sijapp cond.end#
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -