⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainscreen.java

📁 基于Ajax的WebOS————PhoneShow案例
💻 JAVA
字号:
package com.cownew.phoneshow;

import nextapp.echo2.app.Alignment;
import nextapp.echo2.app.Button;
import nextapp.echo2.app.ContentPane;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.FillImage;
import nextapp.echo2.app.Grid;
import nextapp.echo2.app.HttpImageReference;
import nextapp.echo2.app.ImageReference;
import nextapp.echo2.app.SplitPane;
import nextapp.echo2.app.WindowPane;
import nextapp.echo2.app.event.ActionEvent;
import nextapp.echo2.app.event.ActionListener;
import nextapp.echo2.webcontainer.command.BrowserOpenWindowCommand;

import org.apache.commons.lang.StringUtils;

import com.cownew.phoneshow.basedata.user.IUserDAO;
import com.cownew.phoneshow.basedata.user.UserInfo;
import com.cownew.phoneshow.ent.AlbumPane;
import com.cownew.phoneshow.ent.LoveWallWindowPane;
import com.cownew.phoneshow.framework.common.ClientInfo;
import com.cownew.phoneshow.framework.common.ServiceLocator;
import com.cownew.phoneshow.framework.common.Resources;
import com.cownew.phoneshow.framework.ctrl.ConfigPaneListenerAdapter;
import com.cownew.phoneshow.framework.ctrl.InputDialog;
import com.cownew.phoneshow.office.ExcelWindowPane;
import com.cownew.phoneshow.office.FrontPageWindowPane;
import com.cownew.phoneshow.tools.AirPortSearchPane;
import com.cownew.phoneshow.tools.NetDiskWindowPane;
import com.cownew.phoneshow.tools.ShellConfigPane;

import echopointng.ExtentEx;
import echopointng.Menu;
import echopointng.MenuBar;
import echopointng.MenuItem;

public class MainScreen extends ContentPane
{

	public MainScreen()
	{
		super();

		initWallpaper();

		// 初始化容器
		final ContentPane contentPane = new ContentPane();
		add(contentPane);
		// 用splitpane实现上桌面、下任务栏
		final SplitPane desktopPane = new SplitPane(
				SplitPane.ORIENTATION_VERTICAL_TOP_BOTTOM);
		desktopPane.setSeparatorPosition(new ExtentEx("30px"));

		// 初始化开始菜单
		MenuBar menuBar = new MenuBar();
		desktopPane.add(menuBar);

		// 初始化桌面网格
		Grid grid = new Grid(5);
		contentPane.add(desktopPane);
		desktopPane.add(grid);

		Menu menuStart = new Menu("开始");
		menuStart.setMenuAlwaysOnTop(true);
		menuBar.add(menuStart);

		MenuItem miExit = new MenuItem("注销");
		menuStart.add(miExit);
		miExit.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e)
			{
				// 注销并且返回登录界面
				MainApp.disconnectActive();
			}

		});

		MenuItem miIE = new MenuItem("打开网址");
		menuStart.add(miIE);
		miIE.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e)
			{
				ieActionPerformed();
			}

		});

		MenuItem miShellConfig = new MenuItem("桌面配置");
		menuStart.add(miShellConfig);
		miShellConfig.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e)
			{
				ShellConfigPane pane = new ShellConfigPane();
				MainApp.addComponent(pane);
			}

		});

		// 初始化桌面图标
		Button btnFP = new Button();
		btnFP.setText("FrontPage");
		btnFP.setIcon(Resources.getImage("frontpage.png"));
		btnFP.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e)
			{
				FrontPageWindowPane wordPane = new FrontPageWindowPane();
				maxmize(wordPane);
				MainApp.addComponent(wordPane);
			}

		});
		btnFP.setHeight(new ExtentEx("80px"));
		btnFP.setWidth(new ExtentEx("80px"));
		btnFP.setAlignment(Alignment.ALIGN_CENTER);
		btnFP.setTextPosition(Alignment.ALIGN_BOTTOM);
		grid.add(btnFP);

		Button btnExcel = new Button();
		btnExcel.setIcon(Resources.getImage("excel.png"));
		btnExcel.setText("Excel");
		btnExcel.setHeight(new ExtentEx("80px"));
		btnExcel.setWidth(new ExtentEx("80px"));
		btnExcel.setAlignment(Alignment.ALIGN_CENTER);
		btnExcel.setTextPosition(Alignment.ALIGN_BOTTOM);
		btnExcel.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e)
			{
				ExcelWindowPane excelPane = new ExcelWindowPane();
				maxmize(excelPane);
				MainApp.addComponent(excelPane);
			}

		});
		grid.add(btnExcel);

		Button btnAlbum = new Button();
		btnAlbum.setIcon(Resources.getImage("picviewer.png"));
		btnAlbum.setText("相册");
		btnAlbum.setHeight(new ExtentEx("80px"));
		btnAlbum.setWidth(new ExtentEx("80px"));
		btnAlbum.setAlignment(Alignment.ALIGN_CENTER);
		btnAlbum.setTextPosition(Alignment.ALIGN_BOTTOM);
		btnAlbum.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e)
			{
				AlbumPane albumPane = new AlbumPane();
				maxmize(albumPane);
				MainApp.addComponent(albumPane);
			}

		});
		grid.add(btnAlbum);

		Button btnLoveWall = new Button();
		btnLoveWall.setIcon(Resources.getImage("lovewall.png"));
		btnLoveWall.setText("爱墙");
		btnLoveWall.setHeight(new ExtentEx("80px"));
		btnLoveWall.setWidth(new ExtentEx("80px"));
		btnLoveWall.setAlignment(Alignment.ALIGN_CENTER);
		btnLoveWall.setTextPosition(Alignment.ALIGN_BOTTOM);
		btnLoveWall.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e)
			{
				LoveWallWindowPane lwPane = new LoveWallWindowPane();
				maxmize(lwPane);
				MainApp.addComponent(lwPane);
			}

		});
		grid.add(btnLoveWall);

		Button btnDisk = new Button();
		btnDisk.setIcon(Resources.getImage("mycomputer.png"));
		btnDisk.setText("网络硬盘");
		btnDisk.setHeight(new ExtentEx("80px"));
		btnDisk.setWidth(new ExtentEx("80px"));
		btnDisk.setAlignment(Alignment.ALIGN_CENTER);
		btnDisk.setTextPosition(Alignment.ALIGN_BOTTOM);
		btnDisk.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e)
			{
				NetDiskWindowPane pane = new NetDiskWindowPane();
				maxmize(pane);
				MainApp.addComponent(pane);
			}

		});
		grid.add(btnDisk);

		Button btnAirPort = new Button();
		btnAirPort.setIcon(Resources.getImage("airport.png"));
		btnAirPort.setText("机场查询");
		btnAirPort.setHeight(new ExtentEx("80px"));
		btnAirPort.setWidth(new ExtentEx("80px"));
		btnAirPort.setAlignment(Alignment.ALIGN_CENTER);
		btnAirPort.setTextPosition(Alignment.ALIGN_BOTTOM);
		btnAirPort.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e)
			{
				AirPortSearchPane pane = new AirPortSearchPane();
				MainApp.addComponent(pane);
			}

		});
		grid.add(btnAirPort);
	}

	// 初始化墙纸
	private void initWallpaper()
	{
		IUserDAO dao = (IUserDAO) ServiceLocator.getService(IUserDAO.class);
		// 得到当前登录用户的用户名
		String userId = MainApp.getActiveUserId();
		// 加载此用户的用户信息
		UserInfo user = dao.loadByUserId(userId);
		// 得到墙纸的路径
		String wallpaperURL = user.getWallpaper();
		ImageReference imgRef = null;
		if (!StringUtils.isEmpty(wallpaperURL))
		{
			// 如果此用户没有设置墙纸,则显示默认的墙纸
			imgRef = new HttpImageReference(wallpaperURL);
		} else
		{
			imgRef = Resources.getImage("DefaultWallpaper.JPG");
		}
		// 设置桌面的墙纸
		setBackgroundImage(new FillImage(imgRef));
	}

	private void ieActionPerformed()
	{
		final InputDialog dlg = new InputDialog("输入网址");
		dlg.setConfigPaneListener(new ConfigPaneListenerAdapter() {
			public void ok()
			{
				String url = dlg.getInputValue();
				if (!StringUtils.isEmpty(url))
				{
					//打开浏览器窗口
					BrowserOpenWindowCommand cmd = new BrowserOpenWindowCommand(url, null,
							null);
					MainApp.getActive().enqueueCommand(cmd);
				}
			}
		});
		MainApp.addComponent(dlg);
	}

	// 最大化窗口
	private static void maxmize(WindowPane winPane)
	{
		ClientInfo clientInfo = new ClientInfo(MainApp.getActive());
		winPane.setHeight(new Extent(clientInfo.getScreenHeight() - 200));
		winPane.setWidth(new Extent(clientInfo.getScreenWidth() - 50));
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -