Example #1
0
 @Override
 public synchronized List<IGroup> getGroupList() {
   if (groupList.isEmpty() && (!isFakeGroup())) {
     if (isAcquisitionGroup()) {
       // recover file groups
       File[] files = FileSystemView.getFileSystemView().getFiles(referenceFile, false);
       if (files != null) {
         ArrayList<File> fileList = new ArrayList<File>();
         fileList.addAll(Arrays.asList(files));
         Collections.sort(fileList, new FileComparator());
         for (File file : fileList) {
           String path = file.getAbsolutePath();
           int pointIndex = path.lastIndexOf('.');
           if (file.isDirectory()
               || ((pointIndex > -1) && "edf".equalsIgnoreCase(path.substring(pointIndex + 1)))) {
             EdfGroup group = new EdfGroup(file);
             group.setParent(this);
             groupList.add(group);
           }
         }
         fileList.clear();
       }
     }
     // else if (itemList.isEmpty()) {
     //
     // }
   }
   ArrayList<IGroup> result = new ArrayList<IGroup>();
   result.addAll(groupList);
   return result;
 }
Example #2
0
  private List<INode> getNodes() {

    List<INode> nodes = new ArrayList<INode>();

    // if (objectList.isEmpty() && groupList.isEmpty()) {
    // analyzeEdfFile();
    // }

    for (AbstractObject object : objectList) {
      nodes.add(new DefaultNode(object.getName()));
    }

    if (isAcquisitionGroup()) {
      for (EdfGroup group : groupList) {
        nodes.add(new DefaultNode(group.getShortName()));
      }
    }

    return nodes;
  }
Example #3
0
  private List<IContainer> findAllContainer(IContainer container, INode[] nodes, int level) {
    List<IContainer> result = new ArrayList<IContainer>();
    if (container != null) {
      if (container instanceof EdfGroup) {
        EdfGroup group = (EdfGroup) container;
        if (nodes.length > level) {
          // List current node children
          if (group.isAcquisitionGroup()) {
            for (EdfGroup realGroup : groupList) {
              result.addAll(findAllContainer(realGroup, nodes, level));
            }
          }

          List<INode> childs = group.getNodes();

          INode current = nodes[level];

          for (INode node : childs) {
            if (current.matchesPartNode(node)) {

              if (level < nodes.length - 1) {
                result.addAll(
                    findAllContainer(group.getContainer(node.getName()), nodes, level + 1));
              }
              // Create IContainer and add it to result list
              else {
                result.add(group.getContainer(node.getName()));
              }
            }
          }
        }
      } else {
        EdfDataItem dataItem = (EdfDataItem) container;
        result.add(dataItem);
      }
    }
    return result;
  }
Example #4
0
 public static void main(String[] args) {
   EdfGroup group =
       new EdfGroup(new File("/home/viguier/NeXusFiles/EDF/test_264/test_264_test_im_00.edf"));
   group.analyzeEdfFile();
 }
Example #5
0
  private void analyzeEdfFile() {
    if (!analyzed) {

      if (referenceFile != null) {
        HashMap<String, String> headerMap = new HashMap<String, String>();
        try {
          FileInputStream fis = new FileInputStream(referenceFile.getAbsolutePath());
          DataInputStream dis = new DataInputStream(fis);

          int character = -1;

          StringBuffer headerBuffer = new StringBuffer();
          boolean newLine = false;
          while (true) {
            try {
              character = dis.read();
              if (character == -1) {
                break;
              }
              headerBuffer.append((char) character);
              if (character == '\n') {
                newLine = true;
              } else {
                if ((character == '}') && newLine) {
                  character = dis.read();
                  break;
                }
                newLine = false;
              }
            } catch (IOException e) {
              character = -1;
              break;
            }
          }
          if (character != -1) {
            char toCheck = headerBuffer.charAt(0);
            while (Character.isWhitespace(toCheck) || (toCheck == '{')) {
              headerBuffer.delete(0, 1);
              toCheck = headerBuffer.charAt(0);
            }
            toCheck = headerBuffer.charAt(headerBuffer.length() - 1);
            while (Character.isWhitespace(toCheck) || (toCheck == '}')) {
              headerBuffer.delete(headerBuffer.length() - 1, headerBuffer.length());
              toCheck = headerBuffer.charAt(headerBuffer.length() - 1);
            }
            String[] lines = headerBuffer.toString().split(";");
            for (String line : lines) {
              int separatorIndex = line.lastIndexOf('=');
              if (separatorIndex > -1) {
                headerMap.put(
                    line.substring(0, separatorIndex).trim(),
                    line.substring(separatorIndex + 1).trim());
              }
            }
            readImageFromFile(headerMap, dis);
            // Cleaning keys bound to image
            headerMap.remove("ByteOrder");
            headerMap.remove("Dim_1");
            headerMap.remove("Dim_2");
            headerMap.remove("DataType");
            // Avoid having another item with the same name as image item
            headerMap.remove("Image");

            // Other DataItems
            HashMap<String, EdfGroup> subGroupMap = new HashMap<String, EdfGroup>();
            for (String key : headerMap.keySet()) {
              int openIndex = key.lastIndexOf('(');
              int closeIndex = key.lastIndexOf(')');
              if ((openIndex > -1) && (closeIndex > openIndex)) {
                // Group items by name
                String groupName = key.substring(openIndex + 1, closeIndex);
                EdfGroup subGroup = subGroupMap.get(groupName);
                if (subGroup == null) {
                  subGroup = new EdfGroup(null);
                  subGroup.setName(groupName);
                  subGroup.setShortName(groupName);
                  subGroup.setAnalyzed(true);
                  addSubgroup(subGroup);
                  subGroupMap.put(groupName, subGroup);
                }
                String itemName = key.substring(0, openIndex).replaceAll("=", "").trim();
                subGroup.addDataItem(buildDataItem(itemName, headerMap.get(key)));
              } else {
                // Build simple dataItem
                addDataItem(buildDataItem(key, headerMap.get(key)));
              }
            }
            subGroupMap.clear();

            headerMap.clear();
            dis.close();
          }
        } catch (FileNotFoundException e) {
          // Just ignore this case
        } catch (IOException e) {
          // Just ignore this case
        }
      }
    }

    analyzed = true;
  }