commit 40e7969a6264f2d8b679d9b2b7cea0502cf14567 Author: Victor Date: Wed Nov 14 22:59:39 2018 +0200 Initial diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..feb6fce --- /dev/null +++ b/build.xml @@ -0,0 +1,83 @@ + + + + + + Builds, tests, and runs the project . + + + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml new file mode 100644 index 0000000..b1c0798 --- /dev/null +++ b/nbproject/build-impl.xml @@ -0,0 +1,1430 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Classpath to J2ME Ant extension library (libs.j2me_ant_ext.classpath property) is not set. For example: location of mobility/modules/org-netbeans-mobility-antext.jar file in the IDE installation directory. + Platform home (platform.home property) is not set. Value of this property should be ${platform.active.description} emulator home directory location. + Platform boot classpath (platform.bootclasspath property) is not set. Value of this property should be ${platform.active.description} emulator boot classpath containing all J2ME classes provided by emulator. + Must set src.dir + Must set build.dir + Must set dist.dir + Must set dist.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set preprocessed.dir + + + + + + + + + + + + + + + + + + Must set build.classes.dir + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + Must set obfuscated.classes.dir + + + + Must set obfuscated.classes.dir + Must set obfuscator.srcjar + Must set obfuscator.destjar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set preverify.classes.dir + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MicroEdition-Configuration: ${platform.configuration} + + MicroEdition-Configuration: ${platform.configuration} + + + + MicroEdition-Profile: ${platform.profile} + + MicroEdition-Profile: ${platform.profile} + + + + Must set dist.jad + + + + + + + + + + + + + + + + + + + + + + + + ${manifest.midlets}${evaluated.manifest.apipermissions}${evaluated.manifest.pushregistry}${manifest.others}${manifest.jad} + ${manifest.midlets}${evaluated.manifest.apipermissions}${evaluated.manifest.pushregistry}${manifest.others}${manifest.manifest} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Starting emulator with port number ${active.debug.port} + + + + + + + + + + + + + + + + + Starting emulator with port number ${active.debug.port} + + + + + + + + + + + + + + + + + Must set dist.javadoc.dir + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${all.configurations} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Property deployment.${deployment.method}.scriptfile not set. The property should point to an Ant script providing ${deployment.method} deployment. + + + + + + + + Classpath to Ant Contrib library (libs.ant-contrib.classpath property) is not set. + + + + + + + + + Active project configuration: @{cfg} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Property build.root.dir is not set. By default its value should be \"build\". + Property dist.root.dir is not set. By default its value should be \"dist\". + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties new file mode 100644 index 0000000..7430bcc --- /dev/null +++ b/nbproject/genfiles.properties @@ -0,0 +1,8 @@ +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +build.xml.data.CRC32=99778a95 +build.xml.script.CRC32=27b3faaf +build.xml.stylesheet.CRC32=9c6a911d +nbproject/build-impl.xml.data.CRC32=99778a95 +nbproject/build-impl.xml.script.CRC32=a9e16bc6 +nbproject/build-impl.xml.stylesheet.CRC32=7a0aeb65 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties new file mode 100644 index 0000000..5c81830 --- /dev/null +++ b/nbproject/private/private.properties @@ -0,0 +1,8 @@ +#Sat, 02 Jul 2011 16:30:45 +0300 +#Sat Dec 19 15:21:38 EET 2009 +netbeans.user=C\:\\Users\\aNNiMON\\.netbeans\\7.0 +javadoc.preview=true +config.active= +deployment.counter=47 +app-version.autoincrement=true +deployment.number=0.0.46 diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml new file mode 100644 index 0000000..c1f155a --- /dev/null +++ b/nbproject/private/private.xml @@ -0,0 +1,4 @@ + + + + diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..f6cf759 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,142 @@ +abilities=MMAPI=1.1,SATSAJCRMI=1.0,SATSACRYPTO=1.0,JSR82=1.1,NOKIAUI=1.0,JSR226=1.0,MIDP=2.1,JSR229=1.1.0,SATSAAPDU=1.0,CLDC=1.1,JSR177=1.0,JSR179=1.0.1,J2MEWS=1.0,VSCL=2.1,WMA=2.0,JSR172=1.0,SEMC_EXT_JP8=1.0,ColorScreen,OBEX=1.0,NokiaUI=1.0,JSR238=1.0,JSR239=1.0,JSR211=1.0,JSR234=1.0,ScreenWidth=240,lib/semc_ext_jp8.jar=1.0,MascotV3=1.0,JSR75=1.0,JSR184=1.1,SATSAPKI=1.0,ScreenHeight=321,ScreenColorDepth=8,JSR180=1.0.1,J2MEXMLRPC=1.0, +all.configurations=\ +application.args= +application.description= +application.description.detail= +application.name= +application.vendor=Vendor +build.classes.dir=${build.dir}/compiled +build.classes.excludes=**/*.java,**/*.form,**/*.class,**/.nbintdb,**/*.mvd,**/*.wsclient,**/*.vmd +build.dir=build/${config.active} +build.root.dir=build +debug.level=debug +debugger.timeout= +deployment.copy.target=deploy +deployment.instance=default +deployment.jarurl=${dist.jar} +deployment.method=NONE +deployment.override.jarurl=false +dist.dir=dist/${config.active} +dist.jad=Notations.jad +dist.jar=Notations.jar +dist.javadoc.dir=${dist.dir}/doc +dist.root.dir=dist +extra.classpath= +filter.exclude.tests=false +filter.excludes= +filter.more.excludes=**/overview.html,**/package.html +filter.use.standard=true +jar.compress=true +javac.debug=true +javac.deprecation=false +javac.encoding=windows-1251 +javac.optimize=false +javac.source=1.3 +javac.target=1.3 +javadoc.author=false +javadoc.encoding= +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +libs.classpath= +main.class= +main.class.class=applet +manifest.apipermissions= +manifest.file=manifest.mf +manifest.is.liblet=false +manifest.jad= +manifest.manifest= +manifest.midlets=MIDlet-1: Notations,/icon.png,Main\n +manifest.others=MIDlet-Vendor: aNNiMON\nMIDlet-Name: Notations\nMIDlet-Version: 2.0\n +manifest.pushregistry= +name=Notations +no.dependencies=false +nokiaS80.application.icon= +nsicom.application.monitorhost= +nsicom.application.runremote= +nsicom.application.runverbose= +nsicom.remoteapp.location=\\My Documents\\NetBeans Applications +nsicom.remotevm.location=\\Windows\\creme\\bin\\CrEme.exe +obfuscated.classes.dir=${build.dir}/obfuscated +obfuscation.custom=@E:\\SETUPS\\Disk\\Programming\\Java\\annimon.pro\n-optimizationpasses 9 +obfuscation.level=0 +obfuscator.destjar=${build.dir}/obfuscated.jar +obfuscator.srcjar=${build.dir}/before-obfuscation.jar +platform.active=Sony_Ericsson_SDK_2_5_0_6_for_the_Java_TM__ME_Platform_Emulator_ +platform.active.description=Sony Ericsson SDK 2.5.0.6 for the Java(TM) ME Platform(Emulator) +platform.apis=WMA-2.0,JSR211-1.0,JSR82-1.1,JSR177-1.0,JSR234-1.0,J2ME-WS-1.0,JSR239-1.0,JSR238-1.0,MMAPI-1.1,JSR226-1.0,JSR75-1.0,JSR184-1.1 +platform.bootclasspath=${platform.home}/lib/jsr226.jar:${platform.home}/lib/jsr238.jar:${platform.home}/lib/jsr211.jar:${platform.home}/lib/satsa-jcrmi.jar:${platform.home}/lib/jsr082.jar:${platform.home}/lib/satsa-apdu.jar:${platform.home}/lib/jsr184.jar:${platform.home}/lib/jsr239.jar:${platform.home}/lib/jsr75.jar:${platform.home}/lib/mmapi.jar:${platform.home}/lib/j2me-ws.jar:${platform.home}/lib/wma20.jar:${platform.home}/lib/jsr234.jar:${platform.home}/lib/cldcapi11.jar:${platform.home}/lib/midpapi20.jar +platform.configuration=CLDC-1.1 +platform.device=SonyEricsson_JP8_240x320_Emu +platform.fat.jar=true +platform.profile=MIDP-2.0 +platform.trigger=CLDC +platform.type=UEI-1.0.1 +preprocessed.dir=${build.dir}/preprocessed +preverify.classes.dir=${build.dir}/preverified +preverify.sources.dir=${build.dir}/preverifysrc +resources.dir=resources +ricoh.application.email= +ricoh.application.fax= +ricoh.application.icon= +ricoh.application.target-jar= +ricoh.application.telephone= +ricoh.application.uid=48759871 +ricoh.application.version= +ricoh.dalp.application-desc.auto-run=false +ricoh.dalp.application-desc.energy-save= +ricoh.dalp.application-desc.exec-auth= +ricoh.dalp.application-desc.visible=true +ricoh.dalp.argument= +ricoh.dalp.codebase= +ricoh.dalp.display-mode.color=true +ricoh.dalp.display-mode.is-4line-support=false +ricoh.dalp.display-mode.is-hvga-support=true +ricoh.dalp.display-mode.is-vga-support=false +ricoh.dalp.display-mode.is-wvga-support=false +ricoh.dalp.information.abbreviation= +ricoh.dalp.information.icon.basepath= +ricoh.dalp.information.icon.location= +ricoh.dalp.information.is-icon-used=true +ricoh.dalp.install.destination=hdd +ricoh.dalp.install.mode.auto=true +ricoh.dalp.install.work-dir=hdd +ricoh.dalp.is-managed=true +ricoh.dalp.resources.dsdk.version=2.0 +ricoh.dalp.resources.jar.basepath= +ricoh.dalp.resources.jar.version= +ricoh.dalp.version= +ricoh.icon.invert=false +ricoh.platform.target.version= +run.cmd.options= +run.jvmargs= +run.method=STANDARD +run.security.domain=trusted +run.use.security.domain=false +savaje.application.icon= +savaje.application.icon.focused= +savaje.application.icon.small= +savaje.application.uid=TBD +savaje.bundle.base= +savaje.bundle.debug=false +savaje.bundle.debug.port= +semc.application.caps= +semc.application.icon= +semc.application.icon.count= +semc.application.icon.splash= +semc.application.icon.splash.installonly=false +semc.application.uid=E6184713 +semc.certificate.path= +semc.private.key.password= +semc.private.key.path= +sign.alias= +sign.enabled=false +sign.keystore= +src.dir=src +use.emptyapis=true +use.preprocessor=true diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..32d8f2f --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,10 @@ + + + org.netbeans.modules.kjava.j2meproject + + + Notations + 1.6 + + + diff --git a/src/About.java b/src/About.java new file mode 100644 index 0000000..b49067d --- /dev/null +++ b/src/About.java @@ -0,0 +1,186 @@ +/* + * aNNiMON 2010 + * For more info visit http://annimon.com/ + */ + +/* + * На основе класса MultiLineText от А.С. Ледкова + * www.mobilab.ru + */ +import com.annimon.XID; +import com.annimon.ui.ESkin; +import com.annimon.ui.EWindow; +import java.util.Vector; +import javax.microedition.lcdui.*; + +public class About extends EWindow { + + private static final String PATH = "/about"; + private Font def; + private int defHeight; + private String str; // текст + + private int mh, y0; // Положение верхнего края текста + private int dy; // Шаг при прокрутке текста + private int textheight; // Общая высота текста + private Vector strLines; + + public About(String about) { + super(about); + str = new XID().loadText(PATH); + def = Font.getDefaultFont(); + dy = defHeight = def.getHeight()+2; + mh = super.hh - 1; + SetTextPar(); + } + + public void paint(Graphics g, int w, int h) { + g.setFont(def); + g.setColor(ESkin.textColor); + int y1 = y0; + for (int i = 0; i < strLines.size(); i++) { + if ((y1 + defHeight) > 0) { + g.drawString(strLines.elementAt(i).toString(), 1, 3 + y1, Graphics.LEFT | Graphics.TOP); + } + y1 += defHeight; + if (y1 > mh) break; + } + } + + public void keyEvent(int key, byte state) { + if(state!=RELEASED) { + int ga = getGameAction(key); + if(ga==UP) MoveUp(); + else if(ga==DOWN) MoveDown(); + else if(ga==LEFT) PageUp(); + else if(ga==RIGHT) PageDown(); + else if(ga==FIRE || key==KEY_LSK || key==KEY_RSK) + Main.midlet.dsp.setCurrent(Main.midlet.main); + redraw(); + } + } + + protected void pointerPressed(int x, int y) { + int w3 = w/3; + int h3 = h/3; + if(y

w3 && x<(w-w3))) keyPressed(UP); + else if(y>(h-h3) && (x>w3 && x<(w-w3))) keyPressed(DOWN); + + if(xh3 && y<(h-h3))) keyPressed(LEFT); + else if(x>(w-w3) && (y>h3 && y<(h-h3))) keyPressed(RIGHT); + + else if(x(h-h3)) keyPressed(-6); + else if(x>(w-w3) && y>(h-h3)) keyPressed(-7); + else if( (x>w3 && x<(w-w3)) && (y>h3 && y<(h-h3)) ) keyPressed(FIRE); + } + + private void SetTextPar() { + //Разбиваем строку на массив строк + strLines = null; + strLines = new Vector(); + String[] arr = splitString(str, "\n"); + for(int i=0; i w) {//Слово полностью не умещается в строке + space = i0; + while (jw > w) { + j = 0; + while (j < w) { + space++; + j = def.stringWidth(substr.substring(in, space)); + } + space = space - 1; + j = def.stringWidth(substr.substring(in, space)); + strLines.addElement(substr.substring(in, space)); + jw = jw - j; + i0 = space; + in = space; + } + jw = 0; + } else { + i0 = space; + } + } + } + strLines.addElement(substr.substring(in, imax)); + } + textheight = strLines.size() * defHeight; + } + + private void MoveDown() { + if (textheight > mh) { + y0 = y0 - dy; + if (mh - y0 > textheight) { + y0 = mh - textheight; + } + } + } + + private void MoveUp() { + if (textheight > mh) { + y0 = y0 + dy; + if (y0 > 0) { + y0 = 0; + } + } + + } + + private void PageUp() { + if (textheight > mh) { + y0 = y0 + mh; + if (y0 > 0) { + y0 = 0; + } + } + + } + + private void PageDown() { + if (textheight > mh) { + y0 = y0 - mh; + if (mh - y0 > textheight) { + y0 = mh - textheight; + } + } + } + + private String[] splitString(String str, String delim) { + if ("".equals(str) || delim == null || delim.length() == 0) return new String[]{str}; + + Vector v = new Vector(); + int pos = 0; + int newpos = str.indexOf(delim, 0); + + while (newpos != -1) { + v.addElement(str.substring(pos, newpos)); + pos = newpos + delim.length(); + newpos = str.indexOf(delim, pos); + } + v.addElement(str.substring(pos)); + + String[] s = new String[v.size()]; + v.copyInto(s); + return s; + } + +} diff --git a/src/Core.java b/src/Core.java new file mode 100644 index 0000000..8e9b384 --- /dev/null +++ b/src/Core.java @@ -0,0 +1,125 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +import com.annimon.ui.ECanvas; +import com.annimon.ui.ESkin; +import javax.microedition.lcdui.*; + +/** + * @author aNNiMON + */ +public class Core extends ECanvas { + + private static final byte DEC_TO_XXX = 0; + private static final int STEP = 10; + private static final int CELL_SIZE = 14; + + private int x, y, mode; + private Font fnt; + private int fontHeight; + private long num; // исходное число + private int osn; // основание - в какую систему счисления переводить + + public Core(long num, int osn) { + super(); + this.num = num; + this.osn = osn; + x = y = 0; + fnt = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_SMALL); + fontHeight = fnt.getHeight(); + mode = DEC_TO_XXX; + } + + public void paint(Graphics g) { + g.setColor(ESkin.bg); + g.fillRect(0, 0, w, h); + // Клеточки + g.setColor(ESkin.cellColor); + int cellSize = CELL_SIZE * w / 240; + int start = x % cellSize; + for(int xx = start; xx < w; xx += cellSize) { + g.drawLine(xx, 0, xx, h); + } + start = y % cellSize; + for (int yy = start; yy < h; yy += cellSize) { + g.drawLine(0, yy, w, yy); + } + g.setFont(fnt); + if (mode == DEC_TO_XXX) {//DEC to ??? + drawDecToXXX(g, num, osn, x, y + fontHeight); + String number = String.valueOf(num); + String result = ""; + try { + result = Long.toString(num, osn); + } catch (NumberFormatException e) { + } + g.drawString(number + "D = " + result, x, y, 20); + } + } + + + protected void sizeChanged(int w, int h) { + super.sizeChanged(w, h); + super.w = w; + super.h = h; + } + + + private void drawDecToXXX(Graphics g, long num, int osn, int x, int y) { + String number = String.valueOf(num); + int wdh = g.getFont().stringWidth(number) + 2; + g.setColor(0x00); + g.drawString(number + " " + osn, x, y, 20); + g.drawLine(x + wdh, y, x + wdh, y + 3 * fontHeight); + g.drawLine(x + wdh, y + fontHeight, x + 2 * wdh, y + fontHeight); + y += fontHeight; + int digit = (int) (num % osn); + g.drawString(String.valueOf(num - digit), x, y, 20); + num /= osn; + g.drawLine(x, y + fontHeight, x + wdh, y + fontHeight); + g.setColor(0x0000FF); + g.drawChar(toHex(digit), x + 1, y + fontHeight, 20); + x += wdh + 2; + if (num > 0) { + drawDecToXXX(g, num, osn, x, y); + } + } + + private char toHex(int value) { + if (value > 9) { + return (char) (value - 10 + 'a'); + } else { + return (char) (value + '0'); + } + } + + public void keyEvent(int key, byte state) { + if(state != RELEASED) { + int ga = getGameAction(key); + switch (ga) { + case RIGHT: + x -= STEP; + break; + case LEFT: + x += STEP; + break; + case DOWN: + y -= STEP; + break; + case UP: + y += STEP; + break; + case FIRE: + x = y = 0; + break; + default: + if(key==KEY_LSK || key==KEY_RSK || key==KEY_NUM0) + Main.midlet.dsp.setCurrent(Main.midlet.main); + break; + } + repaint(); + } + } +} \ No newline at end of file diff --git a/src/DecToXXX.java b/src/DecToXXX.java new file mode 100644 index 0000000..77909a6 --- /dev/null +++ b/src/DecToXXX.java @@ -0,0 +1,60 @@ + +import javax.microedition.lcdui.*; + +/** + * + * @author aNNiMON + */ +public class DecToXXX extends Form implements CommandListener { + + private static final String ERROR = "Ошибка"; + private Command nextCMD, backCMD; + private TextField numberTF, radixTF; + + public DecToXXX() { + super("Десятичная в ???"); + numberTF = new TextField("Исходное число в десятичной системе счисления", "", 10, TextField.NUMERIC); + radixTF = new TextField("Система счисления, в которую переводим", "", 2, TextField.NUMERIC); + nextCMD = new Command("Далее", Command.OK, 1); + backCMD = new Command("На главную", Command.BACK, 2); + addCommand(nextCMD); + addCommand(backCMD); + append(numberTF); + append(radixTF); + setCommandListener(DecToXXX.this); + } + + public void commandAction(Command c, Displayable d) { + if (c.equals(List.SELECT_COMMAND) || c.equals(nextCMD)) { + long num = 0; + int osn = 2; + try { + String numStr = numberTF.getString(); + String osnStr = radixTF.getString(); + if ("".equals(numStr) || "".equals(osnStr)) { + alert("Не заполнены поля"); + return; + } + num = Long.parseLong(numberTF.getString()); + osn = Integer.parseInt(radixTF.getString()); + if (osn < 2) { + alert("Основание должно быть не меньше 2"); + return; + }else if (osn > 36 ) { + alert("Для систем счисления больше 36 просто не хватит символов =("); + return; + } + } catch (NumberFormatException nun) { + alert("Неверные данные"); + return; + } + Main.midlet.dsp.setCurrent(new Core(num, osn)); + } else if (c.equals(backCMD)) { + Main.midlet.dsp.setCurrent(Main.midlet.main); + } + } + + private void alert(String msg) { + Main.midlet.dsp.setCurrent(new Alert(ERROR, msg, null, AlertType.ERROR), Main.midlet.dsp.getCurrent()); + } +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..97b202d --- /dev/null +++ b/src/Main.java @@ -0,0 +1,30 @@ +import javax.microedition.lcdui.*; +import javax.microedition.midlet.*; + +/** + * @author aNNiMON + */ +public class Main extends MIDlet { + + public Display dsp; + public static Main midlet; + public MenuCanvas main; + + public Main() { + midlet = Main.this; + dsp = Display.getDisplay(Main.this); + + } + + public void startApp() { + main = new MenuCanvas(); + dsp.setCurrent(main); + } + + public void pauseApp() { + } + + public void destroyApp(boolean un) { + notifyDestroyed(); + } +} diff --git a/src/MenuCanvas.java b/src/MenuCanvas.java new file mode 100644 index 0000000..e59113d --- /dev/null +++ b/src/MenuCanvas.java @@ -0,0 +1,81 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +import com.annimon.ui.EConst; +import com.annimon.ui.ESkin; +import com.annimon.ui.EWindow; +import javax.microedition.lcdui.Graphics; + +/** + * + * @author aNNiMON + */ +public class MenuCanvas extends EWindow { + + private String[] elements; + /** Позиция первого пункта меню */ + private int firstItemPosition; + /** Высота шрифта*/ + private int fontHeight; + /** Текущий выбранный пункт */ + private int itemIndex; + /** Плавность курсора */ + private int smoothCursor; + + public MenuCanvas() { + super("Notations"); + elements = new String[] {"DEC в ???", "??? в ???", "О программе", "Выход"}; + fontHeight = EConst.mainFont.getHeight() + 2; + smoothCursor = 0; + itemIndex = 0; + firstItemPosition = hh / 6; + } + + public void paint(Graphics g, int w, int h) { + int hc = firstItemPosition + smoothCursor + itemIndex * fontHeight; + g.setFont(EConst.mainFont); + g.setColor(ESkin.textColor2); + for (int i = 0; i < elements.length; i++) { + if (i == itemIndex) continue; + g.drawString(elements[i], w / 2, firstItemPosition + i * fontHeight, Graphics.HCENTER | Graphics.TOP); + } + g.setColor(ESkin.textColor); + g.drawRoundRect(5, hc, w - 10, fontHeight, 15, 15); + g.drawString(elements[itemIndex], w / 2, firstItemPosition + itemIndex * fontHeight, Graphics.HCENTER | Graphics.TOP); + if (smoothCursor < 0) { + smoothCursor += 2; + } else if (smoothCursor > 0) { + smoothCursor -= 2; + } + if (smoothCursor > 1 || smoothCursor < -1) { + redraw(); + } + } + + public void keyEvent(int key, byte state) { + if (state != RELEASED) { + int ga = getGameAction(key); + if (ga == UP && itemIndex > 0) { + itemIndex--; + smoothCursor = fontHeight; + } else if (ga == DOWN && itemIndex < elements.length - 1) { + itemIndex++; + smoothCursor = -fontHeight; + } else if (ga == FIRE) { + menuAction(itemIndex); + } + } + redraw(); + } + + private void menuAction(int itemIndex) { + switch(itemIndex) { + case 0: Main.midlet.dsp.setCurrent(new DecToXXX()); break; + case 1: Main.midlet.dsp.setCurrent(new XXXToXXX()); break; + case 2: Main.midlet.dsp.setCurrent(new About(elements[2])); break; + case 3: Main.midlet.destroyApp(true); break; + } + } +} diff --git a/src/XXXToXXX.java b/src/XXXToXXX.java new file mode 100644 index 0000000..d5ab884 --- /dev/null +++ b/src/XXXToXXX.java @@ -0,0 +1,59 @@ + +import javax.microedition.lcdui.*; + +/** + * + * @author aNNiMON + */ +public class XXXToXXX extends Form implements CommandListener { + + private Command calcCMD, backCMD; + private TextField numberTF, radixToTF, radixFromTF, resultTF; + + public XXXToXXX() { + super("??? в ???"); + numberTF = new TextField("Исходное число", "", 10, TextField.ANY); + radixFromTF = new TextField("Система счисления этого числа", "", 2, TextField.NUMERIC); + radixToTF = new TextField("Система счисления, в которую переводим", "", 2, TextField.NUMERIC); + resultTF = new TextField("Результат", "", 256, TextField.ANY); + calcCMD = new Command("Расчет", Command.OK, 1); + backCMD = new Command("На главную", Command.BACK, 2); + addCommand(calcCMD); + addCommand(backCMD); + append(numberTF); + append(radixFromTF); + append(radixToTF); + append(resultTF); + setCommandListener(XXXToXXX.this); + } + + private void alert(String msg) { + Main.midlet.dsp.setCurrent(new Alert("Ошибка", msg, null, AlertType.ERROR), Main.midlet.dsp.getCurrent()); + } + + public void commandAction(Command c, Displayable d) { + if (c.equals(List.SELECT_COMMAND) || c.equals(calcCMD)) { + int s1 = 10; + int s2 = 16; + long n1 = 0; + try { + s1 = Integer.parseInt(radixFromTF.getString().trim()); + s2 = Integer.parseInt(radixToTF.getString().trim()); + } catch (Exception ne) { + alert("Неверное число в качестве основания"); + } + if ((s1 < 2) || (s1 > 36) || (s2 < 2) || (s2 > 36)) { + alert("Основание должно быть от 2 до 36"); + return; + } + try { + n1 = Long.parseLong(numberTF.getString().trim(), s1); + } catch (Exception ne) { + alert("Неверное число для конвертирования"); + } + resultTF.setString(Long.toString(n1, s2)); + } else if (c.equals(backCMD)) { + Main.midlet.dsp.setCurrent(Main.midlet.main); + } + } +} diff --git a/src/about b/src/about new file mode 100644 index 0000000..f3e62b9 Binary files /dev/null and b/src/about differ diff --git a/src/com/annimon/StringEncoder.java b/src/com/annimon/StringEncoder.java new file mode 100644 index 0000000..2e4f333 --- /dev/null +++ b/src/com/annimon/StringEncoder.java @@ -0,0 +1,29 @@ +package com.annimon; + +public class StringEncoder { + + protected static char[] cp1251 = { + '\u0410', '\u0411', '\u0412', '\u0413', '\u0414', '\u0415', '\u0416', + '\u0417', '\u0418', '\u0419', '\u041A', '\u041B', '\u041C', '\u041D', + '\u041E', '\u041F', '\u0420', '\u0421', '\u0422', '\u0423', '\u0424', + '\u0425', '\u0426', '\u0427', '\u0428', '\u0429', '\u042A', '\u042B', + '\u042C', '\u042D', '\u042E', '\u042F', '\u0430', '\u0431', '\u0432', + '\u0433', '\u0434', '\u0435', '\u0436', '\u0437', '\u0438', '\u0439', + '\u043A', '\u043B', '\u043C', '\u043D', '\u043E', '\u043F', '\u0440', + '\u0441', '\u0442', '\u0443', '\u0444', '\u0445', '\u0446', '\u0447', + '\u0448', '\u0449', '\u044A', '\u044B', '\u044C', '\u044D', '\u044E', + '\u044F' + }; + + public static char decodeCharCP1251(byte b) { + int ich = b & 0xff; + if (ich == 0xb8) { + return 0x0451; + } else if (ich == 0xa8) { + return 0x0401; + } else if (ich >= 0xc0) { + return cp1251[ich - 192]; + } + return (char) ich; + } +} diff --git a/src/com/annimon/XID.java b/src/com/annimon/XID.java new file mode 100644 index 0000000..6c2bcec --- /dev/null +++ b/src/com/annimon/XID.java @@ -0,0 +1,47 @@ +package com.annimon; + +import java.io.*; + +/** + * + * @author aNNiMON + */ +public class XID { + + public String loadText(String path) { + try { + byte[] data = getBytes(path); + StringBuffer text = new StringBuffer(); + for(int i = 0; i < data.length; i++) { + text.append(StringEncoder.decodeCharCP1251(data[i])); + } + return text.toString(); + } catch (Exception in) { + in.printStackTrace(); + return ""; + } + } + + private byte[] getBytes(String path) throws IOException { + InputStream is = new DataInputStream(getClass().getResourceAsStream(path)); + int b1 = is.read(); + int b2 = is.read(); + int length = ((b2 << 8) | b1); + byte[] data = new byte[length]; + is.read(data, 0, length); + is.close(); + data = invertArray(data); + return data; + } + + + + private byte[] invertArray(byte[] fileData) { + int len = fileData.length; + for (int i = 0; i < len; i++) { + fileData[i] ^= 119; + } + return fileData; + } + +} diff --git a/src/com/annimon/ui/ECanvas.java b/src/com/annimon/ui/ECanvas.java new file mode 100644 index 0000000..f7cb3e7 --- /dev/null +++ b/src/com/annimon/ui/ECanvas.java @@ -0,0 +1,50 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package com.annimon.ui; + +import javax.microedition.lcdui.Canvas; + +/** + * Расширенный класс Canvas + * @author aNNiMON + */ +public abstract class ECanvas extends Canvas { + + public final int //константы клавиш + KEY_LSK = -6, //левый софт + KEY_RSK = -7; //правый софт + public final byte + PRESSED = 0, + REPEATED = 1, + RELEASED = 2; + + public int w,h; + + public ECanvas() { + setFullScreenMode(true); + w = getWidth(); + h = getHeight(); + } + + public void keyPressed(int key) { + keyEvent(key, PRESSED); + } + + public void keyRepeated(int key) { + keyEvent(key, REPEATED); + } + + public void keyReleased(int key) { + keyEvent(key, RELEASED); + } + + /** + * Обработчик клавиатуры + * @param key - код клавиши + * @param state - состояние клавиши (нажата, отпущена, зажата) + */ + public abstract void keyEvent(int key, byte state); +} diff --git a/src/com/annimon/ui/EConst.java b/src/com/annimon/ui/EConst.java new file mode 100644 index 0000000..a0886fd --- /dev/null +++ b/src/com/annimon/ui/EConst.java @@ -0,0 +1,19 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package com.annimon.ui; + +import javax.microedition.lcdui.Font; + +/** + * + * @author aNNiMON + */ +public class EConst { + + public static final Font titleFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE); + public static final Font mainFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM); + +} diff --git a/src/com/annimon/ui/ESkin.java b/src/com/annimon/ui/ESkin.java new file mode 100644 index 0000000..58a02eb --- /dev/null +++ b/src/com/annimon/ui/ESkin.java @@ -0,0 +1,21 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package com.annimon.ui; + +/** + * + * @author aNNiMON + */ +public class ESkin { + + public static int + cellColor = 0xADAFAF, // цвет клеток + textColor = 0x4D3E7E, // цвет текста + textColor2 = 0x5D5D5D, // цвет недоступного текста + lineColor = 0xEE487A, // цвет линии полей + + bg = 0xECF1FF; //фон +} \ No newline at end of file diff --git a/src/com/annimon/ui/EWindow.java b/src/com/annimon/ui/EWindow.java new file mode 100644 index 0000000..e0c1cdd --- /dev/null +++ b/src/com/annimon/ui/EWindow.java @@ -0,0 +1,87 @@ +/* + * aNNiMON 2011 + * For more info visit http://annimon.com/ + */ + +package com.annimon.ui; + +import javax.microedition.lcdui.Graphics; + +/** + * Класс окна EmOS + * @author aNNiMON + */ +public abstract class EWindow extends ECanvas { + + /** Отуступ */ + private static final int BORDER = 5; + /** Размер клеточек */ + private static final int CELL_SIZE = 14; + + /** Размеры рабочей области */ + protected int ww, hh; + + /** Заголовок окна */ + private String title; + /** Размер шрифта */ + private int fontHeight; + + public EWindow(String title) { + super(); + this.title = title; + fontHeight = EConst.titleFont.getHeight(); + ww = w - BORDER * 2; + hh = h - fontHeight - BORDER * 2; + } + + protected void sizeChanged(int w, int h) { + super.w = w; + super.h = h; + ww = w - BORDER * 2; + hh = h - fontHeight - BORDER * 2; + super.sizeChanged(w, h); + } + + + public void paint(Graphics g) { + // Задний фон + g.setColor(ESkin.bg); + g.fillRect(0, 0, w, h); + // Клеточки + g.setColor(ESkin.cellColor); + int cellSize = CELL_SIZE * w / 240; + for(int x = 0; x < w; x += cellSize) { + g.drawLine(x, 0, x, h); + } + for (int y = 0; y < h; y += cellSize) { + g.drawLine(0, y, w, y); + } + // Текст заголовка + g.setFont(EConst.titleFont); + g.setColor(ESkin.textColor); + g.drawString(title, BORDER, 0, 20); + // Линия полей + g.setColor(ESkin.lineColor); + int y = fontHeight + BORDER / 2; + g.drawLine(0, y, w, y); + // Ограничение рабочей области + g.setClip(BORDER, fontHeight + BORDER, ww, hh); + g.translate(BORDER, fontHeight + BORDER); + + paint(g, ww, hh); + } + + /** Перерисовка рабочей области окна */ + protected void redraw() { + repaint(BORDER, fontHeight + BORDER, ww, hh); + } + + /** + * Метод отрисовки рабочей области окна + * @param g - Graphics + * @param w - ширина рабочей области + * @param h - высота рабочей области + */ + public abstract void paint(Graphics g, int w, int h); + +} diff --git a/src/icon.png b/src/icon.png new file mode 100644 index 0000000..1d36344 Binary files /dev/null and b/src/icon.png differ