home *** CD-ROM | disk | FTP | other *** search
- package sub_arctic.lib;
-
- import sub_arctic.input.*;
- import sub_arctic.output.*;
- import sub_arctic.constraints.std_function;
-
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.util.StringTokenizer;
- import java.util.Vector;
- import java.awt.Color;
-
- /**
- * This class takes a string and breaks it into lines which "fit" into
- * the text column's width based on embedded HTML (subset) formatting. This
- * object provides no input behavior.
- *
- * @author Ian Smith
- */
- public class text_flow extends column {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * The text of this object
- */
- protected String _text;
-
- /**
- * Get the text of this object.
- * @return String the text contained in this flow
- */
- public String text() { return _text;}
-
- /**
- * Set the text in this object.
- * @param String t the new text of this object
- */
- public void set_text(String t) {
- _text=t;
- do_layout();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is the minimum size that this object can be before we bother
- * to try to do a layout. This is in pixels.
- */
- protected int minimum_layout_size=20;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Create a new text flow with a given string. This constructor assumes
- * that you are going to set the position of this object with
- * constraints.
- *
- * @param String v the string to put in this text flow.
- * @param int w width of the interactor.
- * @param int h height of the interactor.
- */
- public text_flow(String v, int w, int h)
- {
- /* we DO NOT want size by children */
- super(0 /* ignored */,0 /*ignored */,
- w, h, 2,0,true,true,false /* crucial */,column.LEFT_JUSTIFIED,null);
- set_text(v);
- }
-
- //had:
- //* @exception general PROPAGATED
- //* @exception bad_value PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Create a new text flow with a given string. This constructor assumes
- * that you are going to set the position of this object with
- * constraints and that it is ok for this object to get as tall
- * as necessary to fit the string. If you are using this version,
- * you should probably be using this in conjunction with a
- * panner.
- *
- * @param String v the string to put in this text flow.
- * @param int w width of the interactor.
- */
- public text_flow(String v, int w)
- {
- /* we DO NOT want size by children */
- super(0 /* ignored */,0 /*ignored */,
- w, 10 /*ignored*/, 2,0,true,true,false /* crucial */,
- column.LEFT_JUSTIFIED,null);
-
- /* put a constraint on our height to grow to be the right size */
- set_h_constraint(std_function.offset(LAST_CHILD.Y2(),0));
-
- set_text(v);
- }
-
- //had:
- //* @exception general PROPAGATED
- //* @exception bad_value PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Do the layout procedure. This ends up removing all the children
- * and re-parsing the text. Notes about this parser:<P>
- * <OL>
- * <LI> It is not robust in the face of badly formed HTML.
- * <LI> It expects the <I>de facto</I> standard of using the P tag to
- * separate paragraphs, rather than the more correct P matched with a
- * slash P.
- * <LI> We don't check to see that the tags are matched with the correct
- * slash tag. We just blindly assume you matched them right.
- * </OL>
- */
- protected void do_layout()
- {
-
- /* if we don't have any text, don't bother to do a layout */
- if ((text()==null) ||
- (text()=="")) return;
-
- /* if the object is too small, don't bother because the display
- * will be so ugly as to be useless */
- if (w()<minimum_layout_size) {
- return;
- }
-
- /* remove all the children */
- while (num_children()>0) {
- remove_child(0);
- }
-
- /* initialization of the parser */
- html_element.init(this,text());
- /* do the parse and layout */
- html_element.parse();
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This variable holds the string for the base font name. We
- * default to Helvetica.
- */
- protected String _font_name="Helvetica";
-
- /**
- * Retrieve the current base font name
- * @return String the string with with font name we are using
- */
- public String font_name() { return _font_name;}
-
- /**
- * Set the current base font name. Be aware that this better be a
- * font name that exists on your system and it will only take effect
- * the next time this variable is consulted by the parser. Thus
- * if you want to force this change you'll need to call do_layout
- * yourself.
- */
- public void set_font_name(String fn) {
- _font_name=fn;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * We override the set_raw_w so we can catch changes to the
- * width and do a re-layout.
- * @param int n the new width
- */
- public void set_raw_w(int n)
- {
- super.set_raw_w(n);
- do_layout();
- }
-
- //had:
- //* @exception general PROPAGATED
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is where we hold the basic font size for this text flow.
- */
- protected int _font_size=12;
-
- /**
- * Retrieve the basic font size for this text flow.
- * @return int the font size (in points) for basic text in this flow
- */
- public int font_size() { return _font_size;}
-
- /**
- * Set the font size of this text flow. This does <B>not</B> take
- * effect immediately, but rather on the next layout. Thus, you
- * have to force a re-layout with "do_layout()" if you want this
- * happen now. <H6> When you say "now", what exactly do you mean?</H6>
- * @param int n new basic font size for this flow (in points)
- */
- public void set_font_size(int n) { _font_size=n;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
-
-
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-