📄 listcomposemsg.java
字号:
/**
* Class : short description
* @author Michele 'Miccar' Cardinale miccar@gmail.com
* @author Natale Vinto ebballon@interfree.it
* @version 1.0
*/
/*
* goText : text messaging over GPRS
* Copyright (C) 2006 Natale Vinto <ebballon@interfree.it>
* OpenJLab Group www.openjlab.org
* Copyright (C) 2006 Michele Cardinale 'Miccar' <miccar@gmail.com>
* www.miccar.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.
*
* 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 program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
import javax.microedition.lcdui.*;
public class ListComposeMsg extends List implements CommandListener {
protected Message m;
protected Service s;
protected goText gotext;
protected Lang l;
private Command command_back;
private String[] list_string;
private Image[] list_image={null,null,null,null};
public ListComposeMsg(goText gotext,Message m,Service s) {
super("",List.IMPLICIT);
this.gotext=gotext;
this.m=m;
this.s=s;
l=new Lang(gotext.lang);
this.setTitle(s.getName());
list_string=new String[4];
list_string[0]=l.LCM_TEXT;
list_string[1]=l.LCM_DEST;
list_string[2]=l.COMMAND_SEND;
list_string[3]=l.LCM_SAVE;
this.start();
}
private void start(){
m.setForService(s);
for (int i=0;i<list_image.length;i++){
this.append(list_string[i], list_image[i]);
}
command_back=new Command(l.COMMAND_BACK,Command.BACK,4);
this.addCommand(command_back);
this.setCommandListener(this);
this.refresh();
}
public void refresh(){
Image ico_yes=null,ico_no=null,ico_invia=null,ico_salva=null;
try{
ico_yes = Image.createImage("/img/ok.png");
ico_no = Image.createImage("/img/no.png");
ico_invia = Image.createImage("/img/invia.png");
ico_salva = Image.createImage("/img/salva.png");
} catch (Exception e){}
list_string[0]=l.LCM_TEXT+" ("+m.getText().length()+"/"+s.getMaxCharsWithSign()+")";
if((m.getText().length()>0)&&(m.getText().length()<=s.getMaxCharsWithSign())){
list_image[0]=ico_yes;
} else {
list_image[0]=ico_no;
}
list_string[1]=l.LCM_DEST+" ("+m.getRecipientsArray().length+"/"+s.getMaxRecipients()+")";
if((m.getRecipients().length()>0)||(s.getMaxRecipients()==0)){
list_image[1]=ico_yes;
} else {
list_image[1]=ico_no;
}
if(m.isReadyToSend(s)){ //INVIA
list_image[2]=ico_invia;
} else {
list_image[2]=ico_no;
}
if(m.getText().length()>0){//SALVA
list_image[3]=ico_salva;
} else {
list_image[3]=ico_no;
}
for (int i=0;i<list_string.length;i++){
this.set(i,list_string[i], list_image[i]);
}
this.show();
}
public void show(){
gotext.display.setCurrent(this);
}
public void commandAction(Command c, Displayable d){
if (c==List.SELECT_COMMAND){
switch(this.getSelectedIndex()){
case 0:
new TextForm();
break;
case 1:
new RecipientsForm();
break;
case 2:
if(m.isReadyToSend(s)){
gotext.last_message=new Message(m);
new FormSend(gotext, s, m);
} else {
utils.popup(l.ALERT_WARNING_TITLE, l.ALERT_WARNING1, gotext, AlertType.WARNING);
}
break;
case 3:
if(m.getText().length()>0){
int response=m.saveMessage(false);
if(response>0){
utils.popup(l.ALERT_INFO_TITLE, l.ALERT_INFO , gotext, AlertType.INFO);
} else if(response==-2){
utils.popup(l.ALERT_WARNING_TITLE, l.ALERT_WARNING2+" "+m.MAX_MEM_MESSAGES+" "+l.ALERT_WARNING2_2, gotext, AlertType.WARNING);
} else {
utils.popup(l.ALERT_ERROR_TITLE, l.ALERT_ERROR1, gotext, AlertType.ERROR);
}
} else {
utils.popup(l.ALERT_WARNING_TITLE, l.ALERT_WARNING3, gotext, AlertType.WARNING);
}
break;
}
} else if (c==command_back){
gotext.last_message=new Message(m);
new ListMessages(gotext,s);
}
}
private class TextForm extends TextBox implements CommandListener {
static final int TEXTFORM_MAX_CHARS=1000;
private Command command_pul,command_ok,command_compr;
public TextForm(){
super(l.LCM_WRITE, "", 600, TextField.ANY);
this.start();
}
private void start(){
this.setMaxSize(TEXTFORM_MAX_CHARS);
if(m.getText().length()<=TEXTFORM_MAX_CHARS){
this.setString(m.getText());
} else {
this.setString(m.getText().substring(0, TEXTFORM_MAX_CHARS));
}
command_ok=new Command(l.COMMAND_OK,Command.SCREEN,1);
command_pul=new Command(l.COMMAND_PUL,Command.SCREEN,2);
command_compr=new Command(l.COMMAND_COMPR,Command.SCREEN,3);
this.addCommand(command_ok);
this.addCommand(command_pul);
this.addCommand(command_compr);
this.setCommandListener(this);
if(gotext.options.getCharsCounter()>0)
new ContaCaratteri().start();
this.show();
}
public void show(){
gotext.display.setCurrent(this);
}
public void commandAction(Command c, Displayable d){
if (c==command_pul){
this.setString("");
} else if (c==command_ok){
m.setText(this.getString());
ListComposeMsg.this.refresh();
} else if (c==command_compr){
m.setText(this.getString());
new FormCompressText();
}
}
private class ContaCaratteri extends Thread{
public void run(){
while(true){
if(TextForm.this.isShown()){
TextForm.this.setTitle(TextForm.this.getString().length()+"/"+s.getMaxCharsWithSign());
try{
this.sleep(1000);
}catch(Exception e){}
}
}
}
}
public class FormCompressText extends Form implements CommandListener,ItemStateListener{
private Command command_back,command_ok;
private StringItem stringitem_text;
private Gauge gauge_compressor;
private int compression_level=0;
public FormCompressText() {
super(l.LCM_COMPRESS);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -