Article View: borland.public.jbuilder.java.swing
Article #712Re: lost text
From: Alan Shiers
Date: Thu, 30 Dec 2004 15:28
Date: Thu, 30 Dec 2004 15:28
161 lines
5246 bytes
5246 bytes
"GUI-Majician" <nospam@centurytel.net> wrote in message
news:41d31fc6@newsgroups.borland.com...
> Looks to me like what your doing is serializing/de-serializing the Visual
> Component and not the ListModel. Whats happening is that when you
> de-serialize, the data is loaded into the View but then its overwritten by
> the Model, which has not been loaded. This is why I always ser./de-ser.
the
> Model and it will update the View. Why do you need to serialize the View
> and not the Model?
I've never had an occasion when I ever had to serialize anything for
purposes of saving to file. This is my first time trying this. I didn't know
that, when serializing/deserializing an object, that had a model, that you
concentrated on just the model of that object.
>
> If you need to serialize a container full of visual components, then you
> need to split it up into serializing the models of the components, that
have
> one, and then serialize the attributes of the panel itself. Make sense?
If this is the way it is done, then I can only accept your analysis.
>
> And do it in the right order, serialize vc models, then serialize panel
> attributes, and then reverse the order for de-ser so the models get loaded
> last and they update the views.
Given a container that contains other objects, such as my Listbox object,
could you show me a simple demo program that demonstrates the
serializing/deserializing of the objects model? I need a sample to go by to
see how it is done. I've provided my Listbox class below for your
convenience.
Alan
********************************************
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;
import java.awt.event.MouseEvent;
import java.io.*;
public class Listbox extends JScrollPane implements InputTool, Serializable
{
private JList list = null;
private String id = "";
private String[] values = null;
private static final String[] EMPTY_ARRAY = new String[0];
private boolean haveValues;
private int item = 0; //default
private InputType type = null;
public Listbox()
{
list = new JList();
super.getViewport().add(list);
list.setVisibleRowCount(4);
setPreferredSize(new Dimension(140,90));
setMaximumSize(new Dimension(140,90));
ItemListener listener = new ItemListener();
list.addMouseListener(listener);
setMultipleSelect(false);//default
}
public int getItemNumber(){return item;}
public void setItemNumber(int number)
{
item = number;
}
public InputType getInputType(){return type;}
public void setInputType(InputType type){this.type = type;}
public JList getList()
{
return list;
}
public String[] getOptions()
{
ListModel model = list.getModel();
if(model.getSize() == 0)return EMPTY_ARRAY;
String[] st = new String[model.getSize()];
for(int i = 0; i < model.getSize(); i++)
{
st[i] = (String)model.getElementAt(i);
}
return st;
}
public void setOptions(String[] options)
{
list.setListData(options);
}
public String[] getValues()
{
if(haveValues)
{
return values;
}
return EMPTY_ARRAY;
}
public void setValues(String[] values)
{
this.values = values;
haveValues = true;
}
public void setID(String ID)
{
this.id = ID;
}
public String getID()
{
return id;
}
public String getListSize()
{
return String.valueOf(list.getModel().getSize());
}
public boolean isMultipleSelect()
{
int value = list.getSelectionMode();
if(value == ListSelectionModel.MULTIPLE_INTERVAL_SELECTION)
return true;
if(value == ListSelectionModel.SINGLE_INTERVAL_SELECTION)
return true;
return false;
}
public void setMultipleSelect(boolean value)
{
if(value)
{
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
}
else
{
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}
}
class ItemListener extends MouseInputAdapter implements Serializable
{
public void mousePressed(MouseEvent e)
{
JTestComposer.setEditor(Listbox.this);
}
}
}
Technical Details
Message-ID:
<41d41faf$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<41d30d52$1@newsgroups.borland.com> <41d31fc6@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,a60f7bec7c6371ad X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Alan Shiers" <ashiers@hfx.eastlink.ca> Newsgroups: borland.public.jbuilder.java.swing References: <41d30d52$1@newsgroups.borland.com> <41d31fc6@newsgroups.borland.com> Subject: Re: lost text Date: Thu, 30 Dec 2004 11:28:29 -0400 Lines: 163 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 24.222.101.2 Message-ID: <41d41faf$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1104420783 24.222.101.2 (30 Dec 2004 07:33:03 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!proxad.net!proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail