001: package com.salmonllc.examples.example15;
002:
003: //The Salmon Open Framework for Internet Applications (SOFIA)
004: //Copyright (C) 1999 - 2002, Salmon LLC
005: //
006: //This program is free software; you can redistribute it and/or
007: //modify it under the terms of the GNU General Public License version 2
008: //as published by the Free Software Foundation;
009: //
010: //This program is distributed in the hope that it will be useful,
011: //but WITHOUT ANY WARRANTY; without even the implied warranty of
012: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: //GNU General Public License for more details.
014: //
015: //You should have received a copy of the GNU General Public License
016: //along with this program; if not, write to the Free Software
017: //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: //
019: //For more information please visit http://www.salmonllc.com
020:
021: import java.awt.GridLayout;
022: import java.awt.event.MouseAdapter;
023: import java.awt.event.MouseEvent;
024:
025: import javax.swing.BorderFactory;
026: import javax.swing.JApplet;
027: import javax.swing.JPanel;
028:
029: import com.salmonllc.swing.SComponentHelper;
030:
031: /**
032: * The data entry screen hosted in an applet container
033: */
034: public class DataEntryApplet extends JApplet {
035:
036: private MainPanel _main;
037:
038: /**
039: * A work around for a bug in the Java plug where the applet doesn't
040: * always get repainted after a browser resize. This will cause the applet
041: * to be repainted if the users enters it with the mouse.
042: */
043: private class Repainter extends MouseAdapter {
044: public void mouseEntered(MouseEvent e) {
045: getContentPane().repaint();
046: }
047:
048: public void mouseMoved(MouseEvent e) {
049: getContentPane().repaint();
050: }
051: }
052:
053: /**
054: * Does the initialization for the applet
055: */
056: public void init() {
057: //figure out the url for the server from the code base for the applet
058: String serverURL = null;
059: String codeBase = getCodeBase().toString();
060: if (codeBase != null) {
061: int pos = codeBase.indexOf("/Jsp/");
062: if (pos != -1)
063: serverURL = codeBase.substring(0, pos);
064: }
065:
066: //if we are running from the ide, the codebase isn't the server URL so use a parm from the applet parms instead
067: if (serverURL == null) {
068: codeBase = getParameter("codeBase");
069: if (codeBase != null)
070: serverURL = codeBase;
071: }
072:
073: //default serverURL if none is set
074: if (serverURL == null)
075: serverURL = "http://localhost:8080/sofiaExamplesEclipse";
076:
077: //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
078: String sessionId = getParameter("servletSessionID");
079:
080: //set up the screen
081: JPanel border = new JPanel(new GridLayout(1, 1));
082: border.add(_main = new MainPanel(serverURL, sessionId,
083: getBounds().width));
084: if (_main.checkServerConnection()) {
085: getContentPane().add(border);
086: SComponentHelper.setAllComponentsToFocusable(_main);
087: _main.addMouseListener(new Repainter());
088: border.addMouseListener(new Repainter());
089: border.setBorder(BorderFactory
090: .createEmptyBorder(5, 5, 5, 5));
091: }
092: }
093:
094: /**
095: * @see java.applet.Applet#stop()
096: */
097: public void destroy() {
098: super .destroy();
099: //stop the ping thread. The ping thread keeps the server session from
100: //expiring while the applet is running.
101: _main.stopPinging();
102: }
103:
104: }
|