htmlinfo.java

来自「Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI」· Java 代码 · 共 156 行

JAVA
156
字号
/*--------------------------------------------------------------------------*
 | Copyright (C) 2006 Christopher Kohlhaas                                  |
 |                                                                          |
 | This program is free software; you can redistribute it and/or modify     |
 | it under the terms of the GNU General Public License as published by the |
 | Free Software Foundation. A copy of the license has been included with   |
 | these distribution in the COPYING file, if not go to www.fsf.org         |
 |                                                                          |
 | As a special exception, you are granted the permissions to link this     |
 | program with every library, which license fulfills the Open Source       |
 | Definition as published by the Open Source Initiative (OSI).             |
 *--------------------------------------------------------------------------*/
package org.rapla.gui.internal.view;

import java.util.Collection;
import java.util.Iterator;

import org.rapla.components.util.xml.XMLWriter;
import org.rapla.entities.Named;
import org.rapla.facade.RaplaComponent;
import org.rapla.framework.RaplaContext;
import org.rapla.framework.RaplaException;

public abstract class HTMLInfo extends RaplaComponent {
    public HTMLInfo(RaplaContext sm) throws RaplaException {
        super(sm);
    }

    protected String createTitle(String type,Object obj) {
        return type;
    }

    /** performs xml-encoding of a string the output goes to the buffer*/
    static public void encode(String text,StringBuffer buf) {
        buf.append( encode ( text ));
    }

    static public String encode(String string) {
        String text = XMLWriter.encode( string );
        if ( text.indexOf('\n') > 0 ) {
            StringBuffer buf = new StringBuffer();
            int size = text.length();
            for ( int i= 0; i<size; i++) {
                char c = text.charAt(i);
                if ( c == '\n' ) {
                   buf.append("<br>");
                } else {
                   buf.append( c );
                } // end of switch ()
            } // end of for ()
            text = buf.toString();
        }
        return text;
    }

    
    static public void addColor(String color,StringBuffer buf) {
        buf.append(" color=\"");
        buf.append(color);
        buf.append('\"');
    }
    
    static public void createTable(Collection attributes,StringBuffer buf,boolean encodeValues) {
        buf.append("<table class=\"infotable\" cellpadding=\"1\">");
        Iterator it = attributes.iterator();
        while (it.hasNext()) {
            Row att =  (Row) it.next();
            buf.append("<tr>\n");
            buf.append("<td class=\"label\" valign=\"top\" style=\"white-space:nowrap\">");
            encode(att.field,buf);
            buf.append(":</td>\n");
            buf.append("<td class=\"value\" valign=\"top\">");
            if (att.value != null) {
                if (encodeValues)
                    encode((String)att.value,buf);
                else
                    buf.append(att.value);
            }
            buf.append("</td>");
            buf.append("</tr>\n");
        }
        buf.append("</table>");
    }

    static public String createTable(Collection attributes, boolean encodeValues) {
        StringBuffer buf = new StringBuffer();
        createTable(attributes, buf, encodeValues);
        return buf.toString();
    }

    static public void createTable(Collection attributes,StringBuffer buf) {
        createTable(attributes,buf,true);
    }


    static public String createTable(Collection attributes) {
        StringBuffer buf = new StringBuffer();
        createTable(attributes,buf);
        return buf.toString();
    }

    
    static public void highlight(String text,StringBuffer buf) {
        buf.append("<FONT color=\"red\">");
        encode(text,buf);
        buf.append("</FONT>");
    }

    static public String highlight(String text) {
        StringBuffer buf = new StringBuffer();
        highlight(text,buf);
        return buf.toString();
    }

    static public void strong(String text,StringBuffer buf) {
        buf.append("<strong>");
        encode(text,buf);
        buf.append("</strong>");
    }

    static public String strong(String text) {
        StringBuffer buf = new StringBuffer();
        strong(text,buf);
        return buf.toString();
    }
    
    abstract protected String getHTML(Object object,LinkController controller) throws RaplaException ;
    protected String getTooltip(Object object) {
        if (object instanceof Named)
            return ((Named) object).getName(getI18n().getLocale());
        return null;
    }

    public class Row {
        String field;
        String value;
        Row(String field,String value) {
            this.field = field;
            this.value = value;
        }
        public String getField() {
            return field;
        }
        public String getValue() {
            return value;
        }
    }

}






⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?