/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MapEdit.java
 *
 * Created on 04.05.2010, 13:58:53
 */

package csa.tiletools.map;

import csa.Global;
import csa.config.Configuration;
import csa.gui.CSAMainFrame;
import csa.gui.ImageCache;
import csa.gui.TimingTriggerer;
import csa.gui.TriggerCallback;
import csa.gui.Windowable;
import csa.gui.components.CSAInternalFrame;
import csa.gui.components.CSAView;
import csa.gui.components.ModalInternalFrame;
import csa.gui.dialogs.InternalFrameFileChoser;
import csa.gui.dialogs.ShowInfoDialog;
import csa.tiletools.graphics.BaseImageData;
import csa.tiletools.graphics.ImageComponent;
import csa.tiletools.graphics.ImageSequence;
import csa.tiletools.graphics.ImageSequenceData;
import csa.tiletools.graphics.ImageSequenceDataPool;
import csa.tiletools.graphics.MustSaveAsOneDialog;
import csa.tiletools.script.ExportFrame;
import csa.tiletools.sprites.Sprite;
import csa.tiletools.sprites.SpriteAttribute;
import csa.tiletools.sprites.SpriteData;
import csa.tiletools.sprites.SpriteDataPool;
import csa.tiletools.tiles.CompositeTile;
import csa.tiletools.tiles.Tile;
import csa.tiletools.tiles.TileData;
import csa.tiletools.tiles.TileDataPool;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.*;
import javax.imageio.ImageIO;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableModel;

/**
 *
 * @author malban
 * Thought:
 *
 *
 */
public class MapEdit extends javax.swing.JPanel implements
        Windowable{

    private GridSettingsDataPool mGridSettingsDataPool;
    private GridSettingsData mGridSettingsData = new GridSettingsData();
    private MapData mMapData = new MapData();
    private MapDataPool mMapDataPool;

    private TileListForm mTileListForm =null;

    private TMap currentMap = null;
    private TileData mCurrentTile=null;
    private CompositeTile mCurrentCompositeTile = null;

    // only used for refference, the "real" pool is in currentMap
    private LayerDataPool mLayerDataPool;

    private Vector <TileData> mCurrentDisplayedTileList = new Vector <TileData>();
    private Vector <CompositeTile> mCurrentDisplayedCompositeTileList = new Vector <CompositeTile>();

    private CSAView mParent = null;
    private javax.swing.JMenuItem mParentMenuItem = null;
    private int mClassSetting=0;
    private TileData leftMouseTile = null;
    private TileData rightMouseTile = null;
    private TileData sleftMouseTile = null;
    private TileData srightMouseTile = null;
    private TileData middleMouseTile = null;
    private TileData smiddleMouseTile = null;

    private int selectionLayerNo=-1;
    private int selectionTileNo = -1;
    private int selectionSpriteNo = -1;
    final TimingTriggerer timer = TimingTriggerer.getTimer();

    private TileDataPool mTileDataPool = null;
    private TileDataPool mCompositeTileDataPool = null;

    @Override
    public void closing()
    {
        deinit();
    }
    @Override
    public void setParentWindow(CSAView jpv)
    {
        mParent = jpv;
    }
    @Override
    public void setMenuItem(javax.swing.JMenuItem item)
    {
        mParentMenuItem = item;
        mParentMenuItem.setText("Map Resourcer");
    }
    @Override
    public javax.swing.JMenuItem getMenuItem()
    {
        return mParentMenuItem;
    }
    @Override
    public javax.swing.JPanel getPanel()
    {
        return this;
    }
    /** Creates new form MapEdit */
    public MapEdit() {
        initComponents();
        timer.setResolution(50); //100*1ms resoltuion is 0,1seconds


        mapPanel.addMapListerner(new MapListener()  {

            @Override
            public void mapOffsetChanged(MapEvent e)
            {
                jLabelOffset.setText(""+mapPanel.getOffsetX(jCheckBox4.isSelected())+"/"+mapPanel.getOffsetY(jCheckBox4.isSelected()));
                jLabelCoords.setText(mapPanel.getMouseCoordinatesAsString());
            }

            @Override
            synchronized public void mousePositionChanged(MapEvent e)
            {
                jLabelCoords.setText(mapPanel.getMouseCoordinatesAsString());
                //jLabelCoords.setText(""+(e.mouseX+mapPanel.getOffsetX(jCheckBox4.isSelected()))+"/"+(e.mouseY+mapPanel.getOffsetY(jCheckBox4.isSelected())));
                selectionLayerNo=-1;
                selectionTileNo = -1;

                selectionSpriteNo = -1;

                jLabel3.setForeground(Color.black);
                if (leftMouseTile != null)
                {
                    //also look for overlapping for current selcted tile?
                    // problem - which selection to take?
                    if (!jCheckBoxLayerAllowTileOverlap.isSelected())
                    {
                       
                        if (!checkTileOverlap(leftMouseTile , e.nearestHotSpot.x, e.nearestHotSpot.y))
                        {
                            jLabel3.setForeground(Color.red);
                        }
                    }

                }
                else
                {
                    if (mCurrentCompositeTile != null)
                    {
                        if (!checkTileOverlap(mCurrentCompositeTile , e.nearestHotSpot.x, e.nearestHotSpot.y))
                        {
                            jLabel3.setForeground(Color.red);
                        }
                    }
                }
                if (inSpriteTab)
                {
                    ArrayList<Sprite> sprites = mapPanel.getSpritesOnPosition(e.mouseX, e.mouseY);


                    if (sprites.size()>0)
                    {
                        imageComponentUnderCursor.setSequence(new ImageSequence(getImageSequenceDataForSprite(sprites.get(0).data)));
                        imageComponentUnderCursor.setScaled(true, 22,22);

                        selectionLayerNo = sprites.get(0).layer;
                        selectionSpriteNo = sprites.get(0).spriteInLayer;

                        mapPanel.highliteSprite(selectionLayerNo, selectionSpriteNo);
                    }
                    else
                    {
                        imageComponentUnderCursor.setSequence(null);
                        mapPanel.highliteSprite(-1, -1);
                    }                    
                }
                else
                {
                    ArrayList<Tile> tiles = mapPanel.getTilesOnPosition(e.mouseX, e.mouseY);
                    if (tiles.size()>0)
                    {
                        imageComponentUnderCursor.setSequence(new ImageSequence(getImageSequenceDataForTile(tiles.get(0).getData())));
                        imageComponentUnderCursor.setScaled(true, 22,22);

                        selectionLayerNo = tiles.get(0).layer;
                        selectionTileNo = tiles.get(0).tileInLayer;

                        mapPanel.highliteTile(selectionLayerNo,selectionTileNo);
                    }
                    else
                    {
                        imageComponentUnderCursor.setSequence(null);
                        mapPanel.highliteTile(-1, -1);
                    }                    
                }
                
                if (inSpriteTab)
                {
                    if (mapPanel.isSpriteSelected()) return;
                    mClassSetting++;
                    
                    
                    jTextFieldSpriteX.setText(""+(e.mapXOffset+ mapPanel.unscaleIt(e.mouseX)));
                    jTextFieldSpriteY.setText(""+(e.mapYOffset+mapPanel.unscaleIt(e.mouseY)));
                    
                    if (mCurrentSprite != null)
                    {
                        mCurrentSprite.setX((e.mapXOffset+ mapPanel.unscaleIt(e.mouseX)));
                        mCurrentSprite.setY((e.mapYOffset+ mapPanel.unscaleIt(e.mouseY)));
                    }
                    mClassSetting--;
                }
                
            }

            @Override
            public void mouseButtonChanged(MapEvent e)
            {
                if (inSpriteTab)
                {
                    // delete selected sprite
                    if ((jToggleButtonSetErase.isSelected()) || ((e.orgMouseEvent.isControlDown())))
                    {
                        // erase current sprite under cursor
                        if (selectionLayerNo == -1 ) return;
                        mapPanel.deleteSprite(selectionLayerNo, selectionSpriteNo);
                        selectionLayerNo = -1;
                        return;
                    }
                    
                    // set a sprite
                    if ((e.orgMouseEvent.getButton() == MouseEvent.BUTTON1) )
                    {
                        if (mCurrentSprite == null) return; // dont add NO Sprite!
                        
                        if (mapPanel.isSpriteSelected())
                        {
                            mapPanel.selectSprite(-1, -1);
                            JPanel panel = currentSelectedSpriteImagePanel;
                            currentSelectedSpriteImagePanel = null;
                            selectSprite(panel);
                            return;
                        }
                        
                        
                        addSprite(mCurrentSprite);
                        mapPanel.updateNeeded(true);
                        //mapPanel.setMapChanged(true); done by add tile
                        return;
                    }                    
                    // select a sprite
                    if ((e.orgMouseEvent.getButton() == MouseEvent.BUTTON3) )
                    {
                        if ((selectionLayerNo==-1) || (selectionSpriteNo==-1)) return;
                        
                        mapPanel.setMouseGrabSprite(null);
                        
                        if (mCurrentSprite != null)
                        {
                            // deinit
                        }
                        Sprite sprite  = mapPanel.selectSprite(selectionLayerNo, selectionSpriteNo);

                        jTextFieldSpriteFile.setText(sprite.data.getPoolName());
                        loadSpriteCollection();
                        jComboBoxSpriteKlasse.setSelectedItem(sprite.data.getCClass());
                        mapPanel.setMouseGrabSprite(null);
                        mapPanel.selectSprite(selectionLayerNo, selectionSpriteNo);
                        
                        mCurrentSprite = sprite;
                        setCurrentSpriteInfo();
                        String action = mCurrentSprite.getActiveAction();
                        String direction = mCurrentSprite.getActiveDirection();
                        Layer layer = currentMap.getLayer(selectionLayerNo);
        
                        mClassSetting++;
                        jComboBoxAction.setSelectedItem(action);
                        jComboBoxActionSpriteDirection.setSelectedItem(direction);
                        jTextFieldSpriteX.setText(""+layer.getSpriteStartX(selectionSpriteNo));
                        jTextFieldSpriteY.setText(""+layer.getSpriteStartY(selectionSpriteNo));
                        jComboBoxCoordinator.setSelectedItem(layer.getCoordinatorName(selectionSpriteNo));
                        mClassSetting--;
                        jButtonSpriteChanges.setEnabled(true);
                        fillExample();
                        return;
                    }                    
                }
                // else tiles....
                
                
                if (e.orgMouseEvent.isAltDown())
                {
                    if (selectionLayerNo==-1) return;
                    Layer layer = currentMap.mLayers.get(selectionLayerNo);
                    Tile tile = layer.mTiles.get(selectionTileNo);

                    
                    jTextFieldTileFile.setText(tile.getData().getTileSetFileName());
                    
                    jTextFieldTileFileActionPerformed(null);
                    jComboBoxTileKlasse.setSelectedItem(tile.getData().getCClass());
                    
                    resetActiveTileList(tile.getData().mName);
                    
                    return;
                }
                
                if (jCheckBoxlightOnClick.isSelected())
                {
                    if (currentMap.getCurrentLayer().getData().mpurposeTyp.equals("FOG"))
                    {
                        if ((e.orgMouseEvent.getButton() == MouseEvent.BUTTON1) || (e.draging))
                        {
                            int radius = csa.util.UtilityString.IntX(jTextFieldRadius.getText(),2);
                            mapPanel.liftFog(e.nearestHotSpot.x, e.nearestHotSpot.y, radius);
                            
                            return;
                        }
                    }
                }
                
                
                
                if ((jToggleButtonSetErase.isSelected()) || ((e.orgMouseEvent.isControlDown())))
                {
                    // erase current tile under cursor
                    if (selectionLayerNo == -1 ) return;

                    mapPanel.deleteTile(selectionLayerNo, selectionTileNo);

                    selectionLayerNo = -1;
                    selectionTileNo = -1;
                    if (mTileListForm != null)
                    {
                        mTileListForm.updateTileList();
                    }
                    updateLayerSize();
                    return;
                }
                selectionLayerNo=-1;
                selectionTileNo = -1;

                // set a tile
                if ((e.orgMouseEvent.getButton() == MouseEvent.BUTTON1) || (e.draging))
                {
                    if (e.orgMouseEvent.isShiftDown())
                    {
                        if (sleftMouseTile == null) return;
                        addTile(sleftMouseTile, e.nearestHotSpot.x, e.nearestHotSpot.y);
                        mapPanel.updateNeeded(true);
                    }
                    else
                    {
                        
                        
                        if (leftMouseTile == null)
                        {
                            if (mCurrentCompositeTile!=null)
                            {
                                addTile(mCurrentCompositeTile, e.nearestHotSpot.x, e.nearestHotSpot.y);
                                mapPanel.updateNeeded(true);
                            }
                            return;
                        }
                        
                        addTile(leftMouseTile, e.nearestHotSpot.x, e.nearestHotSpot.y);
                        mapPanel.updateNeeded(true);
                        //mapPanel.setMapChanged(true); done by add tile
                    }
                }
                if (e.orgMouseEvent.getButton() == MouseEvent.BUTTON3)
                {
                    if (e.orgMouseEvent.isShiftDown())
                    {
                        if (srightMouseTile == null) return;
                        addTile(srightMouseTile, e.nearestHotSpot.x, e.nearestHotSpot.y);
                        mapPanel.updateNeeded(true);
                    }
                    else
                    {
                        if (rightMouseTile == null) return;
                        addTile(rightMouseTile, e.nearestHotSpot.x, e.nearestHotSpot.y);
                        mapPanel.updateNeeded(true);
                    }
                }
                if (e.orgMouseEvent.getButton() == MouseEvent.BUTTON2)
                {
                    if (e.orgMouseEvent.isShiftDown())
                    {
                        if (smiddleMouseTile == null) return;
                        addTile(smiddleMouseTile, e.nearestHotSpot.x, e.nearestHotSpot.y);
                        mapPanel.updateNeeded(true);
                    }
                    else
                    {
                        if (middleMouseTile == null) return;
                        addTile(middleMouseTile, e.nearestHotSpot.x, e.nearestHotSpot.y);
                        mapPanel.updateNeeded(true);
                    }
                }
                if (mTileListForm != null)
                {
                    mTileListForm.updateTileList();
                }
            }
        });

        mMapDataPool = new MapDataPool("Maps"+File.separator+ "MapData.xml");
        resetMapConfigPool();



        currentMap = new TMap();
        mMapData = currentMap.getData();
        mLayerDataPool = currentMap.getLayerPool();
        mapPanel.setMap(currentMap);

        mGridSettingsDataPool = new GridSettingsDataPool("Maps"+File.separator+ "GridSettingsData.xml");
        resetGridConfigPool();

        MouseAdapter ma=null;
        jTableLayer.removeMouseListener(ma);
        ma = new java.awt.event.MouseAdapter() {
            @Override public void mouseClicked(java.awt.event.MouseEvent evt) {
                ;
            }
            @Override public void mousePressed(java.awt.event.MouseEvent e) {
                mousePressedOnTable(e);
            }
        };
        jTableLayer.addMouseListener(ma);

        initLayersFromMap();
    }

    private void resetMapConfigPool()
    {
        mClassSetting++;
        int i = 0;

        Collection<MapData> colC = mMapDataPool.getHashMap().values();
        Iterator<MapData> iterC = colC.iterator();

        jComboBoxMapName.removeAllItems();
        while (iterC.hasNext())
        {
            MapData item = iterC.next();
            jComboBoxMapName.addItem(item.mName);
            i++;
        }
        jComboBoxMapName.setSelectedIndex(-1);
        mClassSetting--;
    }


    void initLayersFromMap()
    {
        if (jTextFieldMapName.getText().trim().length()==0)
        {
            currentMap = new TMap();
            mMapData = currentMap.getData();
            mLayerDataPool = currentMap.getLayerPool();
            mapPanel.setMap(currentMap);

            clearAllLayerData();
            resetLayerConfigPool();

            setSelectedLayer("", 0);
            setMapSelectedGrid();
            initLayerTable();

            return;
        }
        else
            currentMap = new TMap(mMapData);
        mLayerDataPool = currentMap.getLayerPool();

        clearAllLayerData();
        resetLayerConfigPool();

        setSelectedLayer("", 0);
        setMapSelectedGrid();
        initLayerTable();
        updateLayerSize();
    }

    void initLayerTable()
    {
        TableModel  lModel =
        new AbstractTableModel() {
            @Override
            public String getColumnName(int col) {
                if (col == 0) return "Depth";
                if (col == 1) return "Name";
                if (col == 2) return "Visible";
                if (col == 3) return "Active";
                return "";
            }
            @Override
            public int getRowCount() { return currentMap.getCurrentLayers().size(); }
            @Override
            public int getColumnCount() { return 4; }
            @Override
            public Object getValueAt(int row, int col)
            {
                if (col == 0) return currentMap.getCurrentLayers().get(row).getData().mLayerNumber;
                if (col == 1) return currentMap.getCurrentLayers().get(row).getData().mLayerName;
                if (col == 2) return currentMap.getCurrentLayers().get(row).getData().misVisible;
                if (col == 3) return row == currentMap.getCurrentLayerNo();


                return "";
            }
            @Override
            public boolean isCellEditable(int row, int col)
                { if (col == 2) return true; return false;}

            @Override
            public Class getColumnClass(int col)
            {
                if (col == 0) return Integer.class;
                if (col == 1) return String.class;
                if (col == 2) return Boolean.class;
                if (col == 3) return Boolean.class;
                return String.class;
            }
            @Override
            public void setValueAt(Object value, int row, int col)
            {
                if (value == null) return;
                Boolean b = (Boolean) value;

                // aktive layer darf nicht unsichtbar werden!
                if (currentMap.getCurrentLayerNo() == row) return;

                currentMap.getCurrentLayers().get(row).getData().misVisible =b;
                mapPanel.visibilityChanged();

                fireTableCellUpdated(row, col);
            }
        };



        jTableLayer.setModel(lModel);


        DefaultTableCellRenderer renderer = new DefaultTableCellRenderer() {
            @Override
        public Component getTableCellRendererComponent(
                                    JTable table, Object color,
                                    boolean isSelected, boolean hasFocus,
                                    int row, int column) {
                super.getTableCellRendererComponent( table, color, isSelected, hasFocus, row, column);
                if (row == currentMap.getCurrentLayerNo())
                {
                    setBackground(Color.lightGray);
                }
                else
                {
                    setBackground(Color.WHITE);
                }
                return this;
            }
        };
    }
    public void deinit()
    {
        imageComponentLeft.deinit();
        imageComponentRight.deinit();
        imageComponentSLeft.deinit();
        imageComponentSRight.deinit();
        mapPanel.deinit();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel4 = new javax.swing.JPanel();
        jSlider1 = new javax.swing.JSlider();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jButtonLayerDown = new javax.swing.JButton();
        jButtonLayerUp = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableLayer = new javax.swing.JTable();
        jTextFieldLayerWidth = new javax.swing.JTextField();
        jTextFieldLayerHeight = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jCheckBoxLayerIsBackground = new javax.swing.JCheckBox();
        jTextFieldColorR = new javax.swing.JTextField();
        jTextFieldColorG = new javax.swing.JTextField();
        jTextFieldColorB = new javax.swing.JTextField();
        jLabel40 = new javax.swing.JLabel();
        jLabel39 = new javax.swing.JLabel();
        jLabel35 = new javax.swing.JLabel();
        jButtonLayerNew = new javax.swing.JButton();
        jButtonLayerDelete = new javax.swing.JButton();
        jButtonLayerSave = new javax.swing.JButton();
        jTextFieldLayerName = new javax.swing.JTextField();
        jButtonSaveAsNew = new javax.swing.JButton();
        jCheckBoxLayerAllowTileOverlap = new javax.swing.JCheckBox();
        jButton1 = new javax.swing.JButton();
        jCheckBoxLayerOnlyOnePosition = new javax.swing.JCheckBox();
        jCheckBoxLayerWrapVertical = new javax.swing.JCheckBox();
        jCheckBoxLayerWrapHorizontal = new javax.swing.JCheckBox();
        jButton12 = new javax.swing.JButton();
        jLabel21 = new javax.swing.JLabel();
        jTextFieldTileCount = new javax.swing.JTextField();
        jCheckBoxISOAssumed = new javax.swing.JCheckBox();
        jButton11 = new javax.swing.JButton();
        jLabel30 = new javax.swing.JLabel();
        jLabel31 = new javax.swing.JLabel();
        jTextFieldTileComplete = new javax.swing.JTextField();
        jTextFieldTileRegular = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldMapWidth = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldHeight = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldGridName = new javax.swing.JTextField();
        jComboBoxGridNameCombo = new javax.swing.JComboBox();
        jPanel6 = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        jTextFieldGridEveryX = new javax.swing.JTextField();
        jLabel28 = new javax.swing.JLabel();
        jTextFieldGridOffsetX1 = new javax.swing.JTextField();
        jCheckBoxXAltertating = new javax.swing.JCheckBox();
        jPanel7 = new javax.swing.JPanel();
        jTextFieldGridOffsetY1 = new javax.swing.JTextField();
        jTextFieldGridEveryY = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        jCheckBoxYAltertating = new javax.swing.JCheckBox();
        jButtonGridNew = new javax.swing.JButton();
        jButtonGridSave = new javax.swing.JButton();
        jComboBoxDrawType = new javax.swing.JComboBox();
        jLabel34 = new javax.swing.JLabel();
        jTextFieldColorRGrid = new javax.swing.JTextField();
        jLabel36 = new javax.swing.JLabel();
        jTextFieldColorGGrid = new javax.swing.JTextField();
        jLabel41 = new javax.swing.JLabel();
        jLabel42 = new javax.swing.JLabel();
        jTextFieldColorBGrid = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jCheckBoxSHowHotsspot = new javax.swing.JCheckBox();
        jCheckBoxLayerBinary = new javax.swing.JCheckBox();
        jLabel27 = new javax.swing.JLabel();
        jTextFieldTileCountMap = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButtonInsertTransitionTiles = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jButtonLayerFromImage1 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButtonLayerFromImage2 = new javax.swing.JButton();
        jButtonGrowTiles = new javax.swing.JButton();
        jCheckBoxConsidderWrapping = new javax.swing.JCheckBox();
        jButton5 = new javax.swing.JButton();
        jButtonAddFogOfWar = new javax.swing.JButton();
        jCheckBoxlightOnClick = new javax.swing.JCheckBox();
        jTextFieldRadius = new javax.swing.JTextField();
        jLabel47 = new javax.swing.JLabel();
        jPanel11 = new javax.swing.JPanel();
        jPanel12 = new javax.swing.JPanel();
        jButton4 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jCheckBox4 = new javax.swing.JCheckBox();
        jPanel13 = new javax.swing.JPanel();
        jButtonOffsetUp = new javax.swing.JButton();
        jButtonOffsetDown = new javax.swing.JButton();
        jButtonOffsetRight = new javax.swing.JButton();
        jButtonOffsetLeft = new javax.swing.JButton();
        jTextField7 = new javax.swing.JTextField();
        jTextField8 = new javax.swing.JTextField();
        jTextField9 = new javax.swing.JTextField();
        jTextField10 = new javax.swing.JTextField();
        jCheckBox5 = new javax.swing.JCheckBox();
        jButton9 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jButton15 = new javax.swing.JButton();
        mapPanel = new csa.tiletools.map.MapPanel();
        jPanel8 = new javax.swing.JPanel();
        jCheckBoxGridEnable = new javax.swing.JCheckBox();
        jCheckBoxSnapToGrid = new javax.swing.JCheckBox();
        jToggleButtonSetErase = new javax.swing.JToggleButton();
        jLabel3 = new javax.swing.JLabel();
        imageComponentUnderCursor = new csa.tiletools.graphics.ImageComponent();
        jLabelCoords = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jLabelOffset = new javax.swing.JLabel();
        jLabelSize = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jCheckBoxReplaceTile = new javax.swing.JCheckBox();
        jTabbedPane2 = new javax.swing.JTabbedPane();
        jPanel9 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldTileFile = new javax.swing.JTextField();
        jButtonFileSelect1 = new javax.swing.JButton();
        jPanelTileView = new javax.swing.JPanel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        imageComponentLeft = new csa.tiletools.graphics.ImageComponent();
        imageComponentSLeft = new csa.tiletools.graphics.ImageComponent();
        imageComponentRight = new csa.tiletools.graphics.ImageComponent();
        imageComponentSRight = new csa.tiletools.graphics.ImageComponent();
        imageComponentMiddle = new csa.tiletools.graphics.ImageComponent();
        imageComponentSMiddle = new csa.tiletools.graphics.ImageComponent();
        jLabel11 = new javax.swing.JLabel();
        jCheckBoxTileScale = new javax.swing.JCheckBox();
        jLabel13 = new javax.swing.JLabel();
        jLabelTileSize = new javax.swing.JLabel();
        jComboBoxTileKlasse = new javax.swing.JComboBox();
        jLabel33 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jPanelIMageCollection1 = new javax.swing.JPanel();
        jPanel17 = new javax.swing.JPanel();
        jPanel14 = new javax.swing.JPanel();
        jLabel24 = new javax.swing.JLabel();
        jTextFieldTileFile1 = new javax.swing.JTextField();
        jButtonFileSelect2 = new javax.swing.JButton();
        jComboBoxTileKlasse1 = new javax.swing.JComboBox();
        jLabel37 = new javax.swing.JLabel();
        jLabelTileSize1 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel38 = new javax.swing.JLabel();
        jTextFieldCompositeName = new javax.swing.JTextField();
        jButtonMapDelete1 = new javax.swing.JButton();
        jButtonMapSave1 = new javax.swing.JButton();
        jLabel43 = new javax.swing.JLabel();
        jTextFieldCompositeClass = new javax.swing.JTextField();
        jScrollPane3 = new javax.swing.JScrollPane();
        jPanelIMageCollection2 = new javax.swing.JPanel();
        jPanel18 = new javax.swing.JPanel();
        jPanel15 = new javax.swing.JPanel();
        jLabel44 = new javax.swing.JLabel();
        jLabel45 = new javax.swing.JLabel();
        jTextFieldSpriteFile = new javax.swing.JTextField();
        jComboBoxSpriteKlasse = new javax.swing.JComboBox();
        jButtonSpriteFileSelect = new javax.swing.JButton();
        jPanelSpriteImageCollection = new javax.swing.JPanel();
        jPanel16 = new javax.swing.JPanel();
        jPanel19 = new javax.swing.JPanel();
        jComboBoxAction = new javax.swing.JComboBox();
        jLabel127 = new javax.swing.JLabel();
        jComboBoxActionSpriteDirection = new javax.swing.JComboBox();
        jLabel128 = new javax.swing.JLabel();
        jLabel129 = new javax.swing.JLabel();
        jTextFieldSpriteX = new javax.swing.JTextField();
        jTextFieldSpriteY = new javax.swing.JTextField();
        jLabel46 = new javax.swing.JLabel();
        jComboBoxCoordinator = new javax.swing.JComboBox();
        jButtonSpriteChanges = new javax.swing.JButton();
        jPanelExample = new javax.swing.JPanel();
        jButtonScaleToFit = new javax.swing.JButton();
        jPanel10 = new javax.swing.JPanel();
        jComboBoxMapName = new javax.swing.JComboBox();
        jLabel32 = new javax.swing.JLabel();
        jTextFieldMapName = new javax.swing.JTextField();
        jButtonMapNew = new javax.swing.JButton();
        jButtonMapSave = new javax.swing.JButton();
        jButtonMapSaveAsNew = new javax.swing.JButton();
        jButtonMapDelete = new javax.swing.JButton();
        jButtonExport = new javax.swing.JButton();

        setPreferredSize(new java.awt.Dimension(800, 600));

        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setPreferredSize(new java.awt.Dimension(1024, 768));

        jSlider1.setMajorTickSpacing(100);
        jSlider1.setMaximum(1000);
        jSlider1.setMinimum(-1000);
        jSlider1.setMinorTickSpacing(20);
        jSlider1.setOrientation(javax.swing.JSlider.VERTICAL);
        jSlider1.setPaintTicks(true);
        jSlider1.setValue(0);
        jSlider1.setName("jSlider1"); // NOI18N
        jSlider1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jSlider1MouseReleased(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jSlider1MousePressed(evt);
            }
        });
        jSlider1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSlider1StateChanged(evt);
            }
        });

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        jButtonLayerDown.setLabel("Down");
        jButtonLayerDown.setName("jButtonLayerDown"); // NOI18N
        jButtonLayerDown.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLayerDownActionPerformed(evt);
            }
        });

        jButtonLayerUp.setLabel("Up");
        jButtonLayerUp.setName("jButtonLayerUp"); // NOI18N
        jButtonLayerUp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLayerUpActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTableLayer.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTableLayer.setName("jTableLayer"); // NOI18N
        jTableLayer.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        jScrollPane1.setViewportView(jTableLayer);

        jTextFieldLayerWidth.setEditable(false);
        jTextFieldLayerWidth.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        jTextFieldLayerWidth.setText("1000");
        jTextFieldLayerWidth.setName("jTextFieldLayerWidth"); // NOI18N

        jTextFieldLayerHeight.setEditable(false);
        jTextFieldLayerHeight.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        jTextFieldLayerHeight.setText("1000");
        jTextFieldLayerHeight.setName("jTextFieldLayerHeight"); // NOI18N

        jLabel15.setText("Height");
        jLabel15.setName("jLabel15"); // NOI18N

        jLabel16.setText("Width");
        jLabel16.setName("jLabel16"); // NOI18N

        jCheckBoxLayerIsBackground.setText("is Background");
        jCheckBoxLayerIsBackground.setName("jCheckBoxLayerIsBackground"); // NOI18N
        jCheckBoxLayerIsBackground.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxLayerIsBackgroundActionPerformed(evt);
            }
        });

        jTextFieldColorR.setText("0");
        jTextFieldColorR.setName("jTextFieldColorR"); // NOI18N
        jTextFieldColorR.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldColorRFocusLost(evt);
            }
        });

        jTextFieldColorG.setText("0");
        jTextFieldColorG.setName("jTextFieldColorG"); // NOI18N
        jTextFieldColorG.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldColorGFocusLost(evt);
            }
        });

        jTextFieldColorB.setText("0");
        jTextFieldColorB.setName("jTextFieldColorB"); // NOI18N
        jTextFieldColorB.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldColorBFocusLost(evt);
            }
        });

        jLabel40.setText("B");
        jLabel40.setName("jLabel40"); // NOI18N

        jLabel39.setText("G");
        jLabel39.setName("jLabel39"); // NOI18N

        jLabel35.setText("R");
        jLabel35.setName("jLabel35"); // NOI18N

        jButtonLayerNew.setText("New");
        jButtonLayerNew.setName("jButtonLayerNew"); // NOI18N
        jButtonLayerNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLayerNewActionPerformed(evt);
            }
        });

        jButtonLayerDelete.setText("Delete");
        jButtonLayerDelete.setToolTipText("Does not commit delete to disk. Use save for that.");
        jButtonLayerDelete.setName("jButtonLayerDelete"); // NOI18N
        jButtonLayerDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLayerDeleteActionPerformed(evt);
            }
        });

        jButtonLayerSave.setText("Save");
        jButtonLayerSave.setName("jButtonLayerSave"); // NOI18N
        jButtonLayerSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLayerSaveActionPerformed(evt);
            }
        });

        jTextFieldLayerName.setName("jTextFieldLayerName"); // NOI18N

        jButtonSaveAsNew.setText("As new");
        jButtonSaveAsNew.setEnabled(false);
        jButtonSaveAsNew.setName("jButtonSaveAsNew"); // NOI18N
        jButtonSaveAsNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveAsNewActionPerformed(evt);
            }
        });

        jCheckBoxLayerAllowTileOverlap.setText("allow tile overlap");
        jCheckBoxLayerAllowTileOverlap.setToolTipText("If selected the placing of tiles on each other is allowed in the current layer.");
        jCheckBoxLayerAllowTileOverlap.setName("jCheckBoxLayerAllowTileOverlap"); // NOI18N
        jCheckBoxLayerAllowTileOverlap.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxLayerAllowTileOverlapActionPerformed(evt);
            }
        });

        jButton1.setText("Tilelist");
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jCheckBoxLayerOnlyOnePosition.setSelected(true);
        jCheckBoxLayerOnlyOnePosition.setText("single position");
        jCheckBoxLayerOnlyOnePosition.setToolTipText("If selected placing tiles on exact the same position is not allowed.");
        jCheckBoxLayerOnlyOnePosition.setName("jCheckBoxLayerOnlyOnePosition"); // NOI18N
        jCheckBoxLayerOnlyOnePosition.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxLayerOnlyOnePositionActionPerformed(evt);
            }
        });

        jCheckBoxLayerWrapVertical.setText("Wrap vertically");
        jCheckBoxLayerWrapVertical.setName("jCheckBoxLayerWrapVertical"); // NOI18N
        jCheckBoxLayerWrapVertical.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxLayerWrapVerticalActionPerformed(evt);
            }
        });

        jCheckBoxLayerWrapHorizontal.setText("Wrap horizontally");
        jCheckBoxLayerWrapHorizontal.setName("jCheckBoxLayerWrapHorizontal"); // NOI18N
        jCheckBoxLayerWrapHorizontal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxLayerWrapHorizontalActionPerformed(evt);
            }
        });

        jButton12.setText("Join");
        jButton12.setToolTipText("<html>\nJoin selected Layers.<BR>\nSelected layers will be joined to a new created layer.<br>\n\"Old\" - selected layers will be deleted.<br>\nTiles in the new layer will be ordered to be displayed like ordered\nin the old layers.\n</html>\n");
        jButton12.setName("jButton12"); // NOI18N
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });

        jLabel21.setText("Tilecount");
        jLabel21.setName("jLabel21"); // NOI18N

        jTextFieldTileCount.setEditable(false);
        jTextFieldTileCount.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        jTextFieldTileCount.setText("0");
        jTextFieldTileCount.setName("jTextFieldTileCount"); // NOI18N

        jCheckBoxISOAssumed.setText("assume ISO");
        jCheckBoxISOAssumed.setToolTipText("<html>\nRegard Layer as ISO layer, in regard to:<BR>\n- Wrapping<BR>\n- Regularity<BR> <BR>\nIf the Map is an ISO BLock map,<BR>\nand would like to wrap it, you<BR>\nshould check here, the wrapping algorithm<BR>\nwill than consider a half tile offset on the edges.\n</html>");
        jCheckBoxISOAssumed.setName("jCheckBoxISOAssumed"); // NOI18N
        jCheckBoxISOAssumed.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxISOAssumedActionPerformed(evt);
            }
        });

        jButton11.setText("test");
        jButton11.setToolTipText("Test again if regular");
        jButton11.setName("jButton11"); // NOI18N
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });

        jLabel30.setText("is regular:");
        jLabel30.setName("jLabel30"); // NOI18N

        jLabel31.setText("is complete:");
        jLabel31.setName("jLabel31"); // NOI18N

        jTextFieldTileComplete.setEditable(false);
        jTextFieldTileComplete.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        jTextFieldTileComplete.setText("no");
        jTextFieldTileComplete.setToolTipText("Complete & Ordered!");
        jTextFieldTileComplete.setName("jTextFieldTileComplete"); // NOI18N

        jTextFieldTileRegular.setEditable(false);
        jTextFieldTileRegular.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        jTextFieldTileRegular.setText("no");
        jTextFieldTileRegular.setName("jTextFieldTileRegular"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonLayerDown)
                    .addComponent(jButtonLayerUp, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(jTextFieldLayerName, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jCheckBoxLayerIsBackground))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel35)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldColorR))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel40)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jTextFieldColorB, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel39)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldColorG, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(104, 104, 104))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(9, 9, 9)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButtonLayerSave)
                    .addComponent(jButtonLayerNew)
                    .addComponent(jButtonLayerDelete)
                    .addComponent(jButtonSaveAsNew, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(30, 30, 30))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(12, 12, 12)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel16)
                                    .addComponent(jLabel15)))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel21)))
                        .addGap(1, 1, 1)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldLayerWidth, javax.swing.GroupLayout.DEFAULT_SIZE, 63, Short.MAX_VALUE)
                            .addComponent(jTextFieldTileCount)
                            .addComponent(jTextFieldLayerHeight)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel31)
                            .addComponent(jLabel30))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldTileRegular, javax.swing.GroupLayout.DEFAULT_SIZE, 35, Short.MAX_VALUE)
                            .addComponent(jTextFieldTileComplete))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBoxLayerOnlyOnePosition, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBoxLayerWrapHorizontal)
                            .addComponent(jCheckBoxLayerWrapVertical)
                            .addComponent(jCheckBoxLayerAllowTileOverlap)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jCheckBoxISOAssumed)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButton11)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(jTextFieldLayerWidth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBoxLayerAllowTileOverlap))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(jTextFieldLayerHeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBoxLayerOnlyOnePosition))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel30)
                        .addComponent(jTextFieldTileRegular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jCheckBoxLayerWrapHorizontal))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel31)
                        .addComponent(jTextFieldTileComplete, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jCheckBoxLayerWrapVertical))
                .addGap(4, 4, 4)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(jTextFieldTileCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBoxISOAssumed)
                    .addComponent(jButton11))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButtonLayerNew)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonLayerSave)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonLayerDelete)
                        .addGap(2, 2, 2)
                        .addComponent(jButtonSaveAsNew)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton12)
                        .addGap(15, 15, 15))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel35)
                            .addComponent(jTextFieldColorR, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldColorG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel39))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldColorB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel40)))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButtonLayerDown)
                            .addComponent(jTextFieldLayerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButtonLayerUp)
                            .addComponent(jCheckBoxLayerIsBackground, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(65, 65, 65))
        );

        jTabbedPane1.addTab("Layers", jPanel2);

        jPanel1.setName("MapProperties"); // NOI18N

        jLabel7.setText("Width");
        jLabel7.setName("jLabel7"); // NOI18N

        jTextFieldMapWidth.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        jTextFieldMapWidth.setText("1000");
        jTextFieldMapWidth.setEnabled(false);
        jTextFieldMapWidth.setName("jTextFieldMapWidth"); // NOI18N

        jLabel8.setText("Height");
        jLabel8.setName("jLabel8"); // NOI18N

        jTextFieldHeight.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        jTextFieldHeight.setText("1000");
        jTextFieldHeight.setEnabled(false);
        jTextFieldHeight.setName("jTextFieldHeight"); // NOI18N

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Grid Settings"));
        jPanel5.setName("jPanel5"); // NOI18N

        jLabel4.setText("Name:");
        jLabel4.setName("jLabel4"); // NOI18N

        jTextFieldGridName.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        jTextFieldGridName.setName("jTextFieldGridName"); // NOI18N

        jComboBoxGridNameCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBoxGridNameCombo.setName("jComboBoxGridNameCombo"); // NOI18N
        jComboBoxGridNameCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxGridNameComboActionPerformed(evt);
            }
        });

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("X-Axis"));
        jPanel6.setName("jPanel6"); // NOI18N

        jLabel18.setText("Every:");
        jLabel18.setName("jLabel18"); // NOI18N

        jTextFieldGridEveryX.setName("jTextFieldGridEveryX"); // NOI18N
        jTextFieldGridEveryX.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldGridEveryXActionPerformed(evt);
            }
        });

        jLabel28.setText("Offsets:");
        jLabel28.setName("jLabel28"); // NOI18N

        jTextFieldGridOffsetX1.setName("jTextFieldGridOffsetX1"); // NOI18N
        jTextFieldGridOffsetX1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldGridOffsetX1ActionPerformed(evt);
            }
        });

        jCheckBoxXAltertating.setText("Alternating");
        jCheckBoxXAltertating.setToolTipText("Alternates the direction of the \"Every X\" with each Y Line!");
        jCheckBoxXAltertating.setName("jCheckBoxXAltertating"); // NOI18N
        jCheckBoxXAltertating.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxXAltertatingActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel18)
                            .addComponent(jLabel28))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldGridOffsetX1, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)
                            .addComponent(jTextFieldGridEveryX)))
                    .addComponent(jCheckBoxXAltertating))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(jTextFieldGridEveryX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldGridOffsetX1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel28))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jCheckBoxXAltertating))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Y-Axis"));
        jPanel7.setName("jPanel7"); // NOI18N

        jTextFieldGridOffsetY1.setEditable(false);
        jTextFieldGridOffsetY1.setEnabled(false);
        jTextFieldGridOffsetY1.setName("jTextFieldGridOffsetY1"); // NOI18N
        jTextFieldGridOffsetY1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldGridOffsetY1ActionPerformed(evt);
            }
        });

        jTextFieldGridEveryY.setName("jTextFieldGridEveryY"); // NOI18N
        jTextFieldGridEveryY.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldGridEveryYActionPerformed(evt);
            }
        });

        jLabel19.setText("Every:");
        jLabel19.setName("jLabel19"); // NOI18N

        jLabel29.setText("Offsets:");
        jLabel29.setName("jLabel29"); // NOI18N

        jCheckBoxYAltertating.setText("Alternating");
        jCheckBoxYAltertating.setEnabled(false);
        jCheckBoxYAltertating.setName("jCheckBoxYAltertating"); // NOI18N
        jCheckBoxYAltertating.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxYAltertatingActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel19)
                            .addComponent(jLabel29))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldGridEveryY, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldGridOffsetY1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jCheckBoxYAltertating))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(jTextFieldGridEveryY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldGridOffsetY1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel29))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jCheckBoxYAltertating))
        );

        jButtonGridNew.setText("New");
        jButtonGridNew.setName("jButtonGridNew"); // NOI18N
        jButtonGridNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGridNewActionPerformed(evt);
            }
        });

        jButtonGridSave.setText("Save");
        jButtonGridSave.setName("jButtonGridSave"); // NOI18N
        jButtonGridSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGridSaveActionPerformed(evt);
            }
        });

        jComboBoxDrawType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Dots", "Square", "Hex", "ISO" }));
        jComboBoxDrawType.setName("jComboBoxDrawType"); // NOI18N
        jComboBoxDrawType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxDrawTypeActionPerformed(evt);
            }
        });

        jLabel34.setText("Drawtype");
        jLabel34.setName("jLabel34"); // NOI18N

        jTextFieldColorRGrid.setText("0");
        jTextFieldColorRGrid.setName("jTextFieldColorRGrid"); // NOI18N
        jTextFieldColorRGrid.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldColorRGridFocusLost(evt);
            }
        });

        jLabel36.setText("R");
        jLabel36.setName("jLabel36"); // NOI18N

        jTextFieldColorGGrid.setText("0");
        jTextFieldColorGGrid.setName("jTextFieldColorGGrid"); // NOI18N
        jTextFieldColorGGrid.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldColorGGridFocusLost(evt);
            }
        });

        jLabel41.setText("G");
        jLabel41.setName("jLabel41"); // NOI18N

        jLabel42.setText("B");
        jLabel42.setName("jLabel42"); // NOI18N

        jTextFieldColorBGrid.setText("0");
        jTextFieldColorBGrid.setName("jTextFieldColorBGrid"); // NOI18N
        jTextFieldColorBGrid.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldColorBGridFocusLost(evt);
            }
        });

        jLabel22.setText("Grid Color");
        jLabel22.setName("jLabel22"); // NOI18N

        jCheckBoxSHowHotsspot.setText("hotspot");
        jCheckBoxSHowHotsspot.setName("jCheckBoxSHowHotsspot"); // NOI18N
        jCheckBoxSHowHotsspot.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxSHowHotsspotActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(4, 4, 4)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jCheckBoxSHowHotsspot, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel22, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel36)
                                    .addComponent(jLabel41)
                                    .addComponent(jLabel42))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldColorBGrid, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldColorGGrid, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldColorRGrid, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(7, 7, 7)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addComponent(jComboBoxGridNameCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButtonGridNew))
                            .addGroup(jPanel5Layout.createSequentialGroup()
                                .addComponent(jTextFieldGridName, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel34)))
                        .addGap(8, 8, 8)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jComboBoxDrawType, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonGridSave))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBoxGridNameCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButtonGridNew)
                                .addComponent(jButtonGridSave)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldGridName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4)
                            .addComponent(jLabel34)))
                    .addComponent(jComboBoxDrawType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel22)
                        .addGap(8, 8, 8)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel36)
                            .addComponent(jTextFieldColorRGrid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel41)
                            .addComponent(jTextFieldColorGGrid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldColorBGrid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel42)))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jCheckBoxSHowHotsspot))))
        );

        jCheckBoxLayerBinary.setText("Layer as binary");
        jCheckBoxLayerBinary.setName("jCheckBoxLayerBinary"); // NOI18N

        jLabel27.setText("Tilecount");
        jLabel27.setName("jLabel27"); // NOI18N

        jTextFieldTileCountMap.setEditable(false);
        jTextFieldTileCountMap.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
        jTextFieldTileCountMap.setText("0");
        jTextFieldTileCountMap.setName("jTextFieldTileCountMap"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addGap(14, 14, 14)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldMapWidth, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
                            .addComponent(jTextFieldHeight))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel27)
                        .addGap(15, 15, 15)
                        .addComponent(jTextFieldTileCountMap, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jCheckBoxLayerBinary))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel5, 321, 321, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 3, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel27)
                        .addComponent(jTextFieldTileCountMap, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(jTextFieldMapWidth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jTextFieldHeight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBoxLayerBinary)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Map Properties", jPanel1);

        jPanel3.setName("jPanel3"); // NOI18N

        jButton2.setText("Save map as Image");
        jButton2.setToolTipText("No animations, the map as it is in THIS moment!");
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButtonInsertTransitionTiles.setText("Build Transition layer");
        jButtonInsertTransitionTiles.setName("jButtonInsertTransitionTiles"); // NOI18N
        jButtonInsertTransitionTiles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonInsertTransitionTilesActionPerformed(evt);
            }
        });

        jLabel6.setFont(jLabel6.getFont().deriveFont(jLabel6.getFont().getSize()-1f));
        jLabel6.setText("Transitions will be done for current active layer.");
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel12.setFont(jLabel12.getFont().deriveFont(jLabel12.getFont().getSize()-1f));
        jLabel12.setText("A new \"transition\"-layer will be inserted after current layer.");
        jLabel12.setName("jLabel12"); // NOI18N

        jLabel14.setFont(jLabel14.getFont().deriveFont(jLabel14.getFont().getSize()-1f));
        jLabel14.setText("Assumed is a grid of the tile size, end expected whether");
        jLabel14.setName("jLabel14"); // NOI18N

        jLabel17.setFont(jLabel17.getFont().deriveFont(jLabel17.getFont().getSize()-1f));
        jLabel17.setText("direct neighbours can be found.");
        jLabel17.setName("jLabel17"); // NOI18N

        jButtonLayerFromImage1.setText("Build layer from algorythm (or image)");
        jButtonLayerFromImage1.setName("jButtonLayerFromImage1"); // NOI18N
        jButtonLayerFromImage1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLayerFromImage1ActionPerformed(evt);
            }
        });

        jButton10.setText("make regular");
        jButton10.setToolTipText("<html>\nTries to make the layer into a regular layer. In order to be possible,<BR>\nall tiles must be of same size!<BR>\nIf all tiles have the same size, than the tiles in the layer will be sorted by <BR>\nposition, so that:<BR>\n\t<LI>yPos*LineWitdh+xPos </LI><BR>\nwill be in ascending order for all tiles.<BR>\n</html><BR>\n");
        jButton10.setName("jButton10"); // NOI18N
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        jButtonLayerFromImage2.setText("Build layer from text");
        jButtonLayerFromImage2.setEnabled(false);
        jButtonLayerFromImage2.setName("jButtonLayerFromImage2"); // NOI18N
        jButtonLayerFromImage2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonLayerFromImage2ActionPerformed(evt);
            }
        });

        jButtonGrowTiles.setText("Grow tiles");
        jButtonGrowTiles.setName("jButtonGrowTiles"); // NOI18N
        jButtonGrowTiles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGrowTilesActionPerformed(evt);
            }
        });

        jCheckBoxConsidderWrapping.setText("considder wrapping");
        jCheckBoxConsidderWrapping.setToolTipText("<html>\nIf selected the border tiles will not have transition tiles \"over the borders\".<B>\nIf selected it means, that usually the resulting transitionlayer has on each side one tile more\nthan the original map.<BR>\n<BR>\nThis is expecially \"bad\" if you want to wrap both layers.\n</html>");
        jCheckBoxConsidderWrapping.setName("jCheckBoxConsidderWrapping"); // NOI18N

        jButton5.setText("x, y -> 0");
        jButton5.setToolTipText("<html>\nZeros the coordinates.<br>\nMeaning:<br>\n- the lowes x coordinate is set to 0<br>\nand<br>\n- the lowes y coordinate is set to 0.<br>\n</html>");
        jButton5.setName("jButton5"); // NOI18N
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButtonAddFogOfWar.setText("add fog of war");
        jButtonAddFogOfWar.setToolTipText("<html>Uses selected tile as fog tile! <BR>Selected tile should support transitions!</html>");
        jButtonAddFogOfWar.setName("jButtonAddFogOfWar"); // NOI18N
        jButtonAddFogOfWar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAddFogOfWarActionPerformed(evt);
            }
        });

        jCheckBoxlightOnClick.setText("light on click");
        jCheckBoxlightOnClick.setName("jCheckBoxlightOnClick"); // NOI18N
        jCheckBoxlightOnClick.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);

        jTextFieldRadius.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        jTextFieldRadius.setText("2");
        jTextFieldRadius.setName("jTextFieldRadius"); // NOI18N

        jLabel47.setText("radius:");
        jLabel47.setName("jLabel47"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(jLabel6)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonInsertTransitionTiles, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(36, 36, 36)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBoxConsidderWrapping)
                            .addComponent(jButton5)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButtonAddFogOfWar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonGrowTiles, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonLayerFromImage2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonLayerFromImage1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel17, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBoxlightOnClick, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel47)))
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jTextFieldRadius, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel14)))
                .addContainerGap(31, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton10)
                    .addComponent(jButton5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonInsertTransitionTiles)
                    .addComponent(jCheckBoxConsidderWrapping))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel17)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonLayerFromImage1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonLayerFromImage2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonGrowTiles)
                    .addComponent(jLabel47)
                    .addComponent(jTextFieldRadius, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonAddFogOfWar)
                    .addComponent(jCheckBoxlightOnClick))
                .addContainerGap(111, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Operations", jPanel3);

        jPanel11.setName("jPanel11"); // NOI18N

        jPanel12.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel12.setName("jPanel12"); // NOI18N
        jPanel12.setLayout(null);

        jButton4.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        jButton4.setText("+");
        jButton4.setEnabled(false);
        jButton4.setName("jButton4"); // NOI18N
        jPanel12.add(jButton4);
        jButton4.setBounds(88, 4, 32, 32);

        jButton6.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        jButton6.setText("+");
        jButton6.setEnabled(false);
        jButton6.setName("jButton6"); // NOI18N
        jPanel12.add(jButton6);
        jButton6.setBounds(88, 126, 32, 32);

        jButton8.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        jButton8.setText("+");
        jButton8.setEnabled(false);
        jButton8.setName("jButton8"); // NOI18N
        jPanel12.add(jButton8);
        jButton8.setBounds(150, 68, 32, 32);

        jButton7.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        jButton7.setText("+");
        jButton7.setEnabled(false);
        jButton7.setName("jButton7"); // NOI18N
        jPanel12.add(jButton7);
        jButton7.setBounds(22, 68, 32, 32);

        jTextField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextField1.setText("100");
        jTextField1.setEnabled(false);
        jTextField1.setName("jTextField1"); // NOI18N
        jPanel12.add(jTextField1);
        jTextField1.setBounds(89, 40, 24, 20);

        jTextField2.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextField2.setText("100");
        jTextField2.setEnabled(false);
        jTextField2.setName("jTextField2"); // NOI18N
        jPanel12.add(jTextField2);
        jTextField2.setBounds(86, 102, 30, 20);

        jTextField5.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextField5.setText("100");
        jTextField5.setEnabled(false);
        jTextField5.setName("jTextField5"); // NOI18N
        jPanel12.add(jTextField5);
        jTextField5.setBounds(54, 74, 30, 20);

        jTextField6.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextField6.setText("100");
        jTextField6.setEnabled(false);
        jTextField6.setName("jTextField6"); // NOI18N
        jPanel12.add(jTextField6);
        jTextField6.setBounds(117, 74, 24, 20);

        jCheckBox4.setSelected(true);
        jCheckBox4.setText("All layers");
        jCheckBox4.setToolTipText("Alternatly - only current selected layer!");
        jCheckBox4.setName("jCheckBox4"); // NOI18N

        jPanel13.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel13.setName("jPanel13"); // NOI18N
        jPanel13.setLayout(null);

        jButtonOffsetUp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/csa/images/UpArrow.png"))); // NOI18N
        jButtonOffsetUp.setName("jButtonOffsetUp"); // NOI18N
        jButtonOffsetUp.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButtonOffsetUpMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButtonOffsetUpMouseReleased(evt);
            }
        });
        jButtonOffsetUp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOffsetUpActionPerformed(evt);
            }
        });
        jPanel13.add(jButtonOffsetUp);
        jButtonOffsetUp.setBounds(88, 4, 32, 32);

        jButtonOffsetDown.setIcon(new javax.swing.ImageIcon(getClass().getResource("/csa/images/DownArrow.png"))); // NOI18N
        jButtonOffsetDown.setName("jButtonOffsetDown"); // NOI18N
        jButtonOffsetDown.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButtonOffsetDownMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButtonOffsetDownMouseReleased(evt);
            }
        });
        jButtonOffsetDown.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOffsetDownActionPerformed(evt);
            }
        });
        jPanel13.add(jButtonOffsetDown);
        jButtonOffsetDown.setBounds(88, 126, 32, 32);

        jButtonOffsetRight.setIcon(new javax.swing.ImageIcon(getClass().getResource("/csa/images/RightArrow.png"))); // NOI18N
        jButtonOffsetRight.setName("jButtonOffsetRight"); // NOI18N
        jButtonOffsetRight.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButtonOffsetRightMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButtonOffsetRightMouseReleased(evt);
            }
        });
        jButtonOffsetRight.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOffsetRightActionPerformed(evt);
            }
        });
        jPanel13.add(jButtonOffsetRight);
        jButtonOffsetRight.setBounds(152, 68, 32, 32);

        jButtonOffsetLeft.setIcon(new javax.swing.ImageIcon(getClass().getResource("/csa/images/LeftArrow.png"))); // NOI18N
        jButtonOffsetLeft.setName("jButtonOffsetLeft"); // NOI18N
        jButtonOffsetLeft.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButtonOffsetLeftMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jButtonOffsetLeftMouseReleased(evt);
            }
        });
        jButtonOffsetLeft.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOffsetLeftActionPerformed(evt);
            }
        });
        jPanel13.add(jButtonOffsetLeft);
        jButtonOffsetLeft.setBounds(20, 68, 32, 32);

        jTextField7.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextField7.setText("100");
        jTextField7.setName("jTextField7"); // NOI18N
        jPanel13.add(jTextField7);
        jTextField7.setBounds(89, 40, 30, 20);

        jTextField8.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextField8.setText("100");
        jTextField8.setName("jTextField8"); // NOI18N
        jPanel13.add(jTextField8);
        jTextField8.setBounds(89, 102, 30, 20);

        jTextField9.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextField9.setText("100");
        jTextField9.setName("jTextField9"); // NOI18N
        jPanel13.add(jTextField9);
        jTextField9.setBounds(54, 74, 30, 20);

        jTextField10.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextField10.setText("100");
        jTextField10.setName("jTextField10"); // NOI18N
        jPanel13.add(jTextField10);
        jTextField10.setBounds(120, 74, 30, 20);

        jCheckBox5.setText("Auto");
        jCheckBox5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jCheckBox5.setName("jCheckBox5"); // NOI18N
        jCheckBox5.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
        jCheckBox5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jCheckBox5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox5ActionPerformed(evt);
            }
        });
        jPanel13.add(jCheckBox5);
        jCheckBox5.setBounds(89, 66, 25, 33);

        jButton9.setText("0,0");
        jButton9.setName("jButton9"); // NOI18N
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });
        jPanel13.add(jButton9);
        jButton9.setBounds(12, 8, 50, 20);

        jButton13.setText("Navi");
        jButton13.setName("jButton13"); // NOI18N
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });

        jButton14.setText("-");
        jButton14.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton14.setMargin(new java.awt.Insets(1, 1, 1, 1));
        jButton14.setName("jButton14"); // NOI18N
        jButton14.setPreferredSize(new java.awt.Dimension(14, 14));
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });

        jButton15.setText("+");
        jButton15.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton15.setMargin(new java.awt.Insets(1, 1, 1, 1));
        jButton15.setName("jButton15"); // NOI18N
        jButton15.setPreferredSize(new java.awt.Dimension(14, 14));
        jButton15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton15ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBox4)
                            .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(jPanel11Layout.createSequentialGroup()
                                    .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jButton13, javax.swing.GroupLayout.Alignment.LEADING))))
                    .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(35, Short.MAX_VALUE))
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addComponent(jCheckBox4)
                        .addGap(33, 33, 33)
                        .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton13))
                    .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel12, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(27, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Map Navigation", jPanel11);

        mapPanel.setName("mapPanel"); // NOI18N

        javax.swing.GroupLayout mapPanelLayout = new javax.swing.GroupLayout(mapPanel);
        mapPanel.setLayout(mapPanelLayout);
        mapPanelLayout.setHorizontalGroup(
            mapPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        mapPanelLayout.setVerticalGroup(
            mapPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jPanel8.setName("jPanel8"); // NOI18N
        jPanel8.setPreferredSize(new java.awt.Dimension(200, 36));

        jCheckBoxGridEnable.setText("Grid");
        jCheckBoxGridEnable.setName("jCheckBoxGridEnable"); // NOI18N
        jCheckBoxGridEnable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxGridEnableActionPerformed(evt);
            }
        });

        jCheckBoxSnapToGrid.setText("snap");
        jCheckBoxSnapToGrid.setToolTipText("Snap to nearest hotspot of current grid");
        jCheckBoxSnapToGrid.setEnabled(false);
        jCheckBoxSnapToGrid.setName("jCheckBoxSnapToGrid"); // NOI18N
        jCheckBoxSnapToGrid.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxSnapToGridActionPerformed(evt);
            }
        });

        jToggleButtonSetErase.setText("Set Tile");
        jToggleButtonSetErase.setName("jToggleButtonSetErase"); // NOI18N
        jToggleButtonSetErase.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButtonSetEraseActionPerformed(evt);
            }
        });

        jLabel3.setText("Tile");
        jLabel3.setName("jLabel3"); // NOI18N

        imageComponentUnderCursor.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        imageComponentUnderCursor.setToolTipText("This is the uppermost tile in the current selected layer.");
        imageComponentUnderCursor.setName("imageComponentUnderCursor"); // NOI18N
        imageComponentUnderCursor.setPreferredSize(new java.awt.Dimension(22, 22));

        javax.swing.GroupLayout imageComponentUnderCursorLayout = new javax.swing.GroupLayout(imageComponentUnderCursor);
        imageComponentUnderCursor.setLayout(imageComponentUnderCursorLayout);
        imageComponentUnderCursorLayout.setHorizontalGroup(
            imageComponentUnderCursorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );
        imageComponentUnderCursorLayout.setVerticalGroup(
            imageComponentUnderCursorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jLabelCoords.setText("0 / 0");
        jLabelCoords.setName("jLabelCoords"); // NOI18N

        jLabel20.setText("Coords:");
        jLabel20.setName("jLabel20"); // NOI18N

        jLabel26.setText("Offset:");
        jLabel26.setName("jLabel26"); // NOI18N

        jLabelOffset.setText("0 / 0");
        jLabelOffset.setName("jLabelOffset"); // NOI18N

        jLabelSize.setText("0 / 0");
        jLabelSize.setName("jLabelSize"); // NOI18N

        jLabel23.setText("Size:");
        jLabel23.setName("jLabel23"); // NOI18N

        jLabel2.setText("100%");
        jLabel2.setName("jLabel2"); // NOI18N

        jCheckBoxReplaceTile.setToolTipText("<html>\nIf selected: Tiles will be replaced if possible<BR>\n(Not with composite tiles.)<BR>\n<BR>\n<B>Note</b><BR>\nIf \"not overlap\" is selected, and tile is overlapping but no replace tile is<BR>\nfound at the current x,y position, a add is performed nonethless<BR> \n-> overlapping tiles are possible with replacement enabled!\n\n</html>");
        jCheckBoxReplaceTile.setName("jCheckBoxReplaceTile"); // NOI18N
        jCheckBoxReplaceTile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxReplaceTileActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(imageComponentUnderCursor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBoxGridEnable)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBoxSnapToGrid)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToggleButtonSetErase, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCheckBoxReplaceTile)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel20)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelCoords, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel26)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelOffset, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel23)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelSize, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBoxReplaceTile, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jCheckBoxGridEnable, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jCheckBoxSnapToGrid, javax.swing.GroupLayout.Alignment.TRAILING)))
                    .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel2)
                        .addComponent(imageComponentUnderCursor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel3))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGap(2, 2, 2)
                        .addComponent(jToggleButtonSetErase))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel20))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabelCoords))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel26))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabelOffset))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabelSize))
                    .addGroup(jPanel8Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel23)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane2.setName("jTabbedPane2"); // NOI18N
        jTabbedPane2.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jTabbedPane2StateChanged(evt);
            }
        });

        jPanel9.setName("jPanel9"); // NOI18N

        jLabel5.setText("Tile Collection");
        jLabel5.setName("jLabel5"); // NOI18N

        jTextFieldTileFile.setName("jTextFieldTileFile"); // NOI18N
        jTextFieldTileFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldTileFileActionPerformed(evt);
            }
        });
        jTextFieldTileFile.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldTileFileFocusLost(evt);
            }
        });

        jButtonFileSelect1.setText("...");
        jButtonFileSelect1.setMargin(new java.awt.Insets(0, 1, 0, -1));
        jButtonFileSelect1.setName("jButtonFileSelect1"); // NOI18N
        jButtonFileSelect1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFileSelect1ActionPerformed(evt);
            }
        });

        jPanelTileView.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanelTileView.setName("jPanelTileView"); // NOI18N
        jPanelTileView.setPreferredSize(new java.awt.Dimension(130, 130));

        javax.swing.GroupLayout jPanelTileViewLayout = new javax.swing.GroupLayout(jPanelTileView);
        jPanelTileView.setLayout(jPanelTileViewLayout);
        jPanelTileViewLayout.setHorizontalGroup(
            jPanelTileViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 128, Short.MAX_VALUE)
        );
        jPanelTileViewLayout.setVerticalGroup(
            jPanelTileViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 128, Short.MAX_VALUE)
        );

        jCheckBox1.setSelected(true);
        jCheckBox1.setText("Anim");
        jCheckBox1.setEnabled(false);
        jCheckBox1.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jCheckBox1.setName("jCheckBox1"); // NOI18N
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jLabel1.setText("Left");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel9.setText("Right");
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText("Middle");
        jLabel10.setName("jLabel10"); // NOI18N

        imageComponentLeft.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        imageComponentLeft.setName("imageComponentLeft"); // NOI18N
        imageComponentLeft.setPreferredSize(new java.awt.Dimension(22, 22));
        imageComponentLeft.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                imageComponentLeftMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout imageComponentLeftLayout = new javax.swing.GroupLayout(imageComponentLeft);
        imageComponentLeft.setLayout(imageComponentLeftLayout);
        imageComponentLeftLayout.setHorizontalGroup(
            imageComponentLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );
        imageComponentLeftLayout.setVerticalGroup(
            imageComponentLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        imageComponentSLeft.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        imageComponentSLeft.setName("imageComponentSLeft"); // NOI18N
        imageComponentSLeft.setPreferredSize(new java.awt.Dimension(22, 22));

        javax.swing.GroupLayout imageComponentSLeftLayout = new javax.swing.GroupLayout(imageComponentSLeft);
        imageComponentSLeft.setLayout(imageComponentSLeftLayout);
        imageComponentSLeftLayout.setHorizontalGroup(
            imageComponentSLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );
        imageComponentSLeftLayout.setVerticalGroup(
            imageComponentSLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        imageComponentRight.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        imageComponentRight.setName("imageComponentRight"); // NOI18N
        imageComponentRight.setPreferredSize(new java.awt.Dimension(22, 22));

        javax.swing.GroupLayout imageComponentRightLayout = new javax.swing.GroupLayout(imageComponentRight);
        imageComponentRight.setLayout(imageComponentRightLayout);
        imageComponentRightLayout.setHorizontalGroup(
            imageComponentRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );
        imageComponentRightLayout.setVerticalGroup(
            imageComponentRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        imageComponentSRight.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        imageComponentSRight.setName("imageComponentSRight"); // NOI18N
        imageComponentSRight.setPreferredSize(new java.awt.Dimension(22, 22));

        javax.swing.GroupLayout imageComponentSRightLayout = new javax.swing.GroupLayout(imageComponentSRight);
        imageComponentSRight.setLayout(imageComponentSRightLayout);
        imageComponentSRightLayout.setHorizontalGroup(
            imageComponentSRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );
        imageComponentSRightLayout.setVerticalGroup(
            imageComponentSRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        imageComponentMiddle.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        imageComponentMiddle.setName("imageComponentMiddle"); // NOI18N
        imageComponentMiddle.setPreferredSize(new java.awt.Dimension(22, 22));

        javax.swing.GroupLayout imageComponentMiddleLayout = new javax.swing.GroupLayout(imageComponentMiddle);
        imageComponentMiddle.setLayout(imageComponentMiddleLayout);
        imageComponentMiddleLayout.setHorizontalGroup(
            imageComponentMiddleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );
        imageComponentMiddleLayout.setVerticalGroup(
            imageComponentMiddleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        imageComponentSMiddle.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        imageComponentSMiddle.setName("imageComponentSMiddle"); // NOI18N
        imageComponentSMiddle.setPreferredSize(new java.awt.Dimension(22, 22));

        javax.swing.GroupLayout imageComponentSMiddleLayout = new javax.swing.GroupLayout(imageComponentSMiddle);
        imageComponentSMiddle.setLayout(imageComponentSMiddleLayout);
        imageComponentSMiddleLayout.setHorizontalGroup(
            imageComponentSMiddleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );
        imageComponentSMiddleLayout.setVerticalGroup(
            imageComponentSMiddleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );

        jLabel11.setText("SHIFT");
        jLabel11.setName("jLabel11"); // NOI18N

        jCheckBoxTileScale.setText("Scale");
        jCheckBoxTileScale.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        jCheckBoxTileScale.setName("jCheckBoxTileScale"); // NOI18N
        jCheckBoxTileScale.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxTileScaleActionPerformed(evt);
            }
        });

        jLabel13.setText("Size:");
        jLabel13.setName("jLabel13"); // NOI18N

        jLabelTileSize.setText("32x32");
        jLabelTileSize.setName("jLabelTileSize"); // NOI18N

        jComboBoxTileKlasse.setName("jComboBoxTileKlasse"); // NOI18N
        jComboBoxTileKlasse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxTileKlasseActionPerformed(evt);
            }
        });

        jLabel33.setText("Class");
        jLabel33.setName("jLabel33"); // NOI18N

        jButton3.setText("!");
        jButton3.setToolTipText("No Mousetile!");
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jPanelIMageCollection1.setMinimumSize(new java.awt.Dimension(20, 20));
        jPanelIMageCollection1.setName("jPanelIMageCollection1"); // NOI18N
        jPanelIMageCollection1.setLayout(null);

        jPanel17.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel17.setName("jPanel17"); // NOI18N
        jPanel17.setPreferredSize(new java.awt.Dimension(52, 52));

        javax.swing.GroupLayout jPanel17Layout = new javax.swing.GroupLayout(jPanel17);
        jPanel17.setLayout(jPanel17Layout);
        jPanel17Layout.setHorizontalGroup(
            jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 50, Short.MAX_VALUE)
        );
        jPanel17Layout.setVerticalGroup(
            jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 50, Short.MAX_VALUE)
        );

        jPanelIMageCollection1.add(jPanel17);
        jPanel17.setBounds(5, 5, 52, 52);

        jScrollPane2.setViewportView(jPanelIMageCollection1);

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jPanelTileView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBox1, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jCheckBoxTileScale, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addComponent(jLabelTileSize, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel33))
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel9Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jComboBoxTileKlasse, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel9Layout.createSequentialGroup()
                                .addGap(12, 12, 12)
                                .addComponent(jTextFieldTileFile, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(19, 19, 19)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButtonFileSelect1)
                            .addComponent(jLabel11)))
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addGap(133, 133, 133)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel9Layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(imageComponentMiddle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel9Layout.createSequentialGroup()
                                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(imageComponentLeft, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(imageComponentRight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(imageComponentSMiddle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(imageComponentSRight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(imageComponentSLeft, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(10, 10, 10)
                        .addComponent(jButton3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 838, Short.MAX_VALUE))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addGap(1, 1, 1)
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5)
                                .addComponent(jButtonFileSelect1))
                            .addComponent(jTextFieldTileFile, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBoxTileKlasse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel33, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel9Layout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(imageComponentLeft, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(imageComponentSLeft, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jLabel1)
                                    .addComponent(jButton3))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(imageComponentSRight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(imageComponentRight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(imageComponentSMiddle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(imageComponentMiddle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jLabel10))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jCheckBoxTileScale)
                                    .addComponent(jLabel13))
                                .addGap(5, 5, 5)
                                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jCheckBox1)
                                    .addComponent(jLabelTileSize)))
                            .addGroup(jPanel9Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanelTileView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))))
        );

        jTabbedPane2.addTab("Tiles", jPanel9);

        jPanel14.setName("jPanel14"); // NOI18N

        jLabel24.setText("Tile Collection");
        jLabel24.setName("jLabel24"); // NOI18N

        jTextFieldTileFile1.setName("jTextFieldTileFile1"); // NOI18N
        jTextFieldTileFile1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldTileFile1ActionPerformed(evt);
            }
        });
        jTextFieldTileFile1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldTileFile1FocusLost(evt);
            }
        });

        jButtonFileSelect2.setText("...");
        jButtonFileSelect2.setMargin(new java.awt.Insets(0, 1, 0, -1));
        jButtonFileSelect2.setName("jButtonFileSelect2"); // NOI18N
        jButtonFileSelect2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFileSelect2ActionPerformed(evt);
            }
        });

        jComboBoxTileKlasse1.setName("jComboBoxTileKlasse1"); // NOI18N
        jComboBoxTileKlasse1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxTileKlasse1ActionPerformed(evt);
            }
        });

        jLabel37.setText("Class");
        jLabel37.setName("jLabel37"); // NOI18N

        jLabelTileSize1.setText("32x32");
        jLabelTileSize1.setName("jLabelTileSize1"); // NOI18N

        jLabel25.setText("Size:");
        jLabel25.setName("jLabel25"); // NOI18N

        jLabel38.setText("Name");
        jLabel38.setName("jLabel38"); // NOI18N

        jTextFieldCompositeName.setName("jTextFieldCompositeName"); // NOI18N
        jTextFieldCompositeName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldCompositeNameActionPerformed(evt);
            }
        });
        jTextFieldCompositeName.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldCompositeNameFocusLost(evt);
            }
        });

        jButtonMapDelete1.setText("Delete");
        jButtonMapDelete1.setEnabled(false);
        jButtonMapDelete1.setName("jButtonMapDelete1"); // NOI18N
        jButtonMapDelete1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMapDelete1ActionPerformed(evt);
            }
        });

        jButtonMapSave1.setText("Save current layer as composite tile");
        jButtonMapSave1.setName("jButtonMapSave1"); // NOI18N
        jButtonMapSave1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMapSave1ActionPerformed(evt);
            }
        });

        jLabel43.setText("Class");
        jLabel43.setName("jLabel43"); // NOI18N

        jTextFieldCompositeClass.setName("jTextFieldCompositeClass"); // NOI18N
        jTextFieldCompositeClass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldCompositeClassActionPerformed(evt);
            }
        });
        jTextFieldCompositeClass.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldCompositeClassFocusLost(evt);
            }
        });

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jPanelIMageCollection2.setMinimumSize(new java.awt.Dimension(20, 20));
        jPanelIMageCollection2.setName("jPanelIMageCollection2"); // NOI18N
        jPanelIMageCollection2.setLayout(null);

        jPanel18.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel18.setName("jPanel18"); // NOI18N
        jPanel18.setPreferredSize(new java.awt.Dimension(152, 152));
        jPanel18.setLayout(new java.awt.BorderLayout());
        jPanelIMageCollection2.add(jPanel18);
        jPanel18.setBounds(5, 5, 152, 152);

        jScrollPane3.setViewportView(jPanelIMageCollection2);

        javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel14Layout.createSequentialGroup()
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel24)
                            .addComponent(jLabel37)
                            .addComponent(jLabel43)
                            .addComponent(jLabel38)
                            .addComponent(jLabel25))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldCompositeClass, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBoxTileKlasse1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel14Layout.createSequentialGroup()
                                .addComponent(jTextFieldTileFile1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jButtonFileSelect2))
                            .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabelTileSize1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jTextFieldCompositeName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel14Layout.createSequentialGroup()
                        .addComponent(jButtonMapSave1)
                        .addGap(18, 18, 18)
                        .addComponent(jButtonMapDelete1)))
                .addGap(12, 12, 12)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 846, Short.MAX_VALUE))
        );
        jPanel14Layout.setVerticalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addGap(1, 1, 1)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel14Layout.createSequentialGroup()
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextFieldTileFile1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel24)
                            .addComponent(jButtonFileSelect2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel37)
                            .addComponent(jComboBoxTileKlasse1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(15, 15, 15)
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButtonMapSave1)
                            .addComponent(jButtonMapDelete1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel43)
                            .addComponent(jTextFieldCompositeClass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel38)
                            .addComponent(jTextFieldCompositeName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel25)
                            .addComponent(jLabelTileSize1))
                        .addContainerGap(31, Short.MAX_VALUE))
                    .addComponent(jScrollPane3)))
        );

        jTabbedPane2.addTab("Composite tiles", jPanel14);

        jPanel15.setName("jPanel15"); // NOI18N

        jLabel44.setText("Filename");
        jLabel44.setName("jLabel44"); // NOI18N

        jLabel45.setText("Class");
        jLabel45.setName("jLabel45"); // NOI18N

        jTextFieldSpriteFile.setName("jTextFieldSpriteFile"); // NOI18N
        jTextFieldSpriteFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldSpriteFileActionPerformed(evt);
            }
        });
        jTextFieldSpriteFile.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldSpriteFileFocusLost(evt);
            }
        });

        jComboBoxSpriteKlasse.setName("jComboBoxSpriteKlasse"); // NOI18N
        jComboBoxSpriteKlasse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxSpriteKlasseActionPerformed(evt);
            }
        });

        jButtonSpriteFileSelect.setText("...");
        jButtonSpriteFileSelect.setMargin(new java.awt.Insets(0, 1, 0, -1));
        jButtonSpriteFileSelect.setName("jButtonSpriteFileSelect"); // NOI18N
        jButtonSpriteFileSelect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSpriteFileSelectActionPerformed(evt);
            }
        });

        jPanelSpriteImageCollection.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanelSpriteImageCollection.setForeground(new java.awt.Color(204, 204, 204));
        jPanelSpriteImageCollection.setMinimumSize(new java.awt.Dimension(15, 62));
        jPanelSpriteImageCollection.setName("jPanelSpriteImageCollection"); // NOI18N
        jPanelSpriteImageCollection.setLayout(new java.awt.FlowLayout(3));

        jPanel16.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel16.setName("jPanel16"); // NOI18N
        jPanel16.setPreferredSize(new java.awt.Dimension(52, 52));

        javax.swing.GroupLayout jPanel16Layout = new javax.swing.GroupLayout(jPanel16);
        jPanel16.setLayout(jPanel16Layout);
        jPanel16Layout.setHorizontalGroup(
            jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 50, Short.MAX_VALUE)
        );
        jPanel16Layout.setVerticalGroup(
            jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 50, Short.MAX_VALUE)
        );

        jPanelSpriteImageCollection.add(jPanel16);

        jPanel19.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel19.setName("jPanel19"); // NOI18N
        jPanel19.setPreferredSize(new java.awt.Dimension(52, 52));

        javax.swing.GroupLayout jPanel19Layout = new javax.swing.GroupLayout(jPanel19);
        jPanel19.setLayout(jPanel19Layout);
        jPanel19Layout.setHorizontalGroup(
            jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 50, Short.MAX_VALUE)
        );
        jPanel19Layout.setVerticalGroup(
            jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 50, Short.MAX_VALUE)
        );

        jPanelSpriteImageCollection.add(jPanel19);

        jComboBoxAction.setEditable(true);
        jComboBoxAction.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Stand", "Walk", "Talk", "Run", "Attack", "Been Hit", "Die", "Shoot", "Paused", "Shoot", "Running", "Stopped" }));
        jComboBoxAction.setName("jComboBoxAction"); // NOI18N
        jComboBoxAction.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxActionSpritePerformed(evt);
            }
        });

        jLabel127.setText("Action");
        jLabel127.setName("jLabel127"); // NOI18N

        jComboBoxActionSpriteDirection.setEditable(true);
        jComboBoxActionSpriteDirection.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "n", "s", "e", "w", "c", "nw", "ne", "se", "sw", " " }));
        jComboBoxActionSpriteDirection.setName("jComboBoxActionSpriteDirection"); // NOI18N
        jComboBoxActionSpriteDirection.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxActionSpriteDirectionPerformed(evt);
            }
        });

        jLabel128.setText("Direction");
        jLabel128.setName("jLabel128"); // NOI18N

        jLabel129.setText("Position");
        jLabel129.setName("jLabel129"); // NOI18N

        jTextFieldSpriteX.setText("0");
        jTextFieldSpriteX.setName("jTextFieldSpriteX"); // NOI18N

        jTextFieldSpriteY.setText("0");
        jTextFieldSpriteY.setName("jTextFieldSpriteY"); // NOI18N

        jLabel46.setText("Coordinator");
        jLabel46.setName("jLabel46"); // NOI18N

        jComboBoxCoordinator.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "none" }));
        jComboBoxCoordinator.setName("jComboBoxCoordinator"); // NOI18N
        jComboBoxCoordinator.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxKlasseSpriteCoordinatorPerformed(evt);
            }
        });

        jButtonSpriteChanges.setText("Accept Changes");
        jButtonSpriteChanges.setEnabled(false);
        jButtonSpriteChanges.setName("jButtonSpriteChanges"); // NOI18N
        jButtonSpriteChanges.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSpriteChangesActionPerformed(evt);
            }
        });

        jPanelExample.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanelExample.setName("jPanelExample"); // NOI18N
        jPanelExample.setPreferredSize(new java.awt.Dimension(52, 52));

        javax.swing.GroupLayout jPanelExampleLayout = new javax.swing.GroupLayout(jPanelExample);
        jPanelExample.setLayout(jPanelExampleLayout);
        jPanelExampleLayout.setHorizontalGroup(
            jPanelExampleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 50, Short.MAX_VALUE)
        );
        jPanelExampleLayout.setVerticalGroup(
            jPanelExampleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 50, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel15Layout = new javax.swing.GroupLayout(jPanel15);
        jPanel15.setLayout(jPanel15Layout);
        jPanel15Layout.setHorizontalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel15Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel45)
                    .addComponent(jLabel44)
                    .addGroup(jPanel15Layout.createSequentialGroup()
                        .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel129)
                            .addComponent(jLabel127)
                            .addComponent(jLabel128))
                        .addGap(36, 36, 36)
                        .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBoxActionSpriteDirection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel15Layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jComboBoxCoordinator, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel15Layout.createSequentialGroup()
                                        .addComponent(jTextFieldSpriteX, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jTextFieldSpriteY, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(jPanel15Layout.createSequentialGroup()
                                .addComponent(jTextFieldSpriteFile, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonSpriteFileSelect))
                            .addComponent(jComboBoxSpriteKlasse, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jComboBoxAction, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jLabel46))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelSpriteImageCollection, javax.swing.GroupLayout.PREFERRED_SIZE, 766, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonSpriteChanges)
                    .addComponent(jPanelExample, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(102, Short.MAX_VALUE))
        );
        jPanel15Layout.setVerticalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel15Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel15Layout.createSequentialGroup()
                        .addComponent(jPanelSpriteImageCollection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelExample, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel15Layout.createSequentialGroup()
                            .addComponent(jLabel44)
                            .addGap(15, 15, 15)
                            .addComponent(jLabel45)
                            .addGap(18, 18, 18)
                            .addComponent(jLabel127, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jLabel128, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(21, 21, 21)
                            .addComponent(jLabel129, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel15Layout.createSequentialGroup()
                            .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jTextFieldSpriteFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jButtonSpriteFileSelect))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jComboBoxSpriteKlasse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jComboBoxAction, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jComboBoxActionSpriteDirection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jTextFieldSpriteX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jTextFieldSpriteY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel46)
                    .addComponent(jComboBoxCoordinator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonSpriteChanges))
                .addGap(0, 16, Short.MAX_VALUE))
        );

        jTabbedPane2.addTab("Sprites", jPanel15);

        jButtonScaleToFit.setText("To Fit");
        jButtonScaleToFit.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jButtonScaleToFit.setName("jButtonScaleToFit"); // NOI18N
        jButtonScaleToFit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonScaleToFitActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane2)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 328, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButtonScaleToFit, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jSlider1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(mapPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, 731, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(mapPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                                .addComponent(jSlider1, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonScaleToFit)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(14, 14, 14)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(3, 3, 3))
        );

        jTabbedPane1.getAccessibleContext().setAccessibleName("Layers");

        jPanel10.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel10.setName("jPanel10"); // NOI18N
        jPanel10.setPreferredSize(new java.awt.Dimension(200, 50));

        jComboBoxMapName.setName("jComboBoxMapName"); // NOI18N
        jComboBoxMapName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxMapNameActionPerformed(evt);
            }
        });

        jLabel32.setText("Name");
        jLabel32.setName("jLabel32"); // NOI18N

        jTextFieldMapName.setName("jTextFieldMapName"); // NOI18N

        jButtonMapNew.setText("New");
        jButtonMapNew.setName("jButtonMapNew"); // NOI18N
        jButtonMapNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMapNewActionPerformed(evt);
            }
        });

        jButtonMapSave.setText("Save");
        jButtonMapSave.setName("jButtonMapSave"); // NOI18N
        jButtonMapSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMapSaveActionPerformed(evt);
            }
        });

        jButtonMapSaveAsNew.setText("Save as new");
        jButtonMapSaveAsNew.setName("jButtonMapSaveAsNew"); // NOI18N
        jButtonMapSaveAsNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMapSaveAsNewActionPerformed(evt);
            }
        });

        jButtonMapDelete.setText("Delete");
        jButtonMapDelete.setName("jButtonMapDelete"); // NOI18N
        jButtonMapDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMapDeleteActionPerformed(evt);
            }
        });

        jButtonExport.setText("User Export");
        jButtonExport.setName("jButtonExport"); // NOI18N
        jButtonExport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonExportActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel32)
                .addGap(16, 16, 16)
                .addComponent(jTextFieldMapName, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBoxMapName, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonMapNew)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonMapSave)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonMapSaveAsNew)
                .addGap(37, 37, 37)
                .addComponent(jButtonMapDelete)
                .addGap(30, 30, 30)
                .addComponent(jButtonExport)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jComboBoxMapName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel32)
                            .addComponent(jTextFieldMapName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButtonMapDelete)
                        .addComponent(jButtonMapNew)
                        .addComponent(jButtonMapSave)
                        .addComponent(jButtonMapSaveAsNew)
                        .addComponent(jButtonExport)))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel10, javax.swing.GroupLayout.DEFAULT_SIZE, 1115, Short.MAX_VALUE)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 1115, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 616, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonFileSelect1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFileSelect1ActionPerformed
        InternalFrameFileChoser fc = new csa.gui.dialogs.InternalFrameFileChoser();
        fc.setCurrentDirectory(new java.io.File("xml"+File.separator+"Tile"));
        FileNameExtensionFilter  filter = new  FileNameExtensionFilter("xml", "xml");
        fc.setFileFilter(filter);
        int r = fc.showOpenDialog(Configuration.getConfiguration().getMainFrame());
        if (r != InternalFrameFileChoser.APPROVE_OPTION) return;
        String name = fc.getSelectedFile().getName();
        jTextFieldTileFile.setText(csa.util.UtilityString.replace(name, ".xml",""));
        jTextFieldTileFileActionPerformed(null);
}//GEN-LAST:event_jButtonFileSelect1ActionPerformed
    public void loadTileMap()
    {
        String file = jTextFieldTileFile.getText().trim();

        if (file.length() == 0) return;

        mTileDataPool = new TileDataPool("Tile"+File.separator+file+".xml");
        if (mTileDataPool == null) return;

        fillTileList();
    }


    void fillTileList()
    {

    }

    // Config Pool for TileMap
    private void resetTileConfigPool(boolean select, String klasseToSet, String tileToSet) /* allneeded*/
    {
        mClassSetting++;
        jComboBoxTileKlasse.removeAllItems();
        mClassSetting--;
        if (mTileDataPool == null) return;

        mClassSetting++;
        Collection<String> collectionKlasse = mTileDataPool.getKlassenHashMap().values();
        Iterator<String> iterKlasse = collectionKlasse.iterator();
        int i = 0;
        String klasse = "";

        while (iterKlasse.hasNext())
        {
            String item = iterKlasse.next();
            jComboBoxTileKlasse.addItem(item);
            if (select)
            {
                if (klasseToSet.length()==0)
                {
                    if (i==0)
                    {
                        jComboBoxTileKlasse.setSelectedIndex(i);
                        klasse = item;
                    }
                }
                else
                {
                    if (klasseToSet.equalsIgnoreCase(item))
                    {
                        jComboBoxTileKlasse.setSelectedIndex(i);
                        klasse = item;
                    }
                }
            }
            i++;
        }
        if ((select) && (klasse.length()==0))
        {
            if (jComboBoxTileKlasse.getItemCount()>0)
            {
                jComboBoxTileKlasse.setSelectedIndex(0);
                // klasse = jComboBoxTileKlasse.getSelectedItem().toString();
            }
        }
        if (!select)  jComboBoxTileKlasse.setSelectedIndex(-1);

        mClassSetting--;
        resetActiveTileList(tileToSet);
    }

    // Config Pool for TileMap
    private void resetCompositeTileConfigPool(boolean select, String klasseToSet, String tileToSet) /* allneeded*/
    {
        mClassSetting++;
        jComboBoxTileKlasse1.removeAllItems();
        mClassSetting--;
        if (mCompositeTileDataPool == null) return;

        mClassSetting++;
        Collection<String> collectionKlasse = mCompositeTileDataPool.getKlassenHashMap().values();
        Iterator<String> iterKlasse = collectionKlasse.iterator();
        int i = 0;
        String klasse = "";

        while (iterKlasse.hasNext())
        {
            String item = iterKlasse.next();
            jComboBoxTileKlasse1.addItem(item);
            if (select)
            {
                if (klasseToSet.length()==0)
                {
                    if (i==0)
                    {
                        jComboBoxTileKlasse1.setSelectedIndex(i);
                        klasse = item;
                    }
                }
                else
                {
                    if (klasseToSet.equalsIgnoreCase(item))
                    {
                        jComboBoxTileKlasse1.setSelectedIndex(i);
                        klasse = item;
                    }
                }
            }
            i++;
        }
        if ((select) && (klasse.length()==0))
        {
            if (jComboBoxTileKlasse1.getItemCount()>0)
            {
                jComboBoxTileKlasse1.setSelectedIndex(0);
                // klasse = jComboBoxTileKlasse.getSelectedItem().toString();
            }
        }
        if (!select)  jComboBoxTileKlasse1.setSelectedIndex(-1);

        mClassSetting--;
        resetActiveCompositeTileList(tileToSet);
    }

    String getTileClass()
    {
        String _class = "";
        if (jComboBoxTileKlasse.getSelectedIndex() != -1) _class = jComboBoxTileKlasse.getSelectedItem().toString().trim();
        return _class;
    }
    String getCompositeTileClass()
    {
        String _class = "";
        if (jComboBoxTileKlasse1.getSelectedIndex() != -1) _class = jComboBoxTileKlasse1.getSelectedItem().toString().trim();
        return _class;
    }

    TileDataPool getTilePool()
    {
        return mTileDataPool;
    }
    TileDataPool getCompositeTilePool()
    {
        return mCompositeTileDataPool;
    }

    void resetActiveTileList(String selectName)
    {
        mCurrentDisplayedTileList = new Vector <TileData>();

        String _class = getTileClass();
        TileDataPool pool = getTilePool();

        if (pool == null) return;

        Collection<TileData> colDk = pool.getMapForKlasse(_class).values();
        Iterator<TileData> iterDk = colDk.iterator();
        /** Sorting */  Vector<String> names = new Vector<String>();
        while (iterDk.hasNext())
        {
            TileData deck = iterDk.next();
            if (deck.getIsCompositeTile()) continue;
            mCurrentDisplayedTileList.addElement(deck);
            names.addElement(deck.mName);

        }
        Collections.sort(names, new Comparator<String>() {@Override
                public int compare(String s1, String s2) { return s1.compareTo(s2); } });
        Collections.sort(mCurrentDisplayedTileList, new Comparator<TileData>() {@Override
            public int compare(TileData s1, TileData s2) { return s1.mName.compareTo(s2.mName); } });
        setAllActiveTiles(selectName);
        
 
    }

    JPanel currentSelectedTileImagePanel = null;

    
    void resetActiveCompositeTileList(String selectName)
    {
        mCurrentDisplayedCompositeTileList = new Vector <CompositeTile>();

        String _class = getCompositeTileClass();
        TileDataPool pool = getCompositeTilePool();

        if (pool == null) return;

        Collection<TileData> colDk = pool.getMapForKlasse(_class).values();
        Iterator<TileData> iterDk = colDk.iterator();
        /** Sorting */  Vector<String> names = new Vector<String>();
        while (iterDk.hasNext())
        {
            TileData deck = iterDk.next();
            if (!deck.getIsCompositeTile()) continue;
            
            mCurrentDisplayedCompositeTileList.addElement(new CompositeTile(deck));
            names.addElement(deck.mName);

        }
        Collections.sort(names, new Comparator<String>() {@Override
                public int compare(String s1, String s2) { return s1.compareTo(s2); } });
        Collections.sort(mCurrentDisplayedCompositeTileList, new Comparator<CompositeTile>() 
        {
            @Override
            public int compare(CompositeTile s1, CompositeTile s2) 
            { 
                return s1.getData().mName.compareTo(s2.getData().mName); 
            } });
        setAllActiveCompositeTiles(selectName);
    }

    void setAllActiveTiles(String selectName)
    {
        jPanelIMageCollection1.removeAll();
        currentSelectedTileImagePanel = null;

        int selected = 0;
        for (int t = 0; t < mCurrentDisplayedTileList.size(); t++)
        {
            TileData tileData = mCurrentDisplayedTileList.elementAt(t);
            if (tileData.mName.equals(selectName))
            {
                selected = t;
                break;
            }
        }
        int x = 5;
        int y = 5;
        for (int t = 0; t < mCurrentDisplayedTileList.size(); t++)
        {
            // first line
            TileData tileData = mCurrentDisplayedTileList.elementAt(t);
            // jPanelIMageCollection1

            ImageSequenceData iSData = getImageSequenceDataForTile(tileData);
            String name = tileData.mName;
            if (iSData == null)
            {
                JPanel ipanel = new JPanel();
                if (t==selected)
                {
                    currentSelectedTileImagePanel = ipanel;
                    ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(Color.ORANGE));
                    mCurrentTile = tileData;
                    mClassSetting++;
                    setCurrentTileInfo();
                    mClassSetting--;
                }
                else
                    ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

                ipanel.setName(""+name);
                ipanel.setPreferredSize(new java.awt.Dimension(52, 52));
                ipanel.setLayout(new BorderLayout());

                ImageComponent mip = new ImageComponent();

                ipanel.add(mip, BorderLayout.CENTER);
               // mip.setImages(images);

                mip.addMouseListener(new java.awt.event.MouseAdapter() {
                    @Override
                    public void mousePressed(java.awt.event.MouseEvent evt) {
                        jPanelMouseTileClickedImage(evt);
                    }
                });

                ipanel.setBounds(x, y, 52, 52);

                jPanelIMageCollection1.add(ipanel);

                mip.setScaled(true, 52, 52);
                mip.setVisible(true);
                y += 52;
                y += 5;
            }
            else
            {
                Vector <BaseImageData> data = BaseImageData.toBase(iSData);
                if (data.size()>0)
                {
                    Vector<Image> images = new Vector<Image>();
                    for (int i = 0; i < data.size(); i++)
                    {
                        BaseImageData baseImageData = data.elementAt(i);
                        images.addElement(baseImageData.image);
                    }

                    JPanel ipanel = new JPanel();
                    if (t==selected)
                    {
                        currentSelectedTileImagePanel = ipanel;
                        ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(Color.ORANGE));
                        mCurrentTile = tileData;
                        mClassSetting++;
                        setCurrentTileInfo();

                        // set as usage for map Panel
                        leftMouseTile = Tile.cloneTileData(mCurrentTile);
                        if (leftMouseTile != null) 
                        {
                            leftMouseTile.setTileSetFileName(jTextFieldTileFile.getText());
                            mapPanel.setMouseGrabTile(new Tile(leftMouseTile), new Tile(sleftMouseTile));
                            // set to display
                            setMouseTile(leftMouseTile, imageComponentLeft);
                        }
                        
                        mClassSetting--;
                    }
                    else
                        ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

                    ipanel.setName(""+name);
                    ipanel.setPreferredSize(new java.awt.Dimension(52, 52));
                    ipanel.setLayout(new BorderLayout());
                    ImageComponent mip = new ImageComponent();

                    ipanel.add(mip, BorderLayout.CENTER);
                    //mip.setImages(images);
                    mip.setSequence(new ImageSequence(iSData));


                    mip.addMouseListener(new java.awt.event.MouseAdapter() {
                        @Override
                        public void mousePressed(java.awt.event.MouseEvent evt) {
                            jPanelMouseTileClickedImage(evt);
                        }
                    });

                    ipanel.setBounds(x, y, 52, 52);

                    jPanelIMageCollection1.add(ipanel);
    //                if (jToggleButtonPlayAnimMain.isSelected())
    //                {
                        mip.setDelay(iSData.getDelay());
    //                }
    //                else
    //                {
    //                    mip.setDelay(-1);
    //                }

                    mip.setScaled(true, 52, 52);
                    mip.setVisible(true);
                    y += 52;
                    y += 5;

                }
            }


            t++;
            // second line
            if (t>=mCurrentDisplayedTileList.size())
                continue;


            tileData = mCurrentDisplayedTileList.elementAt(t);
            // jPanelIMageCollection1

            iSData = getImageSequenceDataForTile(tileData);
            name = tileData.mName;
            if (iSData == null)
            {
                JPanel ipanel = new JPanel();
                if (t==selected)
                {
                    currentSelectedTileImagePanel = ipanel;
                    ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(Color.ORANGE));
                    mCurrentTile = tileData;
                    mClassSetting++;
                    setCurrentTileInfo();
                    mClassSetting--;
                }
                else
                    ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

                ipanel.setName(""+name);
                ipanel.setPreferredSize(new java.awt.Dimension(52, 52));
                ipanel.setLayout(new BorderLayout());

                ImageComponent mip = new ImageComponent();

                ipanel.add(mip, BorderLayout.CENTER);
               // mip.setImages(images);

                mip.addMouseListener(new java.awt.event.MouseAdapter() {
                    @Override
                    public void mousePressed(java.awt.event.MouseEvent evt) {
                        jPanelMouseTileClickedImage(evt);
                    }
                });

                ipanel.setBounds(x, y, 52, 52);

                jPanelIMageCollection1.add(ipanel);

                mip.setScaled(true, 52, 52);
                mip.setVisible(true);
                y += 52;
                y += 5;
            }
            else
            {
                Vector <BaseImageData> data = BaseImageData.toBase(iSData);
                if (data.size()>0)
                {
                    Vector<Image> images = new Vector<Image>();
                    for (int i = 0; i < data.size(); i++)
                    {
                        BaseImageData baseImageData = data.elementAt(i);
                        images.addElement(baseImageData.image);
                    }

                    JPanel ipanel = new JPanel();
                    if (t==selected)
                    {
                        currentSelectedTileImagePanel = ipanel;
                        ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(Color.ORANGE));
                        mCurrentTile = tileData;
                        mClassSetting++;
                        setCurrentTileInfo();
                        mClassSetting--;
                    }
                    else
                        ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

                    ipanel.setName(""+name);
                    ipanel.setPreferredSize(new java.awt.Dimension(52, 52));
                    ipanel.setLayout(new BorderLayout());
                    ImageComponent mip = new ImageComponent();

                    ipanel.add(mip, BorderLayout.CENTER);
                    // mip.setImages(images);
                    mip.setSequence(new ImageSequence(iSData));

                    mip.addMouseListener(new java.awt.event.MouseAdapter() {
                        @Override
                        public void mousePressed(java.awt.event.MouseEvent evt) {
                            jPanelMouseTileClickedImage(evt);
                        }
                    });

                    ipanel.setBounds(x, y, 52, 52);

                    jPanelIMageCollection1.add(ipanel);
    //                if (jToggleButtonPlayAnimMain.isSelected())
    //                {
                        mip.setDelay(iSData.getDelay());
    //                }
    //                else
    //                {
    //                    mip.setDelay(-1);
    //                }

                    mip.setScaled(true, 52, 52);
                    mip.setVisible(true);
                    y += 52;
                    y += 5;
                }
            }


            t++;
            // second line
            if (t>=mCurrentDisplayedTileList.size())
                continue;


            tileData = mCurrentDisplayedTileList.elementAt(t);
            // jPanelIMageCollection1

            iSData = getImageSequenceDataForTile(tileData);
            name = tileData.mName;
            if (iSData == null)
            {
                JPanel ipanel = new JPanel();
                if (t==selected)
                {
                    currentSelectedTileImagePanel = ipanel;
                    ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(Color.ORANGE));
                    mCurrentTile = tileData;
                    mClassSetting++;
                    setCurrentTileInfo();
                    mClassSetting--;
                }
                else
                    ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

                ipanel.setName(""+name);
                ipanel.setPreferredSize(new java.awt.Dimension(52, 52));
                ipanel.setLayout(new BorderLayout());

                ImageComponent mip = new ImageComponent();

                ipanel.add(mip, BorderLayout.CENTER);
               // mip.setImages(images);

                mip.addMouseListener(new java.awt.event.MouseAdapter() {
                    @Override
                    public void mousePressed(java.awt.event.MouseEvent evt) {
                        jPanelMouseTileClickedImage(evt);
                    }
                });

                ipanel.setBounds(x, y, 52, 52);

                jPanelIMageCollection1.add(ipanel);

                mip.setScaled(true, 52, 52);
                mip.setVisible(true);
            }
            else
            {
                Vector <BaseImageData> data = BaseImageData.toBase(iSData);
                if (data.size()>0)
                {
                    Vector<Image> images = new Vector<Image>();
                    for (int i = 0; i < data.size(); i++)
                    {
                        BaseImageData baseImageData = data.elementAt(i);
                        images.addElement(baseImageData.image);
                    }

                    JPanel ipanel = new JPanel();
                    if (t==selected)
                    {
                        currentSelectedTileImagePanel = ipanel;
                        ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(Color.ORANGE));
                        mCurrentTile = tileData;
                        mClassSetting++;
                        setCurrentTileInfo();
                        mClassSetting--;
                    }
                    else
                        ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

                    ipanel.setName(""+name);
                    ipanel.setPreferredSize(new java.awt.Dimension(52, 52));
                    ipanel.setLayout(new BorderLayout());
                    ImageComponent mip = new ImageComponent();

                    ipanel.add(mip, BorderLayout.CENTER);
                    //mip.setImages(images);
                    mip.setSequence(new ImageSequence(iSData));

                    mip.addMouseListener(new java.awt.event.MouseAdapter() {
                        @Override
                        public void mousePressed(java.awt.event.MouseEvent evt) {
                            jPanelMouseTileClickedImage(evt);
                        }
                    });

                    ipanel.setBounds(x, y, 52, 52);

                    jPanelIMageCollection1.add(ipanel);
    //                if (jToggleButtonPlayAnimMain.isSelected())
    //                {
                        mip.setDelay(iSData.getDelay());
    //                }
    //                else
    //                {
    //                    mip.setDelay(-1);
    //                }

                    mip.setScaled(true, 52, 52);
                    mip.setVisible(true);
                }
            }


            y -= 52;
            y -= 5;
            y -= 52;
            y -= 5;
            x += 52;
            x += 5;
        }
        x += 52;
        x += 5;

        jPanelIMageCollection1.setBounds(0,0,x,y);
        jPanelIMageCollection1.setPreferredSize(new Dimension(x,y));
        jPanelIMageCollection1.invalidate();
        jPanelIMageCollection1.validate();
        jPanelIMageCollection1.repaint();

        repaint();
    }

    ImageSequenceData getImageSequenceDataForTile(TileData tileData)
    {
        if (tileData==null) return null;
        if (tileData.getImageDataFile().trim().length()==0) return null;

        String imageFilename = "Graphics"+File.separator+tileData.getImageDataFile()+".xml";
        ImageSequenceDataPool imagePool = new ImageSequenceDataPool(imageFilename);
        if (imagePool == null) return null;
        String nameToSet = tileData.getImageDataName();

        return imagePool.get(nameToSet);
    }

    private void jTextFieldTileFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldTileFileActionPerformed

        String file = jTextFieldTileFile.getText().trim();
        String _class = "";
        if (jComboBoxTileKlasse.getSelectedIndex() != -1)
            _class = jComboBoxTileKlasse.getSelectedItem().toString().trim();
        if (file.length() == 0) return;

        mTileDataPool = new TileDataPool("Tile"+File.separator+file+".xml");
        if (mTileDataPool == null) return;

        resetTileConfigPool(true, _class, "");
}//GEN-LAST:event_jTextFieldTileFileActionPerformed

    private void jTextFieldTileFileFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldTileFileFocusLost
        jTextFieldTileFileActionPerformed(null);
}//GEN-LAST:event_jTextFieldTileFileFocusLost

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jCheckBoxTileScaleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxTileScaleActionPerformed
        setCurrentTileInfo();
    }//GEN-LAST:event_jCheckBoxTileScaleActionPerformed

    private void jComboBoxMapNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxMapNameActionPerformed
        if (mClassSetting > 0) {
            return;
        }

        String key = jComboBoxMapName.getSelectedItem().toString();
        mMapData = mMapDataPool.get(key);
        setAllMapFromCurrent();
        jButtonSpriteChanges.setEnabled(false);
    }//GEN-LAST:event_jComboBoxMapNameActionPerformed

    private void jButtonMapNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMapNewActionPerformed
        mClassSetting++;
        currentMap = new TMap();
        mMapData = currentMap.getData();
        clearAll();
        mClassSetting--;
    }//GEN-LAST:event_jButtonMapNewActionPerformed

    private void clearAll() /* allneeded*/
    {
        mClassSetting++;
        jTextFieldMapName.setText("");
        jTextFieldMapWidth.setText("");
        jCheckBoxLayerBinary.setSelected(false);

        jTextFieldHeight.setText("");
        jTextFieldGridName.setText("");
        jComboBoxGridNameCombo.setSelectedIndex(-1);

        initLayersFromMap();

        mapPanel.setMap(currentMap);
        jTableLayer.tableChanged(null);
        mClassSetting--;

    }

    private void jButtonMapSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMapSaveActionPerformed

        mMapDataPool.remove(mMapData); // in case of a name change -> remove old!
        readAllMapToCurrent();

        if (currentMap.getData().mLayerSaveTyp!=1)
        {
            int tileSize = 0;
            for (int l=0; l < currentMap.getCurrentLayers().size();l++)
            {
                Layer layer = currentMap.getCurrentLayers().get(l);
                tileSize += layer.mTiles.size();
            }
            if (tileSize>10000)
            {
                boolean cont = false;
                cont = ToManyTilesWarningDialog.doWarning();

                if (!cont)
                    return;
            }

        }



        saveAllLayers();

        mMapData.mClass="ALL";
        mMapDataPool.put(mMapData);



        mMapDataPool.save();

        String name = mMapData.mName;

        mClassSetting++;
        resetMapConfigPool();
        jComboBoxMapName.setSelectedItem(name);
        mClassSetting--;
    }//GEN-LAST:event_jButtonMapSaveActionPerformed

    private void clearMapAll() /* allneeded*/
    {
        mClassSetting++;
        mMapData = new MapData();
        setAllMapFromCurrent();
        mClassSetting--;
    }

    private void setAllMapFromCurrent()
    {
        mClassSetting++;
        jComboBoxMapName.setSelectedItem(mMapData.mName);
        jTextFieldMapName.setText(mMapData.mName);
        jCheckBoxLayerBinary.setSelected(mMapData.mLayerSaveTyp==1);

        jTextFieldMapWidth.setText(""+mMapData.mSizeX);
        jTextFieldHeight.setText(""+mMapData.mSizeY);
        jTextFieldGridName.setText(mMapData.mGridSettings);

        initLayersFromMap();
        initMapPanel();
        updateLayerSize();
        jLabelOffset.setText(""+mapPanel.getOffsetX(jCheckBox4.isSelected())+"/"+mapPanel.getOffsetY(jCheckBox4.isSelected()));

        mClassSetting--;
        jComboBoxGridNameCombo.setSelectedItem(mMapData.mGridSettings);
    }

    private void readAllMapToCurrent()
    {
        mMapData.mName = jTextFieldMapName.getText();
        mMapData.mClass = "ALL";


        mMapData.mSizeX = csa.util.UtilityString.Int0(jTextFieldMapWidth.getText());
        mMapData.mSizeY = csa.util.UtilityString.Int0(jTextFieldHeight.getText());
 
        mMapData.mGridSettings = jTextFieldGridName.getText();

        if (jCheckBoxLayerBinary.isSelected())
            mMapData.mLayerSaveTyp = 1;
        else
            mMapData.mLayerSaveTyp=0;
    }

    private void jButtonMapSaveAsNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMapSaveAsNewActionPerformed
        mMapData = new MapData();
        readAllMapToCurrent();
        
        TMap newMap = new TMap(mMapData);

        // read in current layer info - if hanged
        String name = jTextFieldLayerName.getText();
        currentMap.getCurrentLayer().getData().mClass = "ALL";
        currentMap.getCurrentLayer().getData().mName = name;
        currentMap.getCurrentLayer().getData().mLayerName = name;
        currentMap.getCurrentLayer().isInMap = true;

        int d = currentMap.getCurrentLayerNo();
        readLayerToCurrent();
        
        // put all layers to new map
        for (int l=0; l < currentMap.getCurrentLayers().size();l++)
        {
            Layer layer = currentMap.getCurrentLayers().get(l);
            newMap.addLayer(layer);
        }
        
        // make it current
        currentMap = newMap;
        

        
/*
    private void setAllMapFromCurrent()
    {
        mClassSetting++;
        jComboBoxMapName.setSelectedItem(mMapData.mName);
        jTextFieldMapName.setText(mMapData.mName);
        jCheckBoxLayerBinary.setSelected(mMapData.mLayerSaveTyp==1);

        jTextFieldMapWidth.setText(""+mMapData.mSizeX);
        jTextFieldHeight.setText(""+mMapData.mSizeY);
        jTextFieldGridName.setText(mMapData.mGridSettings);

        initLayersFromMap();
        initMapPanel();
        updateLayerSize();
        jLabelOffset.setText(""+mapPanel.getOffsetX(jCheckBox4.isSelected())+"/"+mapPanel.getOffsetY(jCheckBox4.isSelected()));

        mClassSetting--;
        jComboBoxGridNameCombo.setSelectedItem(mMapData.mGridSettings);
    }
*/        
        
        //saveAllLayers();

        currentMap.reInitLayerPool();
        mLayerDataPool = currentMap.getLayerPool();


        for (int l=0; l < currentMap.getCurrentLayers().size();l++)
        {
            mLayerDataPool.put(currentMap.getCurrentLayers().get(l).getData());
        }
        mLayerDataPool.save(mMapData.mLayerSaveTyp);
        currentMap.updateMapLayerData();

        mMapData.mClass="ALL";
        mMapDataPool.put(mMapData);
        mMapDataPool.save();

        name = mMapData.mName;

        mClassSetting++;
        resetMapConfigPool();
        jComboBoxMapName.setSelectedItem(name);
        mClassSetting--;
        

        
        
        
        setAllMapFromCurrent();
        
        
        /*
        mClassSetting++;
        resetLayerConfigPool();
        setSelectedLayer(name, d);
        initLayerTable();
        mClassSetting--;        
        
        */

        
    }//GEN-LAST:event_jButtonMapSaveAsNewActionPerformed

    private void jButtonMapDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMapDeleteActionPerformed
        readAllMapToCurrent();
        mMapDataPool.remove(mMapData);
        mMapDataPool.save();
        resetMapConfigPool();

        // clearAll
        jButtonMapNewActionPerformed(null);
    }//GEN-LAST:event_jButtonMapDeleteActionPerformed

    private void jButtonLayerNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLayerNewActionPerformed
        mClassSetting++;
        clearAllLayerData();

        Layer newLayer = new Layer();
        currentMap.addLayer(newLayer);

        //jTextFieldDeptch.setText(""+currentMap.getCurrentLayerNo());
        jTextFieldLayerName.setText(""+currentMap.getCurrentLayerNo());
        setSelectedLayer(""+currentMap.getCurrentLayerNo(), currentMap.getCurrentLayerNo());
        mClassSetting--;
    }//GEN-LAST:event_jButtonLayerNewActionPerformed

    void clearAllLayerData()
    {
        jCheckBoxLayerAllowTileOverlap.setSelected(false);
        jCheckBoxLayerOnlyOnePosition.setSelected(false);
        jCheckBoxISOAssumed.setSelected(false);


        jCheckBoxLayerWrapHorizontal.setSelected(false);
        jCheckBoxLayerWrapVertical.setSelected(false);
        jTextFieldLayerName.setText("");
        jCheckBoxLayerIsBackground.setSelected(false);
        jTextFieldColorR.setText("");
        jTextFieldColorG.setText("");
        jTextFieldColorB.setText("");
        jTextFieldLayerWidth.setText("");
        jTextFieldLayerHeight.setText("");
        jTextFieldTileCount.setText("");
        
        jTextFieldTileRegular.setText("");
        jTextFieldTileComplete.setText("");
        
    }
    private void jButtonLayerDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLayerDeleteActionPerformed

        int[] rows = jTableLayer.getSelectedRows();
        for (int rc = rows.length-1; rc>= 0; rc--)
        {
            int r = rows[rc];
            if (r > currentMap.mLayers.size()-1) continue;
            int row = jTableLayer.convertRowIndexToModel(r);
            currentMap.removeLayer(row);
            currentMap.updateMapLayerData();
        }
        /*
        int r = jTableLayer.getSelectedRow();
        if (r==-1) return;
        if (r > currentMap.mLayers.size()-1) return;
        int row = jTableLayer.convertRowIndexToModel(r);


        currentMap.removeLayer(row);
        currentMap.updateMapLayerData();
        */
        mLayerDataPool = currentMap.getLayerPool();

        mClassSetting++;
        resetLayerConfigPool();
        setSelectedLayer("", currentMap.getCurrentLayerNo());
        initLayerTable();
        mapPanel.setMapChanged(true, true);
        mapPanel.updateNeeded(true);

        mClassSetting--;
    }//GEN-LAST:event_jButtonLayerDeleteActionPerformed

    private void readLayerToCurrent() /* allneeded*/
    {
        LayerData data = currentMap.getCurrentLayer().getData();
        data.mClass = "ALL";
        data.mName = jTextFieldLayerName.getText();
        data.mLayerName= jTextFieldLayerName.getText();

        data.mallowTileOverlap = jCheckBoxLayerAllowTileOverlap.isSelected();
        data.monlyOneTileOnOnePosition = jCheckBoxLayerOnlyOnePosition.isSelected();
        data.misBackground = jCheckBoxLayerIsBackground.isSelected();

        data.mWrapHorizontal = jCheckBoxLayerWrapHorizontal.isSelected();
        data.mWrapVertical = jCheckBoxLayerWrapVertical.isSelected();
        data.mISOBlockWrap = jCheckBoxISOAssumed.isSelected();
        
        
        int r = csa.util.UtilityString.Int0(jTextFieldColorR.getText())*256*256;
        int g = csa.util.UtilityString.Int0(jTextFieldColorG.getText())*256;
        int b = csa.util.UtilityString.Int0(jTextFieldColorB.getText());
        int rgb = r+g+b;
        data.mbackgroundColor = rgb;

/*

        data.mscrollBehaviour;


        data.mhorizontalSpeed;
        data.misBackgroundCollision;
        data.misChangeable;
        data.misForgroundCollision;
        data.misVisible;
        data.mmustBePainted;
        data.mpurposeTyp;
        data.mverticalSpeed;
*/
        currentMap.updateMapLayerData();
    }

    private void resetLayerConfigPool()
    {
        mClassSetting++;
        int i = 0;

        Collection<LayerData> colC = mLayerDataPool.getHashMap().values();
        Iterator<LayerData> iterC = colC.iterator();

        /*
        jComboBoxLayerName.removeAllItems();
        while (iterC.hasNext())
        {
            LayerData item = iterC.next();
            jComboBoxLayerName.addItem(item.mName);
            i++;
        }
        jComboBoxLayerName.setSelectedIndex(-1);
        */
        mClassSetting--;
    }

    private void jButtonLayerSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLayerSaveActionPerformed
        if (currentMap.getCurrentLayer() == null) return;

        if (jTextFieldLayerName.getText().trim().length()==0) return;
        String name = jTextFieldLayerName.getText();
        currentMap.getCurrentLayer().getData().mClass = "ALL";
        currentMap.getCurrentLayer().getData().mName = name;
        currentMap.getCurrentLayer().getData().mLayerName = name;
        currentMap.getCurrentLayer().isInMap = true;

        int d = currentMap.getCurrentLayerNo();
        readLayerToCurrent();

        currentMap.reInitLayerPool();
        mLayerDataPool = currentMap.getLayerPool();


        mLayerDataPool.put(currentMap.getCurrentLayer().getData());
        mLayerDataPool.save(currentMap.getData().mLayerSaveTyp);
        currentMap.updateMapLayerData();

        mClassSetting++;
        resetLayerConfigPool();
        setSelectedLayer(name, d);
        initLayerTable();
        mClassSetting--;
    }//GEN-LAST:event_jButtonLayerSaveActionPerformed

    void setSelectedLayer(String name, int d)
    {
        // for now relay on "d"
        if (d<0) return;
        if (currentMap.getCurrentLayers().isEmpty())
        {
            jButtonLayerNewActionPerformed(null);
            return;
        }
        currentMap.setCurrentLayerNo(d);

        LayerData data = currentMap.getCurrentLayer().getData();

        //jComboBoxLayerName.setSelectedItem(data.mName);
        jTextFieldLayerName.setText(data.mName);

        jCheckBoxLayerAllowTileOverlap.setSelected(data.mallowTileOverlap);
        jCheckBoxLayerOnlyOnePosition.setSelected(data.monlyOneTileOnOnePosition);
        jCheckBoxLayerIsBackground.setSelected(data.misBackground);
        jCheckBoxISOAssumed.setSelected(data.mISOBlockWrap);


        jCheckBoxLayerWrapHorizontal.setSelected(data.mWrapHorizontal);
        jCheckBoxLayerWrapVertical.setSelected(data.mWrapVertical);

        int r = data.mbackgroundColor/(256*256);
        int g = (data.mbackgroundColor-(r*(256*256)))/(256);
        int b = (data.mbackgroundColor-(r*(256*256))-(g*(256)))/(1);
        jTextFieldColorR.setText(""+r);
        jTextFieldColorG.setText(""+g);
        jTextFieldColorB.setText(""+b);

        //jTextFieldDeptch.setText(""+currentMap.getCurrentLayerNo());
        mapPanel.setSelectedLayer(currentMap.getCurrentLayerNo());

        jLabelOffset.setText(""+mapPanel.getOffsetX(jCheckBox4.isSelected())+"/"+mapPanel.getOffsetY(jCheckBox4.isSelected()));

/*

        data.mWrapHorizontal;
        data.mWrapVertical;
        data.mscrollBehaviour;


        data.mhorizontalSpeed;
        data.misBackgroundCollision;
        data.misChangeable;
        data.misForgroundCollision;
        data.misVisible;
        data.mmustBePainted;
        data.mpurposeTyp;
        data.mverticalSpeed;
*/
    }


    private void jButtonSaveAsNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveAsNewActionPerformed
        //mLayerData = new LayerData();
        //readAllToCurrent();
        //mLayerDataPool.putAsNew(mLayerData);
        //mLayerDataPool.save();
        mClassSetting++;
        //String klasse = jTextFieldLayerKlasse.getText();
        //resetConfigPool(true, klasse);
        //jComboBoxLayerName.setSelectedItem(mLayerData.mName);
        mClassSetting--;
    }//GEN-LAST:event_jButtonSaveAsNewActionPerformed

    private void resetGridConfigPool()
    {
        mClassSetting++;
        int i = 0;
        Collection<GridSettingsData> colC = mGridSettingsDataPool.getHashMap().values();
        Iterator<GridSettingsData> iterC = colC.iterator();

        jComboBoxGridNameCombo.removeAllItems();
        while (iterC.hasNext())
        {
            GridSettingsData item = iterC.next();
            jComboBoxGridNameCombo.addItem(item.mName);
            i++;
        }
        jComboBoxGridNameCombo.setSelectedIndex(-1);
        mClassSetting--;
    }

    void setMapSelectedGrid()
    {
        clearGridAll();
        if (currentMap == null) return;
        String gridName = currentMap.getData().mGridSettings;
        if (gridName.trim().length() == 0) return;

        mGridSettingsData = mGridSettingsDataPool.get(gridName);
        if (mGridSettingsData == null) mGridSettingsData = new GridSettingsData();
        setGridAllFromCurrent();
    }

    private void clearGridAll() /* allneeded*/
    {
        mClassSetting++;
        mGridSettingsData = new GridSettingsData();
        setGridAllFromCurrent();
        mClassSetting--;
    }

    private void setGridAllFromCurrent() /* allneeded*/
    {
        mClassSetting++;
        jComboBoxGridNameCombo.setSelectedItem(mGridSettingsData.mName);
        jTextFieldGridName.setText(mGridSettingsData.mName);

        String x = "";
        for(int i=0; i<mGridSettingsData.meveryX.size();i++)
        {
            if (i!= 0) x+=", ";
            x+=""+mGridSettingsData.meveryX.elementAt(i);
        }
        String y = "";
        for(int i=0; i<mGridSettingsData.meveryY.size();i++)
        {
            if (i!= 0) y+=", ";
            y+=""+mGridSettingsData.meveryY.elementAt(i);
        }

        jTextFieldGridEveryX.setText(x);
        jTextFieldGridEveryY.setText(y);


        jComboBoxDrawType.setSelectedIndex(mGridSettingsData.mDrawTyp);
        x="";
        for(int i=0; i<mGridSettingsData.mXOffset.size();i++)
        {
            if (i!= 0) x+=", ";
            x+=""+mGridSettingsData.mXOffset.elementAt(i);
        }
        jTextFieldGridOffsetX1.setText(x);
        y = "";
        for(int i=0; i<mGridSettingsData.mYOffset.size();i++)
        {
            if (i!= 0) y+=", ";
            y+=""+mGridSettingsData.mYOffset.elementAt(i);
        }
        jTextFieldGridOffsetY1.setText(y);

        jCheckBoxSHowHotsspot.setSelected(mGridSettingsData.mSHowHotSpot);

        int r = mGridSettingsData.mGridColor/(256*256);
        int g = (mGridSettingsData.mGridColor-(r*(256*256)))/(256);
        int b = (mGridSettingsData.mGridColor-(r*(256*256))-(g*(256)))/(1);
        jTextFieldColorRGrid.setText(""+r);
        jTextFieldColorGGrid.setText(""+g);
        jTextFieldColorBGrid.setText(""+b);

        jCheckBoxXAltertating.setSelected(mGridSettingsData.mXAlternating);
        jCheckBoxYAltertating.setSelected(mGridSettingsData.mYAlternating);

        mClassSetting--;
    }

    private void readGridAllToCurrent() /* allneeded*/
    {
        mGridSettingsData.mClass = "ALL";
        mGridSettingsData.mName = jTextFieldGridName.getText();

        mGridSettingsData.meveryX = csa.util.UtilityString.intVector(jTextFieldGridEveryX.getText());
        mGridSettingsData.meveryY = csa.util.UtilityString.intVector(jTextFieldGridEveryY.getText());
        mGridSettingsData.mXAlternating = jCheckBoxXAltertating.isSelected();
        mGridSettingsData.mYAlternating = jCheckBoxYAltertating.isSelected();


        mGridSettingsData.mDrawTyp = jComboBoxDrawType.getSelectedIndex();

        mGridSettingsData.mXOffset = csa.util.UtilityString.intVector(jTextFieldGridOffsetX1.getText());
        mGridSettingsData.mYOffset = csa.util.UtilityString.intVector(jTextFieldGridOffsetY1.getText());

        int r = csa.util.UtilityString.Int0(jTextFieldColorRGrid.getText())*256*256;
        int g = csa.util.UtilityString.Int0(jTextFieldColorGGrid.getText())*256;
        int b = csa.util.UtilityString.Int0(jTextFieldColorBGrid.getText());
        int rgb = r+g+b;
        mGridSettingsData.mGridColor = rgb;
        mGridSettingsData.mSHowHotSpot = jCheckBoxSHowHotsspot.isSelected();
    }
    private void jButtonGridNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGridNewActionPerformed
        mClassSetting++;
        mGridSettingsData = new GridSettingsData();
        clearGridAll();
        mClassSetting--;
    }//GEN-LAST:event_jButtonGridNewActionPerformed

    private void jButtonGridSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGridSaveActionPerformed

        String name = jTextFieldGridName.getText().trim();
        if (name.length()==0) return;
        readGridAllToCurrent();
        mGridSettingsDataPool.put(mGridSettingsData);
        mGridSettingsDataPool.save();
        mClassSetting++;
        currentMap.getData().mGridSettings = name;
        resetGridConfigPool();
        setGridAllFromCurrent();
        mClassSetting--;
    }//GEN-LAST:event_jButtonGridSaveActionPerformed

    private void jComboBoxGridNameComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxGridNameComboActionPerformed
        if (mClassSetting > 0 ) return;
        String key = jComboBoxGridNameCombo.getSelectedItem().toString();
        mGridSettingsData = mGridSettingsDataPool.get(key);
        setGridAllFromCurrent();
        jCheckBoxGridEnableActionPerformed(null);


    }//GEN-LAST:event_jComboBoxGridNameComboActionPerformed

    private void jComboBoxTileKlasseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxTileKlasseActionPerformed
        if (mClassSetting > 0) {
            return;
        }
        mClassSetting++;

        String selected = jComboBoxTileKlasse.getSelectedItem().toString();

        //clearAll();
        resetTileConfigPool(true, selected, "");
        mClassSetting--;
    }//GEN-LAST:event_jComboBoxTileKlasseActionPerformed

    private void imageComponentLeftMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_imageComponentLeftMouseClicked
    }//GEN-LAST:event_imageComponentLeftMouseClicked

    private void jCheckBoxLayerIsBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxLayerIsBackgroundActionPerformed
        backgroundChanged();
    }//GEN-LAST:event_jCheckBoxLayerIsBackgroundActionPerformed

    private void jTextFieldColorRFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldColorRFocusLost
        backgroundChanged();
    }//GEN-LAST:event_jTextFieldColorRFocusLost

    private void jTextFieldColorGFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldColorGFocusLost
        backgroundChanged();
    }//GEN-LAST:event_jTextFieldColorGFocusLost

    private void jTextFieldColorBFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldColorBFocusLost
        backgroundChanged();
    }//GEN-LAST:event_jTextFieldColorBFocusLost

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        if (mTileListForm == null)
            mTileListForm =new TileListForm();
        mTileListForm.setMap(currentMap, mapPanel, this);
        mTileListForm.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButtonLayerDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLayerDownActionPerformed

        int r = jTableLayer.getSelectedRow();
        if (r==-1) return;
        if (r > currentMap.mLayers.size()-1) return;
        int row = jTableLayer.convertRowIndexToModel(r);
        if (row == 0) return;

        mapPanel.downLayer(row);
        jTableLayer.repaint();

        ListSelectionModel selectionModel =  jTableLayer.getSelectionModel();
        selectionModel.setSelectionInterval(row-1, row-1);
        repaint();
    }//GEN-LAST:event_jButtonLayerDownActionPerformed

    private void jButtonLayerUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLayerUpActionPerformed
        int r = jTableLayer.getSelectedRow();
        if (r==-1) return;
        if (r > currentMap.mLayers.size()-1) return;
        int row = jTableLayer.convertRowIndexToModel(r);
        if (row == currentMap.mLayers.size()-1) return;

        mapPanel.upLayer(row);

        jTableLayer.repaint();
        ListSelectionModel selectionModel =  jTableLayer.getSelectionModel();
        selectionModel.setSelectionInterval(row+1, row+1);

        repaint();
    }//GEN-LAST:event_jButtonLayerUpActionPerformed

    private void jToggleButtonSetEraseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButtonSetEraseActionPerformed
        if (jToggleButtonSetErase.isSelected())
        {
            jToggleButtonSetErase.setText("Delete Tile");
            jToggleButtonSetErase.setForeground(Color.red);

            mapPanel.setMouseGrabTile(new Tile(null), new Tile(null));
        }
        else
        {
            jToggleButtonSetErase.setText("Set Tile");
            jToggleButtonSetErase.setForeground(Color.black);
            mapPanel.setMouseGrabTile(new Tile(leftMouseTile), new Tile(sleftMouseTile));
        }
    }//GEN-LAST:event_jToggleButtonSetEraseActionPerformed

    private void jButtonExportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonExportActionPerformed

        String name = jTextFieldMapName.getText().trim();
        if (name.length() == 0) {
            return;
        }
        ExportFrame exportFrame = new ExportFrame(currentMap);
        exportFrame.setVisible(true);
    }//GEN-LAST:event_jButtonExportActionPerformed

    private void jCheckBoxGridEnableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxGridEnableActionPerformed

        if (mClassSetting>0) return;
        if (jCheckBoxGridEnable.isSelected())
        {
            readGridAllToCurrent();
            if (mGridSettingsData.mName == null) return;
            if (mGridSettingsData.mName.length() == 0) return;
            jCheckBoxSnapToGrid.setEnabled(true);

            if (mGridSettingsData.getCClass().length() == 0)
                    mapPanel.setGrid(null, false);
                else
                    mapPanel.setGrid(mGridSettingsData, true);
        }
        else
        {
            mapPanel.setGrid(null, false);
            jCheckBoxSnapToGrid.setEnabled(false);
        }

    }//GEN-LAST:event_jCheckBoxGridEnableActionPerformed

    private void jTextFieldGridOffsetX1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldGridOffsetX1ActionPerformed
        jCheckBoxGridEnableActionPerformed(null);
    }//GEN-LAST:event_jTextFieldGridOffsetX1ActionPerformed

    private void jTextFieldColorRGridFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldColorRGridFocusLost
        jCheckBoxGridEnableActionPerformed(null);
    }//GEN-LAST:event_jTextFieldColorRGridFocusLost

    private void jTextFieldColorGGridFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldColorGGridFocusLost
        jCheckBoxGridEnableActionPerformed(null);
    }//GEN-LAST:event_jTextFieldColorGGridFocusLost

    private void jTextFieldColorBGridFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldColorBGridFocusLost
        jCheckBoxGridEnableActionPerformed(null);
    }//GEN-LAST:event_jTextFieldColorBGridFocusLost

    private void jComboBoxDrawTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxDrawTypeActionPerformed
        jCheckBoxGridEnableActionPerformed(null);
    }//GEN-LAST:event_jComboBoxDrawTypeActionPerformed

    private void jCheckBoxSHowHotsspotActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxSHowHotsspotActionPerformed
        jCheckBoxGridEnableActionPerformed(null);
    }//GEN-LAST:event_jCheckBoxSHowHotsspotActionPerformed

    private void jTextFieldGridEveryXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldGridEveryXActionPerformed
        jCheckBoxGridEnableActionPerformed(null);
    }//GEN-LAST:event_jTextFieldGridEveryXActionPerformed

    private void jTextFieldGridEveryYActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldGridEveryYActionPerformed
        jCheckBoxGridEnableActionPerformed(null);
    }//GEN-LAST:event_jTextFieldGridEveryYActionPerformed

    private void jTextFieldGridOffsetY1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldGridOffsetY1ActionPerformed
        jCheckBoxGridEnableActionPerformed(null);
    }//GEN-LAST:event_jTextFieldGridOffsetY1ActionPerformed

    private void jCheckBoxYAltertatingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxYAltertatingActionPerformed
        jCheckBoxGridEnableActionPerformed(null);
    }//GEN-LAST:event_jCheckBoxYAltertatingActionPerformed

    private void jCheckBoxXAltertatingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxXAltertatingActionPerformed
        jCheckBoxGridEnableActionPerformed(null);
    }//GEN-LAST:event_jCheckBoxXAltertatingActionPerformed

    private void jCheckBoxSnapToGridActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxSnapToGridActionPerformed
        mapPanel.setSnap(jCheckBoxSnapToGrid.isSelected());
    }//GEN-LAST:event_jCheckBoxSnapToGridActionPerformed

    private void jSlider1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSlider1StateChanged

        if (mClassSetting>0) return;
        int value = jSlider1.getValue();
        int scalePercent=100;
        if (value >0)
        {
            scalePercent = value+100;
        }
        if (value <0)
        {
            scalePercent =(int) ((-100.0/((((double)value)-100.0))) * 100.0);
        }
        jLabel2.setText(""+scalePercent+"%");
        mapPanel.setScalingPercent(scalePercent);
    }//GEN-LAST:event_jSlider1StateChanged

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        Configuration C = Configuration.getConfiguration();
        if (C.getMainFrame() == null) {
            return;
        }
        MustSaveAsOneDialog ac = new MustSaveAsOneDialog();
        ModalInternalFrame modal = new ModalInternalFrame("Save as new image!", C.getMainFrame().getRootPane(), C.getMainFrame(), ac);
        ac.setDialog(modal);
        modal.setVisible(true);
        String filename = ac.getFilename();
        if (filename.length() == 0)
        {
            return;
        }
        filename = "images"+File.separator+ filename+".png";

        Image img = mapPanel.getImage();
        try
        {
            File outputfile = new File(filename);
            ImageIO.write(csa.util.UtilityImage.toBufferedImage(img), "png", outputfile);
        }
        catch (IOException e)
        {
        }

    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        mapPanel.setMouseGrabTile(new Tile(null), new Tile(null));
        sleftMouseTile = null;
        leftMouseTile = null;
        setMouseTile(null, imageComponentLeft);
        setMouseTile(null, imageComponentSLeft);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButtonOffsetRightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOffsetRightActionPerformed
        // mapPanel.offsetXInc(csa.util.UtilityString.Int0(jTextField10.getText()), jCheckBox4.isSelected());
        // jLabelOffset.setText(""+mapPanel.getOffsetX(jCheckBox4.isSelected())+"/"+mapPanel.getOffsetY(jCheckBox4.isSelected()));
    }//GEN-LAST:event_jButtonOffsetRightActionPerformed

    private void jButtonOffsetUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOffsetUpActionPerformed
        // mapPanel.offsetYInc(-csa.util.UtilityString.Int0(jTextField7.getText()), jCheckBox4.isSelected());
        // jLabelOffset.setText(""+mapPanel.getOffsetX(jCheckBox4.isSelected())+"/"+mapPanel.getOffsetY(jCheckBox4.isSelected()));
    }//GEN-LAST:event_jButtonOffsetUpActionPerformed

    private void jButtonOffsetLeftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOffsetLeftActionPerformed
        // mapPanel.offsetXInc(-csa.util.UtilityString.Int0(jTextField9.getText()), jCheckBox4.isSelected());
        // jLabelOffset.setText(""+mapPanel.getOffsetX(jCheckBox4.isSelected())+"/"+mapPanel.getOffsetY(jCheckBox4.isSelected()));
    }//GEN-LAST:event_jButtonOffsetLeftActionPerformed

    private void jButtonOffsetDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOffsetDownActionPerformed
        // mapPanel.offsetYInc(csa.util.UtilityString.Int0(jTextField8.getText()), jCheckBox4.isSelected());
        // jLabelOffset.setText(""+mapPanel.getOffsetX(jCheckBox4.isSelected())+"/"+mapPanel.getOffsetY(jCheckBox4.isSelected()));
    }//GEN-LAST:event_jButtonOffsetDownActionPerformed

    TriggerCallback movementCallback = new TriggerCallback()
            {
                @Override
                public void doIt(int state, Object o)
                {
                    if (movementXInc)
                    {
                        mapPanel.offsetXInc(csa.util.UtilityString.Int0(jTextField10.getText()), jCheckBox4.isSelected());
                    }
                    if (movementYInc)
                    {
                        mapPanel.offsetYInc(csa.util.UtilityString.Int0(jTextField8.getText()), jCheckBox4.isSelected());
                    }
                    if (movementXDec)
                    {
                        mapPanel.offsetXInc(-csa.util.UtilityString.Int0(jTextField9.getText()), jCheckBox4.isSelected());
                    }
                    if (movementYDec)
                    {
                        mapPanel.offsetYInc(-csa.util.UtilityString.Int0(jTextField7.getText()), jCheckBox4.isSelected());
                    }
                    jLabelOffset.setText(""+mapPanel.getOffsetX(jCheckBox4.isSelected())+"/"+mapPanel.getOffsetY(jCheckBox4.isSelected()));
                    timer.addTrigger(movementCallback, movementDelay, 0, null);
                }
            };
    boolean movementXInc = false;
    boolean movementYInc = false;
    boolean movementXDec = false;
    boolean movementYDec = false;
    boolean movementActive = false;
    int movementDelay = 50;

    private void changeMoving()
    {
        boolean oldActive = movementActive;
        movementActive = movementXInc || movementYInc || movementXDec || movementYDec;
        if (oldActive == movementActive) return;
        if (!movementActive)
        {
            timer.removeTrigger(movementCallback);
        }
        else
        {
            timer.addTrigger(movementCallback, movementDelay, 0, null);
        }
    }

    private void jButtonOffsetRightMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonOffsetRightMousePressed
        movementXInc = true;
        changeMoving();
    }//GEN-LAST:event_jButtonOffsetRightMousePressed

    private void jButtonOffsetRightMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonOffsetRightMouseReleased
        if (jCheckBox5.isSelected()) return;
        movementXInc = false;
        changeMoving();
    }//GEN-LAST:event_jButtonOffsetRightMouseReleased

    private void jButtonOffsetUpMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonOffsetUpMousePressed
        movementYDec = true;
        changeMoving();
    }//GEN-LAST:event_jButtonOffsetUpMousePressed

    private void jButtonOffsetUpMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonOffsetUpMouseReleased
        if (jCheckBox5.isSelected()) return;
        movementYDec = false;
        changeMoving();
    }//GEN-LAST:event_jButtonOffsetUpMouseReleased

    private void jButtonOffsetLeftMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonOffsetLeftMousePressed
        movementXDec = true;
        changeMoving();
    }//GEN-LAST:event_jButtonOffsetLeftMousePressed

    private void jButtonOffsetLeftMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonOffsetLeftMouseReleased
        if (jCheckBox5.isSelected()) return;
        movementXDec = false;
        changeMoving();
    }//GEN-LAST:event_jButtonOffsetLeftMouseReleased

    private void jButtonOffsetDownMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonOffsetDownMousePressed
        movementYInc = true;
        changeMoving();
    }//GEN-LAST:event_jButtonOffsetDownMousePressed

    private void jButtonOffsetDownMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonOffsetDownMouseReleased
        if (jCheckBox5.isSelected()) return;
        movementYInc = false;
        changeMoving();
    }//GEN-LAST:event_jButtonOffsetDownMouseReleased

    private void jCheckBox5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox5ActionPerformed
        if (jCheckBox5.isSelected()) return;

        movementYInc = false;
        movementXInc = false;
        movementYDec = false;
        movementXDec = false;
        changeMoving();
    }//GEN-LAST:event_jCheckBox5ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        mapPanel.setOffsetX(0, jCheckBox4.isSelected());
        mapPanel.setOffsetY(0, jCheckBox4.isSelected());
        jLabelOffset.setText(""+mapPanel.getOffsetX(jCheckBox4.isSelected())+"/"+mapPanel.getOffsetY(jCheckBox4.isSelected()));

    }//GEN-LAST:event_jButton9ActionPerformed

    private void jSlider1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jSlider1MousePressed
        ImageCache.getImageCache().setCacheActive(false);
    }//GEN-LAST:event_jSlider1MousePressed

    private void jSlider1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jSlider1MouseReleased
        ImageCache.getImageCache().setCacheActive(true);
    }//GEN-LAST:event_jSlider1MouseReleased

    boolean checkLayer(Layer layer)
    {
        boolean b = layer.isRegular();
        if (b) return b;
        b = LayerWarningDialog.doWarning(layer);
        return b;
    }

    private void jButtonInsertTransitionTilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonInsertTransitionTilesActionPerformed

        if (!checkLayer(currentMap.getCurrentLayer()))
        {
            return;
        }

        Layer newLayer = new Layer();

        mapPanel.buildTransitions(currentMap.getCurrentLayer(), newLayer, jCheckBoxConsidderWrapping.isSelected());

        currentMap.addLayer(newLayer, currentMap.getCurrentLayerNo()+1);
        String name ="Transition layer";
        newLayer.getData().mLayerName = name;
        newLayer.getData().mName = name;
        for (int i=0;i<currentMap.getData().mLayerData.size(); i++)
        {
            if (currentMap.getData().mLayerData.elementAt(i).equals(name))
            {
                name = name +"_"+i;
                i=-1;
            }

        }

        currentMap.getData().mLayerData.add(currentMap.getCurrentLayerNo()+1, name);
        //currentMap.getData().mLayerData.remove(currentMap.getCurrentLayerNo()+2);
        jTableLayer.tableChanged(null);
    }//GEN-LAST:event_jButtonInsertTransitionTilesActionPerformed

    private void jCheckBoxLayerAllowTileOverlapActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxLayerAllowTileOverlapActionPerformed
        mapPanel.setMultiTile(jCheckBoxLayerAllowTileOverlap.isSelected());
    }//GEN-LAST:event_jCheckBoxLayerAllowTileOverlapActionPerformed

    private void jButtonLayerFromImage1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLayerFromImage1ActionPerformed
        Layer newLayer = new Layer();
        String name ="Algorythm layer";
        newLayer.getData().mLayerName = name;
        newLayer.getData().mName = name;

        CSAMainFrame frame = (CSAMainFrame) Global.mMainWindow;
        BuildLayerFromAlgorythmPanel c = new BuildLayerFromAlgorythmPanel(newLayer, this);
        frame.addPanel(c);
        frame.setMainPanel(c);
        frame.windowMe(c,1018,680, "Algorythm to Layer Conversion");
    }//GEN-LAST:event_jButtonLayerFromImage1ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
       currentMap.getCurrentLayer().makeRegular();
       mapPanel.setMapChanged(true, true);
       mapPanel.updateNeeded(true);
       updateLayerSize();
       
    }//GEN-LAST:event_jButton10ActionPerformed

    private void jButtonLayerFromImage2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLayerFromImage2ActionPerformed
    }//GEN-LAST:event_jButtonLayerFromImage2ActionPerformed

    public int growLayer=0;
    private void jButtonGrowTilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGrowTilesActionPerformed

        Layer newLayer = new Layer();
        String name ="Grow layer_"+growLayer;
        growLayer++;
        newLayer.getData().mLayerName = name;
        newLayer.getData().mName = name;

        
        
        
        CSAMainFrame frame = (CSAMainFrame) Global.mMainWindow;
        GrowTilesPanel c = new GrowTilesPanel(newLayer, this, currentMap.getCurrentLayer());
        frame.addPanel(c);
        frame.setMainPanel(c);
        frame.windowMe(c,600,400, "Grow Tiles");
        
    }//GEN-LAST:event_jButtonGrowTilesActionPerformed

    private void jCheckBoxLayerOnlyOnePositionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxLayerOnlyOnePositionActionPerformed
        mapPanel.setOnlyOneOnPosition(jCheckBoxLayerOnlyOnePosition.isSelected());
    }//GEN-LAST:event_jCheckBoxLayerOnlyOnePositionActionPerformed

    private void jCheckBoxLayerWrapHorizontalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxLayerWrapHorizontalActionPerformed
        LayerData data = currentMap.getCurrentLayer().getData();
        data.mWrapHorizontal = jCheckBoxLayerWrapHorizontal.isSelected();
        data.mWrapVertical = jCheckBoxLayerWrapVertical.isSelected();
        mapPanel.updateNeeded(true);
        mapPanel.setMapChanged(true, false);
    }//GEN-LAST:event_jCheckBoxLayerWrapHorizontalActionPerformed

    private void jCheckBoxLayerWrapVerticalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxLayerWrapVerticalActionPerformed
        LayerData data = currentMap.getCurrentLayer().getData();
        data.mWrapHorizontal = jCheckBoxLayerWrapHorizontal.isSelected();
        data.mWrapVertical = jCheckBoxLayerWrapVertical.isSelected();
        mapPanel.updateNeeded(true);
        mapPanel.setMapChanged(true, false);
    }//GEN-LAST:event_jCheckBoxLayerWrapVerticalActionPerformed

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed

        int[] rows = jTableLayer.getSelectedRows();

        int[] rowConvert = new int[rows.length];
        for (int rc = rows.length-1; rc>= 0; rc--)
        {
            int r = rows[rc];
            rowConvert[rc] = -1;
            if (r > currentMap.mLayers.size()-1) continue;
            int row = jTableLayer.convertRowIndexToModel(r);
            rowConvert[rc] = row;
        }
        currentMap.joinLayers(rowConvert);
        
        mLayerDataPool = currentMap.getLayerPool();

        mClassSetting++;
        resetLayerConfigPool();
        setSelectedLayer("", currentMap.getCurrentLayerNo());
        initLayerTable();
        
        mapPanel.setOffsetX(0, jCheckBox4.isSelected());
        mapPanel.setOffsetY(0, jCheckBox4.isSelected());
        jLabelOffset.setText(""+mapPanel.getOffsetX(jCheckBox4.isSelected())+"/"+mapPanel.getOffsetY(jCheckBox4.isSelected()));
        mapPanel.setScalingPercent(100);

        mapPanel.initBackground();
        mapPanel.setMapChanged(true, false);
        mapPanel.updateNeeded(true);

        
        
        mClassSetting--;
       
    }//GEN-LAST:event_jButton12ActionPerformed

    private void jTextFieldTileFile1FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldTileFile1FocusLost
        jTextFieldTileFile1ActionPerformed(null);
    }//GEN-LAST:event_jTextFieldTileFile1FocusLost

    private void jButtonFileSelect2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFileSelect2ActionPerformed
        InternalFrameFileChoser fc = new csa.gui.dialogs.InternalFrameFileChoser();
        fc.setCurrentDirectory(new java.io.File("xml"+File.separator+"Tile"));
        FileNameExtensionFilter  filter = new  FileNameExtensionFilter("xml", "xml");
        fc.setFileFilter(filter);
        int r = fc.showOpenDialog(Configuration.getConfiguration().getMainFrame());
        if (r != InternalFrameFileChoser.APPROVE_OPTION) return;
        String name = fc.getSelectedFile().getName();
        jTextFieldTileFile1.setText(csa.util.UtilityString.replace(name, ".xml",""));
        jTextFieldTileFile1ActionPerformed(null);
    }//GEN-LAST:event_jButtonFileSelect2ActionPerformed

    private void jComboBoxTileKlasse1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxTileKlasse1ActionPerformed
        if (mClassSetting > 0) {
            return;
        }
        mClassSetting++;

        String selected = jComboBoxTileKlasse1.getSelectedItem().toString();

        //clearAll();
        resetCompositeTileConfigPool(true, selected, "");
        mClassSetting--;
    }//GEN-LAST:event_jComboBoxTileKlasse1ActionPerformed

    private void jTextFieldCompositeNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldCompositeNameActionPerformed
    }//GEN-LAST:event_jTextFieldCompositeNameActionPerformed

    private void jTextFieldCompositeNameFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldCompositeNameFocusLost
    }//GEN-LAST:event_jTextFieldCompositeNameFocusLost

    private void jButtonMapDelete1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMapDelete1ActionPerformed
    }//GEN-LAST:event_jButtonMapDelete1ActionPerformed

    private void jButtonMapSave1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMapSave1ActionPerformed
       
        String filename =jTextFieldTileFile1.getText().trim();
        String className = jTextFieldCompositeClass.getText();
        String name = jTextFieldCompositeName.getText();
        
        if (filename.length()==0) return;
        if (className.trim().length()==0) return;
        if (name.trim().length()==0) return;
        if (mCompositeTileDataPool == null) return;        
                
        Layer l = currentMap.getCurrentLayer();
        l = l.cloneLayer();
        // l.getData().mClass = className;
        
        CompositeTile ctile = new CompositeTile();

        // save layer
        String layerFileName = filename+"CompositeData";
        String layerClassName = className+"CompositeData";
        String layerName = name+"CompositeData";

        ctile.getData().setTileSetFileName(filename);
        ctile.getData().setCClass(className);
        ctile.getData().setName(name);

        l.getData().mName = layerName;
        l.getData().mLayerName = layerName;
        l.getData().mClass = layerClassName;
        
        boolean success = l.saveAsCompositeTileLayer(layerFileName, layerClassName, layerName);
        if (!success) return;
        
        ctile.getData().setCompositeFile(layerFileName);
        ctile.getData().setCompositeClass(layerClassName);
        ctile.getData().setCompositeName(layerName);

        if (mCompositeTileDataPool == null) return;        
        mCompositeTileDataPool.put(ctile.getData());
        mCompositeTileDataPool.save();

        resetCompositeTileConfigPool(true, className, name);
    }//GEN-LAST:event_jButtonMapSave1ActionPerformed

    private void jButtonScaleToFitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonScaleToFitActionPerformed

        int scale = mapPanel.scaleToFit();
        if (scale != -1)
            jLabel2.setText(""+scale+"%");
        jLabelOffset.setText(""+mapPanel.getOffsetX(jCheckBox4.isSelected())+"/"+mapPanel.getOffsetY(jCheckBox4.isSelected()));

        
        
        mClassSetting++;
        if (scale >= 100)
        {
            jSlider1.setValue(scale-100);
        }
        else
        {
            int v = 100/scale;
            v*=-100;
            jSlider1.setValue(v);
        }
        mClassSetting--;
        
    }//GEN-LAST:event_jButtonScaleToFitActionPerformed

    private void jTextFieldCompositeClassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldCompositeClassActionPerformed
    }//GEN-LAST:event_jTextFieldCompositeClassActionPerformed

    private void jTextFieldCompositeClassFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldCompositeClassFocusLost
    }//GEN-LAST:event_jTextFieldCompositeClassFocusLost

    private void jTextFieldTileFile1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldTileFile1ActionPerformed

        String file = jTextFieldTileFile1.getText().trim();
        String _class = "";
        if (jComboBoxTileKlasse1.getSelectedIndex() != -1)
            _class = jComboBoxTileKlasse1.getSelectedItem().toString().trim();
        if (file.length() == 0) return;

        mCompositeTileDataPool = new TileDataPool("Tile"+File.separator+file+".xml");
        if (mCompositeTileDataPool == null) return;

        resetCompositeTileConfigPool(true, _class, "");
    }//GEN-LAST:event_jTextFieldTileFile1ActionPerformed

    private void jCheckBoxISOAssumedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxISOAssumedActionPerformed
        currentMap.getCurrentLayer().setISOAssumed(jCheckBoxISOAssumed.isSelected());
        mapPanel.updateNeeded(true);
        mapPanel.setMapChanged(true, true);
        updateLayerSize();
    }//GEN-LAST:event_jCheckBoxISOAssumedActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        currentMap.getCurrentLayer().testRegular();
        updateLayerSize();
    }//GEN-LAST:event_jButton11ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        currentMap.toZero();
        mapPanel.updateNeeded(true);
        mapPanel.setMapChanged(true, true);
        updateLayerSize();
        
    }//GEN-LAST:event_jButton5ActionPerformed

//    boolean inResize = false;

    Windowable naviPanel=null;
    CSAInternalFrame naviFrame=null;

    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed

        CSAMainFrame frame = (CSAMainFrame) Global.mMainWindow;
        
        naviPanel = mapPanel.getNaviPanel(offsetNaviSize, offsetNaviSize);
        if (naviPanel==null) return;
        frame.addPanel(naviPanel);
        frame.setMainPanel((JPanel) naviPanel);
        final Dimension in = frame.getInternalFrameDifference();
//        naviFrame = frame.windowMe(naviPanel,((JPanel)naviPanel).getWidth()+in.width,((JPanel)naviPanel).getHeight()+in.height, "Navi");
        naviFrame = frame.windowMe(naviPanel,offsetNaviSize+in.width,offsetNaviSize+in.height, "Navi");
        
        naviFrame.setResizable(false);
        
        final ComponentAdapter cal = new ComponentAdapter() 
        {
            public void componentResized(ComponentEvent ce) 
            {
            }        
        };
                
        naviFrame.addComponentListener(cal);
        
        final javax.swing.event.InternalFrameAdapter l = new javax.swing.event.InternalFrameAdapter()
        {
            javax.swing.event.InternalFrameAdapter ll=this;
            @Override public void internalFrameClosed(javax.swing.event.InternalFrameEvent e)
            {
                naviFrame.removeInternalFrameListener(ll);
                naviFrame.removeComponentListener(cal);
                naviFrame = null;
                naviPanel = null;
            }
        };
        naviFrame.addInternalFrameListener(l);        
        
    }//GEN-LAST:event_jButton13ActionPerformed

    int offsetNaviSize = 100;
    private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton15ActionPerformed
        if (naviPanel==null) return;
        
        int oldPrefferedSize = ((JPanel)naviPanel).getPreferredSize().width*((JPanel)naviPanel).getPreferredSize().height;
        do
        {
            offsetNaviSize+=10;


            mapPanel.resizedNaviWindow(offsetNaviSize, offsetNaviSize);
        }
        while (oldPrefferedSize == ((JPanel)naviPanel).getPreferredSize().width*((JPanel)naviPanel).getPreferredSize().height);
        
        //System.out.println("Panel Size:" + ((JPanel)naviPanel).getSize());
        //System.out.println("Panel PSize:" + ((JPanel)naviPanel).getPreferredSize());

        CSAMainFrame frame = (CSAMainFrame) Global.mMainWindow;
        final Dimension in = frame.getInternalFrameDifference();

        naviFrame.setSize(((JPanel)naviPanel).getPreferredSize().width+in.width,((JPanel)naviPanel).getPreferredSize().height+in.height);

        //System.out.println(naviFrame.getSize());
    }//GEN-LAST:event_jButton15ActionPerformed

    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
     
        if (naviPanel==null) return;
        
        int oldPrefferedSize = ((JPanel)naviPanel).getPreferredSize().width*((JPanel)naviPanel).getPreferredSize().height;
        do
        {
            if (offsetNaviSize<=10)
            {
                return;
            }
            offsetNaviSize-=10;

            mapPanel.resizedNaviWindow(offsetNaviSize, offsetNaviSize);
        }
        while (oldPrefferedSize == ((JPanel)naviPanel).getPreferredSize().width*((JPanel)naviPanel).getPreferredSize().height);
        
        //System.out.println("Panel Size:" + ((JPanel)naviPanel).getSize());
        //System.out.println("Panel PSize:" + ((JPanel)naviPanel).getPreferredSize());

        CSAMainFrame frame = (CSAMainFrame) Global.mMainWindow;
        final Dimension in = frame.getInternalFrameDifference();

        naviFrame.setSize(((JPanel)naviPanel).getPreferredSize().width+in.width,((JPanel)naviPanel).getPreferredSize().height+in.height);

        //System.out.println(naviFrame.getSize());        
    }//GEN-LAST:event_jButton14ActionPerformed

    private void jTextFieldSpriteFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldSpriteFileActionPerformed

        loadSpriteCollection();
    }//GEN-LAST:event_jTextFieldSpriteFileActionPerformed

    private void jTextFieldSpriteFileFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldSpriteFileFocusLost
        // if enabled, switching to another tab also loses focus
        //jTextFieldTileFileActionPerformed(null);
    }//GEN-LAST:event_jTextFieldSpriteFileFocusLost

    private void jComboBoxSpriteKlasseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxSpriteKlasseActionPerformed
        if (mClassSetting >0 ) return;
        mClassSetting++;

        String selected = jComboBoxSpriteKlasse.getSelectedItem().toString();
        int ind = jComboBoxSpriteKlasse.getSelectedIndex();
        //clearAll();

        jComboBoxSpriteKlasse.setSelectedIndex(ind);
        resetSpriteConfigPool(true, selected, "");
        mClassSetting--;
    }//GEN-LAST:event_jComboBoxSpriteKlasseActionPerformed

    private void jButtonSpriteFileSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSpriteFileSelectActionPerformed
        InternalFrameFileChoser fc = new csa.gui.dialogs.InternalFrameFileChoser();
        fc.setCurrentDirectory(new java.io.File("xml"+File.separator+"Sprite"));
        FileNameExtensionFilter  filter = new  FileNameExtensionFilter("xml", "xml");
        fc.setFileFilter(filter);
        int r = fc.showOpenDialog(Configuration.getConfiguration().getMainFrame());
        if (r != InternalFrameFileChoser.APPROVE_OPTION) return;
        String name = fc.getSelectedFile().getName();
        jTextFieldSpriteFile.setText(csa.util.UtilityString.replace(name, ".xml",""));
        jTextFieldSpriteFileActionPerformed(null);
    }//GEN-LAST:event_jButtonSpriteFileSelectActionPerformed

    private void jComboBoxActionSpritePerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxActionSpritePerformed

        
        if (mClassSetting>0) return;
        String action = jComboBoxAction.getSelectedItem().toString();
        
        mClassSetting++;
        if (mCurrentSprite.getDirections(action).size()>0)
        {
             int oldIndex = jComboBoxActionSpriteDirection.getSelectedIndex();
             jComboBoxActionSpriteDirection.setModel(new DefaultComboBoxModel(mCurrentSprite.getDirections(action)));
             if (mCurrentSprite.getDirections(action).size()>oldIndex)
             {
                jComboBoxActionSpriteDirection.setSelectedIndex(oldIndex);
             }
             else
             {
                 if (mCurrentSprite.getDirections(action).size() == 0)
                     jComboBoxActionSpriteDirection.setSelectedIndex(-1);
                 else
                     jComboBoxActionSpriteDirection.setSelectedIndex(0);
             }
        }
        mClassSetting--;
        
        
        String direction = jComboBoxActionSpriteDirection.getSelectedItem().toString();
        mCurrentSprite.setActiveActionDirection(action, direction);
        fillExample();
    }//GEN-LAST:event_jComboBoxActionSpritePerformed

    private void jComboBoxActionSpriteDirectionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxActionSpriteDirectionPerformed
        if (mClassSetting>0) return;
        String action = jComboBoxAction.getSelectedItem().toString();
        String direction = jComboBoxActionSpriteDirection.getSelectedItem().toString();
        mCurrentSprite.setActiveActionDirection(action, direction);
        fillExample();
    }//GEN-LAST:event_jComboBoxActionSpriteDirectionPerformed

    private void jComboBoxKlasseSpriteCoordinatorPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxKlasseSpriteCoordinatorPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxKlasseSpriteCoordinatorPerformed

    private void jTabbedPane2StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jTabbedPane2StateChanged
        
        JTabbedPane sourceTabbedPane = (JTabbedPane) evt.getSource();
        int index = sourceTabbedPane.getSelectedIndex();
        System.out.println("Tab changed to: " + sourceTabbedPane.getTitleAt(index));        
        if (sourceTabbedPane.getTitleAt(index).indexOf("Sprite") != -1)
            inSpriteTab = true;
        else
            inSpriteTab = false;
        mapPanel.setSpriteEditMode(inSpriteTab);
    }//GEN-LAST:event_jTabbedPane2StateChanged

    private void jButtonSpriteChangesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSpriteChangesActionPerformed
        int spriteSel = mapPanel.getSelectedSpriteNo();
        int layerSel = mapPanel.getSelectedSpriteLayerNo();
        if (spriteSel == -1) return;
        if (layerSel == -1) return;
        
        Layer layer = currentMap.getLayer(layerSel);
        String pool = jTextFieldSpriteFile.getText();
        String name = mCurrentSprite.data.getName();
        String action = jComboBoxAction.getSelectedItem().toString();
        String direction = jComboBoxActionSpriteDirection.getSelectedItem().toString();
        String coordinator = jComboBoxCoordinator.getSelectedItem().toString();
        int x = csa.util.UtilityString.Int0(jTextFieldSpriteX.getText());
        int y = csa.util.UtilityString.Int0(jTextFieldSpriteY.getText());
        
        
        layer.setSpriteData(spriteSel, action, direction, x,y,coordinator, pool, name);
        mapPanel.reinitSprite(layerSel, spriteSel);
        

                
        mapPanel.selectSprite(-1, -1);
        mapPanel.setMapChanged(true,false);

        JPanel panel = currentSelectedSpriteImagePanel;
        currentSelectedSpriteImagePanel = null;
        selectSprite(panel);
        
    }//GEN-LAST:event_jButtonSpriteChangesActionPerformed

    private void jButtonAddFogOfWarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddFogOfWarActionPerformed
        // test if transitions are possible!
        TileData fogTile=mCurrentTile;
        
        if (fogTile == null)
        {
            ShowInfoDialog.showInfoDialog("No Fog-Tile selected!");
            return;
        }
        if (!fogTile.getIsTransitionSource())
        {
            ShowInfoDialog.showInfoDialog("Tile does not support transitions!");
            return;
        }
        mClassSetting++;
        clearAllLayerData();

        jButton5ActionPerformed(null);                                         
        mapPanel.setOffsetX(0, true);
        mapPanel.setOffsetY(0, true);
        jLabelOffset.setText(""+mapPanel.getOffsetX(jCheckBox4.isSelected())+"/"+mapPanel.getOffsetY(jCheckBox4.isSelected()));
        
        
        Layer newLayer = currentMap.buildFogLayer(fogTile);
        if (newLayer == null) return;
        

        
        
        
        

        //jTextFieldDeptch.setText(""+currentMap.getCurrentLayerNo());
        jTextFieldLayerName.setText(newLayer.getData().getName());
        setSelectedLayer(""+currentMap.getCurrentLayerNo(), currentMap.getCurrentLayerNo());

        initLayerTable();
        updateLayerSize();
        mClassSetting--;
        
    }//GEN-LAST:event_jButtonAddFogOfWarActionPerformed

    private void jCheckBoxReplaceTileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxReplaceTileActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jCheckBoxReplaceTileActionPerformed

    public void growTilesDone(GrowTilesPanel c, Layer newLayer)
    {
        if (!c.successfull()) return;
        layerBuildDone(newLayer);

        Layer nLayer = new Layer();
        String name ="Grow layer_"+growLayer;
        growLayer++;
        nLayer.getData().mLayerName = name;
        nLayer.getData().mName = name;
        c.setLayer(nLayer);
    }

    public void growTilesExit(GrowTilesPanel c)
    {
        ((CSAMainFrame)Global.mMainWindow).closeMyWindow(c);
    }
    
    public void buildAlgorythmLayerDone(BuildLayerFromAlgorythmPanel c, Layer newLayer)
    {
        // todo ((CSAMainFrame)Global.mMainWindow).closeMyWindow(c);
        if (!c.successfull()) return;
        layerBuildDone(newLayer);
    }
    public void buildImageLayerDone(BuildLayerFromImagePanel c, Layer newLayer)
    {
        ((CSAMainFrame)Global.mMainWindow).closeMyWindow(c);
        if (!c.successfull()) return;
        layerBuildDone(newLayer);
    }
    void layerBuildDone(Layer newLayer)
    {
        currentMap.addLayer(newLayer, currentMap.getCurrentLayerNo()+1);
        newLayer.getData().misLayerOrdered = true;
        for (int i=0;i<currentMap.getData().mLayerData.size(); i++)
        {
            if (currentMap.getData().mLayerData.elementAt(i).equals(newLayer.getData().mLayerName))
            {
                newLayer.getData().mLayerName = newLayer.getData().mLayerName +"_"+i;
                newLayer.getData().mName = newLayer.getData().mLayerName +"_"+i;
                i=-1;
            }

        }

        currentMap.getData().mLayerData.add(currentMap.getCurrentLayerNo()+1,newLayer.getData().mLayerName);
        mapPanel.visibilityChanged();
        //currentMap.getData().mLayerData.remove(currentMap.getCurrentLayerNo()+2);
        jTableLayer.tableChanged(null);
    }

    void backgroundChanged()
    {
        LayerData data = currentMap.getCurrentLayer().getData();
        data.misBackground = jCheckBoxLayerIsBackground.isSelected();

        int r = csa.util.UtilityString.Int0(jTextFieldColorR.getText())*256*256;
        int g = csa.util.UtilityString.Int0(jTextFieldColorG.getText())*256;
        int b = csa.util.UtilityString.Int0(jTextFieldColorB.getText());
        int rgb = r+g+b;
        data.mbackgroundColor = rgb;
        mapPanel.visibilityChanged();


    }

    void setMouseTile(TileData tileData, ImageComponent work)
    {

        if (tileData == null)
        {
            work.setSequence(null);
            return;
        }
        work.setVisible(false);

        ImageSequenceDataPool mImageSequenceDataPool;

        String name = "Graphics"+File.separator+tileData.getImageDataFile()+".xml";
        mImageSequenceDataPool = new ImageSequenceDataPool(name);

        ImageSequenceData mData = mImageSequenceDataPool.get(tileData.getImageDataName());

        Vector<Image> images = new Vector<Image>();

        Vector <BaseImageData> mBData = BaseImageData.toBase(mData);
        for (int i = 0; i < mBData.size(); i++)
        {
            BaseImageData baseImageData = mBData.elementAt(i);
            images.addElement(baseImageData.image);
        }

        //work.setImages(images);
        work.setSequence(new ImageSequence(mData));
        work.setScaled(true, 22,22);
        work.setDelay(mData.getDelay());
        work.setVisible(true);
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private csa.tiletools.graphics.ImageComponent imageComponentLeft;
    private csa.tiletools.graphics.ImageComponent imageComponentMiddle;
    private csa.tiletools.graphics.ImageComponent imageComponentRight;
    private csa.tiletools.graphics.ImageComponent imageComponentSLeft;
    private csa.tiletools.graphics.ImageComponent imageComponentSMiddle;
    private csa.tiletools.graphics.ImageComponent imageComponentSRight;
    private csa.tiletools.graphics.ImageComponent imageComponentUnderCursor;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JButton jButtonAddFogOfWar;
    private javax.swing.JButton jButtonExport;
    private javax.swing.JButton jButtonFileSelect1;
    private javax.swing.JButton jButtonFileSelect2;
    private javax.swing.JButton jButtonGridNew;
    private javax.swing.JButton jButtonGridSave;
    private javax.swing.JButton jButtonGrowTiles;
    private javax.swing.JButton jButtonInsertTransitionTiles;
    private javax.swing.JButton jButtonLayerDelete;
    private javax.swing.JButton jButtonLayerDown;
    private javax.swing.JButton jButtonLayerFromImage1;
    private javax.swing.JButton jButtonLayerFromImage2;
    private javax.swing.JButton jButtonLayerNew;
    private javax.swing.JButton jButtonLayerSave;
    private javax.swing.JButton jButtonLayerUp;
    private javax.swing.JButton jButtonMapDelete;
    private javax.swing.JButton jButtonMapDelete1;
    private javax.swing.JButton jButtonMapNew;
    private javax.swing.JButton jButtonMapSave;
    private javax.swing.JButton jButtonMapSave1;
    private javax.swing.JButton jButtonMapSaveAsNew;
    private javax.swing.JButton jButtonOffsetDown;
    private javax.swing.JButton jButtonOffsetLeft;
    private javax.swing.JButton jButtonOffsetRight;
    private javax.swing.JButton jButtonOffsetUp;
    private javax.swing.JButton jButtonSaveAsNew;
    private javax.swing.JButton jButtonScaleToFit;
    private javax.swing.JButton jButtonSpriteChanges;
    private javax.swing.JButton jButtonSpriteFileSelect;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox4;
    private javax.swing.JCheckBox jCheckBox5;
    private javax.swing.JCheckBox jCheckBoxConsidderWrapping;
    private javax.swing.JCheckBox jCheckBoxGridEnable;
    private javax.swing.JCheckBox jCheckBoxISOAssumed;
    private javax.swing.JCheckBox jCheckBoxLayerAllowTileOverlap;
    private javax.swing.JCheckBox jCheckBoxLayerBinary;
    private javax.swing.JCheckBox jCheckBoxLayerIsBackground;
    private javax.swing.JCheckBox jCheckBoxLayerOnlyOnePosition;
    private javax.swing.JCheckBox jCheckBoxLayerWrapHorizontal;
    private javax.swing.JCheckBox jCheckBoxLayerWrapVertical;
    private javax.swing.JCheckBox jCheckBoxReplaceTile;
    private javax.swing.JCheckBox jCheckBoxSHowHotsspot;
    private javax.swing.JCheckBox jCheckBoxSnapToGrid;
    private javax.swing.JCheckBox jCheckBoxTileScale;
    private javax.swing.JCheckBox jCheckBoxXAltertating;
    private javax.swing.JCheckBox jCheckBoxYAltertating;
    private javax.swing.JCheckBox jCheckBoxlightOnClick;
    private javax.swing.JComboBox jComboBoxAction;
    private javax.swing.JComboBox jComboBoxActionSpriteDirection;
    private javax.swing.JComboBox jComboBoxCoordinator;
    private javax.swing.JComboBox jComboBoxDrawType;
    private javax.swing.JComboBox jComboBoxGridNameCombo;
    private javax.swing.JComboBox jComboBoxMapName;
    private javax.swing.JComboBox jComboBoxSpriteKlasse;
    private javax.swing.JComboBox jComboBoxTileKlasse;
    private javax.swing.JComboBox jComboBoxTileKlasse1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel127;
    private javax.swing.JLabel jLabel128;
    private javax.swing.JLabel jLabel129;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    private javax.swing.JLabel jLabel42;
    private javax.swing.JLabel jLabel43;
    private javax.swing.JLabel jLabel44;
    private javax.swing.JLabel jLabel45;
    private javax.swing.JLabel jLabel46;
    private javax.swing.JLabel jLabel47;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelCoords;
    private javax.swing.JLabel jLabelOffset;
    private javax.swing.JLabel jLabelSize;
    private javax.swing.JLabel jLabelTileSize;
    private javax.swing.JLabel jLabelTileSize1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel16;
    private javax.swing.JPanel jPanel17;
    private javax.swing.JPanel jPanel18;
    private javax.swing.JPanel jPanel19;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JPanel jPanelExample;
    private javax.swing.JPanel jPanelIMageCollection1;
    private javax.swing.JPanel jPanelIMageCollection2;
    private javax.swing.JPanel jPanelSpriteImageCollection;
    private javax.swing.JPanel jPanelTileView;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSlider jSlider1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTabbedPane jTabbedPane2;
    private javax.swing.JTable jTableLayer;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField10;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    private javax.swing.JTextField jTextFieldColorB;
    private javax.swing.JTextField jTextFieldColorBGrid;
    private javax.swing.JTextField jTextFieldColorG;
    private javax.swing.JTextField jTextFieldColorGGrid;
    private javax.swing.JTextField jTextFieldColorR;
    private javax.swing.JTextField jTextFieldColorRGrid;
    private javax.swing.JTextField jTextFieldCompositeClass;
    private javax.swing.JTextField jTextFieldCompositeName;
    private javax.swing.JTextField jTextFieldGridEveryX;
    private javax.swing.JTextField jTextFieldGridEveryY;
    private javax.swing.JTextField jTextFieldGridName;
    private javax.swing.JTextField jTextFieldGridOffsetX1;
    private javax.swing.JTextField jTextFieldGridOffsetY1;
    private javax.swing.JTextField jTextFieldHeight;
    private javax.swing.JTextField jTextFieldLayerHeight;
    private javax.swing.JTextField jTextFieldLayerName;
    private javax.swing.JTextField jTextFieldLayerWidth;
    private javax.swing.JTextField jTextFieldMapName;
    private javax.swing.JTextField jTextFieldMapWidth;
    private javax.swing.JTextField jTextFieldRadius;
    private javax.swing.JTextField jTextFieldSpriteFile;
    private javax.swing.JTextField jTextFieldSpriteX;
    private javax.swing.JTextField jTextFieldSpriteY;
    private javax.swing.JTextField jTextFieldTileComplete;
    private javax.swing.JTextField jTextFieldTileCount;
    private javax.swing.JTextField jTextFieldTileCountMap;
    private javax.swing.JTextField jTextFieldTileFile;
    private javax.swing.JTextField jTextFieldTileFile1;
    private javax.swing.JTextField jTextFieldTileRegular;
    private javax.swing.JToggleButton jToggleButtonSetErase;
    private csa.tiletools.map.MapPanel mapPanel;
    // End of variables declaration//GEN-END:variables


    // returns true if tile can be set
    // checks gui checkbox
    // and check overlapping
    // input is unscaled!
    private boolean checkTileOverlap(TileData tile, int x, int y)
    {
        if (jCheckBoxLayerAllowTileOverlap.isSelected()) 
        {
            if (!jCheckBoxLayerOnlyOnePosition.isSelected()) 
                return true;
            else 
                return !mapPanel.hasTileOnPos(x, y);
        }
        if (jCheckBoxLayerOnlyOnePosition.isSelected()) 
            return !mapPanel.hasTileOnPos(x, y);
        
        return !mapPanel.isOverlaping(tile, x, y);
    }

    private boolean checkTileOverlap(CompositeTile tile, int x, int y)
    {
        if (jCheckBoxLayerAllowTileOverlap.isSelected()) 
        {
            if (!jCheckBoxLayerOnlyOnePosition.isSelected()) 
                return true;
            else 
                return !mapPanel.hasTileOnPos(x, y);
        }
        if (jCheckBoxLayerOnlyOnePosition.isSelected()) 
            return !mapPanel.hasTileOnPos(x, y);
        
        return !mapPanel.isOverlaping(tile, x, y);
    }

    // coordinates are given WITHOUT offset, UNSCALED, -> this means in map coordinates!
    private void addSprite(Sprite sprite)
    {
        currentMap.addSprite(sprite);
        
        mapPanel.selectSprite(selectionLayerNo, -1);
        mapPanel.setMapChanged(true, true);
        jButtonSpriteChanges.setEnabled(false);

    }

    // coordinates are given WITHOUT offset, UNSCALED, -> this means in map coordinates!
    private void addTile(TileData tile, int x, int y)
    {
        if (!checkTileOverlap(tile, x, y))
        {
            if (!jCheckBoxReplaceTile.isSelected())
                return;
        }
        currentMap.addTile(tile, x, y, true, mTileDataPool, jCheckBoxReplaceTile.isSelected());
        
        mapPanel.setMapChanged(true, true);
        updateLayerSize();
    }
    private void addTile(CompositeTile tile, int x, int y)
    {
        if (!checkTileOverlap(tile, x, y)) return;
        currentMap.addTile(tile, x, y, true);
        
        mapPanel.setMapChanged(true, true);
        updateLayerSize();
    }

    private void jPanelMouseTileClickedImage(java.awt.event.MouseEvent evt) {
        JComponent c = (JComponent) evt.getSource();
        c = (JComponent) c.getParent();
        JPanel newSelectedImagePanel = (JPanel) c;
//        if (newSelectedImagePanel == currentSelectedTileImagePanel) return;

        if (currentSelectedTileImagePanel != null)
        {
            currentSelectedTileImagePanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        }

        currentSelectedTileImagePanel = newSelectedImagePanel;

        currentSelectedTileImagePanel.setBorder(javax.swing.BorderFactory.createLineBorder(Color.ORANGE));
        String name  = currentSelectedTileImagePanel.getName();

        for (int t = 0; t < mCurrentDisplayedTileList.size(); t++)
        {
            TileData tileData = mCurrentDisplayedTileList.elementAt(t);
            if (tileData.mName.equals(name))
            {
                mCurrentTile = tileData;
                mCurrentCompositeTile = null;
                setCurrentTileInfo();
                break;
            }
        }

        //    TileData leftMouseTile = null;
        //    TileData rightMouseTile = null;
        //    TileData sleftMouseTile = null;
        //    TileData srightMouseTile = null;
        //    TileData middleMouseTile = null;
        //    TileData smiddleMouseTile = null;
        if (evt.getButton() ==  java.awt.event.MouseEvent.BUTTON1)
        {
            if (evt.isShiftDown())
            {
                sleftMouseTile = Tile.cloneTileData(mCurrentTile);
                if (sleftMouseTile == null) return;
                sleftMouseTile.setTileSetFileName(jTextFieldTileFile.getText());
                mapPanel.setMouseGrabTile(new Tile(leftMouseTile), new Tile(sleftMouseTile));

                // set to display
                setMouseTile(sleftMouseTile, imageComponentSLeft);

            }
            else
            {
                leftMouseTile = Tile.cloneTileData(mCurrentTile);
                if (leftMouseTile == null) return;
                leftMouseTile.setTileSetFileName(jTextFieldTileFile.getText());
                mapPanel.setMouseGrabTile(new Tile(leftMouseTile), new Tile(sleftMouseTile));
                // set to display
                setMouseTile(leftMouseTile, imageComponentLeft);
            }
        }

        if (evt.getButton() ==  java.awt.event.MouseEvent.BUTTON3)
        {
            if (evt.isShiftDown())
            {
                srightMouseTile = Tile.cloneTileData(mCurrentTile);
                if (srightMouseTile == null) return;
                srightMouseTile.setTileSetFileName(jTextFieldTileFile.getText());
                // set to display
                setMouseTile(srightMouseTile, imageComponentSRight);
            }
            else
            {
                rightMouseTile = Tile.cloneTileData(mCurrentTile);
                if (rightMouseTile == null) return;
                rightMouseTile.setTileSetFileName(jTextFieldTileFile.getText());
                // set to display
                setMouseTile(rightMouseTile, imageComponentRight);
            }


        }
        if (evt.getButton() ==  java.awt.event.MouseEvent.BUTTON2)
        {
            if (evt.isShiftDown())
            {
                smiddleMouseTile = Tile.cloneTileData(mCurrentTile);
                if (smiddleMouseTile == null) return;
                smiddleMouseTile.setTileSetFileName(jTextFieldTileFile.getText());
                // set to display
                setMouseTile(smiddleMouseTile, imageComponentSMiddle);
            }
            else
            {
                middleMouseTile = Tile.cloneTileData(mCurrentTile);
                if (middleMouseTile == null) return;
                middleMouseTile.setTileSetFileName(jTextFieldTileFile.getText());
                // set to display
                setMouseTile(middleMouseTile, imageComponentMiddle);
            }
        }
    }

    void setCurrentTileInfo()
    {
        jPanelTileView.removeAll();
        if (mCurrentTile == null) return;
        ImageSequenceData tileImageData = getImageSequenceDataForTile(mCurrentTile);

        ImageComponent oneTile = new ImageComponent();
        oneTile.setToolTipText(mCurrentTile.mName);
        oneTile.setSequence(new ImageSequence(tileImageData));

        if (mCurrentTile.getForceTileSize())
            oneTile.setBounds(2,2, mCurrentTile.getWidth(), mCurrentTile.getHeight());
        else
        {
            if ((tileImageData != null) && (tileImageData.getHeight().size()>0))
            {
                oneTile.setBounds(2,2, tileImageData.getWidth().elementAt(0), tileImageData.getHeight().elementAt(0));
            }
        }
        if (tileImageData != null)
        {
            oneTile.setDelay(tileImageData.getDelay());
            if (mCurrentTile.getForceTileSize())
                oneTile.setScaled(true, mCurrentTile.getHeight(), mCurrentTile.getWidth());
        }

        if (jCheckBoxTileScale.isSelected())
        {
            oneTile.setScaled(true, jPanelTileView.getHeight()-4, jPanelTileView.getWidth()-4);
        }

        if (oneTile.getWidth() > jPanelTileView.getWidth()-4)
            oneTile.setBounds(2,2, jPanelTileView.getWidth()-4, oneTile.getHeight());
        if (oneTile.getHeight() > jPanelTileView.getHeight()-4)
            oneTile.setBounds(2,2, oneTile.getWidth(), jPanelTileView.getHeight()-4);

        jPanelTileView.add(oneTile);
        oneTile.setVisible(true);
        jPanelTileView.repaint();
        jLabelTileSize.setText(""+mCurrentTile.getWidth()+"x"+mCurrentTile.getHeight());
    }

    private void initMapPanel()
    {
        mClassSetting++;
        mapPanel.setMap(currentMap);
        mClassSetting--;
    }
    void saveAllLayers()
    {
        // first save current layer display data

        if (currentMap.getCurrentLayer() == null) return;

        if (jTextFieldLayerName.getText().trim().length()==0) return;
        String name = jTextFieldLayerName.getText();
        currentMap.getCurrentLayer().getData().mClass = "ALL";
        currentMap.getCurrentLayer().getData().mName = name;
        currentMap.getCurrentLayer().getData().mLayerName = name;
        currentMap.getCurrentLayer().isInMap = true;

        int d = currentMap.getCurrentLayerNo();
        readLayerToCurrent();

        currentMap.reInitLayerPool();
        mLayerDataPool = currentMap.getLayerPool();


        for (int l=0; l < currentMap.getCurrentLayers().size();l++)
        {
            mLayerDataPool.put(currentMap.getCurrentLayers().get(l).getData());
        }
        mLayerDataPool.save(mMapData.mLayerSaveTyp);
        currentMap.updateMapLayerData();

        mClassSetting++;
        resetLayerConfigPool();
        setSelectedLayer(name, d);
        initLayerTable();
        mClassSetting--;
    }

    public void mousePressedOnTable(java.awt.event.MouseEvent evt)
    {
        if ( evt.getClickCount() == 2 )
        {
            JTable table = (JTable) evt.getSource();
            int mRow = table.convertRowIndexToModel(table.rowAtPoint(evt.getPoint()));
            if (mRow <0) return;

            int d = mRow;
            if (d>=0) setSelectedLayer("", d);

            // make sure the current selected layer is visible
            if (!currentMap.getCurrentLayers().get(d).getData().misVisible)
            {
                currentMap.getCurrentLayers().get(d).getData().misVisible = true;
                mapPanel.visibilityChanged();
            }
            jTableLayer.tableChanged(null);
            if (mTileListForm != null)
                mTileListForm.updateMap();
            updateLayerSize();
        }
    }
    
    public void updateLayerSize()
    {
        jTextFieldLayerWidth.setText(""+currentMap.getCurrentLayer().getLayerWidth());
        jTextFieldLayerHeight.setText(""+currentMap.getCurrentLayer().getLayerHeight());
        jTextFieldTileCount.setText(""+currentMap.getCurrentLayer().getTileCount());
        
        
        if (currentMap.getCurrentLayer().isRegular())
            jTextFieldTileRegular.setText("yes");
        else
            jTextFieldTileRegular.setText("no");
        if (currentMap.getCurrentLayer().isCompletlyOrdered())
            jTextFieldTileComplete.setText("yes");
        else
            jTextFieldTileComplete.setText("no");
        
        
        updateMapSize();
    }
    public void updateMapSize()
    {
        jTextFieldMapWidth.setText(""+currentMap.getMapWidth());
        jTextFieldHeight.setText(""+currentMap.getMapHeight());
        jTextFieldTileCountMap.setText(""+currentMap.getTileCount());
    }

    private void jPanelMouseCompositeTileClickedImage(java.awt.event.MouseEvent evt) {
        JComponent c = (JComponent) evt.getSource();
        c = (JComponent) c.getParent();
        JPanel newSelectedImagePanel = (JPanel) c;
//        if (newSelectedImagePanel == currentSelectedTileImagePanel) return;

        if (currentSelectedCompositeTileImagePanel != null)
        {
            currentSelectedCompositeTileImagePanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        }

        currentSelectedCompositeTileImagePanel = newSelectedImagePanel;

        currentSelectedCompositeTileImagePanel.setBorder(javax.swing.BorderFactory.createLineBorder(Color.ORANGE));
        String name  = currentSelectedCompositeTileImagePanel.getName();

        for (int t = 0; t < mCurrentDisplayedCompositeTileList.size(); t++)
        {
            CompositeTile ctile = mCurrentDisplayedCompositeTileList.elementAt(t);
            if (ctile.getData().mName.equals(name))
            {
                mCurrentCompositeTile = ctile;
                mCurrentTile = null;
                leftMouseTile = null;
                setCurrentCompositeTileInfo();
                break;
            }
        }

        //    TileData leftMouseTile = null;
        //    TileData rightMouseTile = null;
        //    TileData sleftMouseTile = null;
        //    TileData srightMouseTile = null;
        //    TileData middleMouseTile = null;
        //    TileData smiddleMouseTile = null;
        if (evt.getButton() ==  java.awt.event.MouseEvent.BUTTON1)
        {

            // leftMouseTile = Tile.cloneTileData(mCurrentTile);
            // if (leftMouseTile == null) return;
            // leftMouseTile.setTileSetFileName(jTextFieldTileFile.getText());
            mapPanel.setMouseGrabCompositeTile(mCurrentCompositeTile);
            // set to display
        }
    }
    
    JPanel currentSelectedCompositeTileImagePanel = null;
    void setAllActiveCompositeTiles(String selectName)
    {
        jPanelIMageCollection2.removeAll();
        currentSelectedCompositeTileImagePanel = null;

        int selected = 0;
        for (int t = 0; t < mCurrentDisplayedCompositeTileList.size(); t++)
        {
            CompositeTile ctile = mCurrentDisplayedCompositeTileList.elementAt(t);
            if (ctile.getData().mName.equals(selectName))
            {
                selected = t;
                break;
            }
        }
        int x = 5;
        int y = 5;
        for (int t = 0; t < mCurrentDisplayedCompositeTileList.size(); t++)
        {
            // first line
            CompositeTile ctile = mCurrentDisplayedCompositeTileList.elementAt(t);
            
            
            // jPanelIMageCollection1

            BufferedImage bimg = ctile.getImage(150,150);
            
            String name = ctile.getData().mName;
            //if (iSData == null)
            {
                JPanel ipanel = new JPanel();
                if (t==selected)
                {
                    currentSelectedCompositeTileImagePanel = ipanel;
                    ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(Color.ORANGE));
                    mCurrentCompositeTile = ctile;
                    mCurrentTile = ctile.getData();
                    mClassSetting++;
                    setCurrentCompositeTileInfo();
                    mClassSetting--;
                }
                else
                    ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

                ipanel.setName(""+name);
                ipanel.setPreferredSize(new java.awt.Dimension(152, 152));
                ipanel.setLayout(new BorderLayout());

                JLabel mip = new JLabel();

                ipanel.add(mip, BorderLayout.CENTER);
                mip.setIcon(new ImageIcon(bimg));

                mip.addMouseListener(new java.awt.event.MouseAdapter() {
                    @Override
                    public void mousePressed(java.awt.event.MouseEvent evt) {
                        jPanelMouseCompositeTileClickedImage(evt);
                    }
                });

                ipanel.setBounds(x, y, 152, 152);

                jPanelIMageCollection2.add(ipanel);

                mip.setVisible(true);
            }
            x += 152;
            x += 5;
        }
        x += 152;
        x += 5;

        jPanelIMageCollection2.setBounds(0,0,x,y);
        jPanelIMageCollection2.setPreferredSize(new Dimension(x,y));
        jPanelIMageCollection2.invalidate();
        jPanelIMageCollection2.validate();
        jPanelIMageCollection2.repaint();
        repaint();
    }
    
    void setCurrentCompositeTileInfo()
    {
        if (mCurrentCompositeTile == null)
        {
            jTextFieldCompositeClass.setText("");
            jTextFieldCompositeName.setText("");
            jLabelTileSize1.setText("");
        }
        else
        {
            jTextFieldCompositeClass.setText(mCurrentCompositeTile.getData().getCClass());
            jTextFieldCompositeName.setText(mCurrentCompositeTile.getData().getName());
            jLabelTileSize1.setText(""+mCurrentCompositeTile.getMaxWidthUnscaled()+"x"+mCurrentCompositeTile.getMaxHeightUnscaled());
        }
    }

    
    
    // Config Pool for TileMap
    boolean inConfig = false;
    Vector <SpriteData> mAllSpritesInClass = new Vector <SpriteData>();
    Sprite mCurrentSprite=null;
    private SpriteDataPool mSpriteDataPool = null;
    boolean inSpriteTab = false;
    JPanel currentSelectedSpriteImagePanel = null;

    
    public void loadSpriteCollection()
    {
        String _class = "";
        if (jComboBoxSpriteKlasse.getSelectedIndex() != -1 ) 
            _class = jComboBoxSpriteKlasse.getSelectedItem().toString().trim();
        
        
        String file = jTextFieldSpriteFile.getText().trim();
        if (file.length() == 0) return;

        mSpriteDataPool = new SpriteDataPool("Sprite"+File.separator+file+".xml");
        if (mSpriteDataPool == null) return;

        resetSpriteConfigPool(true, _class, "");
    }    
    String getSpriteClass()
    {
        if (jComboBoxSpriteKlasse.getSelectedIndex() == -1 ) return "";
        String _class = jComboBoxSpriteKlasse.getSelectedItem().toString().trim();
        return _class;
    }
    
    private void resetSpriteConfigPool(boolean select, String klasseToSet, String spriteToSet) /* allneeded*/
    {
        if (inConfig) return;
        inConfig = true;
        mClassSetting++;

        jComboBoxSpriteKlasse.removeAllItems();
        mClassSetting--;

        if (mSpriteDataPool == null)
        {
            inConfig = false;
            return;
        }

        mClassSetting++;
        Collection<String> collectionKlasse = mSpriteDataPool.getKlassenHashMap().values();
        Iterator<String> iterKlasse = collectionKlasse.iterator();
        int i = 0;
        String klasse = "";

        while (iterKlasse.hasNext())
        {
            String item = iterKlasse.next();
            jComboBoxSpriteKlasse.addItem(item);
            if (select)
            {
                if (klasseToSet.length()==0)
                {
                    if (i==0)
                    {
                        // allow event to happen
                        mClassSetting--;
                        jComboBoxSpriteKlasse.setSelectedIndex(i);
                        mClassSetting++;
                        klasse = item;
                    }
                }
                else
                {
                    if (klasseToSet.equalsIgnoreCase(item))
                    {
                        // allow event to happen
                        mClassSetting--;
                        jComboBoxSpriteKlasse.setSelectedIndex(i);
                        mClassSetting++;
                        klasse = item;
                    }
                }
            }
            i++;
        }
        mClassSetting--;
        if ((select) && (klasse.length()==0))
        {
            if (jComboBoxSpriteKlasse.getItemCount()>0)
            {
                jComboBoxSpriteKlasse.setSelectedIndex(0);
                klasse = jComboBoxSpriteKlasse.getSelectedItem().toString();
            }
        }
        if (!select)  jComboBoxSpriteKlasse.setSelectedIndex(-1);

        resetSpriteList(spriteToSet);
        inConfig = false;
    }    
    SpriteDataPool getSpritePool()
    {
        return mSpriteDataPool;
    }
    void resetSpriteList(String selectName)
    {
        mAllSpritesInClass = new Vector <SpriteData>();

        String _class = getSpriteClass();
        SpriteDataPool pool = getSpritePool();

        if (pool == null) return;

        Collection<SpriteData> colDk = pool.getMapForKlasse(_class).values();
        Iterator<SpriteData> iterDk = colDk.iterator();
        /** Sorting */  Vector<String> names = new Vector<String>();
        while (iterDk.hasNext())
        {
            SpriteData deck = iterDk.next();
            mAllSpritesInClass.addElement(deck);
            names.addElement(deck.mName);

        }
        Collections.sort(names, new Comparator<String>() {@Override
                public int compare(String s1, String s2) { return s1.compareTo(s2); } });
        Collections.sort(mAllSpritesInClass, new Comparator<SpriteData>() {@Override
            public int compare(SpriteData s1, SpriteData s2) { return s1.mName.compareTo(s2.mName); } });
        setAllSprites(selectName);
    }    

    ImageSequenceData getImageSequenceDataForSprite(SpriteData spriteData)
    {
        Vector<String> poolNames = spriteData.getImageSetName();
        if (poolNames.size()==0) return null; // keine image daten in dem sprite vorhanden!
        
        String imagePoolFilename = poolNames.elementAt(0); // erstes element liefert die Anzeige daten!
        if (imagePoolFilename.trim().length()==0) return null;

        String imageFilename = "Graphics"+File.separator+imagePoolFilename+".xml";
        ImageSequenceDataPool imagePool = new ImageSequenceDataPool(imageFilename);
        if (imagePool == null) return null;
        
        Vector<String> actionNames = spriteData.getActionDirectionImageName(); // get the first available action
        if (actionNames.size()==0) return null; // keine image daten in dem sprite vorhanden!
        
        String nameToSet = Sprite.getImageFromImageActionDirection(actionNames.elementAt(0));
        return imagePool.get(nameToSet);
    }    
    void setCurrentSpriteInfo()
    {
         if (mCurrentSprite == null) return;

         mClassSetting++;
         if (mCurrentSprite.getActions().size()>0)
         {
            jComboBoxAction.setModel(new DefaultComboBoxModel(mCurrentSprite.getActions()));
         }
         if (mCurrentSprite.getDirections(mCurrentSprite.getActions().elementAt(0)).size()>0)
         {
             int oldIndex = jComboBoxActionSpriteDirection.getSelectedIndex();
             jComboBoxActionSpriteDirection.setModel(new DefaultComboBoxModel(mCurrentSprite.getDirections(mCurrentSprite.getActions().elementAt(0))));
             if (mCurrentSprite.getDirections(mCurrentSprite.getActions().elementAt(0)).size()>oldIndex)
             {
                jComboBoxActionSpriteDirection.setSelectedIndex(oldIndex);
             }
             else
             {
                jComboBoxActionSpriteDirection.setSelectedIndex(0);
             }
         }
         jComboBoxAction.setSelectedIndex(0);
         mClassSetting--;
    }
    
    void setAllSprites(String selectName)
    {
        jPanelSpriteImageCollection.removeAll();
        currentSelectedSpriteImagePanel = null;

        int selected = 0;
        for (int t = 0; t < mAllSpritesInClass.size(); t++)
        {
            SpriteData spriteData = mAllSpritesInClass.elementAt(t);
            if ((t == 0) && (selectName.length()==0))
            {
                selectName = spriteData.mName;
            }
            else if (spriteData.mName.equals(selectName))
            {
                selected = t;
                break;
            }
        }
        int x = 5;
        int y = 5;
    
        for (int t = 0; t < mAllSpritesInClass.size(); t++)
        {
            SpriteData spriteData = mAllSpritesInClass.elementAt(t);
            ImageSequenceData iSData = getImageSequenceDataForSprite(spriteData);
            String name = spriteData.mName;

            JPanel ipanel = new JPanel();


            ipanel.setName(""+name);
            ipanel.setPreferredSize(new java.awt.Dimension(52, 52));
            ipanel.setLayout(new BorderLayout());

            ImageComponent mip = new ImageComponent();
            ipanel.add(mip, BorderLayout.CENTER);

            mip.addMouseListener(new java.awt.event.MouseAdapter() {
                @Override
                public void mousePressed(java.awt.event.MouseEvent evt) {
                }
                public void mouseReleased(java.awt.event.MouseEvent evt) {
                        jPanelMouseSpriteClickedImageVertical(evt);
                }
            });
            

            if (iSData != null)
            {
                Vector <BaseImageData> data = BaseImageData.toBase(iSData);
                if (data.size()>0)
                {
                    Vector<Image> images = new Vector<Image>();
                    for (int i = 0; i < data.size(); i++)
                    {
                        BaseImageData baseImageData = data.elementAt(i);
                        images.addElement(baseImageData.image);
                    }
                    mip.setSequence(new ImageSequence(iSData));
                    mip.setDelay(iSData.getDelay());
                }
            }
            ipanel.setBounds(x, y, 52, 52);
            jPanelSpriteImageCollection.add(ipanel);

            if (t==selected)
            {
                //currentSelectedSpriteImagePanel = ipanel;
                //ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(Color.ORANGE));
                mCurrentSprite = Sprite.buildSprite(spriteData);
                
                mClassSetting++;
                setCurrentSpriteInfo();
                mClassSetting--;
                
                currentSelectedSpriteImagePanel = null; // reset display in any Case!
                selectSprite(ipanel);
                if (!mapPanel.isSpriteSelected())
                    jButtonSpriteChanges.setEnabled(false);
            }
            else
                ipanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
            
            x += 52;
            x += 5;
            mip.setScaled(true, 52, 52);
            mip.setVisible(true);
        }

        jPanelSpriteImageCollection.setBounds(0,0,x,62);
        jPanelSpriteImageCollection.setPreferredSize(new Dimension(x,62));
        jPanelSpriteImageCollection.invalidate();
        jPanelSpriteImageCollection.validate();
        jPanelSpriteImageCollection.repaint();


        repaint();
    }
    private void selectSprite(JPanel newSelectedImagePanel)
    {
        if (newSelectedImagePanel == currentSelectedSpriteImagePanel) return;

        if (currentSelectedSpriteImagePanel != null)
        {
            currentSelectedSpriteImagePanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        }

        currentSelectedSpriteImagePanel = newSelectedImagePanel;

        currentSelectedSpriteImagePanel.setBorder(javax.swing.BorderFactory.createLineBorder(Color.ORANGE));
        String name  = currentSelectedSpriteImagePanel.getName();

        for (int t = 0; t < mAllSpritesInClass.size(); t++)
        {
            SpriteData spriteData = mAllSpritesInClass.elementAt(t);
            if (spriteData.mName.equals(name))
            {
                mCurrentSprite = Sprite.buildSprite(spriteData);
                setCurrentSpriteInfo();

                String action = jComboBoxAction.getSelectedItem().toString();
                String direction = jComboBoxActionSpriteDirection.getSelectedItem().toString();
                mCurrentSprite.setActiveActionDirection(action, direction);
                if (!mapPanel.isSpriteSelected())
                    mapPanel.setMouseGrabSprite(mCurrentSprite);
                break;
            }
        }
        if (!mapPanel.isSpriteSelected())
            jButtonSpriteChanges.setEnabled(false);
    
    }
    private void jPanelMouseSpriteClickedImageVertical(java.awt.event.MouseEvent evt) {
        JComponent c = (JComponent) evt.getSource();
        c = (JComponent) c.getParent();
        JPanel newSelectedImagePanel = (JPanel) c;
        
        selectSprite( newSelectedImagePanel);
        
    }    
    private void fillExample()
    {
        if (mCurrentSprite == null) return;
        
        String action = mCurrentSprite.getActiveAction();
        String direction = mCurrentSprite.getActiveDirection();
        
        while (jPanelExample.getComponentCount()>0)
        {
            Component c = jPanelExample.getComponent(0);
            if (c instanceof ImageComponent)
            {
                ImageComponent ic = (ImageComponent) c;
                ic.setVisible(false);
                ic.deinit();
            }
            jPanelExample.remove(0);
        }
        
        ImageComponent mip = new ImageComponent();
        jPanelExample.add(mip, BorderLayout.CENTER);

        ImageSequenceData iSData = mCurrentSprite.getImageSequenceData(action, direction);
            
        if (iSData != null)
        {
            Vector <BaseImageData> data = BaseImageData.toBase(iSData);
            if (data.size()>0)
            {
                Vector<Image> images = new Vector<Image>();
                for (int i = 0; i < data.size(); i++)
                {
                    BaseImageData baseImageData = data.elementAt(i);
                    images.addElement(baseImageData.image);
                }
                mip.setSequence(new ImageSequence(iSData));
                mip.setDelay(iSData.getDelay());
            }
        }
        mip.setScaled(true, 52, 52);
        mip.setVisible(true);        
    }
    
    
    
    
    
    
    
    
    
    
    
}
