Hi,
I am new to JAVA SWING and would like someone to help me out here.
I need to read the INI file to load out the structure and display them
on the JTree.
How can I go about doing that?
The INI file format looks like following:
[R]
ChildsCount = 2
C1 = Enclosure(s)
C2 = JBOD(s)
[R\C1]
ChildsCount = 2
C1 = EnclosureWWN A
C2 = EnclosureWWN B
[R\C1\C1]
ChildsCount = 6
C1 = Power Supply
C2 = Fan
C3 = Battery
C4 = Numeric Sensor
C5 = Controller
C6 = Device Group(s)
[R\C1\C1\C1]
ChildsCount = 2
C1 = PSU0
C2 = PSU1
[R\C1\C1\C2]
ChildsCount = 2
C1 = Fan0
C2 = Fan1
[R\C1\C1\C3]
ChildsCount = 2
C1 = UPS
C2 = Motherboard
[R\C1\C1\C4]
ChildsCount = 3
C1 = NS0
C2 = NS1
C3 = NS2
[R\C1\C1\C5]
ChildsCount = 2
C1 = ControllerWWN A
C2 = ControllerWWN B
[R\C1\C1\C6]
ChildsCount = 7
C1 = Device Group A
C2 = Device Group B
C3 = Device Group C
C4 = Device Group D
C5 = Device Group E
C6 = Device SubGroup A
C7 = Device SubGroup B
[R\C1\C1\C6\C1]
ChildsCount = 3
C1 = Volume 1
C2 = Volume 2
C3 = Volume 3
[R\C1\C1\C6\C1\C1]
ChildsCount = 2
C1 = LUN0
C2 = LUN1
[R\C1\C1\C6\C1\C1\C1]
ChildsCount = 4
C1 = Host A
C2 = Host B
C3 = Host C
C4 = Host D
[R\C1\C1\C6\C1\C1\C2]
ChildsCount = 2
C1 = Host A
C2 = Host C
In the JTree it should shows something like this:
Enclosure(s)
|__EnclosureWWN A
|__Power Supply
|__PSU0
|__PSU1
|__Fan
|__Battery
|__Numeric Sensor
|__Controller
|__Device Group(s)
|__EnclosureWWN B
Thomas Weidenfeller - 06 Feb 2004 08:22 GMT
> I am new to JAVA SWING and would like someone to help me out here.
> I need to read the INI file to load out the structure and display them
> on the JTree.
>
> How can I go about doing that?
* Write your own INI file parser, or search the net for an existing one.
* Read the Swing quick start guide at
http://java.sun.com/docs/books/tutorial/uiswing/mini/index.html
Read it multiple times, until you have understood it. Pay special
attention to layout manager.
* Then read the part about using JTree in the normal Swing tutorial:
http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html
> In the JTree it should shows something like this:
Fine. Write the code to do it. Parse the file into a TreeModel, using
TreeNodes for each element. Build a GUI with all the widgets you need.
Provide the TreeModel as a model to the JTree. If you don't understand
what this means, read the above tutorials again.
/Thomas
Adam - 06 Feb 2004 08:22 GMT
> Hi,
>
[quoted text clipped - 15 lines]
> C1 = EnclosureWWN A
> C2 = EnclosureWWN B
[cut]---------------------
> In the JTree it should shows something like this:
>
[quoted text clipped - 10 lines]
>
> |__EnclosureWWN B
There's no standard class that can help you
transform this kind of INI file to a JTree,
so you have to write your own parser.
Not an easy task.
On the other hand you may use XML
instead fo this very strange file format and
parse it with DOM API. That gives you
a tree of nodes which can easily be transformed
into JTree.
If you are stuck with the file format, you can always
write a Perl script or a Python app (much easier for parsing than
java)
that would transform it into XML which would be given
to your java app.
Adam