/*
The Field has Changed.
Don't need to call inherited.
@param bDisplayOption If true, display the change.
@param iMoveMode The type of move being done (init/read/screen).
@return The error code (or NORMAL_RETURN if okay).
550449
public int fieldChanged(boolean bDisplayOption, int iMoveMode)
    {
    	if (iMoveMode != DBConstants.SCREEN_MOVE)	// This is necessary if an override change the repondsTo.
    	    // Also, if just refreshing the record, don't change this if set
    	    if ((m_bChangeDataOnRefresh) || ((this.getOwner().getRecord().getOpenMode() & DBConstants.OPEN_DONT_CHANGE_CURRENT_LOCK_TYPE) != DBConstants.OPEN_DONT_CHANGE_CURRENT_LOCK_TYPE))
    	        if ((this.getOwner().getRecord().getOpenMode() & DBConstants.OPEN_DONT_UPDATE_LAST_READ) != DBConstants.OPEN_DONT_UPDATE_LAST_READ)    // This is a special case where I want a subsequent write to get an error if changed 
    	            this.setOriginalData(this.getOwner().getData());
    	return super.fieldChanged(bDisplayOption, iMoveMode);
    }
400234
public static Display getDisplay(int mode) {
        if (mode == 0)
            return Display.Required;
        else if (mode == 1)
            return Display.Optional;
        else if (mode == 2)
            return Display.ReadOnly;
        else if (mode == 3)
            return Display.Hidden;
        else
            return null;
    }
265172
public void printDisplayControl(PrintWriter out)
    {
        Convert converter = this.getScreenField().getConverter();
        if (m_vDisplays == null)
        {
            String strField = null;
            if (converter != null) if (converter.getField() != null)
                strField = converter.getField().getString();
            this.scanTableItems();
            if (converter != null) if (converter.getField() != null)
                converter.getField().setString(strField);
        }
        String string = DBConstants.BLANK;
        int iIndex = 0;
        if (converter != null)
        {   // This is required for the display or popup fields because displayField() is never called to get the value.
            iIndex = converter.convertFieldToIndex();
            if (iIndex == -1)
            {
                super.printDisplayControl(out);
                return;
            }
            try {
                string = (String)m_vDisplays.get(iIndex);
            } catch (ArrayIndexOutOfBoundsException ex) {
                string = "&nbsp;";
            }
        }
        out.println("<td>" + string + "</td>");
    }
839906
public int setState(boolean state, boolean bDisplayOption, int iMoveMode)
    {       // Must be overidden
        m_bSetData = true;  // Make sure getNextConverter is called correctly (if it is called).
        int iErrorCode = super.setState(state, bDisplayOption, iMoveMode);
        m_bSetData = false;
        return iErrorCode;
    }
966733
public int setSFieldValue(String strParamValue, boolean bDisplayOption, int iMoveMode)
    {
        String strButtonDesc = this.getButtonDesc();
        String strButtonCommand = this.getButtonCommand();
        if (strButtonCommand != null)
            if (strButtonDesc != null)
                if (strButtonDesc.equals(strParamValue))
        {   // Button was pressed, do command
            this.handleCommand(strButtonCommand, this, ScreenConstants.USE_NEW_WINDOW);
            return DBConstants.NORMAL_RETURN;
        }
        // Often this is called in a report needing a value set, so set it:
        return super.setSFieldValue(strParamValue, bDisplayOption, iMoveMode);
    }
1182455
public int fieldChanged(boolean bDisplayOption, int iMoveMode)
    {
        int iErrorCode = this.moveIt(bDisplayOption, iMoveMode);
        if (iErrorCode != DBConstants.NORMAL_RETURN)
            if (this.getOwner() != m_fldSource)
                if (this.getOwner() != m_fldDest)
                    iErrorCode = DBConstants.NORMAL_RETURN; // If the source and dest are unrelated this this, don't return an error (and revert this field)
        if (iErrorCode == DBConstants.NORMAL_RETURN)
            iErrorCode = super.fieldChanged(bDisplayOption, iMoveMode);
        return iErrorCode;
    }
480254
public String getSFieldValue(boolean bDisplayFormat, boolean bRawData)
    {
        Convert converter = this.getConverter();
        if (converter == null)
            return Constant.BLANK;
        if (bRawData)
        {
            converter = converter.getField();
            if (converter == null)
                return Constant.BLANK;
        }
        return converter.getString();
    }
399406
public int setTime(java.util.Date time, boolean bDisplayOption, int iMoveMode)
    {
        java.util.Date m_DateTime = (java.util.Date)m_data;
        int iYear = DBConstants.FIRST_YEAR;
        int iMonth = DBConstants.FIRST_DAY;
        int iDate = DBConstants.FIRST_MONTH;
        if (m_DateTime != null) //|| (m_CurrentLength == 0))
        {
            m_calendar.setTime(m_DateTime);
            iYear = m_calendar.get(Calendar.YEAR);
            iMonth = m_calendar.get(Calendar.MONTH);
            iDate = m_calendar.get(Calendar.DATE);
        }
        m_calendar.setTime(time);
        int iHour = m_calendar.get(Calendar.HOUR_OF_DAY);
        int iMinute = m_calendar.get(Calendar.MINUTE);
        int iSecond = m_calendar.get(Calendar.SECOND);
        m_calendar.set(iYear, iMonth, iDate, iHour, iMinute, iSecond);
        java.util.Date dateNew = m_calendar.getTime();
        return this.setDateTime(dateNew, bDisplayOption, iMoveMode);
    }
87949
public int setSFieldValue(String strParamValue, boolean bDisplayOption, int iMoveMode)
    {
        char chFirst = 'N';
        if (strParamValue != null) if (strParamValue.length() > 0)
            chFirst = strParamValue.charAt(0);
        boolean bState = false;
        if ((chFirst == 'T') || (chFirst == 'Y')) // True/Yes
            bState = true;
        return this.getConverter().setState(bState, bDisplayOption, iMoveMode);
    }
632185
public void doValidRecord(boolean bDisplayOption) // init this field override for other value
    {
        Object bookmark = null;
        try   {
            bookmark = this.getOwner().getHandle(DBConstants.BOOKMARK_HANDLE);
        } catch (DBException ex)    {
            ex.printStackTrace();
        }
        this.updateListener(bookmark);
        super.doValidRecord(bDisplayOption);
    }
365187
public void setDisplayMode(int width, int height, boolean fullscreen) throws SlickException {
		if ((this.width == width) && (this.height == height) && (isFullscreen() == fullscreen)) {
			return;
		}
		
		try {
			targetDisplayMode = null;
			if (fullscreen) {
				DisplayMode[] modes = Display.getAvailableDisplayModes();
				int freq = 0;
				
				for (int i=0;i<modes.length;i++) {
					DisplayMode current = modes[i];
					
					if ((current.getWidth() == width) && (current.getHeight() == height)) {
						if ((targetDisplayMode == null) || (current.getFrequency() >= freq)) {
							if ((targetDisplayMode == null) || (current.getBitsPerPixel() > targetDisplayMode.getBitsPerPixel())) {
								targetDisplayMode = current;
								freq = targetDisplayMode.getFrequency();
							}
						}

						// if we've found a match for bpp and frequence against the 
						// original display mode then it's probably best to go for this one
						// since it's most likely compatible with the monitor
						if ((current.getBitsPerPixel() == originalDisplayMode.getBitsPerPixel()) &&
						    (current.getFrequency() == originalDisplayMode.getFrequency())) {
							targetDisplayMode = current;
							break;
						}
					}
				}
			} else {
				targetDisplayMode = new DisplayMode(width,height);
			}
			
			if (targetDisplayMode == null) {
				throw new SlickException("Failed to find value mode: "+width+"x"+height+" fs="+fullscreen);
			}
			
			this.width = width;
			this.height = height;

			Display.setDisplayMode(targetDisplayMode);
			Display.setFullscreen(fullscreen);

			if (Display.isCreated()) {
				initGL();
				enterOrtho();
			} 
			
			if (targetDisplayMode.getBitsPerPixel() == 16) {
				InternalTextureLoader.get().set16BitMode();
			}
		} catch (LWJGLException e) {
			throw new SlickException("Unable to setup mode "+width+"x"+height+" fullscreen="+fullscreen, e);
		}
		
		getDelta();
	}
141938
public int setValue(double value, boolean bDisplayOption, int moveMode)
    {           // Set this field's value
        Integer tempLong = new Integer((int)value);
        int iErrorCode = this.setData(tempLong, bDisplayOption, moveMode);
        return iErrorCode;
    }
262654
public int convertIndexToField(int index, boolean bDisplayOption, int iMoveMode)
    {
        String tempString = this.convertIndexToString(index);
        return this.setString(tempString, bDisplayOption, iMoveMode); // Move value to this field
    }
1180883
public int moveSourceToDest(boolean bDisplayOption, int iMoveMode)
    {
        String string = this.getSourceField().getString();        // Get this string
        int i = string.lastIndexOf(' ');
        if (i != -1)
            string = string.substring(i+1);
        return m_fldDest.setData(string, bDisplayOption, iMoveMode);
    }
858669
public void doNewRecord(boolean bDisplayOption)
    {
        super.doNewRecord(bDisplayOption);
        if (this.getOwner().isOpen())   // Don't do first time!
        {
            String strUserID = ((BaseApplication)this.getOwner().getRecordOwner().getTask().getApplication()).getUserID();
            int iUserID = -1;
            if ((strUserID != null) && (strUserID.length() > 0))
                iUserID = Integer.parseInt(strUserID);
            this.getOwner().getField(UserInfo.ID).setValue(iUserID);
            String strOldKey = this.getOwner().getKeyName();
            try   {
                this.getOwner().setKeyArea(UserInfo.ID_KEY);
                if (!this.getOwner().seek("="))
                {
                    this.getOwner().addNew(); // Make a new one
                }
            } catch (DBException ex)    {
                ex.printStackTrace();
            } finally   {
                this.getOwner().setKeyArea(strOldKey);
            }
        }
    }
714508
public int moveFieldToThis(BaseField field, boolean bDisplayOption, int iMoveMode)
    {   // Save the record and datarecord.
        if (field == null)
            return DBConstants.NORMAL_RETURN;
        if (field instanceof CounterField)
        {
            if (this.getReferenceRecord(null, false) == null)
                if (field.getRecord().getListener(ClearFieldReferenceOnCloseHandler.class) == null) // While it is okay to have two fields reference on record, don't default it.
                    this.setReferenceRecord(field.getRecord());
        }
        else if (field instanceof ReferenceField)
        {
//x no           this.setReferenceRecord(((ReferenceField)field).getReferenceRecord());
        }
        else
            this.setReferenceRecord(null);
        return super.moveFieldToThis(field, bDisplayOption, iMoveMode);
    }
208412
private boolean shouldDisplayTooltipAbove() {

        boolean displayAbove;
        if (isSimpleValue()) {
            Direction direction = Direction.none;
            if (m_widget instanceof I_CmsHasDisplayDirection) {
                direction = ((I_CmsHasDisplayDirection)m_widget).getDisplayingDirection();
            }
            switch (direction) {
                case above:
                    displayAbove = true;
                    break;
                case below:
                case none:
                default:
                    displayAbove = true;
                    break;
            }
        } else {
            displayAbove = true;
        }

        m_helpBubble.getStyle().setDisplay(Display.BLOCK);
        int bubbleHeight = m_helpBubble.getOffsetHeight();
        m_helpBubble.getStyle().clearDisplay();

        Element widgetElement = m_widget.asWidget().getElement();
        // Calculate top position for the popup
        int top = widgetElement.getAbsoluteTop();

        int windowTop = Window.getScrollTop();
        int windowBottom = Window.getScrollTop() + Window.getClientHeight();
        CmsDebugLog.consoleLog("window bottom: " + windowBottom + "    window height: " + Window.getClientHeight());

        int distanceFromWindowTop = top - windowTop - TOOLBAR_HEIGHT;

        int distanceToWindowBottom = windowBottom - (top + widgetElement.getOffsetHeight());
        if (displayAbove
            && ((distanceFromWindowTop < bubbleHeight) && (distanceToWindowBottom > distanceFromWindowTop))) {
            // in case there is too little space above, and there is more below, change direction
            displayAbove = false;
        } else if (!displayAbove
            && ((distanceToWindowBottom < bubbleHeight) && (distanceFromWindowTop > distanceToWindowBottom))) {
            // in case there is too little space below, and there is more above, change direction
            displayAbove = true;
        }
        return displayAbove;
    }