danish shaikh

Greenhorn
+ Follow
since Nov 09, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by danish shaikh

Hi all,
I m creating an converter which will convert the HTML data into RTF data.
I m using TextPane to load Html using HTMLEditorKit.. The HTML data is placed perfectly in the TExtPane but when i read the data from that textpane using Pane.getText(), it loses <BR> tag.. So how can i over come this can ne body help me.........plz its last phase of my project..
i m pasting the code...

import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.rtf.*;
import javax.swing.text.html.*;
import java.io.*;

public class HtmlToRtf
extends JFrame {
public static void main(String[] s)
{
new HtmlToRtf();
}

public HtmlToRtf()
{
convertHtmlToRtf();
setSize(100,100);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
show();
}

public void convertHtmlToRtf()
{
RTFEditorKit rtf_edit = new RTFEditorKit();
JTextPane jtp_rtf = new JTextPane();
JEditorPane editor=new JEditorPane();
DefaultStyledDocument rtf_doc;
jtp_rtf.setEditorKit(rtf_edit);
jtp_rtf.setContentType("html/rtf");
editor.setContentType("text/html");
StyledDocument editdoc = (StyledDocument) editor.getDocument ();
EditorKit editkit = editor.getEditorKit ();
rtf_doc=new DefaultStyledDocument();

String data = "<HTML><HEAD>"+
"<TITLE></TITLE>"+
"</HEAD>"+
"<BODY BGCOLOR=\"WHITE\">"+
"<P STYLE=\"margin-top:0px;margin-bottom:0px\" ALIGN=\"center\"><FONT FACE=\"Times New Roman\" SIZE=\"3\"><B>STATEMENT OF ADDITIONAL<BR> INFORMATION </B></FONT></P> <P STYLE=\"margin-top:0px;margin-bottom:0px\"><FONT "+
"SIZE=\"1\"> </FONT></P> <P STYLE=\"margin-top:0px;margin-bottom:0px\"><FONT SIZE=\"1\"> </FONT></P> <P STYLE=\"margin-top:0px;margin-bottom:0px\" ALIGN=\"center\"><FONT FACE=\"Times New Roman\" SIZE=\"3\"><B>M<SMALL>ERRILL</SMALL> L<SMALL>YNCH</SMALL>"+
"B<SMALL>OND</SMALL> F<SMALL>UND</SMALL>, I<SMALL>NC</SMALL>. </B></FONT></P> <P STYLE=\"margin-top:0px;margin-bottom:0px\"><FONT SIZE=\"1\"> </FONT></P> <P STYLE=\"margin-top:0px;margin-bottom:0px\" ALIGN=\"center\"><FONT FACE=\"Times New Roman\""+
"SIZE=\"2\"><B>P.O. Box 9011, Princeton, New Jersey 08543-9011 • Phone No. (609) 282-2800 </B></FONT></P> <P STYLE=\"margin-top:0px;margin-bottom:0px\"><FONT SIZE=\"1\"> </FONT></P> <P STYLE=\"margin-top:0px;margin-bottom:0px\"><FONT SIZE=\"1\"> </FONT></P> <P STYLE=\"margin-top:0px;margin-bottom:0px\"><FONT FACE=\"Times New Roman\" SIZE=\"2\">This Statement of Additional <BR>Information of Merrill Lynch Bond Fund, Inc. (the “Fund” is not a prospectus and should be read in"+
"conjunction with the Prospectus of the Fund, dated January <BR>, 2004, which has been filed with the Securities and Exchange Commission (the “commission” and can be obtained, without charge, by calling 1-800-MER-FUND or by writing to the Fund"+
"at the above address. The fund’s prospectus<BR> is incorporated by reference into this Statement of Additional Information, and Part I of this Statement of Additional Information and the portions of Part II of this Statement of Additional"+
"Information that relate to the Fund have been incorporated by <BR>reference into the Fund’s Prospectus. The portions of Part II of this Statement of Additional Information that do not relate to the Fund, do not form a part of the Fund’s"+
"Statement of Additional Information, have not been incorporated by<BR> reference into the Fund’s Prospectus and should not be relied upon by investors in the Fund. The Fund’s audited financial statements are incorporated by reference into this"+
"Statement of Additional Information by reference to <BR>the Fund’s 2003 Annual Report. You may request a copy of the Annual Report at no charge by calling 1-800-637-3863 between 8:30 a.m. and 5:30 p.m. Eastern time on any business day. </FONT></P>"+
"</BODY></HTML>";

try{
StringReader strReader = new StringReader(data);
editkit.read(strReader,editdoc,0);
//getContentPane().add(editor); //uncomment it to check the behaviour
int len=editdoc.getLength();
for (int i=0;i<len;i++)
{
AttributeSet a = editdoc.getCharacterElement(i).getAttributes();
MutableAttributeSet attr=new SimpleAttributeSet();
StyleConstants.setFontFamily(attr,StyleConstants.getFontFamily(a));
StyleConstants.setFontSize(attr,StyleConstants.getFontSize(a));
StyleConstants.setUnderline(attr,StyleConstants.isUnderline(a));
StyleConstants.setBold(attr,StyleConstants.isBold(a));
StyleConstants.setItalic(attr,StyleConstants.isItalic(a));
StyleConstants.setForeground(attr,StyleConstants.getForeground(a));
String s = editor.getText(i, 1);
jtp_rtf.setCharacterAttributes(attr,true);
rtf_doc.insertString(i,s,attr);
}
jtp_rtf.setStyledDocument(rtf_doc);
ByteArrayOutputStream strBuffer= new ByteArrayOutputStream();
rtf_edit.write(strBuffer,rtf_doc,0,rtf_doc.getLength());
StringReader reader=new StringReader(strBuffer.toString());
JTextPane pane=new JTextPane();
RTFEditorKit kit=new RTFEditorKit();
pane.setEditorKit(kit);
StyledDocument doc=new DefaultStyledDocument();
kit.read(reader,doc,0);
pane.setStyledDocument(doc);
getContentPane().add(pane);

System.out.println(strBuffer.toString());
System.out.println("Converted Successfully");
}catch (Exception ex) {
System.out.println( "Error: " + ex.toString());
}
}
};

Thanks in advance,

Regards,
Danish Shaikh
19 years ago
hi all, I m back.
I m creating an RTF Text Editor, i m just near to finish it. I have used JTextPane to load the file contents, but the contents are not fairly visible in pane i also increased the zoom but still after zooming it showing the gap between the normal text and colored text ne body give me the solution its urgent plz give me reply. i m sending u the code...

class ScaledTextPane extends JTextPane {
String zoomFactor = new String ("125%");
public ScaledTextPane() {
super();
String s = (String) zoomFactor;
s = s.substring(0, s.length() - 1);
double scale = new Double(s).doubleValue() / 100;
ScaledTextPane.this.getDocument().putProperty("ZOOM_FACTOR", new Double(scale));
}

public void setSize(Dimension d)
{
if (d.width < getParent().getSize().width)
d.width = getParent().getSize().width;
super.setSize(d);
}

public boolean getScrollableTracksViewportWidth()
{
return false;
}

public void repaint(int x, int y, int width, int height) {
super.repaint(0,0,getWidth(),getHeight());
}
}

class ScaledEditorKit extends RTFEditorKit {
public ViewFactory getViewFactory() {
return new StyledViewFactory();
}

class StyledViewFactory implements ViewFactory {
public View create(Element elem) {
String kind = elem.getName();
if (kind != null) {
if (kind.equals(AbstractDocument.ContentElementName)) {
return new LabelView(elem);
} else if (kind.equals(AbstractDocument.ParagraphElementName)) {
return new ParagraphView(elem);
} else if (kind.equals(AbstractDocument.SectionElementName)) {
return new ScaledView(elem, View.Y_AXIS);
} else if (kind.equals(StyleConstants.ComponentElementName)) {
return new ComponentView(elem);
} else if (kind.equals(StyleConstants.IconElementName)) {
return new IconView(elem);
}
}
// default to text display
return new LabelView(elem);
}
}
}

//-----------------------------------------------------------------
class ScaledView extends BoxView{
public ScaledView(Element elem, int axis) {
super(elem,axis);
}

public double getZoomFactor() {
Double scale=(Double)getDocument().getProperty("ZOOM_FACTOR");
if (scale!=null) {
return scale.doubleValue();
}
return 1;
}

public void paint(Graphics g, Shape allocation) {
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
double zoomFactor = getZoomFactor();
AffineTransform old=g2d.getTransform();
g2d.scale(zoomFactor, zoomFactor);
super.paint(g2d, allocation);
g2d.setTransform(old);
}

public float getMinimumSpan(int axis) {
float f = super.getMinimumSpan(axis);
f *= getZoomFactor();
return f;
}

public float getMaximumSpan(int axis) {
float f = super.getMaximumSpan(axis);
f *= getZoomFactor();
return f;
}

public float getPreferredSpan(int axis) {
float f = super.getPreferredSpan(axis);
f *= getZoomFactor();
return f;
}

protected void layout(int width, int height) {
super.layout(new Double(width / getZoomFactor()).intValue(),new Double(height *getZoomFactor()).intValue());
}

public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
double zoomFactor = getZoomFactor();
Rectangle alloc;
alloc = a.getBounds();
Shape s = super.modelToView(pos, alloc, b);
alloc = s.getBounds();
alloc.x*=zoomFactor;
alloc.y*=zoomFactor;
alloc.width*=zoomFactor;
alloc.height*=zoomFactor;
return alloc;
}

public int viewToModel(float x, float y, Shape a,Position.Bias[] bias) {
double zoomFactor = getZoomFactor();
Rectangle alloc = a.getBounds();
x/=zoomFactor;
y/=zoomFactor;
alloc.x/=zoomFactor;
alloc.y/=zoomFactor;
alloc.width/=zoomFactor;
alloc.height/=zoomFactor;
return super.viewToModel(x, y, alloc, bias);
}
}

I have created my texpane an instance of ScaledTextPane..

Regards,
Danish Shaikh.
19 years ago
Hi all,
Can nebody help to find how to get the actual GlyphCode of various symbol in webdings, wingdings fonts. I m wanna insert these symbol at the current cursor position in the JTextPane's document.

Reply me soon.

Thanks in advance.
Regards,
Danish Shaikh
[ December 27, 2004: Message edited by: danish shaikh ]
19 years ago
Hi all,

I m creating an application in which i want to insert "Symbol", "Webdings", "Wingdings" etc symbols in a JTextPane's document, how can i do that?
That is it just like n MS-Word Insert Symbol, but i want only Glyph Symbol.
Please help me. its quite urgent.

Thanks in advance.

Regards,
Danish Shaikh
[ December 26, 2004: Message edited by: danish shaikh ]
19 years ago
Hi all,
i m creating a rtftextEditor.. with bold, italic ,underline, strikethroug features... i want to save the text with this attributes in a file but the strikethrough attribute does not save in the file.

the code for that i write is..

File file=new File(curFileName);
OutputStream fo=new FileOutputStream(file);
rtf.write(fo,doc,0,doc.getLength());
fo.close();

so wat can i do now.plz help me
Regards...
19 years ago
Hi,
I m creating an RTF Text Editor in that i hav used an JTextPane...
Now i want to stop the word wrapping ... n there is no function with textpane... like textarea..
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
so wat should i do now.

Regards,
19 years ago
Hi all
i want to change the looks of the Java Buttons n Frame to be looked like an Window-XP how can i do that n which classes i have to use.
Reply soon.

Thanks in advance.
19 years ago
Hi all,
I m creating n Text Editor using JEditorPane().
I want to change the color of the text as i type ne new thing in editorpane.
For that i have used the folloeing code:--
set=new SimpleAttributeSet();
StyleConstants.setForeground(set, Color.RED);
StyleConstants.setUnderline(set, true);StyledEditorKit.StyledTextAction.setCharacterAttributes(editor,set,true);

but it's showing me following error:-

non-static method setCharacterAttributes(javax.swing.JEditorPane,javax.swing.text.AttributeSet,boolean) cannot be referenced from a static context.

What does it means n how to solve it.

Plz help me.
Thanks in Advance.
Regards,
Danish Shaikh.
19 years ago
Hi,
Do u know ne site which can give the better n detail information on richtext.
Thanks.

Regards,
Danish Shaikh
19 years ago
but i want how to use it n what r the different property for that
19 years ago
how to debug the code i m using Textpad as n editor ...
so i dont know how to do debugging..

Thanks.
Bye,
Regards,
Danish Shaikh
19 years ago
hi,
I want to build a text editor using rtf concept..
I have used JTextPane for that i want to replace it with rtf TextField.
How to do that plz help me..

Thanks,
Danish Shaikh.
19 years ago
Hi All,
I have to change the looks of the Java applet n all of its components..
beyond the default one's.. So plz help me how to do that... its quite urgent..

Thanks in advance.


Regards,
Danish Shaikh
19 years ago
Hi,,
thanks for reply.
i m damm sure that the flag will become false.
flag is used to check the existing file is selected or not (true).
The same logic is used for backspace but its working ...
public void keyPressed(KeyEvent ke)
{
int code=ke.getKeyCode();
if(code==KeyEvent.VK_BACK_SPACE && flag==true)
consume=true;
}

thnks in advance,
Bye.Regards,
Danish Shaikh
19 years ago
Hi,
Thanks for reply, but i have already used the same logic but it is not working my logic is:--

public void keyPressed (KeyEvent ke)
{
int code=ke.getKeyCode();
if(code==KeyEvent.VK_DELETE && flag==true)
consume=true;// used to consumed the key in the keytyped event
}

thanks
19 years ago