?? tinyline.java
字號:
if (rec1[i] < rec2[i]) return PRECEDES; else if (rec1[i] > rec2[i]) return FOLLOWS; } return EQUIVALENT; } /** Initialises the Bookmarks data structure */ private void initialize() { // Load the Bookmarks from RMS. recordStoreName = "svg.images"; propertyBaseName = "svg.image"; loadBookmarks(); // Create the Help screen. helpScreen = new Form("Help"); helpScreen.append(new StringItem("",helpString)); helpBackCommand = new Command("Back", Command.BACK, 1); helpScreen.addCommand(helpBackCommand); helpScreen.setCommandListener(this); // Create the Bookmarks screen. addCommand = new Command("Add", Command.SCREEN, 1); editCommand = new Command("Edit", Command.SCREEN, 1); deleteCommand = new Command("Delete", Command.SCREEN, 1); defaultsCommand = new Command("Defaults", Command.SCREEN, 1); listBackCommand = new Command("Back", Command.BACK, 1); bookmarkList = new List("Bookmarks", List.IMPLICIT); fillBookmarkList(); bookmarkList.addCommand(listBackCommand); bookmarkList.addCommand(addCommand); bookmarkList.addCommand(editCommand); bookmarkList.addCommand(deleteCommand); bookmarkList.addCommand(defaultsCommand); bookmarkList.setCommandListener(this); // Create the Bookmark Edit screen. editBackCommand = new Command("Back", Command.BACK, 1); saveCommand = new Command("Save", Command.SCREEN, 1); editForm = new Form("Edit Bookmark"); nameField = new TextField("Name", "", 128, TextField.ANY); URLField = new TextField("URL", "", 256, TextField.URL); editForm.append(nameField); editForm.append(URLField); editForm.addCommand(editBackCommand); editForm.addCommand(saveCommand); editForm.setCommandListener(this); initialized = true; } /** Fills the bookmarkList from the bookmark data */ private void fillBookmarkList() { // First remove all items from the list. while (bookmarkList.size() > 0) bookmarkList.delete(0); // Walk through the vector and add items to the list. Bookmark bookmark = null; for (int i = 0; i < bookmarks.size(); i++) { bookmark = (Bookmark)bookmarks.elementAt(i); bookmarkList.append(bookmark.name, null); } } /** Returns the selected Bookmark */ private Bookmark getSelectedBookmark() { String name = bookmarkList.getString(bookmarkList.getSelectedIndex()); // Get the matching Bookmark. return getBookmark(name); } /** Returns a Bookmark by name */ private Bookmark getBookmark(String name) { Bookmark bookmark = null; for (int i = 0; i < bookmarks.size() && bookmark == null; i++) { bookmark = (Bookmark)bookmarks.elementAt(i); if (name.equals(bookmark.name) == false) bookmark = null; } return bookmark; } /** Validates the input entry */ private boolean validate(String name, String url) { if (name == null) return false; if (url == null) return false; if (name.length() == 0) return false; if (url.length() == 0) return false; return true; } /** Loads Bookmarks from RMS or properties */ private void loadBookmarks() { bookmarks = new Vector(); try { loadBookmarksFromRecordStore(recordStoreName); } catch (RecordStoreNotFoundException rsnfe) { loadBookmarksFromProperties(propertyBaseName); saveBookmarks(); } catch (RecordStoreException rse) { } } /** Loads Bookmarks from RMS */ private void loadBookmarksFromRecordStore(String name) throws RecordStoreException { bookmarks.removeAllElements(); RecordStore rs = null; RecordEnumeration re = null; try { rs = RecordStore.openRecordStore(name, false); if (rs.getNumRecords() == 0) throw new RecordStoreNotFoundException(); re = rs.enumerateRecords(null, this, false); while (re.hasNextElement()) { byte[] raw = re.nextRecord(); Bookmark f = rawToBookmark(raw); bookmarks.addElement(f); } } finally { if (re != null) re.destroy(); if (rs != null) rs.closeRecordStore(); } } /** * Clears the BookmarkStore and loads Bookmarks from using the * specified property base name. */ private void loadBookmarksFromProperties(String baseName) { bookmarks.removeAllElements(); int index = 1; for(;;) { String propertyName = baseName + "."; if(index <=9) propertyName +="0"; propertyName +="" + index++; String BookmarkString = getAppProperty(propertyName); if (BookmarkString == null) { break; } else { Bookmark f = Bookmark.create(BookmarkString); bookmarks.addElement(f); } } } /** Returns the raw byte array representation for the ith Bookmark. */ private byte[] bookmarkToRaw(int i) { Bookmark f = (Bookmark)bookmarks.elementAt(i); byte[] raw = f.getRaw().getBytes(); byte[] ordered = new byte[raw.length + 1]; ordered[0] = (byte)i; // Store the position here. System.arraycopy(raw, 0, ordered, 1, raw.length); return ordered; } /** Creates a new Bookmark object from the given raw bytes array. */ private Bookmark rawToBookmark(byte[] raw) { String s = new String(raw, 1, raw.length - 1); return Bookmark.create(s); } /** Returns true if the byte arrays equal; otherwise return false */ private boolean byteEquals(byte[] one, byte[] two) { if (one.length != two.length) return false; for (int i = 0; i < one.length; i++) if (one[i] != two[i]) return false; return true; } /** * Saves Bookmarks to the RMS. */ private void saveBookmarks() { String name = recordStoreName; RecordStore rs = null; RecordEnumeration re = null; try { rs = RecordStore.openRecordStore(name, true); re = rs.enumerateRecords(null, null, false); boolean[] found = new boolean[bookmarks.size()]; while (re.hasNextElement()) { int id = re.nextRecordId(); byte[] raw = null; if (re.hasPreviousElement()) { re.previousRecordId(); raw = re.nextRecord(); } else if (re.hasNextElement()) { re.nextRecordId(); raw = re.previousRecord(); } else { re.reset(); raw = re.nextRecord(); } // Look for a match in our internal list. boolean recordFound = false; for (int i = 0; i < bookmarks.size(); i++) { byte[] existingRaw = bookmarkToRaw(i); if (byteEquals(raw, existingRaw)) { found[i] = true; recordFound = true; break; } } // Remove records that have no match. if (recordFound == false) { rs.deleteRecord(id); } } // Now look through bookmarks. Anything that wasn't in // the recordstore should be added. for (int i = bookmarks.size() - 1; i >= 0; i--) { if (found[i] == false) { byte[] raw = bookmarkToRaw(i); rs.addRecord(raw, 0, raw.length); } } } catch (RecordStoreException rse) { System.out.println(rse); } finally { try { if (re != null) re.destroy(); if (rs != null) rs.closeRecordStore(); } catch (RecordStoreException rse) {} } } /** Help */ private static String helpString = "TinyLine implements Scalable Vector Graphics Tiny (SVGT) for J2ME." +"\n\n" +"GETTING STARTED\n" +"TinyLine comes with several SVGT samples, other samples located on the tinyline.com. " +"From the TinyLine welcome screen, you can use RIGHT and LEFT keys to navigate " +"among bookmarked links. Or, you can select the <Open> command to open the bookmarks." +"\n\n" +"USING BOOKMARKS\n" +"Use <Add> command to enter a new link. You may edit the bookmarks using <Edit> or " +"<Delete> commands or reset the bookmarks to <Default>." +"\n\n" +"NAVIGATION\n" +"In the <Next Prev> mode (by default) you can use RIGHT and LEFT keys to navigate " +"among bookmarked SVGT links.\n" +"In the <Link> mode you can use UP and DOWN keys to navigate links. A link will be " +"highlighted with a blue rectangle. You can then select it by pressing FIRE key. If your " +"device has a pointer, you can also select any link by tapping your pointer on it.\n" +"In the <Pan> mode you can scroll using LEFT, RIGHT, UP and DOWN keys. If your " +"device has a pointer, you can also scroll by dragging the pointer.\n" +"In the <Zoom> mode you can zoom in or zoom out using UP and DOWN keys.\n" +"The <Orig View> command returns the viewing image to its original view.\n" +"The <Quality> command turns off or on the antialising.\n" +"The <Pause> command stops or resumes animations." +"\n\n" +"MORE\n" +"For more about TinyLine, see http://www.tinyline.com/." +"\n" +"Copyright (c) 2002-2006 TinyLine. All rights reserved." +"\n";}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -