Changeset 214
- Timestamp:
- 05/12/08 14:52:50 (5 years ago)
- Location:
- bbtracker/branches/map/src/org/bbtracker/mobile
- Files:
-
- 2 edited
-
config/ConfigFile.java (modified) (1 diff)
-
gui/MapBackground.java (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bbtracker/branches/map/src/org/bbtracker/mobile/config/ConfigFile.java
r212 r214 137 137 FileConnection connection = 138 138 (FileConnection) Connector.open(url, Connector.WRITE); 139 OutputStream out = connection.openOutputStream(); 140 OutputStreamWriter writer = new OutputStreamWriter(out); 141 142 Enumeration keys = params.keys(); 143 Enumeration values = params.elements(); 144 while (keys.hasMoreElements()) { 145 String key = (String) keys.nextElement(); 146 String value = (String) values.nextElement(); 147 148 writer.write(key); 149 writer.write(' '); 150 writer.write(value); 151 writer.write('\n'); 152 } 153 writer.close(); 154 out.close(); 155 connection.close(); 139 try { 140 OutputStream out = connection.openOutputStream(); 141 OutputStreamWriter writer = new OutputStreamWriter(out); 142 143 try { 144 Enumeration keys = params.keys(); 145 Enumeration values = params.elements(); 146 while (keys.hasMoreElements()) { 147 String key = (String) keys.nextElement(); 148 String value = (String) values.nextElement(); 149 150 writer.write(key); 151 writer.write(' '); 152 writer.write(value); 153 writer.write('\n'); 154 } 155 } finally { 156 writer.close(); 157 out.close(); 158 } 159 } finally { 160 connection.close(); 161 } 156 162 } 157 163 -
bbtracker/branches/map/src/org/bbtracker/mobile/gui/MapBackground.java
r212 r214 19 19 20 20 import java.io.ByteArrayInputStream; 21 import java.io.DataInputStream; 22 import java.io.DataOutputStream; 21 23 import java.io.IOException; 22 24 import java.io.InputStream; … … 93 95 /** Constant for loading progress state. */ 94 96 private static final int STATE_DONE = 2; 97 98 /** Constant for loading progress state. */ 99 private static final int STATE_ERROR = 3; 95 100 96 101 /** Filename. */ … … 149 154 150 155 /** Index in tar file. */ 151 private long[] tarFileIndex;156 private int[] tarFileIndex; 152 157 153 158 /** Index in tar file. */ … … 283 288 if (Math.abs(self.scaleX - googleScale) 284 289 < googleScale / percent) { 285 System.out.println("Using rounded google scale.");286 290 self.scaleX = googleScale; 287 291 break; … … 333 337 paintLoadingProgress(g); 334 338 } 339 paintMemoryStatus(g); 335 340 336 341 g.setColor(POSITION_COLOR); … … 363 368 (int) ((normalisedPixelLat - normalisedPixelLatOffset) * scaleY) 364 369 + centerOffsetY; 365 System.out.println("Offset: " + offX + "," + offY366 + "max: " + maxTileX + ", " + maxTileY);367 370 boolean missingImage = false; 368 371 … … 373 376 int startY = offY + y; 374 377 if (startY < height && startY + tileHeight > 0) { 375 System.out.println("Found tile.");376 378 Image img = getTileImage(x, y); 377 379 if (img != null) { … … 395 397 } 396 398 399 /** 400 * Paint memory status. 401 * 402 * @param g graphic object 403 */ 404 private static void paintMemoryStatus(Graphics g) { 405 g.setColor(PROGRESS_BACKGROUND_COLOR); 406 407 final long totalMemory = Runtime.getRuntime().totalMemory(); 408 final long freeMemory = Runtime.getRuntime().freeMemory(); 409 final int barX = (int) (PROGRESS_BAR_WIDTH * freeMemory / totalMemory); 410 g.fillRect(0, PROGRESS_BAR_HEIGHT, barX, PROGRESS_BAR_HEIGHT); 411 g.setColor(PROGRESS_DONE_COLOR); 412 g.fillRect(barX, PROGRESS_BAR_HEIGHT, 413 PROGRESS_BAR_WIDTH - barX, PROGRESS_BAR_HEIGHT); 414 g.setColor(PROGRESS_TEXT_COLOR); 415 StringBuffer state = new StringBuffer(); 416 state.append(freeMemory); 417 state.append('/'); 418 state.append(totalMemory); 419 g.drawString(state.toString(), 420 PROGRESS_TEXT_POSITION_X, 421 PROGRESS_TEXT_POSITION_Y + PROGRESS_BAR_HEIGHT, 422 Graphics.TOP | Graphics.LEFT); 423 } 424 397 425 /** 398 426 * Paint progress bar. … … 421 449 state.append("Reading"); 422 450 break; 451 case STATE_DONE: 452 state.append("Done"); 453 break; 423 454 default: 424 455 state.append("Error"); … … 476 507 repaint(); 477 508 } catch (Throwable e) { 509 queueState = STATE_ERROR; 478 510 Log.log(this, e, "loading Map Tile " + tile.fileNumber); 479 511 } finally { … … 499 531 } 500 532 } else { 501 if ( !in.markSupported()) {533 if (in != null && !in.markSupported()) { 502 534 closeTarInputStream(); 503 535 } … … 523 555 } 524 556 if (tarFileIndex == null) { 525 readFileIndex(is); 526 if (markSupported) { 527 is.reset(); 528 } else { 529 closeTarInputStream(); 530 is = openTarFileInputStream(); 557 readTarFileIndex(); 558 if (tarFileIndex == null) { 559 readFileIndex(is); 560 if (markSupported) { 561 is.reset(); 562 } else { 563 closeTarInputStream(); 564 is = openTarFileInputStream(); 565 } 566 storeTarFileIndex(); 531 567 } 532 568 } … … 546 582 } 547 583 548 if (is != null ) {584 if (is != null && tarFileIndex != null) { 549 585 try { 550 586 if (markSupported) { … … 582 618 return is; 583 619 } 584 620 621 /** 622 * store tar file index. 623 * 624 * @throws IOException io error 625 */ 626 private void storeTarFileIndex() throws IOException { 627 FileConnection file = 628 (FileConnection) Connector.open( 629 "file:///" + tarFileDirectory + getTarIndexFileName(), 630 Connector.WRITE); 631 try { 632 DataOutputStream out = file.openDataOutputStream(); 633 634 try { 635 out.writeInt(tarFileIndex.length); 636 for (int i = 0; i < tarFileIndex.length; i++) { 637 out.writeInt(tarFileIndex[i]); 638 out.writeInt(tarFileSize[i]); 639 } 640 } finally { 641 out.close(); 642 } 643 } finally { 644 file.close(); 645 } 646 } 647 648 /** 649 * @return tar file index (replace .tar by .idx) 650 */ 651 private String getTarIndexFileName() { 652 int pos = tarFileName.lastIndexOf('.'); 653 if (pos == -1) { 654 throw new RuntimeException("Invalid tar filename"); 655 } 656 return tarFileName.substring(0, pos + 1) + "idx"; 657 } 658 659 /** 660 * open and read tar file index and file sizes. 661 */ 662 private void readTarFileIndex() { 663 int[] tarIndex = null; 664 int[] tarSize = null; 665 try { 666 FileConnection file = 667 (FileConnection) Connector.open( 668 "file:///" + tarFileDirectory + getTarIndexFileName(), 669 Connector.READ); 670 DataInputStream in = file.openDataInputStream(); 671 try { 672 int length = in.readInt(); 673 tarIndex = new int[length]; 674 tarSize = new int[length]; 675 for (int i = 0; i < length; i++) { 676 tarIndex[i] = in.readInt(); 677 tarSize[i] = in.readInt(); 678 } 679 } finally { 680 in.close(); 681 } 682 } catch (IOException e) { 683 Log.log(this, e, "reading tar file index"); 684 tarIndex = null; 685 } 686 tarFileIndex = tarIndex; 687 tarFileSize = tarSize; 688 } 585 689 /** 586 690 * Read Tar file index. … … 593 697 final int nElements = (maxTileX / tileWidth) * (maxTileY / tileHeight); 594 698 queueTotal = nElements; 595 final long[] fileIndex = new long[nElements];596 final int[] tarSize = new int[nElements];699 final int[] fileIndex = new int[nElements]; 700 final int[] tarSize = new int[nElements]; 597 701 long fileOffset = 0; 598 702 final int blockSize = 512; … … 630 734 if (name.startsWith(baseFileName)) { 631 735 final int fileNumber = parseFileNumber(name); 632 fileIndex[fileNumber] = fileOffset;736 fileIndex[fileNumber] = (int) fileOffset; 633 737 tarSize[fileNumber] = fileSize; 634 738 ++imageFound;
Note: See TracChangeset
for help on using the changeset viewer.