KeyboardUtils.setup(pane,actions);
List<Device> boards = new ArrayList<>(Global.getGlobal().getDevices());
boardDropdown.setModel(new DefaultComboBoxModel(boards.toArray()));
boardDropdown.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if(comp instanceof JLabel && value instanceof Device) {
JLabel label = (JLabel) comp;
Device device = (Device) value;
label.setText(device.getName());
}
return comp;
}
});
if(actions.sketch.getCurrentDevice() == null) {
actions.sketch.setCurrentDevice(Global.getGlobal().getDevices().get(0));
}
boardDropdown.setSelectedItem(actions.sketch.getCurrentDevice());
List<SerialPort> ports = Global.getGlobal().getPorts();
portDropdown.setModel(new DefaultComboBoxModel(ports.toArray()));
portDropdown.setRenderer(new SerialPortComboBoxRenderer());
if(actions.sketch.getCurrentPort() == null && !Global.getGlobal().getPorts().isEmpty()) {
actions.sketch.setCurrentPort(Global.getGlobal().getPorts().get(0));
}
if(actions.sketch.getCurrentPort() != null) {
actions.sketch.getCurrentPort().addListener(this);
}
rebuildWindowMenu();
//register to listen for changes
Global.getGlobal().addPropertyChangeListener("sketches", new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
rebuildWindowMenu();
}
});
//set sizing so that we can open and close the split pane
consoleTabPane.setMinimumSize(new Dimension());
helpScroll.setMinimumSize(new Dimension());
try {
String helptext = Util.toString(getClass().getResource("resources/cheatsheet.html"));
helpPane.setText(helptext);
} catch (IOException ex) {
Logger.getLogger(EditorWindow.class.getName()).log(Level.SEVERE, null, ex);
}
serialRateCombo.setModel(new DefaultComboBoxModel(Global.SERIAL_RATE_STRINGS));
try {
int rate = actions.sketch.getSerialRate();
int n = Arrays.binarySearch(Global.SERIAL_RATE_INTS, rate);
serialRateCombo.setSelectedIndex(n);
} catch (Exception ex) {
ex.printStackTrace();
}
autoScroll.setSelected(actions.sketch.isAutoScroll());
examplesList.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if(value != null && value instanceof Example) {
Example ex = (Example) value;