Results 1 to 5 of 5
  1. #1
    Camzie is offline Member
    Join Date
    Nov 2009
    Location
    Pretoria
    Posts
    12
    Rep Power
    0

    Exclamation Creating and running Java .ini files

    Hi there

    Iam busy creating an .ini file for an application, but it is throwing a null pointer exception the whole time and can't seem to figure out what the problem is.

    Why would it throw such an error and what does it mean?

    Could you please help me?
    Will appreciate it...

    Here is the code for the .ini file InteractiveScreen.ini:

    ;@InteractiveScreen
    ;
    ;This interactive screen shows the general information on SmartVillage and Neotel.
    ;Smart Village
    ;
    ;Set page properties
    [PortalPage]
    OnShow=focus:buttonInformation
    Type=com.mca.portal.PortalPage
    ;
    ;Places the logo onto the screen
    ;
    ;Create the complex logo image
    [iconLogo1]
    Graphic=Normal, images/smartVillage.jpg
    Location=50, 50
    Size=150, 150
    Type=org.havi.ui.HStaticIcon
    ;
    ;Places text content on to the screen
    ;
    ;Set the page header
    [textHeader1]
    Text=Smart Village
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent1]
    Text=Smart Village™ is South Africa’s leading, next generation network and infrastructure solutions provider.
    Location=50, 60
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent2]
    Text=By utilising state-of-the-art fibre optic networks, Smart Village is able to deliver fully integrated multimedia,telecommunication and security solutions to residential, commercial and hospitality developments.
    Location=50, 61
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent3]
    Text=Our competitive advantage draws its strength from the diversity and technical capabilities of our networks, which guarantees a solid base for our core and value added service offerings.
    Location=50, 62
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent4]
    Text=From humble beginnings in 2004, the company has grown from a small start-up venture, into South Africa’s premier multi-play service provider.
    Location=50, 63
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent5]
    Text=Smart Village has a very strong national footprint, with over a thousand homes and businesses already connected.
    Location=50, 64
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent6]
    Text=Having already secured a significant portion of the market, accelerated growth is expected as Multichoice has acquired a controlling stake in Smart Village to broaden its core DStv offerings, by using Smart Village's next generation networks.
    Location=50, 65
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent7]
    Text=By providing a totally unique turnkey solution, Smart Village enables clients to deal with a single provider for multimedia, telecommunication, data and security services.
    Location=50, 66
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent8]
    Text=Smart Village also offers all the necessary service, maintenance and support that clients require, ensuring complete and total peace of mind.
    Location=50, 67
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Contact details
    ;
    ;Set the page text content
    [textContent9]
    Text=Smart Village Head Office
    Location=50, 68
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent10]
    Text=Tel : +27 (0) 12 679 3400
    Location=50, 69
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent11]
    Text=Fax : +27 (0) 12 679 3401
    Location=50, 70
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent12]
    Text=Post Box : ////////throws an error right here!!!!!!!!!!!!!!
    Location=50, 71
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent13]
    Text=Postnet Suite 422
    Location=50, 72
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent14]
    Text=Privatebag x 108
    Location=50, 73
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent15]
    Text=Centurion
    Location=50, 74
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent16]
    Text=0046
    Location=50, 75
    Size=90, 90
    Type=otg.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent17]
    Text=Physical Address :
    Location=50, 76
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent18]
    Text=Centurion Gate Complex
    Location=50, 77
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent19]
    Text=2nd Floor
    Location=50, 78
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent20]
    Text=Cnr John Vorster & Akkerboom Street
    Location=50, 79
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;
    ;Set the page text content
    [textContent21]
    Text=Centurion
    Location=50, 80
    Size=90, 90
    Type=org.havi.ui.HStaticText
    ;

    Here is the code that gets the text content from the .ini file and places it on the page

    private void SetHStaticText(HStaticText component, String name, ArrayList<Property> propertyList)
    {
    //gets the text content from the .ini file
    //places the text content on the page
    if (component == null)
    {
    component = new HStaticText();
    component.setName(name);
    _owner.AddComponent(component);
    }

    // Set base class properties first
    SetHVisible((HVisible)component, name, propertyList);

    }

    Thanx
    Camzie

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    What line number is reported for the exception in your code?

    P.S Why did you abandon your ealier thread for the same problem?

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    828
    Rep Power
    6

    Default

    U please paste ur complete code i which reads the ini file i
    if possible
    Ramya:cool:

  4. #4
    Camzie is offline Member
    Join Date
    Nov 2009
    Location
    Pretoria
    Posts
    12
    Rep Power
    0

    Default

    Hi there
    Here is the rest of the code for the .ini files where it reads the .ini files from

    package com.mca.portal;

    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Image;
    import java.awt.MediaTracker;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.Toolkit;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.net.URL;
    import java.util.ArrayList;
    import java.util.Hashtable;
    import org.havi.ui.HAnimateEffect;
    import org.havi.ui.HAnimation;
    import org.havi.ui.HBackgroundImage;
    import org.havi.ui.HComponent;
    import org.havi.ui.HGraphicButton;
    import org.havi.ui.HIcon;
    import org.havi.ui.HSinglelineEntry;
    import org.havi.ui.HSound;
    import org.havi.ui.HState;
    import org.havi.ui.HStaticAnimation;
    import org.havi.ui.HStaticIcon;
    import org.havi.ui.HStaticText;
    import org.havi.ui.HText;
    import org.havi.ui.HTextButton;
    import org.havi.ui.HToggleButton;
    import org.havi.ui.HVisible;

    /**
    * This is the INI settings class
    *
    * @author Jonathan Jandrell
    * @version 1.0
    *
    */
    public class INI extends Component
    {
    // Constants
    public static final int ACTION_SOUND = 1;
    public static final int ANIMATE = 2;
    public static final int ANIMATE_EFFECT = 3;
    public static final int BACKGROUND_COLOR = 4;
    public static final int BACKGROUND_MODE = 5;
    public static final int BORDERS_ENABLED = 6;
    public static final int BOUNDS = 7;
    public static final int DELAY = 8;
    public static final int ENABLED = 9;
    public static final int FILE = 10;
    public static final int FONT = 11;
    public static final int FOREGROUND_COLOR = 12;
    public static final int GAIN_FOCUS_SOUND = 13;
    public static final int GRAPHIC = 14;
    public static final int HORIZONTAL_ALIGNMENT = 15;
    public static final int LOCATION = 16;
    public static final int LOSE_FOCUS_SOUND = 17;
    public static final int NEXT_PAGE = 18;
    public static final int PASSCODE = 19;
    public static final int PLAY_MODE = 20;
    public static final int POSITION = 21;
    public static final int REPEAT_COUNT = 22;
    public static final int RESIZE_MODE = 23;
    public static final int RETURN_PAGE = 24;
    public static final int SIZE = 25;
    public static final int TAB_DOWN = 26;
    public static final int TAB_LEFT = 27;
    public static final int TAB_RIGHT = 28;
    public static final int TAB_UP = 29;
    public static final int TEXT = 30;
    public static final int TYPE = 31;
    public static final int URL = 32;
    public static final int VERTICAL_ALIGNMENT = 33;
    public static final int VISIBLE = 34;

    // Member variables
    //protected Hashtable<String, Image> _images = null;
    private PortalPage _owner;
    private INI _parent;
    private Hashtable<String, ArrayList<Property>> _objectList;
    protected static Toolkit _toolKit = null;
    protected MediaTracker _tracker = null;
    protected int _trackerId = 0;

    // Constructors
    public INI(PortalPage owner, String filePath)
    {
    System.err.println("com.mca.portal.INI.ctor()");

    _owner = owner;
    _parent = null;
    _objectList = null;
    _toolKit = null;
    _tracker = null;

    Parse(filePath);
    }

    public INI(String filePath)
    {
    this(null, filePath);
    }

    // Methods
    public void Apply()
    {
    System.err.println("com.mca.portal.INI.Apply()");

    if (_objectList == null) return;
    if (_owner == null)
    {
    getOwner();
    }

    String[] keys = _objectList.keySet().toArray(new String[0]);
    if (keys == null) return;

    for (int index = 0; index < keys.length; index++)
    {
    String objectName = keys[index];

    ArrayList<Property> propertyList = _objectList.get(objectName);
    if (propertyList.size() < 1) continue;

    Component component = _owner.getComponent(objectName);

    String type = FindObjectType(propertyList, component);
    System.err.print("+ object: ");
    System.err.print(objectName);
    System.err.print(" [type: ");
    System.err.print(type);
    System.err.println("]");

    type = type.toLowerCase();
    if (type.equals("com.mca.portal.portalpage")) SetPortalPage((com.mca.portal.PortalPage)component , objectName, propertyList);
    else if (type.equals("com.mca.portal.pagepassword")) SetPagePassword((com.mca.portal.PagePassword)compo nent, objectName, propertyList);
    else if (type.equals("org.havi.ui.hanimation")) SetHAnimation((org.havi.ui.HAnimation)component, objectName, propertyList);
    else if (type.equals("org.havi.ui.hbackgroundimage")) SetHBackgroundImage(null, objectName, propertyList);
    else if (type.equals("org.havi.ui.hgraphicbutton")) SetHGraphicButton((org.havi.ui.HGraphicButton)comp onent, objectName, propertyList);
    else if (type.equals("org.havi.ui.hicon")) SetHIcon((org.havi.ui.HIcon)component, objectName, propertyList);
    else if (type.equals("org.havi.ui.hsinglelineentry")) component = new HSinglelineEntry();
    else if (type.equals("org.havi.ui.hstaticanimation")) SetHStaticAnimation((org.havi.ui.HStaticAnimation) component, objectName, propertyList);
    else if (type.equals("org.havi.ui.hstaticicon")) SetHStaticIcon((org.havi.ui.HStaticIcon)component, objectName, propertyList);
    else if (type.equals("org.havi.ui.hstatictext")) SetHStaticText((org.havi.ui.HStaticText)component, objectName, propertyList);
    else if (type.equals("org.havi.ui.htext")) SetHText((org.havi.ui.HText)component, objectName, propertyList);
    else if (type.equals("org.havi.ui.htextbutton")) SetHTextButton((org.havi.ui.HTextButton)component, objectName, propertyList);
    else if (type.equals("org.havi.ui.htogglebutton")) SetHToggleButton((org.havi.ui.HToggleButton)compon ent, objectName, propertyList);
    }
    }

    private PortalPage CreatePage(String type)
    {
    System.err.println("com.mca.portal.INI.CreatePage( )");

    if (type == null) type = "com.mca.portal.portalpage";
    type = Util.TrimString(type).toLowerCase();

    if (type.equals("com.mca.portal.pagepassword")) return new PagePassword();
    else if (type.equals("com.mca.portal.portalpage")) return new PortalPage();
    else return null;
    }

    public ArrayList<Property> FindObject(String name)
    {
    return FindObject(name, false);
    }

    private ArrayList<Property> FindObject(String name, boolean create)
    {
    System.err.print("com.mca.portal.INI.FindObject(") ;
    System.err.print(name);
    System.err.print(",");
    System.err.print(create);
    System.err.println(")");

    name = Util.TrimString(name);
    if (Util.IsEmpty(name)) return null;

    // Get a list of valid object names
    String[] keys = _objectList.keySet().toArray(new String[0]);
    String tempName = name.toLowerCase();
    ArrayList<Property> propertyList = null;

    // Find a matching object name
    for (int index = 0; index < keys.length; index++)
    {
    if (!tempName.equals(keys[index].toLowerCase())) continue;

    propertyList = _objectList.get(keys[index]);
    break;
    }

    // If we must not create, return whatever we have here...
    if (create == false) return propertyList;
    else if (propertyList == null)
    {
    propertyList = new ArrayList<Property>();
    _objectList.put(name, propertyList);
    }

    if (propertyList == null)
    {
    System.err.print("+ Object not found: ");
    System.err.println(name);
    }

    return propertyList;
    }

    private String FindObjectType(ArrayList<Property> propertyList, Component component)
    {
    //System.err.println("com.mca.portal.INI.FindObjectT ype()");

    String type = (String)FindPropertyValue(propertyList, TYPE);
    if (Util.IsEmpty(type) && (component != null)) type = component.getClass().toString();
    if (type != null) type = Util.TrimString(type);
    if (Util.IsEmpty(type)) return null;

    return type;
    }

    private Object FindPropertyValue(ArrayList<Property> propertyList, int name)
    {
    //System.err.println("com.mca.portal.INI.FindPropert yValue()");

    if (propertyList != null)
    {
    // Find a matching property name
    for (int index = 0; index < propertyList.size(); index++)
    {
    Property property = propertyList.get(index);
    if (name == property.Name)
    {
    if (property.Value == null) return property.ValueInt;
    return property.Value;
    }
    }
    }

    return null;
    }

    public Image getImage(String filePath)
    {
    System.err.println("com.mca.portal.INI.getImage()" );

    // Ensure that the default toolkit is instantiated
    if (_toolKit == null) _toolKit = Toolkit.getDefaultToolkit();
    if (_tracker == null) _tracker = new MediaTracker(this);

    Image image = null;
    try
    {
    // Retrieve the image
    image = _toolKit.getImage(Util.ParseFile(filePath));

    // Tell the media tracker about new image
    _tracker.addImage(image, _trackerId);
    // Make sure image is downloaded
    _tracker.waitForID(_trackerId);
    _tracker.removeImage(image, _trackerId);

    _trackerId++;
    }
    catch (Exception ex)
    {
    ex.printStackTrace();
    }

    if (image == null)
    {
    System.err.print("+ Image not found: ");
    System.err.println(filePath);
    }

    return image;
    }

    private Image[] getImages(String fileList)
    {
    System.err.println("com.mca.portal.INI.getImages() ");

    String[] files = Util.SplitString(fileList, ",");
    ArrayList<Image> imageList = new ArrayList<Image>();

    for (int index = 0; index < files.length; index++)
    {
    Image image = getImage(Util.TrimString(files[index]));
    if (image != null) imageList.add(image);
    }

    if (imageList.size() > 0) return (Image[])imageList.toArray();
    return null;
    }

    public PortalPage getOwner()
    {
    if (_owner == null)
    {
    _owner = CreatePage((String)GetValue("PortalPage", TYPE));
    if (_owner != null) _owner.setSettings(this);
    else System.err.println("Cannot create page! Page type unknown...");
    }
    return _owner;
    }

    public INI getParentINI()
    {
    return _parent;
    }

    public Object GetValue(String object, int name)
    {
    return FindPropertyValue(FindObject(object, false), name);
    }

    public boolean Parse(String filePath)
    {
    System.err.print("com.mca.portal.INI.Parse(");
    System.err.print(filePath);
    System.err.println(")");

    FileReader fileReader = null;
    BufferedReader reader = null;

    try
    {
    fileReader = new FileReader(filePath);
    reader = new BufferedReader(fileReader);
    }
    catch (Exception ex)
    {
    reader = null;
    fileReader = null;
    ex.printStackTrace();
    }
    if (reader == null) return false;

    String objectName = null;
    String line = null;
    ArrayList<Property> propertyList = null;
    try
    {
    // Ensure our object property collection is instantiated
    if (_objectList == null) _objectList = new Hashtable<String, ArrayList<Property>>();

    // Read the entire file
    while ((line = reader.readLine()) != null)
    {
    // First remove any comments
    line = RemoveComment(line);

    // If line is empty, move on to next line
    if (Util.IsEmpty(line)) continue;

    // if the line starts with a [ then it is an object name
    if (line.startsWith("["))
    {
    // make sure to SAVE any previous properties...
    if ((objectName != null) && (propertyList != null))
    {
    _objectList.put(objectName, propertyList);
    }

    // Get the new Object name
    int index = line.indexOf("]");
    if (index < 0) index = line.length();
    objectName = line.substring(1, index);

    // Find / create the new object
    propertyList = FindObject(objectName, true);

    // Move onto next line
    continue;
    }

    // if the current object hasn't been defined, we can't set properties against null
    if (propertyList == null) continue;

    // Split the line into two parts: name, value
    String[] data = Util.SplitString(line, "=", 2);

    // Find existing property
    String propertyName = Util.TrimString(data[0]);
    // We can't deal with empty property names
    if (Util.IsEmpty(propertyName)) continue;

    Property property = Parse(propertyName, data[1]);
    if (property != null)
    {
    // try find previously set property to overwrite
    //for (int index = 0; index < propertyList.size(); index++)
    //{
    // if (property.Name != propertyList.get(index).Name) continue;

    // propertyList.remove(index);
    // break;
    //}

    // Just add the property onto the end, regardless if a similar one exists
    propertyList.add(property);
    }
    }

    // make sure to SAVE any previous properties...
    if ((objectName != null) && (propertyList != null))
    {
    _objectList.put(objectName, propertyList);
    }
    }
    catch (Exception ex)
    {
    ex.printStackTrace();
    }

    try
    {
    reader.close();
    reader = null;
    fileReader.close();
    fileReader = null;
    }
    catch (Exception ex)
    {
    ex.printStackTrace();
    }

    return true;
    }

    public Property Parse(String name, String value)
    {
    name = Util.TrimString(name).toLowerCase();

    try
    {
    if (name.equals("actionsound"))
    {
    return new Property(ACTION_SOUND, Util.ParseSoundFile(value));
    }
    else if (name.equals("animate"))
    {
    String[] data = Util.SplitString(value, ",", 2);
    int state = Util.ParseState(data[0]);
    Image[] images = getImages(data[1]);

    if (images == null) return null;
    return new Property(ANIMATE, images, state);
    }
    else if (name.equals("animateeffect"))
    {
    return new Property(ANIMATE_EFFECT, Util.ParseAnimateEffect(value));
    }
    else if (name.equals("backgroundcolor"))
    {
    return new Property(BACKGROUND_COLOR, Util.ParseColor(value));
    }
    else if (name.equals("backgroundmode"))
    {
    return new Property(BACKGROUND_MODE, Util.ParseBackgroundMode(value));
    }
    else if (name.equals("bordersenabled"))
    {
    return new Property(BORDERS_ENABLED, Util.ParseBoolean(value));
    }
    else if (name.equals("bounds"))
    {
    return new Property(BOUNDS, Util.ParseRectangle(value));
    }
    else if (name.equals("delay"))
    {
    return new Property(DELAY, Util.ParseInt(value));
    }
    else if (name.equals("enabled"))
    {
    return new Property(ENABLED, Util.ParseBoolean(value));
    }
    else if (name.equals("file"))
    {
    return new Property(FILE, Util.ParseFile(value));
    }
    else if (name.equals("font"))
    {
    return new Property(FONT, Util.ParseFont(value));
    }
    else if (name.equals("foregroundcolor"))
    {
    return new Property(FOREGROUND_COLOR, Util.ParseColor(value));
    }
    else if (name.equals("gainfocussound"))
    {
    return new Property(GAIN_FOCUS_SOUND, Util.ParseSoundFile(value));
    }
    else if (name.equals("graphic"))
    {
    String[] data = Util.SplitString(value, ",", 2);
    if (data.length < 1) return null;

    int state;
    Image image;

    if (data.length < 2)
    {
    state = HState.ALL_STATES;
    image = getImage(data[0]);
    }
    else
    {
    state = Util.ParseState(data[0]);
    image = getImage(data[1]);
    }

    if (image == null) return null;
    return new Property(GRAPHIC, image, state);
    }
    else if (name.equals("horizontalalignment"))
    {
    return new Property(HORIZONTAL_ALIGNMENT, Util.ParseHorizontalAlignment(value));
    }
    else if (name.equals("location"))
    {
    return new Property(LOCATION, Util.ParsePoint(value));
    }
    else if (name.equals("losefocussound"))
    {
    return new Property(LOSE_FOCUS_SOUND, Util.ParseSoundFile(value));
    }
    else if (name.equals("onaction"))
    {
    return new Property(PortalPage.ON_ACTION, Util.ParseEvent(value, this));
    }
    else if (name.equals("onfocus"))
    {
    return new Property(PortalPage.ON_GOT_FOCUS, Util.ParseEvent(value, this));
    }
    else if (name.equals("onhide"))
    {
    return new Property(PortalPage.ON_HIDE, Util.ParseEvent(value, this));
    }
    else if (name.equals("onkeydown"))
    {
    return new Property(PortalPage.ON_KEY_DOWN, Util.ParseEvent(value, this));
    }
    else if (name.equals("onkeypress"))
    {
    return new Property(PortalPage.ON_KEY_PRESS, Util.ParseEvent(value, this));
    }
    else if (name.equals("onkeyup"))
    {
    return new Property(PortalPage.ON_KEY_UP, Util.ParseEvent(value, this));
    }
    else if (name.equals("onload"))
    {
    return new Property(PortalPage.ON_LOAD, Util.ParseEvent(value, this));
    }
    else if (name.equals("onlosefocus"))
    {
    return new Property(PortalPage.ON_LOST_FOCUS, Util.ParseEvent(value, this));
    }
    else if (name.equals("onshow"))
    {
    return new Property(PortalPage.ON_SHOW, Util.ParseEvent(value, this));
    }
    else if (name.equals("nextpage"))
    {
    return new Property(NEXT_PAGE, Util.ParseFile(value));
    }
    else if (name.equals("passcode"))
    {
    value = Util.TrimString(value);
    int test = Util.ParseInt(value);
    return new Property(PASSCODE, Util.ParseFile(value));
    }
    else if (name.equals("playmode"))
    {
    return new Property(PLAY_MODE, Util.ParseAnimateEffect(value));
    }
    else if (name.equals("position"))
    {
    return new Property(POSITION, Util.ParsePoint(value));
    }
    else if (name.equals("repeatcount"))
    {
    int mode = 0;
    if (value.toUpperCase().equals("REPEAT_INFINITE")) mode = HAnimateEffect.REPEAT_INFINITE;
    else mode = Util.ParseInt(value);
    return new Property(REPEAT_COUNT, mode);
    }
    else if (name.equals("resizemode"))
    {
    return new Property(RESIZE_MODE, Util.ParseResizeMode(value));
    }
    else if (name.equals("returnpage"))
    {
    return new Property(RETURN_PAGE, Util.ParseFile(value));
    }
    else if (name.equals("size"))
    {
    return new Property(SIZE, Util.ParseDimension(value));
    }
    else if (name.equals("tabdown"))
    {
    return new Property(TAB_DOWN, Util.TrimString(value));
    }
    else if (name.equals("tableft"))
    {
    return new Property(TAB_LEFT, Util.TrimString(value));
    }
    else if (name.equals("tabright"))
    {
    return new Property(TAB_RIGHT, Util.TrimString(value));
    }
    else if (name.equals("tabup"))
    {
    return new Property(TAB_UP, Util.TrimString(value));
    }
    else if (name.equals("text"))
    {
    String[] data = Util.SplitString(value, ",", 2);
    if (data.length < 1) return null;
    if (data.length < 2) return new Property(TEXT, data[0], HState.ALL_STATES);

    int state = Util.ParseState(data[0]);
    return new Property(TEXT, data[1], state);
    }
    else if (name.equals("type"))
    {
    return new Property(TYPE, value);
    }
    else if (name.equals("url"))
    {
    return new Property(URL, Util.ParseURL(value));
    }
    else if (name.equals("verticalalignment"))
    {
    return new Property(VERTICAL_ALIGNMENT, Util.ParseVerticalAlignment(value));
    }
    else if (name.equals("visible"))
    {
    return new Property(VISIBLE, Util.ParseBoolean(value));
    }

    }
    catch (Exception ex) { } //ex.printStackTrace(); }

    return null;
    }

    private String RemoveComment(String text)
    {
    // NOTE: remove this line because we'll get too many
    //System.err.println("com.mca.portal.INI.RemoveComme nt()");

    // Trim whitespace from text
    text = Util.TrimString(text);
    // If the string is empty, just return it as is
    if (Util.IsEmpty(text)) return text;

    // Find the comment in the text
    String[] values = Util.SplitString(text, ";", 2);
    if (values.length == 0) return "";
    else if (values.length > 1)
    {
    // If the comment starts with '@' print it to the err stream
    if (values[1].charAt(0) == '@')
    {
    System.err.print("COMMENT: ");
    System.err.println(Util.TrimString(values[1].substring(1)));
    }
    }

    // If the line starts with '@' print it to the err stream
    if (text.charAt(0) == '@')
    {
    System.err.println(Util.TrimString(text.substring( 1)));

    // Return the property sans the '@' char
    return Util.TrimString(values[0].substring(1));
    }

    return Util.TrimString(values[0]);
    }

    private void SetHAnimation(HAnimation component, String name, ArrayList<Property> propertyList)
    {
    if (component == null)
    {
    component = new HAnimation();
    component.setName(name);
    _owner.AddComponent(component);
    }

    // Set base class properties first
    SetHStaticAnimation((HStaticAnimation)component, name, propertyList);
    }

    private void SetHBackgroundImage(HBackgroundImage component, String name, ArrayList<Property> propertyList)
    {
    for (int index = 0; index < propertyList.size(); index++)
    {
    Property property = propertyList.get(index);
    try
    {
    if (property.Name == FILE)
    {
    component = new HBackgroundImage((String)property.Value);
    PortalPage.getSetBackground().changeBackground(com ponent);
    }
    else if (property.Name == URL)
    {
    component = new HBackgroundImage((URL)property.Value);
    PortalPage.getSetBackground().changeBackground(com ponent);
    }
    }
    catch (Exception ex) { ex.printStackTrace(); }
    }
    }

    private void SetHComponent(HComponent component, String name, ArrayList<Property> propertyList)
    {
    if (component == null) return;

    component.setName(Util.TrimString(name));

    for (int index = 0; index < propertyList.size(); index++)
    {
    Property property = propertyList.get(index);

    switch (property.Name)
    {
    case BACKGROUND_COLOR:
    component.setBackground((Color)property.Value);
    break;

    case BOUNDS:
    component.setBounds((Rectangle)property.Value);
    break;

    case FONT:
    component.setFont((Font)property.Value);
    break;

    case FOREGROUND_COLOR:
    component.setForeground((Color)property.Value);
    break;

    case LOCATION:
    component.setLocation((Point)property.Value);
    break;

    case SIZE:
    component.setSize((Dimension)property.Value);
    break;

    case VISIBLE:
    component.setVisible((property.ValueInt != 0));
    break;
    }
    }
    }

    private void SetHGraphicButton(HGraphicButton component, String name, ArrayList<Property> propertyList)
    {
    // NOTE: remove this line because we'll get too many
    System.err.println("com.mca.portal.INI.SetHGraphic Button()");

    if (component == null)
    {
    component = new HGraphicButton();
    component.setName(name);
    _owner.AddComponent(component);
    }

    // Set base class properties first
    SetHIcon((HIcon)component, name, propertyList);

    for (int index = 0; index < propertyList.size(); index++)
    {
    Property property = propertyList.get(index);

    try
    {
    switch (property.Name)
    {
    case ACTION_SOUND:
    component.setActionSound((HSound)property.Value);
    break;
    }
    }
    catch (Exception ex)
    {
    }
    }

    }

    private void SetHIcon(HIcon component, String name, ArrayList<Property> propertyList)
    {
    if (component == null)
    {
    component = new HIcon();
    component.setName(name);
    _owner.AddComponent(component);
    }

    // Set base class properties first
    SetHStaticIcon((HStaticIcon)component, name, propertyList);

    for (int index = 0; index < propertyList.size(); index++)
    {
    Property property = propertyList.get(index);

    switch (property.Name)
    {
    case GAIN_FOCUS_SOUND:
    component.setGainFocusSound((HSound)property.Value );
    break;

    case LOSE_FOCUS_SOUND:
    component.setGainFocusSound((HSound)property.Value );
    break;
    }
    }
    }

    private void SetHStaticAnimation(HStaticAnimation component, String name, ArrayList<Property> propertyList)
    {
    if (component == null)
    {
    component = new HStaticAnimation();
    component.setName(name);
    _owner.AddComponent(component);
    }

    // Set base class properties first
    SetHVisible((HVisible)component, name, propertyList);

    for (int index = 0; index < propertyList.size(); index++)
    {
    Property property = propertyList.get(index);

    switch (property.Name)
    {
    case DELAY:
    component.setDelay(property.ValueInt);
    break;

    case PLAY_MODE:
    component.setPlayMode(property.ValueInt);
    break;

    case POSITION:
    component.setPosition(property.ValueInt);
    break;

    case REPEAT_COUNT:
    component.setRepeatCount(property.ValueInt);
    break;
    }
    }

    }

    private void SetHStaticIcon(HStaticIcon component, String name, ArrayList<Property> propertyList)
    {
    if (component == null)
    {
    component = new HStaticIcon();
    component.setName(name);
    _owner.AddComponent(component);
    }

    // Set base class properties first
    SetHVisible((HVisible)component, name, propertyList);

    }

    private void SetHStaticText(HStaticText component, String name, ArrayList<Property> propertyList)
    {
    //gets the text from the .ini file
    //places the text content on the page
    if (component == null)
    {
    component = new HStaticText();
    component.setName(name);
    _owner.AddComponent(component);
    }

    // Set base class properties first
    SetHVisible((HVisible)component, name, propertyList);

    }

    private void SetHText(HText component, String name, ArrayList<Property> propertyList)
    {
    if (component == null)
    {
    component = new HText();
    component.setName(name);
    _owner.AddComponent(component);
    }

    // Set base class properties first
    SetHStaticText((HStaticText)component, name, propertyList);

    for (int index = 0; index < propertyList.size(); index++)
    {
    Property property = propertyList.get(index);

    switch (property.Name)
    {
    case GAIN_FOCUS_SOUND:
    component.setGainFocusSound((HSound)property.Value );
    break;

    case LOSE_FOCUS_SOUND:
    component.setLoseFocusSound((HSound)property.Value );
    break;
    }
    }
    }

    private void SetHTextButton(HTextButton component, String name, ArrayList<Property> propertyList)
    {
    if (component == null)
    {
    component = new HTextButton();
    component.setName(name);
    _owner.AddComponent(component);
    }

    // Set base class properties first
    SetHText((HText)component, name, propertyList);

    for (int index = 0; index < propertyList.size(); index++)
    {
    Property property = propertyList.get(index);

    switch (property.Name)
    {
    case ACTION_SOUND:
    component.setActionSound((HSound)property.Value);
    break;
    }
    }
    }

    private void SetHToggleButton(HToggleButton component, String name, ArrayList<Property> propertyList)
    {
    if (component == null)
    {
    component = new HToggleButton();
    component.setName(name);
    _owner.AddComponent(component);
    }

    // Set base class properties first
    SetHGraphicButton((HGraphicButton)component, name, propertyList);

    for (int index = 0; index < propertyList.size(); index++)
    {
    Property property = propertyList.get(index);

    switch (property.Name)
    {
    case ACTION_SOUND:
    component.setActionSound((HSound)property.Value);
    break;
    }
    }
    }

    private void SetHVisible(HVisible component, String name, ArrayList<Property> propertyList)
    {
    // HVisible is a base class, we must not instantiate a type of HVisible
    if (component == null) return;

    // Set base class properties first
    SetHComponent(component, name, propertyList);

    for (int index = 0; index < propertyList.size(); index++)
    {
    Property property = propertyList.get(index);

    switch (property.Name)
    {
    case ANIMATE:
    component.setAnimateContent((Image[])property.Value, property.ValueInt);
    break;

    case BACKGROUND_MODE:
    component.setBackgroundMode(property.ValueInt);
    break;

    case BORDERS_ENABLED:
    component.setBordersEnabled((property.ValueInt != 0));
    break;

    case ENABLED:
    component.setEnabled((property.ValueInt != 0));
    break;

    case GRAPHIC:
    component.setGraphicContent((Image)property.Value, property.ValueInt);
    break;

    case HORIZONTAL_ALIGNMENT:
    component.setHorizontalAlignment(property.ValueInt );
    break;

    case RESIZE_MODE:
    component.setResizeMode(property.ValueInt);
    break;

    case TEXT:
    component.setTextContent((String)property.Value, property.ValueInt);
    break;

    case VERTICAL_ALIGNMENT:
    component.setVerticalAlignment(property.ValueInt);
    break;
    }
    }
    }

    public void setOwner(PortalPage component)
    {
    _owner = component;
    }

    public void setParentINI(INI parent)
    {
    _parent = parent;
    }

    private void SetPortalPage(PortalPage component, String name, ArrayList<Property> propertyList)
    {
    if (component == null) return;

    for (int index = 0; index < propertyList.size(); index++)
    {
    Property property = propertyList.get(index);

    switch (property.Name)
    {
    case BOUNDS:
    component.setBounds((Rectangle)property.Value);
    break;

    case LOCATION:
    component.setLocation((Point)property.Value);
    break;

    case SIZE:
    component.setSize((Dimension)property.Value);
    break;

    case VISIBLE:
    component.setVisible((property.ValueInt != 0));
    }
    }
    }

    private void SetPagePassword(PagePassword component, String name, ArrayList<Property> propertyList)
    {
    if (component == null) return;


    SetPortalPage(component, name, propertyList);

    for (int index = 0; index < propertyList.size(); index++)
    {
    Property property = propertyList.get(index);

    switch (property.Name)
    {
    case PASSCODE:
    component.setPassword((String)property.Value);
    break;

    case NEXT_PAGE:
    component.setNextPage((String)property.Value);
    break;

    case RETURN_PAGE:
    component.setNextPage((String)property.Value);
    break;
    }
    }
    }

    }

  5. #5
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Posting all that code was not neccessary at all.
    Did you read the link I posted earlier?
    Did you read the reply I posted in this thread?

Similar Threads

  1. Creating files stopped creating...
    By Dieter in forum Advanced Java
    Replies: 3
    Last Post: 09-25-2009, 11:45 PM
  2. Creating preview images of files in java
    By sandeepk84@gmail.com in forum Advanced Java
    Replies: 3
    Last Post: 07-04-2009, 10:29 PM
  3. Replies: 6
    Last Post: 02-06-2009, 08:05 PM
  4. Replies: 1
    Last Post: 01-16-2009, 10:14 AM
  5. Running batch files in java
    By pradeesh in forum New To Java
    Replies: 10
    Last Post: 12-04-2008, 09:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •