Previous Next        Current Page: NeXtMidas Training / File Handlers / Lab 1 / Part 4
back
Start Here   
Background   
Common Midas Concepts   
Getting Started - Part 1   
Getting Started - Part 2   
Working with Files   
Option Trees   
Macros - Part 1 (Basics)   
Macros - Part 2 (Graphics)   
NetBeans - Part 1 (Setup)   
NetBeans - Part 2 (GUIs)   
NetBeans - Part 3 (Profiler)   
Eclipse - Part 1 (Setup)   
Eclipse - Part 2 (GUIs)   
Primitives   
WebStart   
Maps & Imagery   
X-Midas Interoperability   
RMIF & Remoting   
Installing NeXtMidas   
Support & Maintenance   
File Handlers   
   + Introduction   
   - Lab 1   
      - File Format   
      - Part 1   
      - Part 1 (ctd.)   
      - Part 1 (ctd.)   
      - Part 2   
      - Part 3   
      - Part 4   
      - Solution   
   + Lab 2   


  • Part 4 - Listing:
    • Now lets add the methods that will be used by commands like DATALIST when listing elements from the file. For the most part these methods look very similar when going from one file handler to the next.
    • listElements(..) and listElementsPerLine(..)
      • The listElementsPerLine(..) method tells datalist how many elements to list on each line. This allows allows DATALIST to conserve vertical space by listing multiple elements per line... we don't realy care about that right now, so just return 1 telling it to display only one element per line.
          public int listElementsPerLine (int lineWidth, String format, int flags) {
            return 1;
          }
        
      • The listElements(..) method actually lists the elements. Again we will go through it line-by-line.
          public String listElements (double start, int elements, String format, int flags) {
            Data data = getDataBuffer(elements);         // 1
            seek(start);                                 // 2
            int numRead = read(data, elements);          // 3
            if (numRead <= 0) return null;               // 4
            return data.toString(0, numRead, 10)+"\n";   // 5
          }
        
        • Line 1: Create a data buffer to use when reading in the data.
        • Line 2: Seek to the start of the data we wantr to read.
        • Line 3: Read in the data.
        • Line 4: If there was nothing available to read (e.g. end-of-file), just return null.
        • Line 5: Convert the data to a string. In this case we are converting to test starting at 0 with numElements total and using base-10. By convention, this always has a newline character added on to the end of the string.
  • continued on next page

back