📄 simplebasisams.java
字号:
/* * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, 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 version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */package com.sun.jumpimpl.presentation.simplebasis;import com.sun.jump.command.JUMPIsolateLifecycleRequest;import com.sun.jump.command.JUMPIsolateWindowRequest;import com.sun.jump.common.JUMPWindow;import com.sun.jump.executive.JUMPExecutive;import com.sun.jump.executive.JUMPIsolateFactory;import com.sun.jump.message.JUMPMessageDispatcher;import com.sun.jump.message.JUMPMessageDispatcherTypeException;import com.sun.jump.module.lifecycle.JUMPApplicationLifecycleModule;import com.sun.jump.module.lifecycle.JUMPApplicationLifecycleModuleFactory;import com.sun.jump.module.presentation.JUMPPresentationModule;import com.sun.jump.common.JUMPApplication;import com.sun.jump.common.JUMPContent;import com.sun.jump.executive.JUMPApplicationProxy;import com.sun.jump.executive.JUMPIsolateProxy;import com.sun.jump.message.JUMPMessage;import com.sun.jump.message.JUMPMessageHandler;import com.sun.jump.module.installer.JUMPInstallerModule;import com.sun.jump.module.installer.JUMPInstallerModuleFactory;import com.sun.jump.module.windowing.JUMPWindowingModule;import com.sun.jump.module.windowing.JUMPWindowingModuleFactory;import java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.Dimension;import java.awt.Font;import java.awt.Frame;import java.awt.Graphics;import java.awt.GridLayout;import java.awt.Image;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.FocusEvent;import java.awt.event.FocusListener;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.io.IOException;import java.net.URL;import java.util.Map;import java.util.Vector;/** * A simple JUMP launcher that uses Personal Basis components. */public class SimpleBasisAMS implements JUMPPresentationModule, JUMPMessageHandler { private Frame frame = null; private CommandContainer commandContainer = null; private ScreenContainer screenContainer = null; private JUMPWindowingModuleFactory wmf = null; private JUMPWindowingModule wm = null; private JUMPApplicationLifecycleModuleFactory almf = null; private JUMPApplicationLifecycleModule alm = null; private JUMPIsolateFactory lcm = null; private JUMPApplicationProxy currentApp = null; private Object timeoutObject = null; private boolean appWindowDisplayState = false; private static final int TIMEOUT_VAL = 2000; protected static final int MAX_TITLE_CHARS = 15; private SimpleBasisAMSImageButton applicationsScreenButtons[] = null; private SimpleBasisAMSImageButton switchScreenButtons[] = null; private SimpleBasisAMSImageButton killScreenButtons[] = null; static final int SCREEN_ROWS = 3; static final int SCREEN_COLUMNS = 3; static final int SCREEN_DISPLAY_ICONS = SCREEN_ROWS * SCREEN_COLUMNS; private int CURRENT_SCREEN = 0; private static final int APPLICATIONS_SCREEN = 1; private static final int SWITCHTO_SCREEN = 2; private static final int KILL_SCREEN = 3; private static final int HELP_SCREEN = 4; private static final int PREFS_SCREEN = 5; private static final Color APPLICATIONS_SCREEN_COLOR = new Color(179, 229, 188); private static final Color SWITCHTO_SCREEN_COLOR = new Color(87, 188, 132); private static final Color KILL_SCREEN_COLOR = new Color(229, 183, 179); private static final Color HELP_SCREEN_COLOR = new Color(225, 227, 187); private static final Color PREFS_SCREEN_COLOR = new Color(255, 188, 157); private static final Color BUTTON_BLUE_COLOR = new Color(86, 135, 248); int applicationsScreenPageNumber = 0; int switchToScreenPageNumber = 0; int killScreenPageNumber = 0; SimpleBasisAMSInstall installer = null; static boolean verbose; Map map = null; JUMPMessageDispatcher md = null; Object isolateWindowHandler = null; Object lifecycleHandler = null; /** * Creates a new instance of SimpleBasisAMS */ public SimpleBasisAMS() { } /** * load the presentation module * @param map the configuration data required for loading this module. */ public void load(Map map) { this.map = map; // check if verbose mode is used String verboseStr = System.getProperty("jump.presentation.verbose"); if (verboseStr == null && map != null) { verboseStr = (String) map.get("jump.presentation.verbose"); } if (verboseStr != null && verboseStr.toLowerCase().equals("true")) { verbose = true; } } public void stop() { } public void unload() { } class ScreenContainer extends Container implements FocusListener, KeyListener { public ScreenContainer() { addKeyListener(this); addFocusListener(this); } public boolean isFocusable() { return true; } public void focusGained(FocusEvent e) { transferFocus(); } public void focusLost(FocusEvent e) { } public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { } } class CommandContainer extends Container implements FocusListener, KeyListener { public CommandContainer() { addKeyListener(this); addFocusListener(this); } public Dimension getPreferredSize() { return new Dimension(480, 50); } public boolean isFocusable() { return true; } public void focusGained(FocusEvent e) { transferFocus(); } public void focusLost(FocusEvent e) { } public void keyTyped(KeyEvent e) { } public void keyPressed(KeyEvent e) {; } public void keyReleased(KeyEvent e) { } } private boolean setup() { // the loading of apps will happen in its own thread LoadAppsThread loadAppsThread = new LoadAppsThread(); loadAppsThread.start(); frame = new Frame(); frame.setLayout(new BorderLayout()); commandContainer = new CommandContainer(); commandContainer.setLayout(new GridLayout(0, 4)); addCommandButton("Apps", commandContainer, new ApplicationsScreenActionListener()); addCommandButton("Switch", commandContainer, new SwitchToScreenActionListener()); addCommandButton("Kill", commandContainer, new KillScreenActionListener()); addCommandButton("Help", commandContainer, new HelpScreenActionListener()); addCommandButton("Install", commandContainer, new InstallScreenActionListener()); addCommandButton("Remove", commandContainer, new RemoveScreenActionListener()); addCommandButton("Prefs", commandContainer, new PrefsScreenActionListener()); addCommandButton("Exit", commandContainer, new ExitActionListener()); screenContainer = new ScreenContainer(); screenContainer.setLayout(new BorderLayout()); frame.add(screenContainer, BorderLayout.CENTER); frame.add(commandContainer, BorderLayout.NORTH); wmf = JUMPWindowingModuleFactory.getInstance(); wm = wmf.getModule(); almf = JUMPApplicationLifecycleModuleFactory.getInstance(); alm = almf.getModule(JUMPApplicationLifecycleModuleFactory.POLICY_ONE_LIVE_INSTANCE_ONLY); JUMPExecutive e = JUMPExecutive.getInstance(); md = e.getMessageDispatcher(); lcm = e.getIsolateFactory(); try { isolateWindowHandler = md.registerHandler(JUMPIsolateWindowRequest.MESSAGE_TYPE, this); lifecycleHandler = md.registerHandler(JUMPIsolateLifecycleRequest.MESSAGE_TYPE, this); } catch (JUMPMessageDispatcherTypeException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } try { loadAppsThread.join(); } catch (InterruptedException ex) { ex.printStackTrace(); } installer = new SimpleBasisAMSInstall(this); return true; } public void refreshApplicationsScreen() { // the loading of apps will happen in its own thread LoadAppsThread loadAppsThread = new LoadAppsThread(); loadAppsThread.start(); try { loadAppsThread.join(); } catch (InterruptedException ex) { ex.printStackTrace(); } } class LoadAppsThread extends Thread { public void run() { JUMPApplication apps[] = getInstalledApps(); applicationsScreenButtons = new SimpleBasisAMSImageButton[apps.length]; for (int i = 0; i < apps.length; i++) { trace("Loading: " + apps[i].getTitle()); applicationsScreenButtons[i] = createScreenButton(apps[i], new LaunchAppActionListener(apps[i]), APPLICATIONS_SCREEN_COLOR); } } } class LaunchThread extends Thread { JUMPApplication app = null; public LaunchThread(JUMPApplication app) { this.app = app; } public void run() { timeoutObject = new Object(); launchApp(app); } } public void handleMessage(JUMPMessage message) { if (JUMPIsolateWindowRequest.MESSAGE_TYPE.equals(message.getType())) { trace("==== MESSAGE RECEIVED: JUMPIsolateWindowRequest.MESSAGE_TYPE"); JUMPIsolateWindowRequest cmd = (JUMPIsolateWindowRequest) JUMPIsolateWindowRequest.fromMessage(message); int isolateID = cmd.getIsolateId(); int windowID = cmd.getWindowId(); JUMPWindow window = wm.idToWindow(isolateID); if (JUMPIsolateWindowRequest.ID_NOTIFY_WINDOW_FOREGROUND.equals (cmd.getCommandId())) { trace("====== COMMAND RECEIVED: JUMPIsolateWindowRequest.ID_NOTIFY_WINDOW_FOREGROUND"); appWindowDisplayState = true; synchronized(timeoutObject) { System.out.println("****** Calling notify() on timout object. ******"); timeoutObject.notify(); } } else if(JUMPIsolateWindowRequest.ID_NOTIFY_WINDOW_BACKGROUND.equals( cmd.getCommandId())) { trace("====== COMMAND RECEIVED: JUMPIsolateWindowRequest.ID_NOTIFY_WINDOW_BACKGROUND"); } } else if(JUMPIsolateLifecycleRequest.MESSAGE_TYPE.equals( message.getType())) { trace("==== MESSAGE RECEIVED: JUMPIsolateLifecycleRequest.MESSAGE_TYPE"); JUMPIsolateLifecycleRequest cmd = (JUMPIsolateLifecycleRequest) JUMPIsolateLifecycleRequest.fromMessage(message); int isolateID = cmd.getIsolateId(); if (JUMPIsolateLifecycleRequest.ID_ISOLATE_DESTROYED.equals (cmd.getCommandId())) { trace("====== COMMAND RECEIVED: JUMPIsolateLifecycleRequest.ID_ISOLATE_DESTROYED"); JUMPIsolateProxy isolateProxy = lcm.getIsolate(isolateID); JUMPApplicationProxy apps[] = isolateProxy.getApps(); // the killApp(app) call below may not be needed and needs // to undergo testing to see if this is necessary. In fact, // it may be the case that the 'app' value returned by // window application is null. If killApp(app) is not needed, // then it should be replaced with a "currentApp = null". if(apps != null) { for(int i = 0; i < apps.length; ++i) { trace("====== killApp( + " + apps[i].getApplication() + ")"); killApp(apps[i]); } } } } } public void displayDialog(String str, ActionListener okActionListener, ActionListener cancelActionListener) { trace("ENTERING DIALOG SCREEN"); if (currentApp != null) { pauseApp(currentApp); bringWindowToBack(currentApp); } Container dialogContainer = new Container(); dialogContainer.setBackground(Color.white); dialogContainer.setLayout(new BorderLayout()); final String displayStr = str; Container textContainer = new Container() { public void paint(Graphics g) { super.paint(g); g.drawString(displayStr, 10, 20); } }; textContainer.setBackground(Color.white); Container buttonContainer = new Container();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -