0001: package com.salmonllc.html;
0002:
0003: import com.salmonllc.html.events.SubmitEvent;
0004: import com.salmonllc.html.events.SubmitListener;
0005:
0006: import com.salmonllc.localizer.LanguagePreferences;
0007: import com.salmonllc.localizer.LanguageResourceFinder;
0008:
0009: import com.salmonllc.properties.Props;
0010:
0011: import com.salmonllc.sql.*;
0012:
0013: import com.salmonllc.util.*;
0014:
0015: /////////////////////////
0016: //$Archive: /SOFIA/SourceCode/com/salmonllc/html/HtmlSubmitImage.java $
0017: //$Author: Dan $
0018: //$Revision: 44 $
0019: //$Modtime: 11/01/04 11:52a $
0020: /////////////////////////
0021: import java.awt.*;
0022: import java.io.IOException;
0023: import java.io.OutputStream;
0024: import java.util.Hashtable;
0025: import java.util.Vector;
0026:
0027: /**
0028: * This class generate an image in the html page that will submit the page when
0029: * clicked.
0030: */
0031: public class HtmlSubmitImage extends HtmlComponent implements
0032: ImageGenerator {
0033: public static final int ALIGN_NONE = 0;
0034: public static final int ALIGN_LEFT = 1;
0035: public static final int ALIGN_RIGHT = 2;
0036: public static final int ALIGN_TOP = 3;
0037: public static final int ALIGN_ABSMIDDLE = 4;
0038: public static final int ALIGN_ABSBOTTOM = 5;
0039: public static final int ALIGN_TEXTTOP = 6;
0040: public static final int ALIGN_MIDDLE = 7;
0041: public static final int ALIGN_BASELINE = 8;
0042: public static final int ALIGN_BOTTOM = 9;
0043: public static final String STYLE_RECTANGLE = "RECTANGLE";
0044: public static final String STYLE_OVAL = "OVAL";
0045: private static String _alignTypes[] = { "", "LEFT", "RIGHT", "TOP",
0046: "ABSMIDDLE", "ABSBOTTOM", "TEXTTOP", "MIDDLE", "BASELINE",
0047: "BOTTOM" };
0048: private Color _backgroundColor = Color.lightGray;
0049: private Color _bottomRightBorder = Color.gray;
0050: private Color _textColor = Color.black;
0051: private Color _topLeftBorder = Color.white;
0052: private Color _transparentColor = Color.magenta;
0053: private DataStoreEvaluator _altEval = null;
0054: private DataStoreEvaluator _dsEval = null;
0055:
0056: // Stuff for image generation
0057: private Font _font;
0058: private HtmlInlineFrame _iFrame = null;
0059: private Integer _tabIndex;
0060: private String _accessKey;
0061: private String _alt = "";
0062: private String _displayStyle = STYLE_RECTANGLE;
0063: private String _iFrameUrl = null;
0064: private String _imageURL;
0065: private String _onClick = "";
0066: private String _onmouseout;
0067: private String _onmouseover;
0068: private String _source = "";
0069: private String _style;
0070: private String _textLocaleKey;
0071: private String _theme = null;
0072: private String _urlLocaleKey;
0073: private Vector _listeners;
0074: private boolean _enabled = true;
0075: private boolean _generateImage = false;
0076: private boolean _updateLocale;
0077: private boolean _useCache = true;
0078: private int _align = ALIGN_NONE;
0079: private int _border = 0;
0080: private int _count;
0081: private int _hSpace = -1;
0082: private int _height;
0083: private int _rowNo = -1;
0084: private int _vSpace = -1;
0085: private int _width;
0086: private long _cacheKey = 0;
0087: private String _title;
0088:
0089: /**
0090: * Constructs a new Submit Image. The image will be generated.
0091: *
0092: * @param name
0093: * Each component on a page must have a unique name.
0094: * @param text
0095: * The Text to put on the button.
0096: * @param width
0097: * The width of the button in pixels
0098: * @param height
0099: * The height of the button in pixels
0100: * @param p
0101: * The page the button will be placed in
0102: */
0103: public HtmlSubmitImage(String name, String text, int width,
0104: int height, HtmlPage p) {
0105: this (name, text, width, height, null, p);
0106: }
0107:
0108: /**
0109: * Constructs a new Submit Image. The image will be generated.
0110: *
0111: * @param name
0112: * Each component on a page must have a unique name.
0113: * @param text
0114: * The Text to put on the button.
0115: * @param width
0116: * The width of the button in pixels
0117: * @param height
0118: * The height of the button in pixels
0119: * @param theme
0120: * The theme to use for the button image
0121: * @param p
0122: * The page the button will be placed in
0123: */
0124: public HtmlSubmitImage(String name, String text, int width,
0125: int height, String theme, HtmlPage p) {
0126: super (name, p);
0127: _source = text;
0128: _width = width;
0129: _height = (height > 0) ? height : getPage().getPageProperties()
0130: .getIntProperty(Props.SUBMIT_IMAGE_DEFAULT_HEIGHT);
0131: _generateImage = true;
0132: p.registerImageGenerator(getFullName(), this );
0133: setTheme(theme);
0134: }
0135:
0136: /**
0137: * Constructs a new Submit Image. The width of the button is determined by
0138: * the width of the text.
0139: *
0140: * @param name
0141: * Each component on a page must have a unique name.
0142: * @param text
0143: * The Text to put on the button.
0144: * @param height
0145: * The height of the button in pixels
0146: * @param p
0147: * The page the button will be placed in
0148: */
0149: public HtmlSubmitImage(String name, String text, int height,
0150: HtmlPage p) {
0151: this (name, text, -1, height, null, p);
0152: }
0153:
0154: /**
0155: * Constructs a new Submit Image. The width of the button is determined by
0156: * the size of the text.
0157: *
0158: * @param name
0159: * Each component on a page must have a unique name.
0160: * @param text
0161: * The Text to put on the button.
0162: * @param height
0163: * The height of the button in pixels
0164: * @param theme
0165: * The theme to use for the button image
0166: * @param p
0167: * The page the button will be placed in
0168: */
0169: public HtmlSubmitImage(String name, String text, int height,
0170: String theme, HtmlPage p) {
0171: this (name, text, -1, height, theme, p);
0172: }
0173:
0174: /**
0175: * Constructs a new Submit Image.
0176: *
0177: * @param name
0178: * Each component on a page must have a unique name.
0179: * @param url
0180: * The url of the image to appear on the button.
0181: * @param p
0182: * The page the button will be placed in
0183: */
0184: public HtmlSubmitImage(String name, String url, HtmlPage p) {
0185: super (name, p);
0186: _source = url;
0187: _generateImage = false;
0188: }
0189:
0190: /**
0191: * DOCUMENT ME!
0192: *
0193: * @param string
0194: * the access key html attribute
0195: */
0196: public void setAccessKey(String string) {
0197: _accessKey = string;
0198: }
0199:
0200: /**
0201: * DOCUMENT ME!
0202: *
0203: * @return the access key html attribute
0204: */
0205: public String getAccessKey() {
0206: return _accessKey;
0207: }
0208:
0209: /**
0210: * This method sets the align property for the component
0211: *
0212: * @param align
0213: * DOCUMENT ME!
0214: */
0215: public void setAlign(int align) {
0216: _align = align;
0217: }
0218:
0219: /**
0220: * This method sets the align property for the component using the HTML
0221: * attribute values
0222: *
0223: * @param align
0224: * DOCUMENT ME!
0225: */
0226: public void setAlign(String align) {
0227: int iAlign = ALIGN_NONE;
0228:
0229: if (align != null) {
0230: align = align.toUpperCase();
0231:
0232: for (int i = 0; i < _alignTypes.length; i++) {
0233: if (_alignTypes[i].equals(align)) {
0234: /*
0235: * srufle : Aug 6, 2004 10 : 26 : 09 AM iAlign = i + 1; To
0236: * compensate for an off by one error I also added a "" to
0237: * the beginning of the _alignTypes
0238: */
0239: iAlign = i;
0240:
0241: break;
0242: }
0243: }
0244: }
0245:
0246: setAlign(iAlign);
0247: }
0248:
0249: /**
0250: * This method gets the align property for the component
0251: *
0252: * @return DOCUMENT ME!
0253: */
0254: public int getAlign() {
0255: return _align;
0256: }
0257:
0258: /**
0259: * This method sets the tool tip for the image
0260: *
0261: * @param alt
0262: * DOCUMENT ME!
0263: */
0264: public void setAlt(String alt) {
0265: _alt = alt;
0266: }
0267:
0268: /**
0269: * Returns the tool tip for the image
0270: *
0271: * @return DOCUMENT ME!
0272: */
0273: public String getAlt() {
0274: return _alt;
0275: }
0276:
0277: /**
0278: * Use this method to bind the alt property to an expression in a DataStore
0279: *
0280: * @param ds
0281: * The DataStore to bind to.
0282: * @param expression
0283: * The expression to bind to.
0284: *
0285: * @throws Exception
0286: * DOCUMENT ME!
0287: *
0288: * @see DataStoreEvaluator
0289: */
0290: public void setAltExpression(DataStoreBuffer ds, String expression)
0291: throws Exception {
0292: _altEval = new DataStoreEvaluator(ds, expression);
0293: }
0294:
0295: /**
0296: * This method gets the DataStoreEvaluator being used for alt expressions.
0297: *
0298: * @return DataStoreEvaluator
0299: *
0300: * @see DataStoreEvaluator
0301: */
0302: public DataStoreEvaluator getAltExpression() {
0303: return _altEval;
0304: }
0305:
0306: /**
0307: * This method sets the background color for the generated image
0308: *
0309: * @param c
0310: * DOCUMENT ME!
0311: */
0312: public void setBackgroundColor(Color c) {
0313: _backgroundColor = c;
0314: }
0315:
0316: /**
0317: * This method sets the background color for the generated image
0318: *
0319: * @param s
0320: * DOCUMENT ME!
0321: */
0322: public void setBackgroundColor(String s) {
0323: Color c = Util.stringToColor(s);
0324:
0325: if (c != null) {
0326: setBackgroundColor(c);
0327: }
0328: }
0329:
0330: /**
0331: * This method returns the background color if the image is generated
0332: *
0333: * @return DOCUMENT ME!
0334: */
0335: public Color getBackgroundColor() {
0336: return _backgroundColor;
0337: }
0338:
0339: /**
0340: * This method sets the border property for the component
0341: *
0342: * @param border
0343: * DOCUMENT ME!
0344: */
0345: public void setBorder(int border) {
0346: _border = border;
0347: }
0348:
0349: /**
0350: * This method gets the border property for the component
0351: *
0352: * @return DOCUMENT ME!
0353: */
0354: public int getBorder() {
0355: return _border;
0356: }
0357:
0358: /**
0359: * This method sets the bottom and right border color for the generated
0360: * image
0361: *
0362: * @param c
0363: * DOCUMENT ME!
0364: */
0365: public void setBottomRightColor(Color c) {
0366: _bottomRightBorder = c;
0367: }
0368:
0369: /**
0370: * This method sets the bottom and right border color for the generated
0371: * image
0372: *
0373: * @param s
0374: * DOCUMENT ME!
0375: */
0376: public void setBottomRightColor(String s) {
0377: Color c = Util.stringToColor(s);
0378:
0379: if (c != null) {
0380: setBottomRightColor(c);
0381: }
0382: }
0383:
0384: /**
0385: * This method returns the bottom right border color if the image is
0386: * generated
0387: *
0388: * @return DOCUMENT ME!
0389: */
0390: public Color getBottomRightColor() {
0391: return _bottomRightBorder;
0392: }
0393:
0394: public void setCacheKey(long key) {
0395: _cacheKey = key;
0396: }
0397:
0398: public long getCacheKey() {
0399: return _cacheKey;
0400: }
0401:
0402: /**
0403: * This method sets the Display Style for a generated image button. Valid
0404: * Values are STYLE_RECTANGLE and STYLE_OVAL
0405: *
0406: * @param style
0407: * DOCUMENT ME!
0408: */
0409: public void setDisplayStyle(String style) {
0410: _displayStyle = style;
0411: }
0412:
0413: /**
0414: * This method gets the Display Style for a generated image button. Valid
0415: * Values are STYLE_RECTANGLE and STYLE_OVAL
0416: *
0417: * @return DOCUMENT ME!
0418: */
0419: public String getDisplayStyle() {
0420: return _displayStyle;
0421: }
0422:
0423: /**
0424: * This method will set whether or not clicking on the image will do a
0425: * submit.
0426: *
0427: * @param enabled
0428: * DOCUMENT ME!
0429: */
0430: public void setEnabled(boolean enabled) {
0431: _enabled = enabled;
0432: }
0433:
0434: /**
0435: * This method returns whether or not clicking on the image will do a
0436: * submit.
0437: *
0438: * @return DOCUMENT ME!
0439: */
0440: public boolean getEnabled() {
0441: return _enabled;
0442: }
0443:
0444: /**
0445: * Use this method to bind this component to an expression in a DataStore
0446: *
0447: * @param ds
0448: * The DataStore to bind to.
0449: * @param expression
0450: * The expression to bind to.
0451: *
0452: * @throws Exception
0453: * DOCUMENT ME!
0454: *
0455: * @see DataStoreEvaluator
0456: */
0457: public void setExpression(DataStoreBuffer ds,
0458: DataStoreExpression expression) throws Exception {
0459: _dsEval = new DataStoreEvaluator(ds, expression);
0460: }
0461:
0462: /**
0463: * Use this method to bind this component to an expression in a
0464: * DataStoreBuffer. The resulting expression wil be formatted according to
0465: * the pattern specified.
0466: *
0467: * @param ds
0468: * The DataStore to bind to.
0469: * @param expression
0470: * The expression to bind to.
0471: * @param format
0472: * The patter to use to format the result
0473: *
0474: * @throws Exception
0475: * DOCUMENT ME!
0476: *
0477: * @see DataStore#setFormat
0478: * @see DataStoreEvaluator
0479: */
0480: public void setExpression(DataStoreBuffer ds,
0481: DataStoreExpression expression, String format)
0482: throws Exception {
0483: _dsEval = new DataStoreEvaluator(ds, expression, format);
0484: }
0485:
0486: /**
0487: * Use this method to bind this component to an expression in a DataStore
0488: *
0489: * @param ds
0490: * The DataStore to bind to.
0491: * @param expression
0492: * The expression to bind to.
0493: *
0494: * @throws Exception
0495: * DOCUMENT ME!
0496: *
0497: * @see DataStoreEvaluator
0498: */
0499: public void setExpression(DataStoreBuffer ds, String expression)
0500: throws Exception {
0501: _dsEval = new DataStoreEvaluator(ds, expression);
0502: }
0503:
0504: /**
0505: * Use this method to bind this component to an expression in a
0506: * DataStoreBuffer. The resulting expression wil be formatted according to
0507: * the pattern specified.
0508: *
0509: * @param ds
0510: * The DataStore to bind to.
0511: * @param expression
0512: * The expression to bind to.
0513: * @param format
0514: * The patter to use to format the result
0515: *
0516: * @throws Exception
0517: * DOCUMENT ME!
0518: *
0519: * @see DataStore#setFormat
0520: * @see DataStoreEvaluator
0521: */
0522: public void setExpression(DataStoreBuffer ds, String expression,
0523: String format) throws Exception {
0524: _dsEval = new DataStoreEvaluator(ds, expression, format);
0525: }
0526:
0527: /**
0528: * This method gets the DataStoreEvaluator being used for expressions.
0529: *
0530: * @return DataStoreEvaluator
0531: *
0532: * @see DataStoreEvaluator
0533: */
0534: public DataStoreEvaluator getExpression() {
0535: return _dsEval;
0536: }
0537:
0538: /**
0539: * This method sets the font used for dynamically generated images.
0540: *
0541: * @param f
0542: * DOCUMENT ME!
0543: */
0544: public void setFont(Font f) {
0545: _font = f;
0546: }
0547:
0548: /**
0549: * This method sets the font used for dynamically generated images.
0550: *
0551: * @param name
0552: * DOCUMENT ME!
0553: * @param style
0554: * DOCUMENT ME!
0555: * @param size
0556: * DOCUMENT ME!
0557: */
0558: public void setFont(String name, int style, int size) {
0559: if ((name == null) && (style == -1) && (size == -1)) {
0560: return;
0561: }
0562:
0563: if (name == null) {
0564: name = "Helvetica";
0565: }
0566:
0567: if ((style < 0) || (style > 3)) {
0568: style = Font.PLAIN;
0569: }
0570:
0571: if (size == -1) {
0572: size = 12;
0573: }
0574:
0575: _font = new Font(name, style, size);
0576: }
0577:
0578: /**
0579: * This method returns the font used for dynamically generated images.
0580: *
0581: * @return DOCUMENT ME!
0582: */
0583: public Font getFont() {
0584: return _font;
0585: }
0586:
0587: /**
0588: * This method sets the width in pixels for the generated image
0589: *
0590: * @param height
0591: * DOCUMENT ME!
0592: */
0593: public void setHeight(int height) {
0594: _height = height;
0595: }
0596:
0597: /**
0598: * This method gets the height in pixels for the generated image
0599: *
0600: * @return DOCUMENT ME!
0601: */
0602: public int getHeight() {
0603: return _height;
0604: }
0605:
0606: /**
0607: * set the hspace.
0608: *
0609: * @param hSpace
0610: * DOCUMENT ME!
0611: */
0612: public void setHorizontalSpace(int hSpace) {
0613: _hSpace = hSpace;
0614: }
0615:
0616: /**
0617: * get the Horizontal Space
0618: *
0619: * @return DOCUMENT ME!
0620: */
0621: public int getHorizontalSpace() {
0622: return _hSpace;
0623: }
0624:
0625: /**
0626: * Use this method if you want the button to submit only a layer of the page
0627: * and not the whole page
0628: *
0629: * @param iFrame
0630: * The IFrame component that should be loaded
0631: */
0632: public void setIFrameSubmit(HtmlInlineFrame iFrame) {
0633: _iFrame = iFrame;
0634: }
0635:
0636: /**
0637: * This method sets the javascript that will be executed when the button is
0638: * clicked.
0639: *
0640: * @param onClick
0641: * DOCUMENT ME!
0642: */
0643: public void setOnClick(String onClick) {
0644: _onClick = onClick;
0645: }
0646:
0647: /**
0648: * This method gets the javascript that will be executed when the button is
0649: * clicked.
0650: *
0651: * @return DOCUMENT ME!
0652: */
0653: public String getOnClick() {
0654: return _onClick;
0655: }
0656:
0657: /**
0658: * DOCUMENT ME!
0659: *
0660: * @param string
0661: * Updates the onmouseout event string
0662: */
0663: public void setOnMouseOut(String string) {
0664: _onmouseout = string;
0665: }
0666:
0667: /**
0668: * DOCUMENT ME!
0669: *
0670: * @param string
0671: * Updates the onmouseover event string
0672: */
0673: public void setOnMouseOver(String string) {
0674: _onmouseover = string;
0675: }
0676:
0677: /**
0678: * Set the html style attribute
0679: *
0680: * @param style
0681: */
0682: public void setStyle(String style) {
0683: _style = style;
0684: }
0685:
0686: /**
0687: * Get the html style attribute
0688: *
0689: * @return
0690: */
0691: public String getStyle() {
0692: return _style;
0693: }
0694:
0695: /**
0696: * DOCUMENT ME!
0697: *
0698: * @param val
0699: * the tab index html attribute. You can also pass
0700: * TAB_INDEX_DEFAULT to use the default tab index for the
0701: * component or TAB_INDEX_NONE to keep this component from being
0702: * tabbed to
0703: */
0704: public void setTabIndex(int val) {
0705: if (val == -1) {
0706: _tabIndex = null;
0707: } else {
0708: _tabIndex = new Integer(val);
0709: }
0710: }
0711:
0712: /**
0713: * DOCUMENT ME!
0714: *
0715: * @return the tab index html attribute
0716: */
0717: public int getTabIndex() {
0718: if (_tabIndex == null) {
0719: return -1;
0720: }
0721:
0722: return _tabIndex.intValue();
0723: }
0724:
0725: /**
0726: * This method sets the text for the for the dynamically generated image.
0727: *
0728: * @param text
0729: * DOCUMENT ME!
0730: */
0731: public void setText(String text) {
0732: if (_generateImage) {
0733: _source = text;
0734: _useCache = false;
0735: }
0736: }
0737:
0738: /**
0739: * This method returns the text for the button
0740: *
0741: * @return java.lang.String
0742: */
0743: public String getText() {
0744: if (_generateImage) {
0745: return _source;
0746: } else {
0747: return null;
0748: }
0749: }
0750:
0751: /**
0752: * This method sets the text color for the generated image
0753: *
0754: * @param c
0755: * DOCUMENT ME!
0756: */
0757: public void setTextColor(Color c) {
0758: _textColor = c;
0759: }
0760:
0761: /**
0762: * This method sets the text color for the generated image
0763: *
0764: * @param s
0765: * DOCUMENT ME!
0766: */
0767: public void setTextColor(String s) {
0768: Color c = Util.stringToColor(s);
0769:
0770: if (c != null) {
0771: setTextColor(c);
0772: }
0773: }
0774:
0775: /**
0776: * This method returns the text color if the image is generated
0777: *
0778: * @return DOCUMENT ME!
0779: */
0780: public Color getTextColor() {
0781: return _textColor;
0782: }
0783:
0784: /**
0785: * Returns the Locale key used for text
0786: *
0787: * @param textLocaleKey
0788: * DOCUMENT ME!
0789: */
0790: public void setTextLocaleKey(String textLocaleKey) {
0791: _textLocaleKey = textLocaleKey;
0792: _updateLocale = true;
0793: }
0794:
0795: /**
0796: * Returns the Locale key used for the text of this component
0797: *
0798: * @return DOCUMENT ME!
0799: */
0800: public String getTextLocaleKey() {
0801: return _textLocaleKey;
0802: }
0803:
0804: /**
0805: * This method sets the property theme for the component.
0806: *
0807: * @param theme
0808: * The theme to use.
0809: */
0810: public void setTheme(String theme) {
0811: Props props = getPage().getPageProperties();
0812:
0813: String font = props.getThemeProperty(theme,
0814: Props.SUBMIT_IMAGE_FONT_FACE);
0815: int fontStyle = props.getThemeIntProperty(theme,
0816: Props.SUBMIT_IMAGE_FONT_STYLE);
0817: int size = props.getThemeIntProperty(theme,
0818: Props.SUBMIT_IMAGE_FONT_SIZE);
0819: setFont(font, fontStyle, size);
0820:
0821: Color c = props.getThemeColorProperty(theme,
0822: Props.SUBMIT_IMAGE_TEXT_COLOR);
0823:
0824: if (c != null) {
0825: _textColor = c;
0826: }
0827:
0828: c = props.getThemeColorProperty(theme,
0829: Props.SUBMIT_IMAGE_BACKGROUND_COLOR);
0830:
0831: if (c != null) {
0832: _backgroundColor = c;
0833: }
0834:
0835: if (_height == -1) {
0836: _height = props.getThemeIntProperty(theme,
0837: Props.SUBMIT_IMAGE_DEFAULT_HEIGHT);
0838: }
0839:
0840: c = props.getThemeColorProperty(theme,
0841: Props.SUBMIT_IMAGE_TOPLEFT_BORDER_COLOR);
0842:
0843: if (c != null) {
0844: _topLeftBorder = c;
0845: }
0846:
0847: c = props.getThemeColorProperty(theme,
0848: Props.SUBMIT_IMAGE_BOTTOMRIGHT_BORDER_COLOR);
0849:
0850: if (c != null) {
0851: _bottomRightBorder = c;
0852: }
0853:
0854: c = props.getThemeColorProperty(theme,
0855: Props.SUBMIT_IMAGE_TRANSPARENT_COLOR);
0856:
0857: if (c != null) {
0858: _transparentColor = c;
0859: }
0860:
0861: String style = props.getThemeProperty(theme,
0862: Props.SUBMIT_IMAGE_STYLE);
0863:
0864: if (style != null) {
0865: if (style.toUpperCase().equals(STYLE_OVAL)) {
0866: _displayStyle = STYLE_OVAL;
0867: } else {
0868: _displayStyle = STYLE_RECTANGLE;
0869: }
0870: }
0871:
0872: _theme = theme;
0873: }
0874:
0875: /**
0876: * This method returns the property theme for the component.
0877: *
0878: * @return DOCUMENT ME!
0879: */
0880: public String getTheme() {
0881: return _theme;
0882: }
0883:
0884: /**
0885: * This method sets the top and left border color for the generated image
0886: *
0887: * @param c
0888: * DOCUMENT ME!
0889: */
0890: public void setTopLeftColor(Color c) {
0891: _topLeftBorder = c;
0892: }
0893:
0894: /**
0895: * This method sets the top and left border color for the generated image
0896: *
0897: * @param s
0898: * DOCUMENT ME!
0899: */
0900: public void setTopLeftColor(String s) {
0901: Color c = Util.stringToColor(s);
0902:
0903: if (c != null) {
0904: setTopLeftColor(c);
0905: }
0906: }
0907:
0908: /**
0909: * This method returns the top and left border color if the image is
0910: * generated
0911: *
0912: * @return DOCUMENT ME!
0913: */
0914: public Color getTopLeftColor() {
0915: return _topLeftBorder;
0916: }
0917:
0918: /**
0919: * This method sets the color that represents tranparent for the generated
0920: * image
0921: *
0922: * @param c
0923: * DOCUMENT ME!
0924: */
0925: public void setTransparentColor(Color c) {
0926: _transparentColor = c;
0927: }
0928:
0929: /**
0930: * This method sets the color that represents tranparent for the generated
0931: * image
0932: *
0933: * @param s
0934: * DOCUMENT ME!
0935: */
0936: public void setTransparentColor(String s) {
0937: Color c = Util.stringToColor(s);
0938:
0939: if (c != null) {
0940: setTransparentColor(c);
0941: }
0942: }
0943:
0944: /**
0945: * This method returns the color that will be represent transparent if the
0946: * image is generated
0947: *
0948: * @return DOCUMENT ME!
0949: */
0950: public Color getTransparentColor() {
0951: return _transparentColor;
0952: }
0953:
0954: /**
0955: * This method sets the url for the image that will be displayed on the
0956: * button in the browser.
0957: *
0958: * @param name
0959: * DOCUMENT ME!
0960: */
0961: public void setURL(String name) {
0962: if (!_generateImage) {
0963: _source = name;
0964: }
0965: }
0966:
0967: /**
0968: * This method returns the url for the image that will be displayed on the
0969: * button in the browser.
0970: *
0971: * @return java.lang.String
0972: */
0973: public String getURL() {
0974: if (!_generateImage) {
0975: return _source;
0976: } else {
0977: return null;
0978: }
0979: }
0980:
0981: /**
0982: * Sets the Locale key used for the image URL
0983: *
0984: * @param urlLocaleKey
0985: * DOCUMENT ME!
0986: */
0987: public void setURLLocaleKey(String urlLocaleKey) {
0988: _urlLocaleKey = urlLocaleKey;
0989: _updateLocale = true;
0990: }
0991:
0992: /**
0993: * Returns the Locale key used for the source url
0994: *
0995: * @return DOCUMENT ME!
0996: */
0997: public String getURLLocaleKey() {
0998: return _urlLocaleKey;
0999: }
1000:
1001: public void setUseCache(boolean useCache) {
1002: _useCache = useCache;
1003: }
1004:
1005: /**
1006: * If the image is dynamically generated, this method will indicate whether
1007: * or not the Objectstore should cache it.
1008: *
1009: * @return DOCUMENT ME!
1010: */
1011: public boolean getUseCache() {
1012: return _useCache;
1013: }
1014:
1015: /**
1016: * set the vspace.
1017: *
1018: * @param vSpace
1019: * DOCUMENT ME!
1020: */
1021: public void setVerticalSpace(int vSpace) {
1022: _vSpace = vSpace;
1023: }
1024:
1025: /**
1026: * get the Vertical Space
1027: *
1028: * @return DOCUMENT ME!
1029: */
1030: public int getVerticalSpace() {
1031: return _vSpace;
1032: }
1033:
1034: /**
1035: * This method sets the width in pixels for the generated image
1036: *
1037: * @param width
1038: * DOCUMENT ME!
1039: */
1040: public void setWidth(int width) {
1041: _width = width;
1042: }
1043:
1044: /**
1045: * This method gets the width in pixels for the generated image
1046: *
1047: * @return DOCUMENT ME!
1048: */
1049: public int getWidth() {
1050: return _width;
1051: }
1052:
1053: /**
1054: * This method adds a listener the will be notified when this image causes
1055: * the page to be submitted.
1056: *
1057: * @param l
1058: * The listener to add.
1059: */
1060: public void addSubmitListener(SubmitListener l) {
1061: if (_listeners == null) {
1062: _listeners = new Vector();
1063: }
1064:
1065: for (int i = 0; i < _listeners.size(); i++) {
1066: if (((SubmitListener) _listeners.elementAt(i)) == l) {
1067: return;
1068: }
1069: }
1070:
1071: _listeners.addElement(l);
1072: }
1073:
1074: public boolean executeEvent(int type) throws Exception {
1075: if (type != EVENT_SUBMIT) {
1076: return true;
1077: }
1078:
1079: if (_listeners == null) {
1080: return true;
1081: }
1082:
1083: SubmitEvent e = new SubmitEvent(getPage(), this , getName(),
1084: getFullName(), _rowNo);
1085:
1086: for (int i = 0; i < _listeners.size(); i++) {
1087: SubmitListener l = (SubmitListener) _listeners.elementAt(i);
1088: e
1089: .setNextListener((_listeners.size() > (i + 1)) ? _listeners
1090: .elementAt(i + 1)
1091: : null);
1092:
1093: if (!l.submitPerformed(e)) {
1094: return false;
1095: }
1096: }
1097:
1098: return true;
1099: }
1100:
1101: public void generateHTML(java.io.PrintWriter p, int rowNo)
1102: throws Exception {
1103: if (!getVisible()) {
1104: return;
1105: }
1106:
1107: processLocaleInfo();
1108:
1109: //
1110: String name = getFullName();
1111:
1112: if (rowNo > -1) {
1113: name += ("_" + rowNo);
1114: }
1115:
1116: //
1117: String jScript = "";
1118: String out = "";
1119:
1120: if ((_iFrame != null) && (_iFrameUrl == null)) {
1121: String uName = getPage().getClass().getName();
1122: int pos = uName.lastIndexOf(".");
1123:
1124: if (pos > -1) {
1125: uName = uName.substring(pos + 1);
1126: }
1127:
1128: uName += ("-" + _iFrame.getName() + "FrameComponent");
1129: _iFrameUrl = uName;
1130: }
1131:
1132: if (_dsEval != null) {
1133: if (rowNo > -1) {
1134: _source = _dsEval.evaluateRowFormat(rowNo);
1135: } else {
1136: _source = _dsEval.evaluateRowFormat();
1137: }
1138: }
1139:
1140: String source = _source;
1141: source = translateSiteMapURL(source);
1142:
1143: if (_generateImage) {
1144: // sr 11-01-2000 this replaces the call to generateImageURL() in the
1145: // constructor
1146: if (_imageURL == null) {
1147: _imageURL = generateImageURL();
1148: }
1149:
1150: source = _imageURL + "default.dgif";
1151: source = translateSiteMapURL(source);
1152:
1153: if (!_useCache) {
1154: source += ("?ct=" + _count++);
1155: }
1156: }
1157:
1158: // ALT
1159: String alt = _alt;
1160:
1161: if (_altEval != null) {
1162: if (rowNo > -1) {
1163: alt = _altEval.evaluateRowFormat(rowNo);
1164: } else {
1165: alt = _altEval.evaluateRowFormat();
1166: }
1167: }
1168:
1169: String onClick = _onClick;
1170: String valScript = HtmlValidatorText
1171: .generateOnClickJavaScriptForButtons(_onClick,
1172: _listeners, getFullName());
1173:
1174: if (valScript != null) {
1175: out += valScript;
1176: onClick = "return "
1177: + HtmlValidatorText
1178: .generateOnClickJavaScriptFunctionName(getFullName())
1179: + ";";
1180: }
1181:
1182: //
1183: if (!_enabled) {
1184: if (_generateImage) {
1185: source = _imageURL + "disabled.dgif";
1186: source = translateSiteMapURL(source);
1187: }
1188:
1189: out += ("<IMG NAME=\"" + getFullName() + "\" BORDER=\""
1190: + _border + "\" NAME=\"" + name + "\" SRC=\""
1191: + source + "\"");
1192:
1193: if (!Util.isNull(alt) && !Util.isEmpty(alt)) {
1194: out += (" ALT=\"" + alt + "\"");
1195: }
1196:
1197: // HSPACE
1198: if (_hSpace > -1) {
1199: out += (" HSPACE=\"" + _hSpace + "\"");
1200: }
1201:
1202: // VSPACE
1203: if (_vSpace > -1) {
1204: out += (" VSPACE=\"" + _vSpace + "\"");
1205: }
1206:
1207: // ALIGN
1208: if ((_align > ALIGN_NONE) && (_align < _alignTypes.length)) {
1209: out += (" ALIGN=\"" + _alignTypes[_align] + "\"");
1210: }
1211:
1212: if (Util.isFilled(getStyle())) {
1213: out += (" style=\"" + getStyle() + "\"");
1214: }
1215:
1216: //onmouseover EVENT
1217: if (_onmouseover != null) {
1218: out += (" ONMOUSEOVER=\"" + _onmouseover + "\"");
1219: }
1220:
1221: //onmouseout EVENT
1222: if (_onmouseout != null) {
1223: out += (" ONMOUSEOUT=\"" + _onmouseout + "\"");
1224: }
1225:
1226: if (_tabIndex != null) {
1227: out += (" tabindex=\"" + _tabIndex + "\"");
1228: }
1229:
1230: if (_accessKey != null) {
1231: out += (" accesskey=\"" + _accessKey + "\"");
1232: }
1233:
1234: out += ">";
1235: } else {
1236: if ((_iFrame == null)
1237: || ((jScript = getPage().getSubmitJavaScript(this ,
1238: _iFrameUrl, _iFrame)) == null)) {
1239: out += ("<INPUT TYPE=\"IMAGE\" BORDER=\"" + _border
1240: + "\" NAME=\"" + name + "\"");
1241:
1242: // ALT
1243: if (!Util.isNull(alt) && !Util.isEmpty(alt)) {
1244: out += (" ALT=\"" + alt + "\"");
1245: }
1246:
1247: // HSPACE
1248: if (_hSpace > -1) {
1249: out += (" HSPACE=\"" + _hSpace + "\"");
1250: }
1251:
1252: // VSPACE
1253: if (_vSpace > -1) {
1254: out += (" VSPACE=\"" + _vSpace + "\"");
1255: }
1256:
1257: // ALIGN
1258: if ((_align > ALIGN_NONE)
1259: && (_align < _alignTypes.length)) {
1260: out += (" ALIGN=\"" + _alignTypes[_align] + "\"");
1261: }
1262:
1263: // STYLE
1264: if (Util.isFilled(getStyle())) {
1265: out += (" style=\"" + getStyle() + "\"");
1266: }
1267:
1268: //onmouseover EVENT
1269: if (_onmouseover != null) {
1270: out += (" ONMOUSEOVER=\"" + _onmouseover + "\"");
1271: }
1272:
1273: //onmouseout EVENT
1274: if (_onmouseout != null) {
1275: out += (" ONMOUSEOUT=\"" + _onmouseout + "\"");
1276: }
1277:
1278: if (_tabIndex != null) {
1279: out += (" tabindex=\"" + _tabIndex + "\"");
1280: }
1281:
1282: if (_accessKey != null) {
1283: out += (" accesskey=\"" + _accessKey + "\"");
1284: }
1285:
1286: // title
1287: if (_title != null)
1288: out += " TITLE=\"" + _title + "\"";
1289:
1290: out += (" SRC=\""
1291: + source
1292: + "\""
1293: + (((onClick != null) && !onClick.trim()
1294: .equals("")) ? (" onClick=\"" + onClick + "\"")
1295: : "") + ">");
1296: } else {
1297: out += ("<A NAME=\"" + getFullName()
1298: + "LINKANCHOR\" HREF=\"javascript:" + jScript + "\" >");
1299: out += ("<IMG NAME=\"" + getFullName() + "\" BORDER=\""
1300: + _border + "\" NAME=\"" + name + "\" SRC=\""
1301: + source + "\"");
1302:
1303: // ALT
1304: if (!Util.isNull(alt) && !Util.isEmpty(alt)) {
1305: out += (" ALT=\"" + alt + "\"");
1306: }
1307:
1308: // HSPACE
1309: if (_hSpace > -1) {
1310: out += (" HSPACE=\"" + _hSpace + "\"");
1311: }
1312:
1313: // VSPACE
1314: if (_vSpace > -1) {
1315: out += (" VSPACE=\"" + _vSpace + "\"");
1316: }
1317:
1318: // ALIGN
1319: if ((_align > ALIGN_NONE)
1320: && (_align < _alignTypes.length)) {
1321: out += (" ALIGN=\"" + _alignTypes[_align] + "\"");
1322: }
1323:
1324: // STYLE
1325: if (Util.isFilled(getStyle())) {
1326: out += (" style=\"" + getStyle() + "\"");
1327: }
1328:
1329: if (_tabIndex != null) {
1330: out += (" tabindex=\"" + _tabIndex + "\"");
1331: }
1332:
1333: if (_accessKey != null) {
1334: out += (" accesskey=\"" + _accessKey + "\"");
1335: }
1336:
1337: //onmouseover EVENT
1338: if (_onmouseover != null) {
1339: out += (" ONMOUSEOVER=\"" + _onmouseover + "\"");
1340: }
1341:
1342: //onmouseout EVENT
1343: if (_onmouseout != null) {
1344: out += (" ONMOUSEOUT=\"" + _onmouseout + "\"");
1345: }
1346:
1347: out += "></A>";
1348: }
1349: }
1350:
1351: p.print(out);
1352: }
1353:
1354: public void generateImage(String img, OutputStream out)
1355: throws IOException {
1356: //create an image to draw
1357: ImageFactory fact = new ImageFactory();
1358: Image i = null;
1359:
1360: if (_displayStyle.equals(STYLE_OVAL)) {
1361: if (_width > 0) {
1362: i = fact.createOvalButton(_width, _height, _font,
1363: _source, _textColor, _backgroundColor,
1364: _topLeftBorder, _bottomRightBorder,
1365: _transparentColor, false, _enabled);
1366: } else {
1367: i = fact.createOvalButton(_height, _font, _source,
1368: _textColor, _backgroundColor, _topLeftBorder,
1369: _bottomRightBorder, _transparentColor, false,
1370: _enabled);
1371: }
1372: } else if (_width > 0) {
1373: i = fact
1374: .createRectangleButton(_width, _height, _font,
1375: _source, _textColor, _backgroundColor,
1376: _topLeftBorder, _bottomRightBorder, false,
1377: _enabled);
1378: } else {
1379: i = fact.createRectangleButton(_height, _font, _source,
1380: _textColor, _backgroundColor, _topLeftBorder,
1381: _bottomRightBorder, false, _enabled);
1382: }
1383:
1384: GifEncoder g = new GifEncoder(i, out, true, _transparentColor);
1385: g.encode();
1386: }
1387:
1388: /**
1389: * This method inserts a listener at the beginning of the the listener list.
1390: * It will be notified first when this button causes the page to be
1391: * submitted.
1392: *
1393: * @param l
1394: * The listener to add.
1395: */
1396: public void insertSubmitListener(SubmitListener l) {
1397: if (_listeners == null) {
1398: _listeners = new Vector();
1399: }
1400:
1401: for (int i = 0; i < _listeners.size(); i++) {
1402: if (((SubmitListener) _listeners.elementAt(i)) == l) {
1403: return;
1404: }
1405: }
1406:
1407: _listeners.insertElementAt(l, 0);
1408: }
1409:
1410: public boolean processParms(Hashtable parms, int rowNo)
1411: throws Exception {
1412: String name = getFullName();
1413:
1414: if (rowNo > -1) {
1415: name += ("_" + rowNo);
1416: }
1417:
1418: if (parms.get(name + ".x") != null) {
1419: _rowNo = rowNo;
1420:
1421: return true;
1422: }
1423:
1424: return false;
1425: }
1426:
1427: /**
1428: * This method removes a listener from the list that will be notified if
1429: * this button causes the page to be submitted.
1430: *
1431: * @param l
1432: * The listener to remove.
1433: */
1434: public void removeSubmitListener(SubmitListener l) {
1435: if (_listeners == null) {
1436: return;
1437: }
1438:
1439: for (int i = 0; i < _listeners.size(); i++) {
1440: if (((SubmitListener) _listeners.elementAt(i)) == l) {
1441: _listeners.removeElementAt(i);
1442:
1443: return;
1444: }
1445: }
1446: }
1447:
1448: /**
1449: * Updates the text and format for the current local
1450: */
1451: public void updateLocale() {
1452: _updateLocale = true;
1453: }
1454:
1455: private void processLocaleInfo() {
1456: if (_updateLocale) {
1457: _updateLocale = false;
1458:
1459: LanguagePreferences p = getPage().getLanguagePreferences();
1460:
1461: if (_textLocaleKey != null) {
1462: String newText = LanguageResourceFinder.getResource(
1463: getPage().getApplicationName(), _textLocaleKey,
1464: p);
1465:
1466: if (newText != null) {
1467: setText(newText);
1468: }
1469: }
1470:
1471: if (_urlLocaleKey != null) {
1472: String newURL = LanguageResourceFinder.getResource(
1473: getPage().getApplicationName(), _urlLocaleKey,
1474: p);
1475:
1476: if (newURL != null) {
1477: setURL(newURL);
1478: }
1479: }
1480: }
1481: }
1482:
1483: /**
1484: * @return Returns the _title.
1485: */
1486: public String getTitle() {
1487: return _title;
1488: }
1489:
1490: /**
1491: * @param string
1492: * The _title to set.
1493: */
1494: public void setTitle(String string) {
1495: _title = string;
1496: }
1497: }
|