string to AttributeSet

it is possible to convert AttributeSet to string and fromstring to AttributeSet
[93 byte] By [argola] at [2007-11-27 7:00:46]
# 1
hi,there are two AttributeSet available. which one you are talking about?regardsAniruddha
Aniruddha-Herea at 2007-7-12 18:51:33 > top of Java-index,Desktop,Core GUI APIs...
# 2
javax.swing.text
argola at 2007-7-12 18:51:33 > top of Java-index,Desktop,Core GUI APIs...
# 3

hi!

this is an interface, so you need to know which implemented class you are using, then either you have to override that class, and write getString, setString on your own, and another option is try to write the class with objectutputstream, and then write to buffer and get the String, use the reverse technology to restore.

regards

Aniruddha

Aniruddha-Herea at 2007-7-12 18:51:33 > top of Java-index,Desktop,Core GUI APIs...
# 4

i do somthing like this but i need to send it over network in a byte array and

whene i convert it to string or byte array the size is about 13KB for one style

whene i have more style in my text it maybe to 300KB it is not to much

public byte [] AtrToBytes(AttributeSet obj) throws java.io.IOException{

ByteArrayOutputStream bos = new ByteArrayOutputStream();

ObjectOutputStream oos = new ObjectOutputStream(bos);

oos.writeObject(obj);

oos.flush();

oos.close();

bos.close();

byte [] data = bos.toByteArray();

return data;

}

argola at 2007-7-12 18:51:33 > top of Java-index,Desktop,Core GUI APIs...
# 5
hi,i guess i would have done same thing what you have done. if some one else finds some better way, may suggest you. but this is my limit in this regardsregardsAniruddha
Aniruddha-Herea at 2007-7-12 18:51:33 > top of Java-index,Desktop,Core GUI APIs...
# 6

another way which i think to send AttributeSet over network is by Style

it is in sun tutorial you can by string recognize Style

protected void addStylesToDocument(StyledDocument doc) {

//Initialize some styles.

Style def = StyleContext.getDefaultStyleContext().

getStyle(StyleContext.DEFAULT_STYLE);

Style regular = doc.addStyle("regular", def);

StyleConstants.setFontFamily(def, "SansSerif");

Style s = doc.addStyle("italic", regular);

StyleConstants.setItalic(s, true);

s = doc.addStyle("italic_off", regular);

StyleConstants.setItalic(s, false);

s = doc.addStyle("bold", regular);

StyleConstants.setBold(s, true);

s = doc.addStyle("bold_off", regular);

StyleConstants.setBold(s, false);

s = doc.addStyle("underline", regular);

StyleConstants.setUnderline(s,true);

s = doc.addStyle("underline_off", regular);

StyleConstants.setUnderline(s,false);

}

Than when i click JToggleButton i add style to String whene i send it

first time evrything is ok but whene i send secode time i must have

start style and i don't know how to do this

String style = "regular#";

public void itemStateChanged(ItemEvent e) {

g = (JToggleButton)e.getSource();

g2 = (JToggleButton)e.getSource();

g3 = (JToggleButton)e.getSource();

String a = g.getActionCommand();

String a2 = g2.getActionCommand();

String a3 = g3.getActionCommand();

if( a.equals("bold") ){

if( e.getStateChange() == 1){

set = doc.getStyle("bold");

set(set);

style +="bold#";

}

else if( e.getStateChange() == 2){

set = doc.getStyle("bold_off");

set(set);

style +="bold_off#";

}

}

if( a2.equals("italic") ){

if( e.getStateChange() == 1){

set = doc.getStyle("italic");

set(set);

style +="italic#";

}

else if( e.getStateChange() == 2){

set = doc.getStyle("italic_off");

set(set);

style +="italic_off#";

}

}

if( a2.equals("underline") ){

if( e.getStateChange() == 1){

set = doc.getStyle("underline");

set(set);

style +="underline#";

}

else if( e.getStateChange() == 2){

set = doc.getStyle("underline_off");

set(set);

style +="underline_off#";

}

}

}

argola at 2007-7-12 18:51:33 > top of Java-index,Desktop,Core GUI APIs...
# 7
it is possibe to add Style to AttributeSet or convert Style to AttributeSet
argola at 2007-7-12 18:51:33 > top of Java-index,Desktop,Core GUI APIs...