📄 mspmotetype.java
字号:
} catch (Exception e2) { } } }); createButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myDialog.dispose(); } }); buttonBox.add(cancelButton); buttonBox.add(Box.createHorizontalStrut(5)); buttonBox.add(cleanButton); buttonBox.add(Box.createHorizontalStrut(5)); buttonBox.add(compileButton); buttonBox.add(Box.createHorizontalStrut(5)); buttonBox.add(createButton); // MAIN DIALOG CONTENTS Box horizBox; JLabel label; Box vertBox = Box.createVerticalBox(); // Source horizBox = Box.createHorizontalBox(); horizBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, LABEL_HEIGHT)); horizBox.setAlignmentX(Component.LEFT_ALIGNMENT); label = new JLabel("Contiki process sourcefile"); label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT)); sourceTextField.setText(""); if (moteType.getSourceFile() != null) { sourceTextField.setText(moteType.getSourceFile().getAbsolutePath()); } sourceTextField.setColumns(25); sourceTextField.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) { updateDialog(DialogState.SELECTED_SOURCE); } public void changedUpdate(DocumentEvent e) { updateDialog(DialogState.SELECTED_SOURCE); } public void removeUpdate(DocumentEvent e) { updateDialog(DialogState.SELECTED_SOURCE); } }); JButton browseButton = new JButton("Browse"); browseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { updateDialog(DialogState.NO_SOURCE); JFileChooser fc = new JFileChooser(); if (lastParentDirectory != null) { fc.setCurrentDirectory(lastParentDirectory); } else { fc.setCurrentDirectory(new java.io.File(GUI .getExternalToolsSetting("PATH_CONTIKI"))); } fc.setFileSelectionMode(JFileChooser.FILES_ONLY); fc.addChoosableFileFilter(new FileFilter() { public boolean accept(File f) { if (f.isDirectory()) { return true; } String filename = f.getName(); if (filename != null) { if (filename.endsWith(".c")) { return true; } } return false; } public String getDescription() { return "Contiki process source"; } }); fc.setDialogTitle("Select Contiki process source"); if (fc.showOpenDialog(myDialog) == JFileChooser.APPROVE_OPTION) { lastParentDirectory = null; sourceTextField.setText(""); File selectedFile = fc.getSelectedFile(); if (!selectedFile.exists()) { return; } if (!selectedFile.getName().endsWith(".c")) { return; } lastParentDirectory = fc.getSelectedFile().getParentFile(); sourceTextField.setText(fc.getSelectedFile().getAbsolutePath()); updateDialog(DialogState.SELECTED_SOURCE); } } }); horizBox.add(label); horizBox.add(Box.createHorizontalStrut(10)); horizBox.add(sourceTextField); horizBox.add(browseButton); vertBox.add(horizBox); vertBox.add(Box.createRigidArea(new Dimension(0, 5))); // Node ID /* * horizBox = Box.createHorizontalBox(); horizBox.setMaximumSize(new * Dimension(Integer.MAX_VALUE,LABEL_HEIGHT)); * horizBox.setAlignmentX(Component.LEFT_ALIGNMENT); label = new * JLabel("Node ID (0=EEPROM)"); label.setPreferredSize(new * Dimension(LABEL_WIDTH,LABEL_HEIGHT)); * * nodeIDTextField = new JFormattedTextField(integerFormat); * nodeIDTextField.setValue(new Integer(0)); * nodeIDTextField.setColumns(25); * nodeIDTextField.addPropertyChangeListener("value", new * PropertyChangeListener() { public void * propertyChange(PropertyChangeEvent e) { * updateDialog(DialogState.SELECTED_SOURCE); } }); * * horizBox.add(label); horizBox.add(Box.createHorizontalStrut(150)); * horizBox.add(nodeIDTextField); * * vertBox.add(horizBox); vertBox.add(Box.createRigidArea(new * Dimension(0,5))); */ // Compile command horizBox = Box.createHorizontalBox(); horizBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, LABEL_HEIGHT)); horizBox.setAlignmentX(Component.LEFT_ALIGNMENT); label = new JLabel("Compile command"); label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT)); compileCommandTextField.setText(""); compileCommandTextField.setColumns(25); compileCommandTextField.setEditable(true); compileCommandTextField.getDocument().addDocumentListener(new DocumentListener() { public void insertUpdate(DocumentEvent e) { setCompileCommand(compileCommandTextField.getText()); } public void changedUpdate(DocumentEvent e) { setCompileCommand(compileCommandTextField.getText()); } public void removeUpdate(DocumentEvent e) { setCompileCommand(compileCommandTextField.getText()); } }); horizBox.add(label); horizBox.add(Box.createHorizontalStrut(10)); horizBox.add(compileCommandTextField); vertBox.add(horizBox); vertBox.add(Box.createRigidArea(new Dimension(0, 5))); vertBox.add(Box.createRigidArea(new Dimension(0, 5))); vertBox.add(new JLabel("Compilation output:")); vertBox.add(Box.createRigidArea(new Dimension(0, 5))); vertBox.add(new JScrollPane(taskOutput)); vertBox.add(Box.createRigidArea(new Dimension(0, 5))); vertBox.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); Container contentPane = myDialog.getContentPane(); contentPane.add(vertBox, BorderLayout.CENTER); contentPane.add(buttonBox, BorderLayout.SOUTH); myDialog.pack(); myDialog.setLocationRelativeTo(parentContainer); myDialog.getRootPane().setDefaultButton(compileButton); // Dispose on escape key InputMap inputMap = myDialog.getRootPane().getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), "dispose"); AbstractAction cancelAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { cancelButton.doClick(); } }; myDialog.getRootPane().getActionMap().put("dispose", cancelAction); myDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); myDialog.addWindowListener(new WindowListener() { public void windowDeactivated(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowOpened(WindowEvent e) { } public void windowClosed(WindowEvent e) { } public void windowActivated(WindowEvent e) { } public void windowClosing(WindowEvent e) { cancelButton.doClick(); } }); updateDialog(DialogState.NO_SOURCE); if (moteType.getSourceFile() != null) { updateDialog(DialogState.SELECTED_SOURCE); if (customizedCompileCommand != null && !customizedCompileCommand.equals("")) { compileCommandTextField.setText(customizedCompileCommand); } compileButton.requestFocus(); } myDialog.setVisible(true); return sourceFile != null; } } public JPanel getTypeVisualizer() { JPanel panel = new JPanel(); JLabel label = new JLabel(); JPanel smallPane; panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); // Identifier smallPane = new JPanel(new BorderLayout()); label = new JLabel("Identifier"); smallPane.add(BorderLayout.WEST, label); label = new JLabel(getIdentifier()); smallPane.add(BorderLayout.EAST, label); panel.add(smallPane); // Description smallPane = new JPanel(new BorderLayout()); label = new JLabel("Description"); smallPane.add(BorderLayout.WEST, label); label = new JLabel(getDescription()); smallPane.add(BorderLayout.EAST, label); panel.add(smallPane); // ELF Hex file smallPane = new JPanel(new BorderLayout()); label = new JLabel("ELF file"); smallPane.add(BorderLayout.WEST, label); label = new JLabel(getELFFile().getName()); label.setToolTipText(getELFFile().getPath()); smallPane.add(BorderLayout.EAST, label); panel.add(smallPane); // Source file smallPane = new JPanel(new BorderLayout()); label = new JLabel("Source file"); smallPane.add(BorderLayout.WEST, label); if (getSourceFile() != null) { label = new JLabel(getSourceFile().getName()); label.setToolTipText(getSourceFile().getPath()); } else { label = new JLabel("[not specified]"); } smallPane.add(BorderLayout.EAST, label); panel.add(smallPane); // Icon (if available) if (!GUI.isVisualizedInApplet()) { Icon moteTypeIcon = getMoteTypeIcon(); if (moteTypeIcon != null) { smallPane = new JPanel(new BorderLayout()); label = new JLabel(moteTypeIcon); smallPane.add(BorderLayout.CENTER, label); panel.add(smallPane); } } else { smallPane = new JPanel(new BorderLayout()); label = new JLabel("No icon available in applet mode"); smallPane.add(BorderLayout.CENTER, label); panel.add(smallPane); } panel.add(Box.createRigidArea(new Dimension(0, 5))); return panel; } public abstract Icon getMoteTypeIcon(); public ProjectConfig getConfig() { logger.warn("Msp mote type project config not implemented"); return null; } public Collection<Element> getConfigXML() { Vector<Element> config = new Vector<Element>(); Element element; // Identifier element = new Element("identifier"); element.setText(getIdentifier()); config.add(element); // Description element = new Element("description"); element.setText(getDescription()); config.add(element); // Source file if (fileSource != null) { element = new Element("source"); fileSource = GUI.stripAbsoluteContikiPath(fileSource); element.setText(fileSource.getPath().replaceAll("\\\\", "/")); config.add(element); element = new Element("command"); element.setText(compileCommand); config.add(element); } else { // ELF file element = new Element("elf"); fileFirmware = GUI.stripAbsoluteContikiPath(fileFirmware); element.setText(fileFirmware.getPath().replaceAll("\\\\", "/")); config.add(element); } return config; } public boolean setConfigXML(Simulation simulation, Collection<Element> configXML, boolean visAvailable) throws MoteTypeCreationException { for (Element element : configXML) { String name = element.getName(); if (name.equals("identifier")) { identifier = element.getText(); } else if (name.equals("description")) { description = element.getText(); } else if (name.equals("source")) { fileSource = new File(element.getText()); } else if (name.equals("command")) { compileCommand = element.getText(); } else if (name.equals("elf")) { fileFirmware = new File(element.getText()); } else { logger.fatal("Unrecognized entry in loaded configuration: " + name); throw new MoteTypeCreationException( "Unrecognized entry in loaded configuration: " + name); } } return configureAndInit(GUI.getTopParentContainer(), simulation, visAvailable); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -