001 /**
002 * $Header: d:\repository\cvs/cc-samples-custom/web/demo/html/AppPainterFactory.html,v 1.4 2006/03/06 19:31:00 P001001 Exp $
003 * $Revision: 1.4 $
004 * $Date: 2006/03/06 19:31:00 $
005 *
006 * ====================================================================
007 *
008 * Copyright (c) 2000 - 2004 SCC Informationssysteme GmbH. All rights
009 * reserved.
010 * Vendor Site : http://www.scc-gmbh.com
011 * Product Site: http://www.common-controls.com
012 *
013 * ====================================================================
014 */
015
016 package com.company.framework.ui.painter.app;
017
018 import com.cc.framework.common.Singleton;
019 import com.cc.framework.ui.MenuType;
020 import com.cc.framework.ui.control.Control;
021 import com.cc.framework.ui.control.ListControl;
022 import com.cc.framework.ui.control.MenuControl;
023 import com.cc.framework.ui.painter.ControlPainter;
024 import com.cc.framework.ui.painter.FramePainter;
025 import com.cc.framework.ui.painter.PainterContext;
026 import com.cc.framework.ui.painter.PainterFactory;
027 import com.cc.framework.ui.painter.ResourceMap;
028 import com.cc.framework.ui.painter.def.DefMenuMainPainter;
029 import com.cc.framework.ui.painter.def.DefMenuToolsPainter;
030 import com.cc.framework.ui.painter.def.DefPainterFactory;
031 import com.company.framework.ui.painter.app.frame.AppSimpleListFramePainter;
032
033 /**
034 * Factory class
035 *
036 * @author <a href="mailto:gschulz@scc-gmbh.com">Gernot Schulz</a>
037 * @version $Revision: 1.4 $
038 * @since 1.0
039 */
040 public final class AppPainterFactory extends DefPainterFactory implements Singleton {
041
042 /**
043 * Serial Version UID
044 */
045 private static final long serialVersionUID = -7067972484030673640L;
046
047 /**
048 * The single instance of this class
049 */
050 private static AppPainterFactory instance = new AppPainterFactory();
051
052 /**
053 * Constructor
054 */
055 protected AppPainterFactory() {
056 super();
057 }
058
059 /**
060 * @see com.cc.framework.ui.painter.PainterFactory#createResourceMap()
061 */
062 protected ResourceMap createResourceMap() {
063 return new AppResourceMap();
064 }
065
066 /**
067 * Returns the unique Id for this Painterfactory
068 *
069 * @return The unique Id for this Painterfactory which is "app"
070 */
071 public String getFactoryId() {
072 return "app";
073 }
074
075 /**
076 * Returns the single instance of the class (singleton)
077 *
078 * @return The single instance of the DefPainterFactory
079 */
080 public static PainterFactory instance() {
081 return instance;
082 }
083
084 /**
085 * @see com.cc.framework.ui.painter.PainterFactory#doCreateFramePainter(com.cc.framework.ui.painter.PainterContext, com.cc.framework.ui.control.Control)
086 */
087 protected FramePainter doCreateFramePainter(PainterContext painterContext, Control ctrl) {
088
089 if (ctrl instanceof ListControl) {
090 return new AppSimpleListFramePainter();
091 } else {
092 return super.doCreateFramePainter(painterContext, ctrl);
093 }
094 }
095
096 /**
097 * @see com.cc.framework.ui.painter.PainterFactory#doCreatePainter(com.cc.framework.ui.painter.PainterContext, com.cc.framework.ui.control.Control)
098 */
099 protected ControlPainter doCreatePainter(PainterContext painterContext, Control ctrl) {
100
101 // In this example we want to use the new AppSimpleListPainter for all ListControls
102 // within the application. To use a painter for only one ListControl you can extend
103 // the ListControl class and register the painter only for this class.
104 if (ctrl instanceof ListControl) {
105 return new AppSimpleListPainter(painterContext, (ListControl) ctrl);
106
107 } else if (ctrl instanceof MenuControl) {
108 MenuType mt = ((MenuControl) ctrl).getType();
109
110 if (MenuType.SIDEBAR.equals(mt)) {
111 return new AppMenuSidebarPainter(painterContext, (MenuControl) ctrl);
112 } else if (MenuType.MAIN.equals(mt)) {
113 return new DefMenuMainPainter(painterContext, (MenuControl) ctrl);
114 } else if (MenuType.TOOLS.equals(mt)) {
115 return new DefMenuToolsPainter(painterContext, (MenuControl) ctrl);
116 }
117 } else {
118 // else let the DefaultPainter render the control
119 return super.doCreatePainter(painterContext, ctrl);
120 }
121
122 return null;
123 }
124 }
|