📄 listmodservices.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.*;
import javax.microedition.io.*;
import java.io.*;
public class ListModServices extends List implements CommandListener{
protected goText gotext;
protected Lang l;
private Command command_back,command_new,command_del,command_mod,command_up,command_down;
public ListModServices(goText gotext) {
super("",List.IMPLICIT);
this.gotext=gotext;
l=new Lang(gotext.lang);
this.setTitle(l.LMS_TITLE);
this.start();
}
private void start(){
this.setTitle(l.LMS_TITLE+": "+gotext.services.length);
if(gotext.services.length==0){
this.setTicker(new Ticker(l.LMS_NOSERVICE));
} else {
Image ico_yes=null,ico_no=null;
try{
ico_yes = Image.createImage("/img/ok.png");
ico_no = Image.createImage("/img/no.png");
} catch (Exception e){}
for(int i=0;i<gotext.services.length;i++){
if(gotext.services[i].isConfigured())
this.append(gotext.services[i].getName(), ico_yes);
else
this.append(gotext.services[i].getName(), ico_no);
}
}
command_new=new Command(l.COMMAND_NEW,Command.SCREEN,1);
command_mod=new Command(l.COMMAND_MOD,Command.SCREEN,2);
command_del=new Command(l.COMMAND_DEL,Command.SCREEN,3);
command_up=new Command(l.COMMAND_UP,Command.SCREEN,4);
command_down=new Command(l.COMMAND_DOWN,Command.SCREEN,5);
command_back=new Command(l.COMMAND_BACK,Command.BACK,6);
if(gotext.services.length<Service.MAX_MEM_SERVICES) this.addCommand(command_new);
this.addCommand(command_mod);
this.addCommand(command_del);
this.addCommand(command_up);
this.addCommand(command_down);
this.addCommand(command_back);
this.setCommandListener(this);
this.show();
}
public void show(){
gotext.display.setCurrent(this);
}
public void commandAction(Command c, Displayable d){
if (c==List.SELECT_COMMAND||c==command_mod){
if (this.getSelectedIndex()>=0) {
new FormModService(gotext, gotext.services[this.getSelectedIndex()]);
}
} else if (c==command_back){
new ListSettings(gotext);
} else if (c==command_new){
new FormNewService(gotext);
} else if (c==command_up){
try{
Service.switchServicePosition(gotext.services[this.getSelectedIndex()], gotext.services[this.getSelectedIndex()-1]);
new ListModServices(gotext);
}catch (Exception e){
//IGNORO
}
} else if (c==command_down){
try{
Service.switchServicePosition(gotext.services[this.getSelectedIndex()], gotext.services[this.getSelectedIndex()+1]);
new ListModServices(gotext);
}catch (Exception e){
//IGNORO
}
} else if (c==command_del){
if(this.getSelectedIndex()>=0){
Service.delService(gotext.services[this.getSelectedIndex()].getRmsId());
new ListModServices(gotext);
}
}
}
public class FormModService extends Form implements CommandListener{
private Service s;
private Command command_back,command_app;
private TextField textfield_name,textfield_user,textfield_pass,textfield_nick,textfield_sign;
private StringItem stringitem_address;
transient String old_name;
public FormModService(goText gotext, Service s) {
super(l.LMS_CONFSERV);
this.s=s;
this.old_name=s.getName();
this.start();
}
private void start(){
textfield_name=new TextField(l.LMS_NAMESERV,s.getName(),16,TextField.ANY);
stringitem_address=new StringItem(l.LMS_URL, s.getAddress());
textfield_user=new TextField("User "+(s.getNeedUser()==1?l.LMS_REQUIRED:l.LMS_OPTIONAL)+":",s.getUser(),30,TextField.ANY);
textfield_pass=new TextField("Pass "+(s.getNeedPass()==1?l.LMS_REQUIRED:l.LMS_OPTIONAL)+":",s.getPass(),30,TextField.PASSWORD);
textfield_nick=new TextField("Nick "+(s.getNeedNick()==1?l.LMS_REQUIRED:l.LMS_OPTIONAL)+":",s.getNick(),30,TextField.ANY);
textfield_sign=new TextField(l.LMS_SIGN,s.getSign(),30,TextField.ANY);
this.append(textfield_name);
this.append(stringitem_address);
if(s.getNeedUser()>0) this.append(textfield_user);
if(s.getNeedPass()>0) this.append(textfield_pass);
if(s.getNeedNick()>0) this.append(textfield_nick);
this.append(textfield_sign);
command_app=new Command(l.COMMAND_APP,Command.SCREEN,1);
command_back=new Command(l.COMMAND_BACK,Command.BACK,2);
this.addCommand(command_app);
this.addCommand(command_back);
this.setCommandListener(this);
this.show();
}
public void show(){
gotext.display.setCurrent(this);
}
public void commandAction(Command c, Displayable d){
if (c==command_back){
new ListModServices(gotext);
} else if (c==command_app){
if((!this.old_name.equals(textfield_name.getString()))&&(Service.existServiceName(textfield_name.getString()))){
utils.popup(l.ALERT_WARNING_TITLE, l.ALERT_WARNING8, gotext, AlertType.WARNING);
} else {
s.set(this.textfield_name.getString(), s.getAddress(), s.getNeedUser(), this.textfield_user.getString(), s.getNeedPass(), this.textfield_pass.getString(), s.getNeedNick(), this.textfield_nick.getString(), s.getMaxRecipients(), s.getMaxChars(), s.getMaxMsg(), s.getSentMsg(),s.getIsNumericRecipient(), this.textfield_sign.getString());
new ListModServices(gotext);
}
}
}
}
public class FormNewService extends Form implements CommandListener{
private Command command_back,command_ins;
private TextField textfield_servicename,textfield_serviceaddress;
public FormNewService(goText gotext) {
super(l.LMS_NEWSERV);
this.start();
}
private void start(){
textfield_servicename=new TextField(l.LMC_NAME,"",16,TextField.ANY);
textfield_serviceaddress=new TextField(l.LMS_URL,"http://",255,TextField.URL);
this.append(textfield_servicename);
this.append(textfield_serviceaddress);
command_ins=new Command(l.COMMAND_INS,Command.SCREEN,1);
command_back=new Command(l.COMMAND_BACK,Command.BACK,2);
this.addCommand(command_ins);
this.addCommand(command_back);
this.setCommandListener(this);
this.show();
}
public void show(){
gotext.display.setCurrent(this);
}
public void commandAction(Command c, Displayable d){
if (c==command_back){
new ListModServices(gotext);
} else if (c==command_ins){
//Effettua il controllo sui dati inseriti e invia la richiesta
if(Service.existServiceName(this.textfield_servicename.getString())){
utils.popup(l.ALERT_WARNING_TITLE, l.ALERT_WARNING8, gotext, AlertType.WARNING);
} else {
this.append(l.LMS_WAIT);
Send send=new Send(this.textfield_servicename.getString(),this.textfield_serviceaddress.getString());
new Thread(send).start();
}
}
}
class Send implements Runnable{
private HttpConnection c;
private InputStream is;
private OutputStream os;
private String name,address;
private String buffer="";
public Send(String name,String address){
this.name=name;
this.address=address;
}
private void processaRisposta(String stringa){//DA IMPLEMENTARE
String config=utils.getTag(stringa, "config");
if(config.length()>0){
String t=utils.getTag(config, "t");
String nu=utils.getTag(config, "nu");
String np=utils.getTag(config, "np");
String nn=utils.getTag(config, "nn");
String mr=utils.getTag(config, "mr");
String mc=utils.getTag(config, "mc");
String mm=utils.getTag(config, "mm");
String sm=0+"";
String in=utils.getTag(config, "in");
int k=Service.insServiceConfig(name, address, nu, np, nn, mr, mc, mm, sm, in);
if (k>0){
FormNewService.this.append(l.LMS_SUCCESS);
FormNewService.this.show();
if(t.length()>0)
t=l.LMS_MESSERV+""+t;
utils.popup(l.ALERT_INFO_TITLE, l.LMS_SUCCESS1+""+t, gotext, AlertType.INFO);
} else {
FormNewService.this.append(l.LMS_ERROR);
FormNewService.this.show();
utils.popup(l.ALERT_ERROR_TITLE, l.LMS_ERROR1+" (err:"+k+")", gotext,AlertType.ERROR);
}
} else {
FormNewService.this.append(l.LMS_ERROR);
FormNewService.this.show();
utils.popup(l.ALERT_ERROR_TITLE, l.LMS_ERROR2+""+stringa, gotext, AlertType.ERROR);
}
}
public void run(){
try {
c=null;
is=null;
os=null;
String request="action=config";
if(gotext.options.getConnectionMethod()==0){
byte[] data = request.getBytes();
c = (HttpConnection)Connector.open(address,Connector.READ_WRITE);
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
c.setRequestProperty("Content-Length",String.valueOf(data.length));
c.setRequestProperty("Connection", "close");
os = c.openOutputStream();
os.write(data);
//os.flush();
os.close();
} else {
c = (HttpConnection)Connector.open(address+"?"+request);
//c.setRequestProperty("Connection", "close");
}
int rc=c.getResponseCode();
if (rc==200) {
is = c.openInputStream();
int ch;
while ((ch = is.read()) != -1) {
buffer=buffer+( (char)ch );
}
is.close();
} else {
buffer="Errore Response Code ("+rc+")";
}
}catch (Exception e) {
buffer=l.FS_ERROR_GPRS;
}finally {
if (os != null)
try {
os.close();
} catch (Exception e) {}
if (is != null)
try {
is.close();
} catch (Exception e) {}
if (c != null)
try{
c.close();
} catch (Exception e){}
processaRisposta(buffer);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -