📄 gvremoteprintwindow.java
字号:
/* * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is * described in this document. In particular, and without limitation, these intellectual property rights may * include one or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents * or pending patent applications in the U.S. and in other countries. * * U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. * standard license agreement and applicable provisions of the FAR and its supplements. * * Use is subject to license terms. * * This distribution may include materials developed by third parties. Sun, Sun Microsystems, the Sun logo and * Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. * * Copyright (c) 2006 Sun Microsystems, Inc. Tous droits r?serv?s. * * Sun Microsystems, Inc. d?tient les droits de propri?t? intellectuels relatifs ? la technologie incorpor?e dans * le produit qui est d?crit dans ce document. En particulier, et ce sans limitation, ces droits de propri?t? * intellectuelle peuvent inclure un ou plus des brevets am?ricains list?s ? l'adresse http://www.sun.com/patents * et un ou les brevets suppl?mentaires ou les applications de brevet en attente aux Etats - Unis et dans les * autres pays. * * L'utilisation est soumise aux termes du contrat de licence. * * Cette distribution peut comprendre des composants d?velopp?s par des tierces parties. * Sun, Sun Microsystems, le logo Sun et Java sont des marques de fabrique ou des marques d?pos?es de Sun * Microsystems, Inc. aux Etats-Unis et dans d'autres pays. */package com.sun.spot.spotworld.gridview;import com.sun.spot.spotworld.gui.IUIObject;//import com.sun.spot.spotworld.gui.RemotePrintHandler;import com.sun.spot.spotworld.gui.RemotePrintWindow;import com.sun.spot.spotworld.gui.SPOTTextWindow;import com.sun.spot.spotworld.participants.SunSPOT;import java.beans.PropertyVetoException;import javax.swing.JOptionPane;import org.sunspotworld.remoteprinting.RemotePrintHandler;/** * * @author randy */public class GVRemotePrintWindow extends RemotePrintWindow { private boolean external; public void open(IUIObject iuio, String isoID, String appName, int portToUse, SunSPOT hostObject){ setHost(hostObject); setPortNumber(portToUse); GVObject gvo = (GVObject) iuio; String inOrOut = askUserInOrOut(); if(inOrOut.equals("")) return; /* this is a user abort */ setExternal(inOrOut.equals("external")); if(isExternal()){ super.open(iuio, isoID, appName, portToUse, hostObject); } else { SPOTTextWindow frame = initAndMakeInternalFrame( iuio, isoID, appName, portToUse, hostObject); GVComponentHolder tch = new GVComponentHolder(); tch.add(frame); if(gvo instanceof GVApplication){ /* place to the right, aligned with top */ tch.setLocation(gvo.getLocation().x + gvo.getBasicWidth() , gvo.getLocation().y ); } else { /* place below, centered on presumably the SPOT */ tch.setLocation(gvo.getLocation().x - ((tch.getBasicWidth() - gvo.getBasicWidth()) / 2) , gvo.getLocation().y + gvo.getBasicHeight()); } gvo.addLoosePiece(tch); tch.addToView(gvo.getView()); frame.setDefaultCloseOperation(SPOTTextWindow.DISPOSE_ON_CLOSE); try { frame.setSelected(true); } catch (PropertyVetoException ex) { ex.printStackTrace(); } String addr = getHost().getAddress(); setRemotePrintHandler(new RemotePrintHandler(addr, getPortNumber(), getPrintStream())); getHost().addRemotePrintHandler(getRemotePrintHandler()); getRemotePrintHandler().start(); } } public SPOTTextWindow initAndMakeInternalFrame(IUIObject uiuo, final String isoID, String appName, int portToUse, SunSPOT hostObject){ String hostName = getHost().getName(); SPOTTextWindow frame = new SPOTTextWindow(){ public void dispose() { super.dispose(); getHost().removeRemotePrintHandler(getRemotePrintHandler()); (GVRemotePrintWindow.this).closeStreams(); getHost().stopRemotePrintingApp(isoID, getPortNumber()); } }; frame.setTitle("Sytem.out from " + appName + " on " + hostName); setPrintStream(frame.makePrintStream()); return frame; } public String askUserInOrOut(){ Object[] options = { "Cancel", "Internal frame", "External window"}; int n = JOptionPane.showOptionDialog(null, "What kind of window?", "", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); switch(n){ case(0): return ""; case(1): return "internal"; case(2): return "external"; } return ""; } public boolean isExternal() { return external; } public void setExternal(boolean external) { this.external = external; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -