📄 spotworldportal.java
字号:
} catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (InvalidPropertiesFormatException ex) { boolean success = file.delete(); if (success) { readPropertiesFromFile(); return; } else { System.out.println("Your SPOTWorld properties file is corrupt and couldn't be fixed. Please close SPOT World and delete it."); ex.printStackTrace(); } } catch (IOException ex) { ex.printStackTrace(); } } public void writePropertiesToFile() { setSPOTWorldProperty(SPOTWORLD_HEIGHT, Integer.toString(SpotWorldPortal.this.getHeight())); setSPOTWorldProperty(SPOTWORLD_WIDTH, Integer.toString(SpotWorldPortal.this.getWidth())); if (topPane.getLeftComponent() != null) { setSPOTWorldProperty(LEFTPANE_HEIGHT, Integer.toString(topPane.getLeftComponent().getHeight())); setSPOTWorldProperty(LEFTPANE_WIDTH, Integer.toString(topPane.getLeftComponent().getWidth())); setSPOTWorldProperty(LEFTPANE_VIEW, topPane.getLeftComponent().getName()); } else { setSPOTWorldProperty(LEFTPANE_VIEW, NO_COMPONENT); } if (topPane.getRightComponent() != null) { setSPOTWorldProperty(RIGHTPANE_HEIGHT, Integer.toString(topPane.getRightComponent().getHeight())); setSPOTWorldProperty(RIGHTPANE_WIDTH, Integer.toString(topPane.getRightComponent().getWidth())); setSPOTWorldProperty(RIGHTPANE_VIEW, topPane.getRightComponent().getName()); } else { setSPOTWorldProperty(RIGHTPANE_VIEW, NO_COMPONENT); } try { File file = new File(spotWorldPropsFileName); FileOutputStream os = new FileOutputStream(file); SPOTWorldProperties.storeToXML(os, SPOTWORLD_PROPERTY_COMMENT); os.close(); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } public void testrun() { myWorld.dummy(); } public JMenuBar createMenuBar() { JMenuBar bar = new JMenuBar(); //File Menu JMenu menu = new JMenu(LocaleUtil.getString("File")); JMenuItem item = new JMenuItem(LocaleUtil.getString("exit")); item.addActionListener(this); menu.add(item); bar.add(menu); menu = new JMenu(LocaleUtil.getString("View")); for (String view : myWorld.getAvailableViews()) { JCheckBoxMenuItem cbMenuItem = new JCheckBoxMenuItem(view); // find out what views we currently have loaded and check the correct ones if (topPane.getLeftComponent() != null && topPane.getLeftComponent().getName().equals(view)) cbMenuItem.setSelected(true); if (topPane.getRightComponent() != null && topPane.getRightComponent().getName().equals(view)) cbMenuItem.setSelected(true); cbMenuItem.setActionCommand(view); cbMenuItem.addActionListener(this); menu.add(cbMenuItem); } bar.add(menu); menu = new JMenu(LocaleUtil.getString("DesktopApps")); item = new JMenuItem(LocaleUtil.getString("Run ...")); item.addActionListener(this); menu.add(item); menu.addSeparator(); for (String fn : desktopAppManager.getRecentDesktopApps()) { String[] pathParts = fn.split(File.separator); /* the desktopAppManager can create special menu items the retain the full file name */ item = desktopAppManager.createMenuItem(pathParts[pathParts.length - 1], fn); item.setToolTipText(fn); item.addActionListener(this); menu.add(item); } bar.add(menu); menu = new JMenu(LocaleUtil.getString("Experimental")); JCheckBoxMenuItem cbItem = new JCheckBoxMenuItem("Allow Running App Drag and Drop"); cbItem.setToolTipText("Enable isolate migration between SPOTs - highly experimental"); cbItem.setState(false); cbItem.addActionListener(this); menu.add(cbItem); bar.add(menu); JButton button = new JButton("What is SPOTWorld?"); button.addActionListener(this); button.setSelected(true); button.setFocusPainted(false); bar.add(button); return bar; } /** * @param args the command line arguments */ public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { // no op } SpotWorldPortal swp = new SpotWorldPortal(); } public void actionPerformed(ActionEvent actionEvent) { if(actionEvent.getActionCommand().equals("What is SPOTWorld?")){ String msg = "SPOTWorld is a framework under development at Sun Labs."; msg = msg + "\nWe thought you might like to see this experimental"; msg = msg + "\napproach to remotely interacting with your Sun SPOTs."; msg = msg + "\nPlease see the documentation for a more"; msg = msg + "\ncomplete description."; msg = msg + "\n"; msg = msg + "\nTo see a SPOT in SPOTWorld, you must deploy Kami"; msg = msg + "\n(with the other apps you want on board) to the SPOT."; msg = msg + "\n(See the SPOTManager tool for deploying Kami)."; JOptionPane.showMessageDialog(this, msg, "", JOptionPane.INFORMATION_MESSAGE); return; } if(actionEvent.getActionCommand().equals(LocaleUtil.getString("exit"))){ exit(); } if(actionEvent.getActionCommand().equals("Allow Running App Drag and Drop")){ JCheckBoxMenuItem cbItem = (JCheckBoxMenuItem) actionEvent.getSource(); Application.ALLOW_APP_MIGRATION = cbItem.getState(); if(Application.ALLOW_APP_MIGRATION){ String msg = "Live app migration is not yet fully supported."; msg = msg + "\nIt currently only works for the WhiteBlinker app, a very simple case."; msg = msg + "\nDrag and drop only works in GridView (not TreeView)."; JOptionPane.showMessageDialog(this, msg, "", JOptionPane.WARNING_MESSAGE); } } if(actionEvent.getActionCommand().equals("Run ...")){ desktopAppManager.runAppFromUser(); return; } /* Try giving event to desktopAppManager. If it acts on it, it will return true, otherwise false */ if(desktopAppManager.doMenuItem((JMenuItem) actionEvent.getSource())){ return; } // Cycle through the available views to see if it is one the user clicked for (String view : myWorld.getAvailableViews()) { if (actionEvent.getActionCommand().equals(view)) { if (((JCheckBoxMenuItem) actionEvent.getSource()).isSelected()) { addView(view); } else { // if we're deselecting that view removeView(view); } // go through the view menu and update the checks on the menu items // get what views we have at the moment Vector<String> names = new Vector<String>(); if (topPane.getLeftComponent() != null) names.addElement(topPane.getLeftComponent().getName()); if (topPane.getRightComponent() != null) names.addElement(topPane.getRightComponent().getName()); JPopupMenu menu = (JPopupMenu) ((JCheckBoxMenuItem) actionEvent.getSource()).getParent(); for (MenuElement element : menu.getSubElements()) { if (element instanceof JCheckBoxMenuItem) { if (names.contains(((JCheckBoxMenuItem) element).getActionCommand())) ((JCheckBoxMenuItem) element).setSelected(true); else ((JCheckBoxMenuItem) element).setSelected(false); } } } } } public void addView(String view){ if (topPane.getLeftComponent() == null) { // if the left pane is empty load the view in the left pane Component comp = myWorld.getView(view); topPane.setLeftComponent(comp); } else if (topPane.getRightComponent() == null) { // or if the left pane is not empty and the right pane // is load the view in the right pane. Component comp = myWorld.getView(view); topPane.setRightComponent(comp); } else { // otherwise bump the rightmost view, shift the left view to // the right and load the new view in the left pane. Component mvComp = topPane.getLeftComponent(); int oldLocation = topPane.getDividerLocation(); // get the new view Component newComp = myWorld.getView(view); // swap views about topPane.setLeftComponent(newComp); topPane.setRightComponent(mvComp); topPane.setDividerLocation(oldLocation); topPane.validate(); topPane.repaint(); } } public void removeView(String view){ // Remove the component if it's in the left pane if (topPane.getLeftComponent() != null && topPane.getLeftComponent().getName().equals(view)) { topPane.setLeftComponent(null); topPane.validate(); topPane.repaint(); } // Remove the component if it's in the right pane if (topPane.getRightComponent() != null && topPane.getRightComponent().getName().equals(view)) { topPane.setRightComponent(null); topPane.validate(); topPane.repaint(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -