/* * MessageEdit.java * * Created on 20.02.2005, 21:20 * * Copyright (c) 2005-2007, Eugene Stahov (evgs), http://bombus-im.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * You can also redistribute and/or modify this program under the * terms of the Psi License, specified in the accompanied COPYING * file, as published by the Psi Project; either dated January 1st, * 2005, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package Client; import Conference.AppendNick; import archive.ArchiveList; import javax.microedition.lcdui.*; import locale.SR; import ui.Time; import ui.VirtualList; //#if CLIPBOARD_EVGS //# import ui.ClipBoard; //#elif CLIPBOARD import util.ClipBoard; // //#endif /** * * @author Eugene Stahov */ public class MessageEdit implements CommandListener, Runnable { private Display display; private Displayable parentView; private TextBox t; private String body; private String subj; private Contact to; //private Command cmdSuspend=new Command(SR.MS_SUSPEND, Command.BACK,90); private Command cmdSuspend; //=new Command(SR.MS_SUSPEND, Command.BACK,90); private Command cmdCancel=new Command(SR.MS_CANCEL, Command.SCREEN,99); //private Command cmdSend=new Command(SR.MS_SEND, Command.OK /*Command.SCREEN*/,1); private Command cmdSend; //=new Command(SR.MS_SEND, Command.OK /*Command.SCREEN*/,1); private Command cmdSmile=new Command(SR.MS_ADD_SMILE, Command.SCREEN,2); private Command cmdInsNick=new Command(SR.MS_NICKNAMES,Command.SCREEN,3); private Command cmdInsMe=new Command(SR.MS_SLASHME, Command.SCREEN, 4); ; // /me private Command cmdSubj=new Command(SR.MS_SET_SUBJECT, Command.SCREEN, 10); //#if (CLIPBOARD_EVGS || CLIPBOARD) private Command cmdPaste=new Command(SR.MS_PASTE, Command.SCREEN, 5); //10? //#endif private Command cmdArchive=new Command(SR.MS_ARCHIVE, Command.SCREEN, 6); private Command cmdABC=new Command("Abc", Command.SCREEN, 15); private Command cmdAbc=new Command("abc", Command.SCREEN, 15); //#if PREV_MSG private Command cmdPrevMessage=new Command(SR.MS_PREVIOUS, Command.SCREEN, 11); //#endif //#ifdef CLIPBOARD private ClipBoard clipboard; //#endif private Config cf=Config.getInstance(); private boolean composing=true; //private Command cmdSubject=new Command("Subject",Command.SCREEN,10); /** Creates a new instance of MessageEdit */ public MessageEdit(Display display, Contact to, String body) { this.to=to; this.display=display; parentView=display.getCurrent(); int maxSize=500; t=new TextBox(to.toString(), null, maxSize, TextField.ANY); try { //expanding buffer as much as possible maxSize=t.setMaxSize(4096); //must not trow if (body!=null) { //trim body to maxSize if (body.length()>maxSize) body=body.substring(0, maxSize-1); t.setString(body); } } catch (Exception e) { t.setString(""); } if (!cf.swapSendAndSuspend) { //<+voffk> cmdSuspend=new Command(SR.MS_SUSPEND, Command.BACK, 90); cmdSend=new Command(SR.MS_SEND, Command.OK, 1); } else { cmdSuspend=new Command(SR.MS_SUSPEND, Command.OK, 1); cmdSend=new Command(SR.MS_SEND, Command.BACK, 90); } t.addCommand(cmdSend); t.addCommand(cmdInsMe); t.addCommand(cmdSmile); if (to.origin>=Contact.ORIGIN_GROUPCHAT) t.addCommand(cmdInsNick); //#if PREV_MSG if (to.previousMessage!=null) t.addCommand(cmdPrevMessage); //#endif //#ifdef CLIPBOARD if (cf.useClipBoard) { clipboard=ClipBoard.getInstance(); if (!clipboard.isEmpty()) t.addCommand(cmdPaste); } //#endif t.addCommand(cmdArchive); //#if CLIPBOARD_EVGS //# if (ClipBoard.hasData()) t.addCommand(cmdPaste); //#endif t.addCommand(cmdSuspend); t.addCommand(cmdCancel); t.setCommandListener(this); if (to.origin==Contact.ORIGIN_GROUPCHAT) t.addCommand(cmdSubj); //t.setInitialInputMode("MIDP_LOWERCASE_LATIN"); new Thread(this).start() ; // composing setInitialCaps(cf.capsState); //<*voffk> display.setCurrent(t); } public void insertText(String s, int caretPos) { String src=t.getString(); StringBuffer sb=new StringBuffer(s); //if (caretPos<0) caretPos=src.length(); if (caretPos>0) if (src.charAt(caretPos-1)!=' ') sb.insert(0, ' '); if (caretPos if (body!=null || subj!=null ) { String from=StaticData.getInstance().account.toString(); Msg msg=new Msg(Msg.MESSAGE_TYPE_OUT,from,subj,body); msg.id=id; // не добавляем в групчат свои сообщения // не шлём composing if (to.origin!=Contact.ORIGIN_GROUPCHAT) { to.addMessage(msg); comp="active"; // composing event in message } } else if (to.acceptComposing) comp=(composing)? "composing":"paused"; if (!cf.eventComposing) comp=null; //<*voffk> try { if (body!=null || subj!=null || comp!=null) { //#if PREV_MSG to.previousMessage=body; //#endif r.sendMessage(to, id, body, subj, comp); } } catch (Exception e) { //#if DEBUG e.printStackTrace(); //#endif } //#ifdef AUTOSCROLLING try { ((ContactMessageList)parentView).forceScrolling(); } catch (Exception e) { } //#else //# ((VirtualList)parentView).redraw(); //#endif } public void destroyView(){ if (display!=null) display.setCurrent(parentView); } private void setInitialCaps(boolean state) { t.setConstraints(state? TextField.INITIAL_CAPS_SENTENCE: TextField.ANY); t.removeCommand(state? cmdABC: cmdAbc); t.addCommand(state? cmdAbc: cmdABC); cf.capsState=state; //<*voffk> } }