📄 gvespot.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.common.LocaleUtil;import com.sun.spot.spotworld.gui.SPOTTextWindow;//import com.sun.spot.spotworld.remoteprinting.RemotePrintServer;import java.awt.AlphaComposite;import java.awt.BorderLayout;import java.awt.Composite;import java.awt.Font;import java.awt.Graphics2D;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.beans.PropertyVetoException;import java.net.URL;import java.util.Map;import javax.swing.BoxLayout;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextArea;import org.sunspotworld.remoteprinting.RemotePrintServer;/** * represents an eSPOT in GridView * @author arshan, randy */public class GVeSPOT extends GVSunSPOT implements ActionListener { ImageIcon icon; ImageIcon iconMask; String imageFilename; String imageMaskFilename; // GVJLabelHolder nameLabel; public void init(){ super.init(); setImageFilenames(); createIcons(); setSize(icon.getImage().getWidth(this), icon.getImage().getHeight(this)); } public void setImageFilenames(){ imageFilename = "images/eSPOTV2.png"; imageMaskFilename = "images/eSPOTV2-MASK.gif"; } public void createIcons(){ URL url = null; URL urlMask = null; try { url = getClass().getResource(imageFilename); urlMask = getClass().getResource(imageMaskFilename); icon = new ImageIcon(url, LocaleUtil.getString("an eSPOT Icon")); iconMask = new ImageIcon(urlMask, LocaleUtil.getString("an eSPOT Icon Mask")); } catch (Exception ex) { ex.printStackTrace(); icon = new ImageIcon(); iconMask = new ImageIcon(); } } public void paintComponentNoShadow(Graphics2D g2){ icon.paintIcon(this, g2, 0, 0); } public void paintShadow(Graphics2D g2){ Composite c = g2.getComposite(); if(c instanceof AlphaComposite) { AlphaComposite ca = (AlphaComposite)c; AlphaComposite a = AlphaComposite.getInstance(ca.getRule(), 0.2f); g2.setComposite(a); iconMask.paintIcon(this, g2, 0,0); g2.setComposite(ca); } } // is this method name abstract enough? --Robert public void displaySPOTTextOutput() { GVComponentHolder tch = new GVComponentHolder(); SPOTTextWindow frm = new SPOTTextWindow(); frm.setTitle("Debug Info"); tch.add(frm); tch.setLocation(getLocation().x + (getBasicWidth() - tch.getBasicWidth()) / 2, getLocation().y + getBasicHeight()); addLoosePiece(tch); tch.addToView(getView()); try { frm.setSelected(true); } catch (PropertyVetoException ex) { ex.printStackTrace(); } RemotePrintServer.enable(); // RemotePrintServer.setRemotePrintStreamFactory(frm); } public void displaySPOTInfo(Map<String, String> dictionary) { final JFrame frame = new JFrame(); frame.setTitle("Info for " + dictionary.get("name") + " (" + dictionary.get("IEEE Address") + ")"); frame.setResizable(false); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); JPanel textPanel = new JPanel(); textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.X_AXIS)); JTextArea textAreaB = new JTextArea(); textAreaB.setFont(new Font("Monospaced", Font.BOLD, 10)); textAreaB.setEditable(false); textAreaB.setAlignmentX(JTextArea.RIGHT_ALIGNMENT); textPanel.add(textAreaB); JTextArea textAreaP = new JTextArea(); textAreaP.setFont(new Font("Monospaced", Font.PLAIN, 10)); textAreaP.setEditable(false); textPanel.add(textAreaP); panel.add(textPanel); for (String key : dictionary.keySet()) { int blanks = 2; if(! dictionary.get(key).equals("")){ blanks = 40 - key.length(); } if(blanks == 2) { textAreaB.append("\n"); textAreaP.append("\n"); } for(int i = 0; i < blanks; i++) textAreaB.append(" "); if(key.endsWith(":") || (blanks == 2) ){ textAreaB.append(key + " \n"); } else { textAreaB.append(key + ": \n"); } textAreaP.append(dictionary.get(key) + "\n"); } JPanel closePanel = new JPanel(new BorderLayout()); JButton closeButton = new JButton("close"); closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { frame.setVisible(false); } }); closePanel.add(closeButton, BorderLayout.EAST); panel.add(closePanel); frame.add(panel); frame.pack(); frame.setVisible(true); } public String getNewNameFromUser() { String message = getSpot().getName(); String name = JOptionPane.showInputDialog(this, "New name", message); if (name == null) name = message; return name; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -