package trypListModels;

import javax.swing.AbstractListModel;
import trypResources.Layer;

/**
 *
 * @author amnesia
 */
public class LayerListModel extends AbstractListModel
{
    Layer[] layers;
    
    public void add(Layer L)
    {
        if(layers != null)
        {
            Layer[] temp = new Layer[layers.length+1];
            for(int i=0; i<layers.length; i++)
            {
                temp[i]=layers[i];
            }
            temp[temp.length-1]=L;
            layers=temp;
        }
        else 
        {
            layers = new Layer[1];
            layers[0]=L;
        }
    }
    
    public boolean checkIndex(int index)
    {
        return index>=0 && index<getSize();
    }
    
    public void setElement(int index, Layer layer)
    {
        if(checkIndex(index) && layer != null)
        {
            layers[index] = layer;
        }
    }
    
    @Override
    public int getSize() 
    {
        if(layers != null)
        {
            return layers.length;
        }
        else return 0;
    }

    @Override
    public Object getElementAt(int index) 
    {
        if(layers != null && checkIndex(index))
        {
            return layers[index];
        }
        else return null;
    }
    
    public Layer[] getList()
    {
        return layers;
    }
    
    public void removeElement(int index)
    {
        if(checkIndex(index))
        {
            Layer[] tmpLayer = new Layer[layers.length-1];
            for(int i=0;i<layers.length-1;i++)
            {
                if(i<index)
                {
                    tmpLayer[i]=layers[i];
                }
                else
                {
                    tmpLayer[i]=layers[i+1];
                }
            }
            layers=tmpLayer;
        }
    }
}

@@ -1,8 +1,193 @@
+/*%0A * To change this license header, choose License Headers in Project Properties.%0A * To change this template file, choose Tools %7C Templates%0A * and open the template in the editor.%0A */%0A
 package 
@@ -313,17 +313,17 @@
 c class 
-L
+l
 ayerList
@@ -797,275 +797,8 @@
    %0A
-    public boolean checkIndex(int index)%0A    %7B%0A        return index%3E=0 && index%3CgetSize();%0A    %7D%0A    %0A    public void setElement(int index, Layer layer)%0A    %7B%0A        if(checkIndex(index) && layer != null)%0A        %7B%0A            layers%5Bindex%5D = layer;%0A        %7D%0A    %7D%0A
     
@@ -945,17 +945,18 @@
  return 
-0
+-1
 ;%0A    %7D%0A
@@ -1048,33 +1048,48 @@
 null && 
-checkIndex(index)
+index %3E=0 && index%3Clayers.length
 )%0A      
@@ -1241,486 +1241,11 @@
   %7D%0A
+
     %0A
-    public void removeElement(int index)%0A    %7B%0A        if(checkIndex(index))%0A        %7B%0A            Layer%5B%5D tmpLayer = new Layer%5Blayers.length-1%5D;%0A            for(int i=0;i%3Clayers.length-1;i++)%0A            %7B%0A                if(i%3Cindex)%0A                %7B%0A                    tmpLayer%5Bi%5D=layers%5Bi%5D;%0A                %7D%0A                else%0A                %7B%0A                    tmpLayer%5Bi%5D=layers%5Bi+1%5D;%0A                %7D%0A            %7D%0A            layers=tmpLayer;%0A        %7D%0A    %7D%0A
 %7D%0A

Revert "Small Change"