From bd3ac77767bcf6de5a317b7bb08911c6616f5ba7 Mon Sep 17 00:00:00 2001 From: Victor Date: Wed, 14 Nov 2018 19:46:26 +0200 Subject: [PATCH] 04 --- res/lang/strings_en.loc | 12 +- res/lang/strings_ru.loc | 12 +- src/main/L.java | 12 +- src/main/P.java | 4 +- src/main/text.txt | 5 +- src/midedit/CompositionForm.java | 2 - src/midedit/Constants.java | 31 -- src/midedit/DrumsCanvas.java | 8 +- src/midedit/MidiFile.java | 1 - src/midedit/MixerCanvas.java | 59 ++-- src/midedit/MixerModel.java | 2 +- src/midedit/NotesCanvas.java | 16 -- src/midedit/TempoList.java | 267 ++++++++---------- src/midedit/io/AbstractFile.java | 66 +++-- src/midedit/io/JSR75File.java | 80 +----- src/midedit/io/RMSFile.java | 20 +- src/midedit/media/Composition.java | 18 -- src/midedit/media/PreviewPlayer.java | 56 ++++ src/ui/FileManager.java | 76 +++-- src/ui/Menu.java | 2 +- src/ui/NewFolderForm.java | 60 ++++ src/ui/{SettingsUI.java => SettingsForm.java} | 16 +- src/ui/TextView.java | 6 + src/ui/UI.java | 70 +---- src/util/BufDataInputStream.java | 62 ---- src/util/StringEncoder.java | 24 +- 26 files changed, 454 insertions(+), 533 deletions(-) create mode 100644 src/midedit/media/PreviewPlayer.java create mode 100644 src/ui/NewFolderForm.java rename src/ui/{SettingsUI.java => SettingsForm.java} (81%) diff --git a/res/lang/strings_en.loc b/res/lang/strings_en.loc index ec109cc..e14e1c4 100644 --- a/res/lang/strings_en.loc +++ b/res/lang/strings_en.loc @@ -56,12 +56,12 @@ Meter Play Play origin Ok -Up one level +Language (need to restart) Delete -Choose folder -Open file +Instruments language +Note width Please wait -Updating list +Note height Save in this folder Insert tempo Delete tempo @@ -91,4 +91,6 @@ Key map Quick commands Navigation Nums, otherwise keypad, when edit notes -Name \ No newline at end of file +Name +Temp directory +New folder \ No newline at end of file diff --git a/res/lang/strings_ru.loc b/res/lang/strings_ru.loc index b666e1d..ef5f88b 100644 --- a/res/lang/strings_ru.loc +++ b/res/lang/strings_ru.loc @@ -56,12 +56,12 @@ Играть Играть оригинал Ok -Назад +Язык (необходим рестарт) Удалить -Выбрать папку -Открытый файл +Язык инструментов +Ширина ноты Пожалуйста, подождите -Обновление списка +Высота ноты Сохранить здесь Вставить Темп Удалить Темп @@ -91,4 +91,6 @@ Ok Быстрые команды Навигация Цифрами, иначе джойстиком, при редактировании нот -Имя \ No newline at end of file +Имя +Временная папка +Новая папка \ No newline at end of file diff --git a/src/main/L.java b/src/main/L.java index 7e51948..f8bb90a 100644 --- a/src/main/L.java +++ b/src/main/L.java @@ -70,12 +70,12 @@ public class L { play = 55, playOrigin = 56, ok = 57, - upOneLevel = 58, + language = 58, delete = 59, - chooseFolder = 60, - openFile = 61, + instrlang = 60, + noteWidth = 61, pleaseWait = 62, - updatingList = 63, + noteHeight = 63, saveInThisFolder = 64, insertTempo = 65, deleteTempo = 66, @@ -105,7 +105,9 @@ public class L { quickCommands = 90, navigation = 91, numkeysOptionString = 92, - midiName = 93; + midiName = 93, + tempDir = 94, + newFolder = 95; /** */ diff --git a/src/main/P.java b/src/main/P.java index 89289ba..f95955c 100644 --- a/src/main/P.java +++ b/src/main/P.java @@ -31,8 +31,8 @@ public class P { // //title and soft - public static int colup = 0xD0604080; - public static int coldn = 0xD0754E9C; + public static int colup = 0x593C77; + public static int coldn = 0x926DB6; // public static int backgrnd = 0xFFFFFF; // diff --git a/src/main/text.txt b/src/main/text.txt index 372c189..332f904 100644 --- a/src/main/text.txt +++ b/src/main/text.txt @@ -5,10 +5,11 @@ MIDedit 2.1 / 3.0 - .mid, .MID - . - . . - + - , , . + - . + - ( ) . ******** . - - Help aNMPWR player.realize \ No newline at end of file diff --git a/src/midedit/CompositionForm.java b/src/midedit/CompositionForm.java index 7624230..33cf6c2 100644 --- a/src/midedit/CompositionForm.java +++ b/src/midedit/CompositionForm.java @@ -358,7 +358,6 @@ public class CompositionForm extends Form implements CommandListener, Runnable, } else if (command == addInstrument) { isAdd = true; display.setCurrent(getListOfInstruments()); - System.out.println("displayable = " + displayable); } else if (command == setInstrument) { isAdd = false; display.setCurrent(getListOfInstruments()); @@ -467,7 +466,6 @@ public class CompositionForm extends Form implements CommandListener, Runnable, return null; }*/ private Form getListOfInstruments() { - System.out.println("in getListInstruments"); if (listInstrumentsForm == null) { ChoiceGroup[] groupsChoiseGroup = new ChoiceGroup[16]; for (int i = 0; i < 16; i++) { diff --git a/src/midedit/Constants.java b/src/midedit/Constants.java index f1790ff..0550f9f 100644 --- a/src/midedit/Constants.java +++ b/src/midedit/Constants.java @@ -1,7 +1,6 @@ package midedit; import java.util.Vector; -import main.Rms; import main.L; //import java.util.*; @@ -56,37 +55,7 @@ public class Constants { * */ public static final int MAX_NOTE_LENGTH = 8; // min == 1/(2^5) - /** - * - */ - public final static String[] KEY_MAP = { - "", L.str[L.menu], - "", L.str[L.back], - ",<5>", L.str[L.insertNoteWithCurrentAttributes] + "\n" + L.str[L.noteAttributeHelp], - "<9>,", L.str[L.deleteNote], - "", L.str[L.undo], - "", L.str[L.noteVolume], - - "<1>", L.str[L.playFromCurrent], - "<3>", L.str[L.playNoteOnCursor], - "<7>,", L.str[L.selectNoteAttribute], - "<*>,<#>,<0>", L.str[L.changeNoteAttribute], - Rms.numKeysEdit ? "<4>,<6>,<2>,<8>" : ",,,", L.str[L.navigationOnComposition], - Rms.numKeysEdit ? ",,," : "<4>,<6>,<2>,<8>", L.str[L.quicknav],}; - public final static String[] QUICK_COMMANDS = { - "<1> ", L.str[L.markBegin], - "<2> ", L.str[L.markEnd], - "<3> ", L.str[L.copy], - "<4> ", L.str[L.pasteInsert], - "<5> ", L.str[L.pasteReplace], - "<6> ", L.str[L.pasteOverwrite], - "<7> ", L.str[L.shiftDelete], - "<8> ", L.str[L.clean], - "<9> ", L.str[L.playChannelOnScreen], - "<*> ", L.str[L.undo], - "<0> ", L.str[L.playChannelAll], - "<#> ", L.str[L.redo]}; static VectorArr instrVectorArr = new VectorArr(L.instr, 1, 128); diff --git a/src/midedit/DrumsCanvas.java b/src/midedit/DrumsCanvas.java index 539d14d..97b31bd 100644 --- a/src/midedit/DrumsCanvas.java +++ b/src/midedit/DrumsCanvas.java @@ -85,13 +85,7 @@ protected void doSmallDown (){ for(int i=0; i", L.str[L.menu], + "", L.str[L.back], + ",<5>", L.str[L.insertNoteWithCurrentAttributes] + "\n" + L.str[L.noteAttributeHelp], + "<9>,", L.str[L.deleteNote], + "", L.str[L.undo], + "", L.str[L.noteVolume], + "<1>", L.str[L.playFromCurrent], + "<3>", L.str[L.playNoteOnCursor], + "<7>,", L.str[L.selectNoteAttribute], + "<*>,<#>,<0>", L.str[L.changeNoteAttribute], + Rms.numKeysEdit ? "<4>,<6>,<2>,<8>" : ",,,", L.str[L.navigationOnComposition], + Rms.numKeysEdit ? ",,," : "<4>,<6>,<2>,<8>", L.str[L.quicknav] + }; + TextView tv = new TextView(createString(KEY_MAP), L.str[L.keymap], MixerCanvas.this); + MixerCanvas.this.display.setCurrent(tv); return true; } }; @@ -1425,10 +1439,22 @@ abstract public class MixerCanvas extends Canvas implements Runnable { MenuItem quickItem = new MenuItem(L.str[L.quickCommands], 0) { public boolean actionPerformed() { - Form form = new Form(L.str[L.quickCommands], createStringItems(Constants.QUICK_COMMANDS)); - form.addCommand(CompositionForm.ok); - form.setCommandListener(Options.this); - MixerCanvas.this.display.setCurrent(form); + String[] QUICK_COMMANDS = { + "<1> ", L.str[L.markBegin], + "<2> ", L.str[L.markEnd], + "<3> ", L.str[L.copy], + "<4> ", L.str[L.pasteInsert], + "<5> ", L.str[L.pasteReplace], + "<6> ", L.str[L.pasteOverwrite], + "<7> ", L.str[L.shiftDelete], + "<8> ", L.str[L.clean], + "<9> ", L.str[L.playChannelOnScreen], + "<*> ", L.str[L.undo], + "<0> ", L.str[L.playChannelAll], + "<#> ", L.str[L.redo] + }; + TextView tv = new TextView(createString(QUICK_COMMANDS), L.str[L.quickCommands], MixerCanvas.this); + MixerCanvas.this.display.setCurrent(tv); return true; } }; @@ -1447,13 +1473,12 @@ abstract public class MixerCanvas extends Canvas implements Runnable { } - private Item[] createStringItems(String strings[]) { - StringItem[] strItem = new StringItem[strings.length / 2]; + private String createString(String[] strings) { + StringBuffer sb = new StringBuffer(); for (int i = 0; i < strings.length / 2; i++) { - strItem[i] = new StringItem(strings[i * 2], strings[i * 2 + 1], 1); - strItem[i].setFont(P.smPlain); + sb.append(strings[i * 2]).append(" - ").append(strings[i * 2 + 1]).append('\n'); } - return strItem; + return sb.toString(); } public void commandAction(Command c, Displayable displayable) { diff --git a/src/midedit/MixerModel.java b/src/midedit/MixerModel.java index 2683777..7ff9e67 100644 --- a/src/midedit/MixerModel.java +++ b/src/midedit/MixerModel.java @@ -31,7 +31,7 @@ public class MixerModel extends Thread { static AbstractFile rmsFile = new RMSFile(), //localFile,//=rmsFile, jsr75File;//=rmsFile;// = new JSR75File(); - AbstractPlayer crossPlayer = null; + public AbstractPlayer crossPlayer = null; public MixerModel() { try { diff --git a/src/midedit/NotesCanvas.java b/src/midedit/NotesCanvas.java index bdfefaf..265f90a 100644 --- a/src/midedit/NotesCanvas.java +++ b/src/midedit/NotesCanvas.java @@ -31,14 +31,6 @@ public class NotesCanvas extends MixerCanvas { channel = ch; } - /** - * - * @return - */ - public int getChannel() { - return channel; - } - /** * * @return @@ -55,14 +47,6 @@ public class NotesCanvas extends MixerCanvas { return true; } - /** - * - * @return - */ - protected String getCurTuneString() { - return "none"; - } - /** * * @param g diff --git a/src/midedit/TempoList.java b/src/midedit/TempoList.java index a7178ac..f9cb303 100644 --- a/src/midedit/TempoList.java +++ b/src/midedit/TempoList.java @@ -1,7 +1,5 @@ package midedit; - - import midedit.media.Composition; import javax.microedition.lcdui.*; import java.util.*; @@ -9,165 +7,150 @@ import javax.microedition.lcdui.List; import main.L; import main.P; - /** * * @author user */ -public class TempoList extends List implements CommandListener -{ - private Composition composition; - private MixerModel model; - private Displayable backForm; - private Vector tempNotes; - static private Command instempo = new Command(L.str[L.insertTempo],Command.ITEM, 1); - static private Command deltempo = new Command(L.str[L.deleteTempo],Command.ITEM, 1); - private int tick = 0; - private int meterNom=4,meterDenom=4; - private int editNum = -1; +public class TempoList extends List implements CommandListener { - /** - * - * @param c - * @param m - * @param back - */ - public TempoList(Composition c,MixerModel m,Displayable back) - { - super(L.str[L.tempo],IMPLICIT); - composition = c; - model = m; - backForm = back; - tempNotes = new Vector(); - meterNom = composition.getNom(); - meterDenom = 1<=0) - delTemp(editNum); - editNum = -1; - - int tempMsPer4 = Composition.getMsPer4(Integer.parseInt(tempoField.getString(), - 10)); - int time = tick * Integer.parseInt(timeField.getString(), 10); - NoteLong noteTemp = composition.addTemp(time, tempMsPer4); - Note note; - int ind; - for (ind = 0; ind < tempNotes.size(); ++ind) { - note = (NoteLong) tempNotes.elementAt(ind); - if (note.t > time) - break; - } - tempNotes.insertElementAt(noteTemp, ind); - TempoList.this.insert(ind, getTempoString(noteTemp, tempMsPer4), null); + private String getTempoString(Note note, int tempMsPer4) { + int tempBPM; + int mod = (composition.getTicksPer4() << 2) >> (composition.getDenomE()); + tempBPM = Composition.getTempBeatPerMin(tempMsPer4); + return "" + note.t / tick + ":" + (note.t * meterNom / tick) % meterNom + ":" + + note.t % mod + " - " + tempBPM; } - model.display.setCurrent(TempoList.this); - } - }); - model.display.setCurrent(textBoxTemp); - } - private void delTemp(int ind) - { - composition.delTemp( (NoteLong) tempNotes.elementAt(ind)); - tempNotes.removeElementAt(ind); - this.delete(ind); - } + private void viewInsertForm(int time, int tempo) { + Form textBoxTemp = new Form(L.str[L.insertTempo]); + final TextField timeField = new TextField(L.str[L.time], "" + time, 4, TextField.NUMERIC); + textBoxTemp.append(timeField); + final TextField tempoField = new TextField(L.str[L.tempo], "" + tempo, 4, TextField.NUMERIC); + textBoxTemp.append(tempoField); + textBoxTemp.addCommand(CompositionForm.ok); + textBoxTemp.addCommand(P.comCancel); + textBoxTemp.setCommandListener(new CommandListener() { - /** - * - * @param command - * @param displayable - */ - public void commandAction(Command command, Displayable displayable) - { - if(command == instempo) - { - editNum = -1; - viewInsertForm(0,120); + public void commandAction(Command command, Displayable displayable) { + if (command == CompositionForm.ok) { + if (editNum >= 0) { + delTemp(editNum); + } + editNum = -1; - } - else if(command == deltempo) - { + int tempMsPer4 = Composition.getMsPer4(Integer.parseInt(tempoField.getString(), + 10)); + int time = tick * Integer.parseInt(timeField.getString(), 10); + NoteLong noteTemp = composition.addTemp(time, tempMsPer4); + Note note; + int ind; + for (ind = 0; ind < tempNotes.size(); ++ind) { + note = (NoteLong) tempNotes.elementAt(ind); + if (note.t > time) { + break; + } + } + tempNotes.insertElementAt(noteTemp, ind); + TempoList.this.insert(ind, getTempoString(noteTemp, tempMsPer4), null); - if(tempNotes.size()>1) - { - delTemp(this.getSelectedIndex()); - } - } - else if(command == CompositionForm.back) - { - model.display.setCurrent(backForm); - } - else - { - int ind = this.getSelectedIndex(); + } + model.display.setCurrent(TempoList.this); + } + }); + model.display.setCurrent(textBoxTemp); - NoteLong notelong = (NoteLong)tempNotes.elementAt(ind); - int tmp = 0; - for (int i = 3; i <= 5; ++i) { - tmp = (tmp << 8) | 0xff & notelong.dat[i]; - } + } - int mod = (composition.getTicksPer4() << 2) >> (composition.getDenomE()); - int tempBPM =Composition.getTempBeatPerMin(tmp); - int time = notelong.t/tick; + private void delTemp(int ind) { + composition.delTemp((NoteLong) tempNotes.elementAt(ind)); + tempNotes.removeElementAt(ind); + this.delete(ind); + } - editNum = ind; + /** + * + * @param command + * @param displayable + */ + public void commandAction(Command command, Displayable displayable) { + if (command == instempo) { + editNum = -1; + viewInsertForm(0, 120); - viewInsertForm(time,tempBPM); + } else if (command == deltempo) { - } - } + if (tempNotes.size() > 1) { + delTemp(this.getSelectedIndex()); + } + } else if (command == CompositionForm.back) { + model.display.setCurrent(backForm); + } else { + int ind = this.getSelectedIndex(); + + NoteLong notelong = (NoteLong) tempNotes.elementAt(ind); + int tmp = 0; + for (int i = 3; i <= 5; ++i) { + tmp = (tmp << 8) | 0xff & notelong.dat[i]; + } + + int mod = (composition.getTicksPer4() << 2) >> (composition.getDenomE()); + int tempBPM = Composition.getTempBeatPerMin(tmp); + int time = notelong.t / tick; + + editNum = ind; + + viewInsertForm(time, tempBPM); + + } + } } diff --git a/src/midedit/io/AbstractFile.java b/src/midedit/io/AbstractFile.java index 97dbae4..9eff9bb 100644 --- a/src/midedit/io/AbstractFile.java +++ b/src/midedit/io/AbstractFile.java @@ -1,6 +1,7 @@ package midedit.io; import java.io.*; +import java.util.Vector; /** * @@ -8,6 +9,7 @@ import java.io.*; */ public abstract class AbstractFile { + public static final String[] types = {"mid", "midi"}; /** * */ @@ -21,22 +23,6 @@ public abstract class AbstractFile { */ public abstract String[] list(String pathName); - /** - * - * @return - */ - public final String getLastListPath() { - return lastPath; - } - - /** - * - * @param pathName - * @return - * @throws IOException - */ - public abstract boolean isDirectory(String pathName) throws IOException; - /** * * @param fileDescriptor @@ -125,7 +111,7 @@ public abstract class AbstractFile { * * @return */ - protected abstract String getPrefix(); + public abstract String getPrefix(); /** * @@ -138,4 +124,50 @@ public abstract class AbstractFile { * @return */ public abstract String getAns(); + + /** + * . + * , + * @param files + * @param reverse true - + * @return + */ + protected static String[] bubbleSort(Vector files) { + String tmp; + for (int i = files.size() - 1; i >= 0; i--) { + for (int j = 0; j < i; j++) { + if ((tmp = (String) files.elementAt(j)).toLowerCase().compareTo(((String) files.elementAt(j + 1)).toLowerCase()) > 0) { + files.setElementAt((String) files.elementAt(j + 1), j); + files.setElementAt(tmp, j + 1); + } + } + } + String[] arr = sortFiles(files); + return arr; + } + + /** + * . + * , . + * @param files + * @return + */ + private static String[] sortFiles(Vector files) { + int length = files.size(); + String[] out = new String[length]; + int i = 0; + for (int j = 0; j < length; j++) { + if (((String)files.elementAt(j)).indexOf("/") != -1) { + out[i] = ((String)files.elementAt(j)); + i++; + } + } + for (int k = 0; k < length; k++) { + if (((String)files.elementAt(k)).indexOf("/") == -1) { + out[i] = ((String)files.elementAt(k)); + i++; + } + } + return out; + } } diff --git a/src/midedit/io/JSR75File.java b/src/midedit/io/JSR75File.java index 0a3d2a7..0e19068 100644 --- a/src/midedit/io/JSR75File.java +++ b/src/midedit/io/JSR75File.java @@ -35,10 +35,16 @@ public class JSR75File extends AbstractFile { currDir = (FileConnection) Connector.open("file://" + pathName, Connector.READ); en = currDir.list(); } - // + // while(en.hasMoreElements()) { String s1 = (String) en.nextElement(); - vector.addElement(s1); + for(int i=0; i= 0; i--) { - for (int j = 0; j < i; j++) { - if ((tmp = (String) files.elementAt(j)).toLowerCase().compareTo(((String) files.elementAt(j + 1)).toLowerCase()) > 0) { - files.setElementAt((String) files.elementAt(j + 1), j); - files.setElementAt(tmp, j + 1); - } - } - } - String[] arr = sortFiles(files); - return arr; - } - - /** - * . - * , . - * @param files - * @return - */ - private static String[] sortFiles(Vector files) { - int length = files.size(); - String[] out = new String[length]; - int i = 0; - for (int j = 0; j < length; j++) { - if (((String)files.elementAt(j)).indexOf("/") != -1) { - out[i] = ((String)files.elementAt(j)); - i++; - } - } - for (int k = 0; k < length; k++) { - if (((String)files.elementAt(k)).indexOf("/") == -1) { - out[i] = ((String)files.elementAt(k)); - i++; - } - } - return out; - } } diff --git a/src/midedit/io/RMSFile.java b/src/midedit/io/RMSFile.java index f88103b..f1781b9 100644 --- a/src/midedit/io/RMSFile.java +++ b/src/midedit/io/RMSFile.java @@ -1,6 +1,7 @@ package midedit.io; import java.io.*; +import java.util.Vector; import javax.microedition.rms.*; /** @@ -17,8 +18,19 @@ public class RMSFile extends AbstractFile { private int recordID = 0; public String[] list(String pathName) { + Vector vector = new Vector(); String[] fileList = RecordStore.listRecordStores(); - return fileList; + for (int idx = 0; idx < fileList.length; idx++) { + String s1 = fileList[idx]; + for(int i=0; i 0) { + // + vt.addElement(L.str[L.open]); + if (getType(TypeMid, data[curFiles])) { + vt.addElement(L.str[L.playStop]); + //vt.addElement(L.str[L.openToBuffer]); + } } } + if((numFiles > 0) && !data[curFiles].endsWith("/")) vt.addElement(L.str[L.delete]); vt.addElement(L.str[L.cancel]); menu = new String[vt.size()]; vt.copyInto(menu); @@ -254,17 +264,39 @@ public class FileManager extends Canvas { nextDir(fileSelected); P.path = pathFile; } - else if (cur.equals(L.str[L.play])) { + else if (cur.equals(L.str[L.playStop])) { // - /*if (getType(TypeMid, fileSelected)) { - Image img = JSR75.getImage(pathFile, fileSelected); - PPM.midlet.imgname = fileSelected.substring(0, fileSelected.lastIndexOf('.')); - PPM.dsp.setCurrent(new Viewer(img, this)); - } else if (getType(TypePpf, fileSelected)) { - Image img = JSR75.getPPFImage(pathFile, fileSelected); - PPM.dsp.setCurrent(new Viewer(img, this)); + if (getType(TypeMid, fileSelected)) { + if(pw.isPlaying()) { + // + try { + pw.stop(); + pw.close(); + } catch (Exception ex) { + ex.printStackTrace(); + } + } else { + String openPath = fileSelected; + if(!P.isRMSMode) openPath = file.getPrefix() + pathFile + fileSelected; + try { + pw.play(openPath); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + } + else if (cur.equals(L.str[L.delete])) { + if(!fileSelected.endsWith("/")) { + String fileToDelete = fileSelected; + if(!P.isRMSMode) fileToDelete = pathFile + fileSelected; + try { + file.delete(fileToDelete); + update(); + } catch (IOException ex) { + ex.printStackTrace(); + } } - P.path = pathFile;*/ } else if (cur.equals( L.str[L.cancel])) { // @@ -289,11 +321,11 @@ public class FileManager extends Canvas { Main.dsp.setCurrent(new SaveName_frm(this, pathFile)); } - /*else if (cur.equals(L.str[L.newFolder])) { + else if (cur.equals(L.str[L.newFolder])) { // NewFolderForm newFolder = new NewFolderForm(L.str[L.newFolder], this, pathFile); - PPM.dsp.setCurrent(newFolder); - }*/ + Main.dsp.setCurrent(newFolder); + } } /** */ @@ -365,7 +397,7 @@ public class FileManager extends Canvas { } public void keyPressed(int i) { - super.keyPressed(i); + int ga = getGameAction(i); if (showMenu) { // - diff --git a/src/ui/Menu.java b/src/ui/Menu.java index 7ec5d0b..9fbb65d 100644 --- a/src/ui/Menu.java +++ b/src/ui/Menu.java @@ -216,7 +216,7 @@ public class Menu extends Canvas { } // else if(v.equals(L.str[L.options])) { - Main.dsp.setCurrent(new SettingsUI(this)); + Main.dsp.setCurrent(new SettingsForm(this)); } // else if(v.equals(L.str[L.help])) { diff --git a/src/ui/NewFolderForm.java b/src/ui/NewFolderForm.java new file mode 100644 index 0000000..304aded --- /dev/null +++ b/src/ui/NewFolderForm.java @@ -0,0 +1,60 @@ +package ui; + +import java.io.IOException; +import javax.microedition.io.Connector; +import javax.microedition.io.file.FileConnection; +import javax.microedition.lcdui.*; +import main.L; +import main.P; + +/** + * + * @author aNNiMON + */ +public class NewFolderForm extends Form implements CommandListener { + + private Command ok, back; + private FileManager fm; + private String basePath; + private TextField newFolderTF; + + public NewFolderForm(String title, FileManager prev, String p) { + super(title); + basePath = p; + fm = prev; + newFolderTF = new TextField("", "NewFolder", 60, TextField.ANY); + ok = new Command(L.str[L.ok], Command.OK, 1); + back = new Command(L.str[L.back], Command.BACK, 3); + append(newFolderTF); + addCommand(back); + addCommand(ok); + setCommandListener(NewFolderForm.this); + } + + public void commandAction(Command c, Displayable d) { + if (c == back) { + fm.setCurrent(false); + } else if ((c == ok || c == List.SELECT_COMMAND)) { + makeFile(basePath, newFolderTF.getString()); + basePath = null; + newFolderTF = null; + fm.pathFile = P.path; + fm.setCurrent(true); + } + } + + /** + * + * @param path + * @param name + */ + private void makeFile(String path, String name) { + try { + FileConnection fc = (FileConnection) Connector.open("file://" + path + name); + fc.mkdir(); + P.path += name + "/"; + fc.close(); + } catch (IOException io) { + } + } +} diff --git a/src/ui/SettingsUI.java b/src/ui/SettingsForm.java similarity index 81% rename from src/ui/SettingsUI.java rename to src/ui/SettingsForm.java index 007ec29..668e62e 100644 --- a/src/ui/SettingsUI.java +++ b/src/ui/SettingsForm.java @@ -7,7 +7,7 @@ import main.*; * * @author aNNiMON */ -public class SettingsUI extends Form implements CommandListener { +public class SettingsForm extends Form implements CommandListener { private static final String[] langAppList = {"English", ""}; private static final String[] langInstrList = {"English", ""}; @@ -21,7 +21,7 @@ public class SettingsUI extends Form implements CommandListener { private Gauge noteWidthGauge; private TextField tempDirField; - public SettingsUI(Displayable prev) { + public SettingsForm(Displayable prev) { super(L.str[L.options]); previousScreen = prev; initComponents(); @@ -35,7 +35,7 @@ public class SettingsUI extends Form implements CommandListener { append(tempDirField); addCommand(ok); addCommand(back); - setCommandListener(SettingsUI.this); + setCommandListener(SettingsForm.this); } private void initComponents() { @@ -44,18 +44,18 @@ public class SettingsUI extends Form implements CommandListener { back = new Command(L.str[L.back], Command.BACK, 3); // - langChoice = new ChoiceGroup("Language", ChoiceGroup.EXCLUSIVE, langAppList, null); - langInstr = new ChoiceGroup("Instruments Language", ChoiceGroup.EXCLUSIVE, langInstrList, null); + langChoice = new ChoiceGroup(L.str[L.language], ChoiceGroup.EXCLUSIVE, langAppList, null); + langInstr = new ChoiceGroup(L.str[L.instrlang], ChoiceGroup.EXCLUSIVE, langInstrList, null); // - noteHeightGauge = new Gauge("Note Height", true, 10, Rms.noteHeight); - noteWidthGauge = new Gauge("Note Length", true, 10, Rms.noteWidth); + noteWidthGauge = new Gauge(L.str[L.noteWidth], true, 10, Rms.noteWidth); + noteHeightGauge = new Gauge(L.str[L.noteHeight], true, 10, Rms.noteHeight); // controlChoice = new ChoiceGroup(L.str[L.navigation], ChoiceGroup.MULTIPLE); // - tempDirField = new TextField("Temp Dir", Rms.tempDir, 64, 4); + tempDirField = new TextField(L.str[L.tempDir], Rms.tempDir, 64, 4); } private void setComponentsParameters() { diff --git a/src/ui/TextView.java b/src/ui/TextView.java index dd4893c..19d4d67 100644 --- a/src/ui/TextView.java +++ b/src/ui/TextView.java @@ -123,6 +123,12 @@ public class TextView extends Canvas { protected void keyRepeated(int key) { keyPressed(key); } + + protected void pointerPressed(int pix, int piy) { + int q = UI.getSoftBarHeight(); + if(pix>w-2*q && piy>h-q) Main.dsp.setCurrent(dspl); + repaint(); + } /** * diff --git a/src/ui/UI.java b/src/ui/UI.java index 8e6f5d4..3604313 100644 --- a/src/ui/UI.java +++ b/src/ui/UI.java @@ -56,34 +56,13 @@ public class UI { g.drawString(title, w / 2, softBarHeight, Graphics.HCENTER | Graphics.BOTTOM); } - - /** - * - * @param g - * @param title - * @param rightsoft - */ - public static void drawMenuInterface(Graphics g, String title, String rightsoft) { - drawTitle(g, title); - drawSoftBar(g, "", rightsoft); - } - - /** - * ( ) - * @param g - * @param dd - */ - public static void drawStatusBar(Graphics g, int[] dd) { - drawStatusBar(g, Math.abs(dd[0]) + dd[1], Math.abs(dd[2]) + Math.abs(dd[0])); - } - /** * ( ) * @param g * @param cur * @param all */ - private static void drawStatusBar(Graphics g, int cur, int all) { + public static void drawStatusBar(Graphics g, int cur, int all) { int w = g.getClipWidth(); int h = g.getClipHeight(); int sw = w / 20; @@ -141,53 +120,6 @@ public class UI { } } - /** - * - * @param g - * @param color1 - * @param color2 - * @param x1 X - * @param y1 Y - * @param w - * @param h - */ - private static void drawRGB(Graphics g, int color1, int color2, int x1, int y1, int w, int h) { - int a1 = (color1 >> 24) & 0xff; - int a2 = (color2 >> 24) & 0xff; - if(a1>253 && a2>253) { - drawRect(g, color1, color2, x1, y1, w, h); - return; - } - - int r1 = (color1 >> 16) & 0xff; - int g1 = (color1 >> 8) & 0xff; - int b1 = color1 & 0xff; - - int r2 = (color2 >> 16) & 0xff; - int g2 = (color2 >> 8) & 0xff; - int b2 = color2 & 0xff; - - int count = h/3; - if (count<0) count=-count; - if (count<8) count = 8; - int crd1, crd2; - - for (int i = count - 1; i >= 0; i--) { - crd1 = i * h / count + y1; - crd2 = (i + 1) * h / count + y1; - if (crd1 == crd2) continue; - int[] pixelArray = new int[w * (crd2 - crd1)]; - int color = (i * (a2 - a1) / (count - 1) + a1) << 24 | - ((i * (r2 - r1) / (count - 1) + r1) << 16) | - ((i * (g2 - g1) / (count - 1) + g1) << 8) | - (i * (b2 - b1) / (count - 1) + b1); - for (int zi = 0; zi < pixelArray.length; zi++) { - pixelArray[zi] = color; - } - g.drawRGB(pixelArray, 0, w, x1, crd1, w, crd2 - crd1, true); - } - } - /** * * @param graphics diff --git a/src/util/BufDataInputStream.java b/src/util/BufDataInputStream.java index 05165d9..a7319fa 100644 --- a/src/util/BufDataInputStream.java +++ b/src/util/BufDataInputStream.java @@ -27,18 +27,6 @@ public class BufDataInputStream extends InputStream implements DataInput { return blen - bpos + is_available; } - public int getCapacity() { - return capacity; - } - - public void seek(int pos) { - bpos = pos; - } - - public int tell() throws IOException { - return capacity - available(); - } - public int read() throws IOException { if (bpos > buffer.length) { return -1; @@ -46,15 +34,6 @@ public class BufDataInputStream extends InputStream implements DataInput { return ((int) buffer[bpos++]) & 0xFF; } - public int readBack() throws IOException { - if (bpos == 0) { - if (available() == capacity) return -1; - int old = tell(); - bpos = old; - } - return ((int) buffer[--bpos]) & 0xFF; - } - public boolean readBoolean() throws IOException { int r = read(); if (r == -1) { @@ -151,27 +130,6 @@ public class BufDataInputStream extends InputStream implements DataInput { throw new UTFDataFormatException(); } - public char readCharBackUTF() throws IOException, UTFDataFormatException { - int b, c, d; - d = readBack(); - c = readBack(); - b = readBack(); - if (d == -1) { - return (char) -1; - } - if ((d & 0x80) == 0) { - read(); - read(); - return (char) d; - } else if ((c & 0xE0) == 0xC0 && (d & 0xC0) == 0x80) { - read(); - return (char) (((c & 0x1F) << 6) | (d & 0x3F)); - } else if ((b & 0xF0) == 0xE0 && (c & 0xC0) == 0x80 && (d & 0xC0) == 0x80) { - return (char) (((b & 0x0F) << 12) | ((c & 0x3F) << 6) | (d & 0x3F)); - } - throw new UTFDataFormatException(); - } - public boolean checkBOM() { try { if (available() < 3 || @@ -185,24 +143,4 @@ public class BufDataInputStream extends InputStream implements DataInput { } return true; } - - public boolean find(byte[] b) { - if (b == null) return false; - int po = 0; - for (int i = bpos + 1; i < buffer.length; i++) { - po = 0; - if (buffer[i] == b[0]) { - for (int j = 0; j < b.length; j++) { //System.out.println("b "+b[j]); - if (buffer[i + j] == b[j]) { - po += 1; - } else break; - } - } - if (po == b.length) { - bpos = i; - break; - } - } - return (po > 0); - } } diff --git a/src/util/StringEncoder.java b/src/util/StringEncoder.java index 0973b0e..de115b1 100644 --- a/src/util/StringEncoder.java +++ b/src/util/StringEncoder.java @@ -1,10 +1,8 @@ package util; - - public class StringEncoder { - protected static char cp1251[] = { + 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', @@ -30,24 +28,4 @@ public class StringEncoder { } return (char) ich; } - - /** windows-1251 */ - public static byte encodeCharCP1251(char ch) { - if (ch > 0 && ch < 128) { - return (byte) ch; - } else if (ch == 0x401) { - return -88; // - } else if (ch == 0x404) { - return -86; // - } else if (ch == 0x407) { - return -81; // - } else if (ch == 0x451) { - return -72; // - } else if (ch == 0x454) { - return -70; // - } else if (ch == 0x457) { - return -65; // - } - return (byte) ((byte) (ch) + 176); - } }