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

📄 sunspotprogressui.java

📁 无线传感器网络节点Sun SPOT管理工具
💻 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.gui;import com.sun.spot.client.IUI;import com.sun.spot.client.SpotClientCommands;import com.sun.spot.client.SpotClientException;import com.sun.spot.client.SpotObsoleteVersionException;import com.sun.spot.client.command.SynchronizeCommand;import com.sun.spot.client.ui.SpotCommandDefinition;import com.sun.spot.spotworld.participants.SunSPOT;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.IOException;import java.util.HashMap;import java.util.Map;import javax.swing.BorderFactory;import javax.swing.BoxLayout;import javax.swing.JButton;import javax.swing.JComponent;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JProgressBar;import javax.swing.SwingUtilities;/** * * @author randy */public class SunSPOTProgressUI implements IUI {        protected Map bootloaderClientCommands = new HashMap();    private SynchronizeCommand synchronizeCommand;    private SpotCommandDefinition[] bootLoaderCommands;    private String remoteAddr;    private JProgressBar progBar;    private String diagnosticMessage;   //this is set from time to time during progress.    final private JFrame frame = new FlexiDisposeFrame();    protected JComponent uiObject;   //With which to be displayed relative to. (? say that without dangling a preposition)    private SunSPOT sunspot;       //Object about which updates are (? say that without dangling a passive verb)    private JLabel infoLabel;    private JPanel pbPanel;         public SunSPOTProgressUI() {        init();    }        public void init(){                  infoLabel = new JLabel("Info:");        progBar =  new JProgressBar();                progBar.setIndeterminate(true);        progBar.setPreferredSize(new Dimension(250, 50));                pbPanel = new JPanel( (new BorderLayout()) );                pbPanel.add(infoLabel, BorderLayout.NORTH);        pbPanel.add(progBar, BorderLayout.CENTER);        pbPanel.setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));        pbPanel.setOpaque(true);         Runnable r = new Runnable(){            public void run(){                 Runnable rr = new Runnable(){                    public void run(){                         frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);                                                //Create and set up the content pane.                        frame.setContentPane(pbPanel);                        frame.setLocationRelativeTo(uiObject);                                                //Display the window.                        frame.pack();                        frame.setVisible(true);                      }                 };                 SwingUtilities.invokeLater(rr);             }        };        (new Thread(r)).start();                pbPanel.paintImmediately(pbPanel.getBounds());    }        public void initCommands(SpotClientCommands commandRepository) {        synchronizeCommand = commandRepository.getSynchronizeCommand();                bootLoaderCommands = new SpotCommandDefinition[] {            new SpotCommandDefinition(                    new String[] {"flashapp", "fa"},                    commandRepository.getFlashAppCommand(),                    "flashapp [name] -- flash the Java application ('fa' for short) "),            new SpotCommandDefinition(                    new String[] {"run", "r"},                    commandRepository.getStartAppCommand(),                    "run [fork]      -- run app, echoing the output or if 'fork' exiting immediately"),        };         for (int i = 0; i < bootLoaderCommands.length; i++) {            String[] names = bootLoaderCommands[i].getNames();            for (int j = 0; j < names.length; j++) {                bootloaderClientCommands.put(names[j], bootLoaderCommands[i]);            }        }    }        public void synchronize() throws IOException {        System.out.println("Waiting for target to synchronise... ");        System.out.println("(please wait for remote SPOT " + remoteAddr + " to respond)");        System.out.println("(if no response ensure SPOT is running OTACommandServer)");        String blIntro = "";        boolean done = false;        while (!done) {            try {                blIntro = (String) synchronizeCommand.execute(null);                done = true;            } catch (SpotObsoleteVersionException e) {                System.out.println("WARNING: " + e.getMessage());                blIntro = e.getBootloaderIdentificationString();                done = true;            } catch (SpotClientException e) {                abort(e.getMessage());            }        }        System.out.println();        System.out.println(blIntro);    }        public void abort(String message) {        System.out.println();        System.out.println("Error: " + message);        System.out.println();        System.out.println("The SPOT client will now exit");    }        public void info(String msg) {        infoLabel.setText(msg);         pbPanel.paintImmediately(pbPanel.getBounds());    }        public void echoFromTarget(String msg) {        System.out.println("echo : " + msg);             }        public void newProgress(final int initialSteps, final int totalSteps, final String title) {        //  SwingUtilities.invokeLater( new Runnable(){        //         public void run(){        progBar.setIndeterminate(false);        progBar.setMinimum(initialSteps);        progBar.setMaximum(totalSteps);        progBar.setValue(initialSteps);        progBar.setStringPainted(true);    }         public void progressUpdate(int stepsComplete, String msg) {        if(progBar != null){            Thread.yield();            progBar.setIndeterminate(false);            progBar.setValue(stepsComplete);            JComponent panel = (JComponent)frame.getContentPane();            panel.paintImmediately(panel.getBounds());        }    }        public void progressEnd(String msg) {        System.out.println("progress end : " + msg);        JPanel panel = new JPanel();        panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));                JPanel textPanel = new JPanel();        textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.X_AXIS));        textPanel.add(new JLabel("Application suite successfully deployed."));        textPanel.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));        panel.add(textPanel);        JPanel closePanel = new JPanel(new BorderLayout());        JButton closeButton = new JButton("OK");        closeButton.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                frame.dispose();            }        });        closePanel.add(closeButton, BorderLayout.EAST);        closePanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));        panel.add(closePanel);        JFrame f = getFrame();        f.remove(f.getContentPane());        f.setContentPane(panel);        f.pack();        f.setVisible(true);    }        public void diagnostic(String msg) {        info("diagnostic : " + msg);    }        public void quit() {        System.out.println("quit");    }        public void setUiObject(JComponent uiObject) {        this.uiObject = uiObject;    }        public SunSPOT getSunspot() {        return sunspot;    }        public void setSunspot(SunSPOT sunspot) {        this.sunspot = sunspot;        String nm = sunspot.getName();        if(nm == null) nm = "Unnamed";        getFrame().setTitle("Progress monitor for " + nm);    }    public JFrame getFrame() {        return frame;    }}/* * This frame will not displose itself until after it has been setVisible(<anything>) at least once.  * and even then it will appear on the screen for a half second.   */class FlexiDisposeFrame extends JFrame {    private boolean readyToDispose = false;    private boolean frameOpenned = false;        /*     * Do not actually dispose unless the frame has been "openned" (setVisible()).     */    synchronized public void dispose(){        readyToDispose = true;        if(frameOpenned){            SwingUtilities.invokeLater(                new Runnable(){                   public void run(){                      FlexiDisposeFrame.super.dispose();                   }                }            );        }    }    /*     * Appear on the screen, but also check to see if there is a pending displose request.     * Note potential oddity: the argument here (vis = true or false) is irrelevant to this behavior.     */    synchronized public void setVisible(boolean vis){        frameOpenned = true; // this call represents some user visible aspect that is post instntiation,.        super.setVisible(vis);        if(readyToDispose){            try {                Thread.sleep(500);            } catch (InterruptedException ex) {                ex.printStackTrace();            }            dispose();        }    }} 

⌨️ 快捷键说明

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