private void setupUI() {

        setBackground(Color.WHITE);

        updateScale();
        updateNameTableTiles(true);


        setMinimumSize(new Dimension(currentPixelArrayWidth * MIN_SCALE, currentPixelArrayHeight * MIN_SCALE));
        //       setPreferredSize(new Dimension(currentWidth, currentHeight));
        setMaximumSize(new Dimension(currentPixelArrayWidth * MAX_SCALE, currentPixelArrayHeight * MAX_SCALE));


        addMouseListener(new MouseInputAdapter() {

        	public void mousePressed(MouseEvent e) {
                if(e.getButton() == MouseEvent.BUTTON1){
                	firstMouseDragEvent = e;
                	resultsModel.resetBox();
                	resultsModel.assignPatternPage(0);                
                }
            }
        	
            public void mouseClicked(MouseEvent e) {
                processMouseActivity(e.getButton(), e.getX(), e.getY(), e.getModifiersEx());
            }
        });
        addMouseMotionListener(new MouseMotionAdapter() {

        	private void updateDragDisplay() {
        		
        	        if (resultsModel == null) {
        	            return;
        	        }
        	    
        	        if (!resultsModel.isBoxValid()) {
        	            return;
        	        }

        	        int minX = constraintsModel.getPositionFromGridXIndex(resultsModel.startX);
        	        int minY = constraintsModel.getPositionFromGridYIndex(resultsModel.startY);
        	        int maxX = constraintsModel.getPositionFromGridXIndex(resultsModel.endX);
        	        int maxY = constraintsModel.getPositionFromGridYIndex(resultsModel.endY);

        	        if (resultsModel.startX > resultsModel.endX) {
        	            int tmp = minX;
        	            minX = maxX;
        	            maxX = tmp;
        	        }
        	        if (resultsModel.startY > resultsModel.endY) {
        	            int tmp = minY;
        	            minY = maxY;
        	            maxY = tmp;
        	        }

        	        // This is UGLY but it works
            		Graphics g = getGraphics();
            		g.setColor(Color.lightGray);
            		g.drawRect(minX, minY, maxX-minX, maxY-minY);
        	}

        	 private void leftDrag(MouseEvent firstEvent, MouseEvent e, GridMouseResultsModel results) {
                 int relX = constraintsModel.getGridXIndexFromPosition(e.getX(), e.getY());
                 boolean changed = results.assignBoxX(relX);

                 int relY = constraintsModel.getGridYIndexFromPosition(e.getX(), e.getY());
                 changed = (changed || results.assignBoxY(relY));

                 if(changed) {
                	 updateDragDisplay();
                 }
                 
             }
        	 
            public void mouseDragged(MouseEvent e) {
                if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK) {
               		leftDrag(firstMouseDragEvent, e, resultsModel);
                } else if ((e.getModifiersEx() & MouseEvent.BUTTON3_DOWN_MASK) == MouseEvent.BUTTON3_DOWN_MASK) {
                    processMouseActivity(MouseEvent.BUTTON3, e.getX(), e.getY(), e.getModifiersEx());
                }
            }

            public void mouseMoved(MouseEvent e) {
                setToolTipText(determineTooltipAtLocation(e.getX(), e.getY()));
            }
        });

     }