001: //The Salmon Open Framework for Internet Applications (SOFIA)
002: //Copyright (C) 1999 - 2002, Salmon LLC
003: //
004: //This program is free software; you can redistribute it and/or
005: //modify it under the terms of the GNU General Public License version 2
006: //as published by the Free Software Foundation;
007: //
008: //This program is distributed in the hope that it will be useful,
009: //but WITHOUT ANY WARRANTY; without even the implied warranty of
010: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: //GNU General Public License for more details.
012: //
013: //You should have received a copy of the GNU General Public License
014: //along with this program; if not, write to the Free Software
015: //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
016: //
017: //For more information please visit http://www.salmonllc.com
018: package com.salmonllc.examples.example16;
019:
020: import com.salmonllc.swing.SComponentHelper;
021: import com.salmonllc.swing.STextField;
022: import com.salmonllc.personalization.SkinManager;
023: import com.salmonllc.personalization.ProxySkinManager;
024: import com.salmonllc.personalization.Skin;
025:
026: import javax.swing.*;
027: import javax.swing.table.TableColumnModel;
028: import java.awt.*;
029:
030: /*
031: * This applet will get embedded in the CustomizeSwingSkin.jsp page and provide a visual representation of the changes to the skin as they are made
032: */
033:
034: public class TestApplet extends JApplet {
035:
036: public void init() {
037: //figure out the url for the server from the code base for the applet
038: String serverURL = null;
039: String codeBase = getCodeBase().toString();
040: if (codeBase != null) {
041: int pos = codeBase.indexOf("/Jsp/");
042: if (pos != -1)
043: serverURL = codeBase.substring(0, pos);
044: }
045: //if we are running from the ide, the codebase isn't the server URL so use a parm from the applet parms instead
046: if (serverURL == null) {
047: codeBase = getParameter("codeBase");
048: if (codeBase != null)
049: serverURL = codeBase;
050: }
051:
052: //if we use a salmon applet tag, it will have a parm with the session id. We can pass it back to the server so our proxy datastores come from the same session as the rest of the web app does
053: String sessionId = getParameter("servletSessionID");
054:
055: //set up the screen
056: JPanel main = new JPanel();
057: Box layout = Box.createVerticalBox();
058: main.add(layout);
059: getContentPane().add(main);
060:
061: JLabel l = new JLabel("Sample View");
062: l.setAlignmentX(Component.CENTER_ALIGNMENT);
063: layout.add(l);
064: layout.add(Box.createVerticalStrut(10));
065: Box buttonBar = Box.createHorizontalBox();
066: buttonBar.add(new JButton("Enabled"));
067: JButton dis = new JButton("Disabled");
068: dis.setEnabled(false);
069: buttonBar.add(dis);
070: layout.add(buttonBar);
071:
072: layout.add(Box.createVerticalStrut(10));
073: Box textBar = Box.createHorizontalBox();
074: STextField enaT = new STextField();
075: enaT.setText("Enabled");
076: textBar.add(enaT);
077: JTextField disT = new JTextField("Disabled");
078: disT.setEnabled(false);
079: textBar.add(disT);
080: layout.add(textBar);
081:
082: layout.add(Box.createVerticalStrut(10));
083: JPanel tabPanel = new JPanel(new GridLayout(1, 1));
084: String tabData[][] = new String[20][2];
085: for (int i = 0; i < 20; i++) {
086: tabData[i][0] = "Sample Column 1 ";
087: tabData[i][1] = "Sample Column 2 ";
088: }
089: String caps[] = { "Sample Caption 1", "Sample Caption 2" };
090: JTable tab = new JTable(tabData, caps);
091: tab.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
092: tabPanel.setPreferredSize(new Dimension(getBounds().width,
093: getBounds().height - 100));
094: tabPanel.add(new JScrollPane(tab));
095: TableColumnModel mod = tab.getColumnModel();
096: mod.getColumn(0).setPreferredWidth(getBounds().width / 2 + 20);
097: mod.getColumn(1).setPreferredWidth(getBounds().width / 2 + 20);
098: mod.getSelectionModel().setSelectionMode(
099: ListSelectionModel.SINGLE_SELECTION);
100: tab.changeSelection(0, -1, false, false);
101:
102: layout.add(tabPanel);
103:
104: //Now set the look and feel to the default one for the application from a special "TEMP" skin that is set by the editor
105: SkinManager man = new ProxySkinManager(serverURL
106: + "/PersonalizationServer", sessionId);
107: Skin sk = new Skin();
108: man.load("TEMP", sk);
109: SComponentHelper.applySkin(sk, main);
110: }
111: }
|