All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.html.custom.MultiSelectExpander Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.html.custom;

import com.hfg.html.Link;

//------------------------------------------------------------------------------
/**
 

Widget for expanding / collapsing a multi-select box.

See this page for an example.

Example:
     HTMLDoc doc = new HTMLDoc();
     HTML html = new HTML();
     doc.setRootTag(html);

     // Add the CSS classes needed
     html.getHead().addStyle(MultiSelectExpander.generateCSS());
     // Add the javascript needed
     html.getHead().addJavascript(MultiSelectExpander.generateJavascript());

     Body body = html.getBody();

     String selectId = "MySelect";

     MultiSelectExpander expander = new MultiSelectExpander(selectId);

     body.br(3);
     body.addSubtag(expander);
     Select select = body.addSelect();

 
@author J. Alex Taylor, hairyfatguy.com */ //------------------------------------------------------------------------------ // com.hfg XML/HTML Coding Library // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com // [email protected] //------------------------------------------------------------------------------ public class MultiSelectExpander extends Link { //########################################################################## // CONSTRUCTORS //########################################################################## //-------------------------------------------------------------------------- public MultiSelectExpander(String inMultiSelectId) { super("javascript:void(0);", "[+]"); setClass("expander"); setTitle("Expand/Contract the multi-select box"); setOnClick("adjustMultiSelectSize(this, '" + inMultiSelectId + "', 0);"); setOnDblClick("adjustMultiSelectSize(this, '" + inMultiSelectId + "', 1);"); } //########################################################################## // PUBLIC METHODS //########################################################################## //-------------------------------------------------------------------------- public static String generateCSS() { StringBuffer css = new StringBuffer(); css.append(".expander {\n" + " background-color: #000000;\n" + " color: #ffffff;\n" + " font-size: 8pt;\n" + " text-decoration: none;\n" + " cursor: default;\n" + " padding: 0px 2px 0px 2px;\n" + " }\n\n"); return css.toString(); } //-------------------------------------------------------------------------- public static String generateJavascript() { StringBuffer js = new StringBuffer(); js.append("//---------------------------------------------------------------\n" + "function adjustMultiSelectSize(inLink, inMultiSelectId, inDblClick)\n" + "{\n" // On a double-click, Safari seems to fire a click event followed by a double-click event. + " var multiSelect = document.getElementById(inMultiSelectId);\n" + " var isExpanded = (inLink.firstChild.data == '[-]');\n" + " if (inDblClick) isExpanded = !isExpanded;\n" + " var newSize = 1;\n" + " \n" + " if (isExpanded)\n" + " {\n" + " inLink.firstChild.data = '[+]';\n" + " newSize = multiSelect.size / 2;\n" + " if (newSize < 1) newSize = 1;\n" + " }\n" + " else\n" + " {\n" + " inLink.firstChild.data = '[-]';\n" + " newSize = multiSelect.size * 2;\n" + " if (newSize > multiSelect.options.length) newSize = multiSelect.options.length;\n" + " }\n" + " \n" + " multiSelect.size = newSize;\n" + " // This forces Safari to redraw the select box\n" + " multiSelect.style.display = 'block';\n" + "}\n\n"); return js.toString(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy