public BufferedImage getNextImage ( boolean forward ) { if ( grid != null ) { if ( forward ) { this . time ++ ; if ( this . time >= this . ntimes ) this . time = 0 ; } else { this . time -- ; if ( this . time < 0 ) this . time = this . ntimes - 1 ; } Array data ; try { data = grid . readDataSlice ( this . time , 0 , - 1 , - 1 ) ; return ImageArrayAdapter . makeGrayscaleImage ( data , grid ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; return null ; } } if ( currentFile == null ) return null ; if ( currentDir == null ) { currentDirFileNo = 0 ; currentDir = currentFile . getParentFile ( ) ; currentDirFileList = new ArrayList <> ( ) ; addToList ( currentDir , currentDirFileList ) ; //Arrays.asList(currentDir.listFiles()); //Collections.sort(currentDirFileList); for ( int i = 0 ; i < currentDirFileList . size ( ) ; i ++ ) { File file = currentDirFileList . get ( i ) ; if ( file . equals ( currentFile ) ) currentDirFileNo = i ; } } if ( forward ) { currentDirFileNo ++ ; if ( currentDirFileNo >= currentDirFileList . size ( ) ) currentDirFileNo = 0 ; } else { currentDirFileNo -- ; if ( currentDirFileNo < 0 ) currentDirFileNo = currentDirFileList . size ( ) - 1 ; } File nextFile = currentDirFileList . get ( currentDirFileNo ) ; try { System . out . println ( "Open image " + nextFile ) ; return javax . imageio . ImageIO . read ( nextFile ) ; } catch ( IOException e ) { System . out . println ( "Failed to open image " + nextFile ) ; return getNextImage ( forward ) ; } }
This assumes you have opened a file . looks in the parent directory .