TestApplet.java :  » J2EE » Sofia » com » salmonllc » examples » example16 » Java Open Source

Java Open Source » J2EE » Sofia 
Sofia » com » salmonllc » examples » example16 » TestApplet.java
//The Salmon Open Framework for Internet Applications (SOFIA)
//Copyright (C) 1999 - 2002, Salmon LLC
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License version 2
//as published by the Free Software Foundation;
//
//This program 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 General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
//
//For more information please visit http://www.salmonllc.com
package com.salmonllc.examples.example16;

import com.salmonllc.swing.SComponentHelper;
import com.salmonllc.swing.STextField;
import com.salmonllc.personalization.SkinManager;
import com.salmonllc.personalization.ProxySkinManager;
import com.salmonllc.personalization.Skin;

import javax.swing.*;
import javax.swing.table.TableColumnModel;
import java.awt.*;

/*
 * 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
 */

public class TestApplet extends JApplet {

    public void init() {
        //figure out the url for the server from the code base for the applet
        String serverURL = null;
        String codeBase = getCodeBase().toString();
        if (codeBase != null) {
            int pos = codeBase.indexOf("/Jsp/");
            if (pos != -1)
                serverURL = codeBase.substring(0, pos);
        }
        //if we are running from the ide, the codebase isn't the server URL so use a parm from the applet parms instead
        if (serverURL == null) {
            codeBase = getParameter("codeBase");
            if (codeBase != null)
                serverURL = codeBase;
        }

        //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
        String sessionId = getParameter("servletSessionID");

        //set up the screen
        JPanel main = new JPanel();
        Box layout = Box.createVerticalBox();
        main.add(layout);
        getContentPane().add(main);

        JLabel l = new JLabel("Sample View");
        l.setAlignmentX(Component.CENTER_ALIGNMENT);
        layout.add(l);
        layout.add(Box.createVerticalStrut(10));
        Box buttonBar = Box.createHorizontalBox();
        buttonBar.add(new JButton("Enabled"));
        JButton dis = new JButton("Disabled");
        dis.setEnabled(false);
        buttonBar.add(dis);
        layout.add(buttonBar);

        layout.add(Box.createVerticalStrut(10));
        Box textBar = Box.createHorizontalBox();
        STextField enaT = new STextField();
        enaT.setText("Enabled");
        textBar.add(enaT);
        JTextField disT = new JTextField("Disabled");
        disT.setEnabled(false);
        textBar.add(disT);
        layout.add(textBar);

        layout.add(Box.createVerticalStrut(10));
        JPanel tabPanel = new JPanel(new GridLayout(1, 1));
        String tabData[][] = new String[20][2];
        for (int i = 0; i < 20; i++) {
            tabData[i][0] = "Sample Column 1 ";
            tabData[i][1] = "Sample Column 2 ";
        }
        String caps[] = {"Sample Caption 1", "Sample Caption 2"};
        JTable tab = new JTable(tabData, caps);
        tab.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        tabPanel.setPreferredSize(new Dimension(getBounds().width, getBounds().height - 100));
        tabPanel.add(new JScrollPane(tab));
        TableColumnModel mod = tab.getColumnModel();
        mod.getColumn(0).setPreferredWidth(getBounds().width / 2 + 20);
        mod.getColumn(1).setPreferredWidth(getBounds().width / 2 + 20);
        mod.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        tab.changeSelection(0, -1, false, false);


        layout.add(tabPanel);

        //Now set the look and feel to the default one for the application from a special "TEMP" skin that is set by the editor
        SkinManager man = new ProxySkinManager(serverURL + "/PersonalizationServer", sessionId);
        Skin sk = new Skin();
        man.load("TEMP", sk);
        SComponentHelper.applySkin(sk, main);
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.