/* * The contents of this file are subject to the Mozilla Public License Version 1.1 * (the "License"); you may not use this file except in compliance with the License. * You may obtain a copy of the License at . * * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT * WARRANTY OF ANY KIND, either express or implied. See the License for the specific * language governing rights and limitations under the License. * * The Original Code is the Venice Web Community System. * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ package com.silverwrist.venice.servlets.format; import java.io.Writer; import java.io.IOException; import java.util.Enumeration; import java.util.Vector; import com.silverwrist.venice.core.UserContext; import com.silverwrist.venice.core.DataException; public abstract class TCStandardPanel extends TopContentPanel { class TCButton implements ComponentRender { private String image; private String alt_text; private String url; private boolean login_only; private int width; private int height; public TCButton(String image, String alt_text, String url, boolean login_only, int width, int height) { this.image = image; this.alt_text = alt_text; this.url = url; this.login_only = login_only; this.width = width; this.height = height; } // end constructor public void renderHere(Writer out, RenderData rdat) throws IOException { if (url!=null) out.write(""); out.write("\"""); if (url!=null) out.write(""); } // end renderHere public boolean isLoginOnly() { return login_only; } // end isLoginOnly } // end class TCButton // Attributes private String title; private String subtitle; private Vector buttons; private String real_title; private String real_subtitle; private boolean logged_in; protected TCStandardPanel(String title, String subtitle) { this.title = title; this.subtitle = subtitle; this.buttons = new Vector(); this.real_title = title; this.real_subtitle = subtitle; } // end constructor protected TCStandardPanel(TCStandardPanel other) { super(other); this.title = other.title; this.subtitle = other.subtitle; this.buttons = other.buttons; this.real_title = other.title; this.real_subtitle = other.subtitle; } // end constructor private boolean displayButtons() { if (buttons.size()==0) return false; else if (logged_in) return true; boolean login_only = true; Enumeration enum = buttons.elements(); while (login_only && enum.hasMoreElements()) { // attempt to determine if there are any non-"login only" buttons TCButton bn = (TCButton)(enum.nextElement()); login_only = bn.isLoginOnly(); } // end while return !login_only; } // end displayButtons protected void addButton(String image, String alt_text, String url, boolean login_only, int width, int height) { buttons.addElement(new TCButton(image,alt_text,url,login_only,width,height)); } // end addButton protected abstract void renderContent(Writer out, RenderData rdat) throws IOException; public void renderHere(Writer out, RenderData rdat) throws IOException { rdat.writeContentHeader(out,real_title,real_subtitle); if (displayButtons()) { // want to print the buttons out.write("
\n"); Enumeration enum = buttons.elements(); boolean first_post = true; while (enum.hasMoreElements()) { // figure out whether to display this button TCButton bn = (TCButton)(enum.nextElement()); boolean display_me = logged_in; if (logged_in) display_me = true; else display_me = !(bn.isLoginOnly()); if (display_me) { // display this button if (first_post) first_post = false; else out.write("  "); bn.renderHere(out,rdat); } // end if } // end while out.write("\n
\n"); } // end if renderContent(out,rdat); } // end renderHere public void configure(UserContext uc, String parameter) throws DataException { logged_in = uc.isLoggedIn(); } // end configure public void setTitle(String title) { this.real_title = title; } // end setTitle public void setSubtitle(String title) { this.real_subtitle = subtitle; } // end setTitle } // end class TCPanelSIGs