-2

i'm stucked with a problem with the ListIterator. I wanted to create an image gallery using LinkedList and mvc pattern, i'm now creating the model of the project so for now i don't have to worry about the GUI. I have created the main class ImageGallery that contains the LinkedList of images.

public class ListaImmagini implements Iterable<Immagine>{

private LinkedList<Immagine> listaImmagini;
private Iteratore iteratore; 

public ListaImmagini(){
    listaImmagini = new LinkedList<Immagine>();
    iteratore = (Iteratore) listaImmagini.iterator();
}

public void addSingleImage(String percorso){
    Immagine img = new Immagine(percorso);
    listaImmagini.addFirst(img);
}

public void addFolder(LinkedList images){
    listaImmagini = images;
}

public Immagine getImg(){
    int currentIndex = iteratore.nextIndex();
    return listaImmagini.get(currentIndex);
}

@Override
public Iterator<Immagine> iterator() {
    Iteratore navigator = new Iteratore(listaImmagini);
    return navigator;
}

The class image is very simple:

public class Immagine {

private File immagine;

public Immagine(String percorso){
    immagine = new File(percorso);
}

public File getImmagine() {
    return immagine;
}

public String toString(){
    return immagine.toString();
}

}

Now, the main problem is that i have to navigate the images with the GUI using buttons, for example, I have a current image bigger than the other ones, a previous image and a next Image(for a preview). Using buttons i can go back or forward with the images. To manage this i used a ListIterator, but i don't know how to apply it to my project.

I tried also to create my own iterator class with all the methods modified and adapted to my project but still i can't understand how can i implement all the methods...

public class Iteratore implements ListIterator<Immagine>{

private LinkedList listaImmagini;

public Iteratore(LinkedList listaImmagini) {
    this.listaImmagini = listaImmagini;
}

@Override
public boolean hasNext() {
    boolean ris = false;
    if (listaImmagini!=null) {
        ris = true;
    }
    else{
        ris = false;
    }
    return ris;
}

@Override
public Immagine next() {
    Immagine img = null;
    if (listaImmagini!=null) {
        int currentIndex = nextIndex();
        listaImmagini.get(currentIndex);
    }
    return img;
}

@Override
public boolean hasPrevious() {
    throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public Immagine previous() {
    throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public int nextIndex() {
    throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public int previousIndex() {
    throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public void remove() {
    throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public void set(Immagine e) {
    throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public void add(Immagine e) {
    throw new UnsupportedOperationException("Not supported yet.");
}

} Can anyone help me? :)

1 Answers1

1

Im unfamiliar with java gui but the basic premise of it is that you need an onClickListener on both your left and right button. when the user clicks the button it will call your iterator.previous() or iterator.next() respectively.

If this is android, I can quick post an example of how this would look.

miversen33
  • 573
  • 5
  • 19