Example usage for javax.swing JComboBox setSelectedIndex

List of usage examples for javax.swing JComboBox setSelectedIndex

Introduction

In this page you can find the example usage for javax.swing JComboBox setSelectedIndex.

Prototype

@BeanProperty(bound = false, preferred = true, description = "The item at index is selected.")
public void setSelectedIndex(int anIndex) 

Source Link

Document

Selects the item at index anIndex.

Usage

From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_link.java

private List<JComponent> getExtraOptions(final int row, final Object itemId) {
    List<JComponent> options = new LinkedList<JComponent>();

    final List<Link> rowVisibleLinks = getVisibleElementsInTable();
    final NetPlan netPlan = callback.getDesign();

    if (itemId != null) {
        final long linkId = (long) itemId;

        JMenuItem lengthToEuclidean_thisLink = new JMenuItem("Set link length to node-pair Euclidean distance");
        lengthToEuclidean_thisLink.addActionListener(new ActionListener() {
            @Override/*from  w w  w .  j a v a2 s  .co  m*/
            public void actionPerformed(ActionEvent e) {
                Link link = netPlan.getLinkFromId(linkId);
                Node originNode = link.getOriginNode();
                Node destinationNode = link.getDestinationNode();
                double euclideanDistance = netPlan.getNodePairEuclideanDistance(originNode, destinationNode);
                link.setLengthInKm(euclideanDistance);
                callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.LINK));
                callback.getUndoRedoNavigationManager().addNetPlanChange();
            }
        });

        options.add(lengthToEuclidean_thisLink);

        JMenuItem lengthToHaversine_allNodes = new JMenuItem(
                "Set link length to node-pair Haversine distance (longitude-latitude) in km");
        lengthToHaversine_allNodes.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Link link = netPlan.getLinkFromId(linkId);
                Node originNode = link.getOriginNode();
                Node destinationNode = link.getDestinationNode();
                double haversineDistanceInKm = netPlan.getNodePairHaversineDistanceInKm(originNode,
                        destinationNode);
                link.setLengthInKm(haversineDistanceInKm);
                callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.LINK));
                callback.getUndoRedoNavigationManager().addNetPlanChange();
            }
        });

        options.add(lengthToHaversine_allNodes);

        JMenuItem scaleLinkLength_thisLink = new JMenuItem("Scale link length");
        scaleLinkLength_thisLink.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                double scaleFactor;

                while (true) {
                    String str = JOptionPane.showInputDialog(null, "(Multiplicative) Scale factor",
                            "Scale link length", JOptionPane.QUESTION_MESSAGE);
                    if (str == null)
                        return;

                    try {
                        scaleFactor = Double.parseDouble(str);
                        if (scaleFactor < 0)
                            throw new RuntimeException();

                        break;
                    } catch (Throwable ex) {
                        ErrorHandling.showErrorDialog(
                                "Non-valid scale value. Please, introduce a non-negative number",
                                "Error setting scale factor");
                    }
                }

                netPlan.getLinkFromId(linkId)
                        .setLengthInKm(netPlan.getLinkFromId(linkId).getLengthInKm() * scaleFactor);
                callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.LINK));
                callback.getUndoRedoNavigationManager().addNetPlanChange();
            }
        });

        options.add(scaleLinkLength_thisLink);

        if (netPlan.isMultilayer()) {
            Link link = netPlan.getLinkFromId(linkId);
            if (link.getCoupledDemand() != null) {
                JMenuItem decoupleLinkItem = new JMenuItem("Decouple link (if coupled to unicast demand)");
                decoupleLinkItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        netPlan.getLinkFromId(linkId).getCoupledDemand().decouple();
                        model.setValueAt("", row, 20);
                        callback.getVisualizationState().resetPickedState();
                        callback.updateVisualizationAfterChanges(
                                Sets.newHashSet(NetworkElementType.LINK, NetworkElementType.DEMAND));
                        callback.getUndoRedoNavigationManager().addNetPlanChange();
                    }
                });

                options.add(decoupleLinkItem);
            } else {
                JMenuItem createLowerLayerDemandFromLinkItem = new JMenuItem(
                        "Create lower layer demand from link");
                createLowerLayerDemandFromLinkItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Collection<Long> layerIds = netPlan.getNetworkLayerIds();
                        final JComboBox layerSelector = new WiderJComboBox();
                        for (long layerId : layerIds) {
                            if (layerId == netPlan.getNetworkLayerDefault().getId())
                                continue;

                            final String layerName = netPlan.getNetworkLayerFromId(layerId).getName();
                            String layerLabel = "Layer " + layerId;
                            if (!layerName.isEmpty())
                                layerLabel += " (" + layerName + ")";

                            layerSelector.addItem(StringLabeller.of(layerId, layerLabel));
                        }

                        layerSelector.setSelectedIndex(0);

                        JPanel pane = new JPanel();
                        pane.add(new JLabel("Select layer: "));
                        pane.add(layerSelector);

                        while (true) {
                            int result = JOptionPane.showConfirmDialog(null, pane,
                                    "Please select the lower layer to create the demand",
                                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                            if (result != JOptionPane.OK_OPTION)
                                return;

                            try {
                                long layerId = (long) ((StringLabeller) layerSelector.getSelectedItem())
                                        .getObject();
                                Link link = netPlan.getLinkFromId(linkId);
                                netPlan.addDemand(link.getOriginNode(), link.getDestinationNode(),
                                        link.getCapacity(), link.getAttributes(),
                                        netPlan.getNetworkLayerFromId(layerId));
                                callback.getVisualizationState().resetPickedState();
                                callback.updateVisualizationAfterChanges(
                                        Sets.newHashSet(NetworkElementType.DEMAND));
                                callback.getUndoRedoNavigationManager().addNetPlanChange();
                                break;
                            } catch (Throwable ex) {
                                ErrorHandling.showErrorDialog(ex.getMessage(),
                                        "Error creating lower layer demand from link");
                            }
                        }
                    }
                });

                options.add(createLowerLayerDemandFromLinkItem);

                JMenuItem coupleLinkToDemand = new JMenuItem("Couple link to lower layer demand");
                coupleLinkToDemand.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        Collection<Long> layerIds = netPlan.getNetworkLayerIds();
                        final JComboBox layerSelector = new WiderJComboBox();
                        final JComboBox demandSelector = new WiderJComboBox();
                        for (long layerId : layerIds) {
                            if (layerId == netPlan.getNetworkLayerDefault().getId())
                                continue;

                            final String layerName = netPlan.getNetworkLayerFromId(layerId).getName();
                            String layerLabel = "Layer " + layerId;
                            if (!layerName.isEmpty())
                                layerLabel += " (" + layerName + ")";

                            layerSelector.addItem(StringLabeller.of(layerId, layerLabel));
                        }

                        layerSelector.addItemListener(new ItemListener() {
                            @Override
                            public void itemStateChanged(ItemEvent e) {
                                if (layerSelector.getSelectedIndex() >= 0) {
                                    long selectedLayerId = (Long) ((StringLabeller) layerSelector
                                            .getSelectedItem()).getObject();

                                    demandSelector.removeAllItems();
                                    for (Demand demand : netPlan
                                            .getDemands(netPlan.getNetworkLayerFromId(selectedLayerId))) {
                                        if (demand.isCoupled())
                                            continue;

                                        long ingressNodeId = demand.getIngressNode().getId();
                                        long egressNodeId = demand.getEgressNode().getId();
                                        String ingressNodeName = demand.getIngressNode().getName();
                                        String egressNodeName = demand.getEgressNode().getName();

                                        demandSelector.addItem(StringLabeller.unmodifiableOf(demand.getId(),
                                                "d" + demand.getId() + " [n" + ingressNodeId + " ("
                                                        + ingressNodeName + ") -> n" + egressNodeId + " ("
                                                        + egressNodeName + ")]"));
                                    }
                                }

                                if (demandSelector.getItemCount() == 0) {
                                    demandSelector.setEnabled(false);
                                } else {
                                    demandSelector.setSelectedIndex(0);
                                    demandSelector.setEnabled(true);
                                }
                            }
                        });

                        layerSelector.setSelectedIndex(-1);
                        layerSelector.setSelectedIndex(0);

                        JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[][]"));
                        pane.add(new JLabel("Select layer: "));
                        pane.add(layerSelector, "growx, wrap");
                        pane.add(new JLabel("Select demand: "));
                        pane.add(demandSelector, "growx, wrap");

                        while (true) {
                            int result = JOptionPane.showConfirmDialog(null, pane,
                                    "Please select the lower layer demand", JOptionPane.OK_CANCEL_OPTION,
                                    JOptionPane.QUESTION_MESSAGE);
                            if (result != JOptionPane.OK_OPTION)
                                return;

                            try {
                                long demandId;
                                try {
                                    demandId = (long) ((StringLabeller) demandSelector.getSelectedItem())
                                            .getObject();
                                } catch (Throwable ex) {
                                    throw new RuntimeException("No demand was selected");
                                }

                                netPlan.getDemandFromId(demandId)
                                        .coupleToUpperLayerLink(netPlan.getLinkFromId(linkId));
                                callback.getVisualizationState().resetPickedState();
                                callback.updateVisualizationAfterChanges(
                                        Sets.newHashSet(NetworkElementType.LINK, NetworkElementType.DEMAND));
                                callback.getUndoRedoNavigationManager().addNetPlanChange();
                                break;
                            } catch (Throwable ex) {
                                ErrorHandling.showErrorDialog(ex.getMessage(),
                                        "Error coupling lower layer demand to link");
                            }
                        }
                    }
                });

                options.add(coupleLinkToDemand);
            }
        }
    }

    if (rowVisibleLinks.size() > 1) {
        if (!options.isEmpty())
            options.add(new JPopupMenu.Separator());

        JMenuItem caFixValue = new JMenuItem("Set capacity to all");
        caFixValue.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                double u_e;

                while (true) {
                    String str = JOptionPane.showInputDialog(null, "Capacity value",
                            "Set capacity to all table links", JOptionPane.QUESTION_MESSAGE);
                    if (str == null)
                        return;

                    try {
                        u_e = Double.parseDouble(str);
                        if (u_e < 0)
                            throw new NumberFormatException();

                        break;
                    } catch (NumberFormatException ex) {
                        ErrorHandling.showErrorDialog(
                                "Non-valid capacity value. Please, introduce a non-negative number",
                                "Error setting capacity value");
                    }
                }

                try {
                    for (Link link : rowVisibleLinks)
                        link.setCapacity(u_e);
                    callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK));
                    callback.getUndoRedoNavigationManager().addNetPlanChange();
                } catch (Throwable ex) {
                    ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set capacity to all links");
                }
            }
        });

        options.add(caFixValue);

        JMenuItem caFixValueUtilization = new JMenuItem("Set capacity to match a given utilization");
        caFixValueUtilization.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                double utilization;

                while (true) {
                    String str = JOptionPane.showInputDialog(null, "Link utilization value",
                            "Set capacity to all table links to match a given utilization",
                            JOptionPane.QUESTION_MESSAGE);
                    if (str == null)
                        return;

                    try {
                        utilization = Double.parseDouble(str);
                        if (utilization <= 0)
                            throw new NumberFormatException();

                        break;
                    } catch (NumberFormatException ex) {
                        ErrorHandling.showErrorDialog(
                                "Non-valid link utilization value. Please, introduce a strictly positive number",
                                "Error setting link utilization value");
                    }
                }

                try {
                    for (Link link : rowVisibleLinks)
                        link.setCapacity(link.getOccupiedCapacity() / utilization);
                    callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK));
                    callback.getUndoRedoNavigationManager().addNetPlanChange();
                } catch (Throwable ex) {
                    ErrorHandling.showErrorDialog(ex.getMessage(),
                            "Unable to set capacity to all links according to a given link utilization");
                }
            }
        });

        options.add(caFixValueUtilization);

        JMenuItem lengthToAll = new JMenuItem("Set link length to all");
        lengthToAll.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                double l_e;

                while (true) {
                    String str = JOptionPane.showInputDialog(null, "Link length value (in km)",
                            "Set link length to all table links", JOptionPane.QUESTION_MESSAGE);
                    if (str == null)
                        return;

                    try {
                        l_e = Double.parseDouble(str);
                        if (l_e < 0)
                            throw new RuntimeException();

                        break;
                    } catch (Throwable ex) {
                        ErrorHandling.showErrorDialog(
                                "Non-valid link length value. Please, introduce a non-negative number",
                                "Error setting link length");
                    }
                }

                NetPlan netPlan = callback.getDesign();

                try {
                    for (Link link : rowVisibleLinks)
                        link.setLengthInKm(l_e);
                    callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK));
                    callback.getUndoRedoNavigationManager().addNetPlanChange();
                } catch (Throwable ex) {
                    ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set link length to all links");
                }
            }
        });

        options.add(lengthToAll);

        JMenuItem lengthToEuclidean_allLinks = new JMenuItem(
                "Set all table link lengths to node-pair Euclidean distance");
        lengthToEuclidean_allLinks.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    for (Link link : rowVisibleLinks)
                        link.setLengthInKm(netPlan.getNodePairEuclideanDistance(link.getOriginNode(),
                                link.getDestinationNode()));
                    callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK));
                    callback.getUndoRedoNavigationManager().addNetPlanChange();
                } catch (Throwable ex) {
                    ErrorHandling.showErrorDialog(ex.getMessage(),
                            "Unable to set link length value to all links");
                }
            }
        });

        options.add(lengthToEuclidean_allLinks);

        JMenuItem lengthToHaversine_allLinks = new JMenuItem(
                "Set all table link lengths to node-pair Haversine distance (longitude-latitude) in km");
        lengthToHaversine_allLinks.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                NetPlan netPlan = callback.getDesign();

                try {
                    for (Link link : rowVisibleLinks) {
                        link.setLengthInKm(netPlan.getNodePairHaversineDistanceInKm(link.getOriginNode(),
                                link.getDestinationNode()));
                    }
                    callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK));
                    callback.getUndoRedoNavigationManager().addNetPlanChange();
                } catch (Throwable ex) {
                    ErrorHandling.showErrorDialog(ex.getMessage(),
                            "Unable to set link length value to all links");
                }
            }
        });

        options.add(lengthToHaversine_allLinks);

        JMenuItem scaleLinkLength_allLinks = new JMenuItem("Scale all table link lengths");
        scaleLinkLength_allLinks.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                double scaleFactor;

                while (true) {
                    String str = JOptionPane.showInputDialog(null, "(Multiplicative) Scale factor",
                            "Scale (all) link length", JOptionPane.QUESTION_MESSAGE);
                    if (str == null)
                        return;

                    try {
                        scaleFactor = Double.parseDouble(str);
                        if (scaleFactor < 0)
                            throw new RuntimeException();

                        break;
                    } catch (Throwable ex) {
                        ErrorHandling.showErrorDialog(
                                "Non-valid scale value. Please, introduce a non-negative number",
                                "Error setting scale factor");
                    }
                }

                NetPlan netPlan = callback.getDesign();

                try {
                    for (Link link : rowVisibleLinks)
                        link.setLengthInKm(link.getLengthInKm() * scaleFactor);
                    callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK));
                    callback.getUndoRedoNavigationManager().addNetPlanChange();
                } catch (Throwable ex) {
                    ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to scale link length");
                }
            }
        });

        options.add(scaleLinkLength_allLinks);

        if (netPlan.isMultilayer()) {
            final Set<Link> coupledLinks = rowVisibleLinks.stream().filter(e -> e.isCoupled())
                    .collect(Collectors.toSet());
            if (!coupledLinks.isEmpty()) {
                JMenuItem decoupleAllLinksItem = new JMenuItem("Decouple all table links");
                decoupleAllLinksItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        for (Link link : coupledLinks)
                            if (link.getCoupledDemand() == null)
                                link.getCoupledMulticastDemand().decouple();
                            else
                                link.getCoupledDemand().decouple();
                        int numRows = model.getRowCount();
                        for (int i = 0; i < numRows; i++)
                            model.setValueAt("", i, 20);
                        callback.getVisualizationState().resetPickedState();
                        callback.updateVisualizationAfterChanges(
                                Sets.newHashSet(NetworkElementType.LINK, NetworkElementType.DEMAND));
                        callback.getUndoRedoNavigationManager().addNetPlanChange();
                    }
                });

                options.add(decoupleAllLinksItem);
            }

            if (coupledLinks.size() < rowVisibleLinks.size()) {
                JMenuItem createLowerLayerDemandsFromLinksItem = new JMenuItem(
                        "Create lower layer unicast demands from uncoupled links");
                createLowerLayerDemandsFromLinksItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        final JComboBox layerSelector = new WiderJComboBox();
                        for (NetworkLayer layer : netPlan.getNetworkLayers()) {
                            if (layer.getId() == netPlan.getNetworkLayerDefault().getId())
                                continue;

                            final String layerName = layer.getName();
                            String layerLabel = "Layer " + layer.getId();
                            if (!layerName.isEmpty())
                                layerLabel += " (" + layerName + ")";

                            layerSelector.addItem(StringLabeller.of(layer.getId(), layerLabel));
                        }

                        layerSelector.setSelectedIndex(0);

                        JPanel pane = new JPanel();
                        pane.add(new JLabel("Select layer: "));
                        pane.add(layerSelector);

                        while (true) {
                            int result = JOptionPane.showConfirmDialog(null, pane,
                                    "Please select the lower layer to create demands",
                                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                            if (result != JOptionPane.OK_OPTION)
                                return;

                            try {
                                long layerId = (long) ((StringLabeller) layerSelector.getSelectedItem())
                                        .getObject();
                                NetworkLayer layer = netPlan.getNetworkLayerFromId(layerId);
                                for (Link link : rowVisibleLinks)
                                    if (!link.isCoupled())
                                        link.coupleToNewDemandCreated(layer);
                                callback.getVisualizationState()
                                        .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals();
                                callback.updateVisualizationAfterChanges(
                                        Sets.newHashSet(NetworkElementType.LINK, NetworkElementType.DEMAND));
                                callback.getUndoRedoNavigationManager().addNetPlanChange();
                                break;
                            } catch (Throwable ex) {
                                ErrorHandling.showErrorDialog(ex.getMessage(),
                                        "Error creating lower layer demands");
                            }
                        }
                    }
                });

                options.add(createLowerLayerDemandsFromLinksItem);
            }
        }
    }
    return options;
}

From source file:edu.ku.brc.specify.prefs.FormattingPrefsPanel.java

/**
 * Create the UI for the panel//from  www.j a  v  a 2  s.c  o m
 */
protected void createUI() {
    createForm("Preferences", "Formatting"); //$NON-NLS-1$ //$NON-NLS-2$

    UIValidator.setIgnoreAllValidation(this, true);

    JLabel fontNamesLabel = form.getLabelFor("fontNames"); //$NON-NLS-1$
    ValComboBox fontNamesVCB = form.getCompById("fontNames"); //$NON-NLS-1$

    JLabel fontSizesLabel = form.getLabelFor("fontSizes"); //$NON-NLS-1$
    ValComboBox fontSizesVCB = form.getCompById("fontSizes"); //$NON-NLS-1$

    JLabel controlSizesLabel = form.getLabelFor("controlSizes"); //$NON-NLS-1$
    ValComboBox controlSizesVCB = form.getCompById("controlSizes"); //$NON-NLS-1$

    formTypesCBX = form.getCompById("formtype"); //$NON-NLS-1$

    fontNames = fontNamesVCB.getComboBox();
    fontSizes = fontSizesVCB.getComboBox();
    controlSizes = controlSizesVCB.getComboBox();

    testField = form.getCompById("fontTest"); //$NON-NLS-1$
    if (testField != null) {
        testField.setText(UIRegistry.getResourceString("FormattingPrefsPanel.THIS_TEST")); //$NON-NLS-1$
    }
    if (UIHelper.isMacOS_10_5_X()) {
        fontNamesLabel.setVisible(false);
        fontNamesVCB.setVisible(false);
        fontSizesLabel.setVisible(false);
        fontSizesVCB.setVisible(false);
        testField.setVisible(false);

        int inx = -1;
        int i = 0;
        Vector<String> controlSizeTitles = new Vector<String>();
        for (UIHelper.CONTROLSIZE cs : UIHelper.CONTROLSIZE.values()) {
            String titleStr = getResourceString(cs.toString());
            controlSizeTitles.add(titleStr);
            controlSizesHash.put(titleStr, cs);
            controlSizes.addItem(titleStr);
            if (cs == UIHelper.getControlSize()) {
                inx = i;
            }
            i++;
        }
        controlSizes.setSelectedIndex(inx);

        Font baseFont = UIRegistry.getBaseFont();
        if (baseFont != null) {
            fontNames.addItem(baseFont.getFamily());
            fontSizes.addItem(Integer.toString(baseFont.getSize()));
            fontNames.setSelectedIndex(0);
            fontSizes.setSelectedIndex(0);
        }

    } else {
        controlSizesLabel.setVisible(false);
        controlSizesVCB.setVisible(false);

        Hashtable<String, Boolean> namesUsed = new Hashtable<String, Boolean>();
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        for (Font font : ge.getAllFonts()) {
            if (namesUsed.get(font.getFamily()) == null) {
                fontNames.addItem(font.getFamily());
                namesUsed.put(font.getFamily(), true); //$NON-NLS-1$
            }
        }
        for (int i = BASE_FONT_SIZE; i < 22; i++) {
            fontSizes.addItem(Integer.toString(i));
        }

        Font baseFont = UIRegistry.getBaseFont();
        if (baseFont != null) {
            fontNames.setSelectedItem(baseFont.getFamily());
            fontSizes.setSelectedItem(Integer.toString(baseFont.getSize()));

            if (testField != null) {
                ActionListener al = new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        testField.setFont(new Font((String) fontNames.getSelectedItem(), Font.PLAIN,
                                fontSizes.getSelectedIndex() + BASE_FONT_SIZE));
                        form.getUIComponent().validate();
                        clearFontSettings = false;
                    }
                };
                fontNames.addActionListener(al);
                fontSizes.addActionListener(al);
            }
        }
    }

    //-----------------------------------
    // Do DisciplineType Icons
    //-----------------------------------

    String iconName = AppPreferences.getRemote().get(getDisciplineImageName(), "CollectionObject"); //$NON-NLS-1$ //$NON-NLS-2$

    List<Pair<String, ImageIcon>> list = IconManager.getListByType("disciplines", IconManager.IconSize.Std16); //$NON-NLS-1$
    Collections.sort(list, new Comparator<Pair<String, ImageIcon>>() {
        public int compare(Pair<String, ImageIcon> o1, Pair<String, ImageIcon> o2) {
            String s1 = UIRegistry.getResourceString(o1.first);
            String s2 = UIRegistry.getResourceString(o2.first);
            return s1.compareTo(s2);
        }
    });

    disciplineCBX = (ValComboBox) form.getCompById("disciplineIconCBX"); //$NON-NLS-1$

    final JLabel dispLabel = form.getCompById("disciplineIcon"); //$NON-NLS-1$
    JComboBox comboBox = disciplineCBX.getComboBox();
    comboBox.setRenderer(new DefaultListCellRenderer() {
        @SuppressWarnings("unchecked") //$NON-NLS-1$
        public Component getListCellRendererComponent(JList listArg, Object value, int index,
                boolean isSelected, boolean cellHasFocus) {
            Pair<String, ImageIcon> item = (Pair<String, ImageIcon>) value;
            JLabel label = (JLabel) super.getListCellRendererComponent(listArg, value, index, isSelected,
                    cellHasFocus);
            if (item != null) {
                label.setIcon(item.second);
                label.setText(UIRegistry.getResourceString(item.first));
            }
            return label;
        }
    });

    int inx = 0;
    Pair<String, ImageIcon> colObj = new Pair<String, ImageIcon>("colobj_backstop", //$NON-NLS-1$
            IconManager.getIcon("colobj_backstop", IconManager.IconSize.Std16)); //$NON-NLS-1$
    comboBox.addItem(colObj);

    int cnt = 1;
    for (Pair<String, ImageIcon> item : list) {
        if (item.first.equals(iconName)) {
            inx = cnt;
        }
        comboBox.addItem(item);
        cnt++;
    }

    comboBox.addActionListener(new ActionListener() {
        @SuppressWarnings("unchecked") //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            JComboBox cbx = (JComboBox) e.getSource();
            Pair<String, ImageIcon> item = (Pair<String, ImageIcon>) cbx.getSelectedItem();
            if (item != null) {
                dispLabel.setIcon(IconManager.getIcon(item.first));
                form.getUIComponent().validate();
            }
        }
    });

    comboBox.setSelectedIndex(inx);

    //-----------------------------------
    // Date Field
    //-----------------------------------
    dateFieldCBX = form.getCompById("scrdateformat"); //$NON-NLS-1$
    fillDateFormat();

    //-----------------------------------
    // FormType
    //-----------------------------------
    fillFormTypes();

    //-----------------------------------
    // Do App Icon
    //-----------------------------------

    final JButton getIconBtn = form.getCompById("GetIconImage"); //$NON-NLS-1$
    final JButton clearIconBtn = form.getCompById("ClearIconImage"); //$NON-NLS-1$
    final JLabel appLabel = form.getCompById("appIcon"); //$NON-NLS-1$
    final JButton resetDefFontBtn = form.getCompById("ResetDefFontBtn"); //$NON-NLS-1$

    String imgEncoded = AppPreferences.getRemote().get(iconImagePrefName, ""); //$NON-NLS-1$
    ImageIcon innerAppImgIcon = null;
    if (StringUtils.isNotEmpty(imgEncoded)) {
        innerAppImgIcon = GraphicsUtils.uudecodeImage("", imgEncoded); //$NON-NLS-1$
        if (innerAppImgIcon != null && innerAppImgIcon.getIconWidth() != 32
                || innerAppImgIcon.getIconHeight() != 32) {
            innerAppImgIcon = null;
            clearIconBtn.setEnabled(false);
        } else {
            clearIconBtn.setEnabled(true);
        }
    }

    if (innerAppImgIcon == null) {
        innerAppImgIcon = IconManager.getIcon("AppIcon"); //$NON-NLS-1$
        clearIconBtn.setEnabled(false);
    } else {
        clearIconBtn.setEnabled(true);
    }
    appLabel.setIcon(innerAppImgIcon);

    getIconBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            chooseToolbarIcon(appLabel, clearIconBtn);
        }
    });

    clearIconBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ImageIcon appIcon = IconManager.getIcon("AppIcon");
            IconEntry entry = IconManager.getIconEntryByName(INNER_APPICON_NAME);
            entry.setIcon(appIcon);
            if (entry.getIcons().get(IconManager.IconSize.Std32) != null) {
                entry.getIcons().get(IconManager.IconSize.Std32).setImageIcon(appIcon);
            }

            appLabel.setIcon(IconManager.getIcon("AppIcon")); //$NON-NLS-1$
            clearIconBtn.setEnabled(false);
            AppPreferences.getRemote().remove(iconImagePrefName);
            form.getValidator().dataChanged(null, null, null);
        }
    });

    resetDefFontBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Font sysDefFont = UIRegistry.getDefaultFont();
            ComboBoxModel model = fontNames.getModel();
            for (int i = 0; i < model.getSize(); i++) {
                //System.out.println("["+model.getElementAt(i).toString()+"]["+sysDefFont.getFamily()+"]");
                if (model.getElementAt(i).toString().equals(sysDefFont.getFamily())) {
                    fontNames.setSelectedIndex(i);
                    clearFontSettings = true;
                    break;
                }
            }

            if (clearFontSettings) {
                fontSizes.setSelectedIndex(sysDefFont.getSize() - BASE_FONT_SIZE);
                clearFontSettings = true; // needs to be redone 
            }

            form.getValidator().dataChanged(null, null, null);
        }
    });

    //-----------------------------------
    // Do Banner Icon Size
    //-----------------------------------

    String fmtStr = "%d x %d pixels";//getResourceString("BNR_ICON_SIZE");
    bnrIconSizeCBX = form.getCompById("bnrIconSizeCBX"); //$NON-NLS-1$

    int size = AppPreferences.getLocalPrefs().getInt(BNR_ICON_SIZE, 20);
    inx = 0;
    cnt = 0;
    for (int pixelSize : pixelSizes) {
        ((DefaultComboBoxModel) bnrIconSizeCBX.getModel())
                .addElement(String.format(fmtStr, pixelSize, pixelSize));
        if (pixelSize == size) {
            inx = cnt;
        }
        cnt++;
    }

    bnrIconSizeCBX.getComboBox().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            form.getUIComponent().validate();
        }
    });

    bnrIconSizeCBX.getComboBox().setSelectedIndex(inx);

    UIValidator.setIgnoreAllValidation(this, false);
    fontNamesVCB.setChanged(false);
    fontSizesVCB.setChanged(false);

    form.getValidator().validateForm();
}

From source file:com.cch.aj.entryrecorder.frame.EntryJFrame.java

private int FillMouldComboBox(JComboBox comboBox, int id) {
    int result = -1;
    List<Mould> moulds = this.mouldService.GetAllEntities();
    if (moulds.size() > 0) {
        List<ComboBoxItem<Mould>> mouldNames = moulds.stream().sorted(comparing(x -> x.getCode()))
                .map(x -> ComboBoxItemConvertor.ConvertToComboBoxItem(x, x.getCode(), x.getId()))
                .collect(Collectors.toList());
        Mould mould = new Mould();
        mould.setId(0);/*from   www . j  a  v  a2  s  .  c o m*/
        mould.setCode("- Select -");
        mouldNames.add(0, new ComboBoxItem<Mould>(mould, mould.getCode(), mould.getId()));
        ComboBoxItem[] mouldNamesArray = mouldNames.toArray(new ComboBoxItem[mouldNames.size()]);
        comboBox.setModel(new DefaultComboBoxModel(mouldNamesArray));
        if (id != 0) {
            ComboBoxItem<Mould> currentMouldName = mouldNames.stream().filter(x -> x.getId() == id).findFirst()
                    .get();
            result = mouldNames.indexOf(currentMouldName);
        } else {
            result = 0;
        }
        comboBox.setSelectedIndex(result);
    }
    return result;
}

From source file:com.cch.aj.entryrecorder.frame.EntryJFrame.java

private int FillMachineComboBox(JComboBox comboBox, int id) {
    int result = -1;
    List<Machine> machines = this.machineService.GetAllEntities();
    if (machines.size() > 0) {
        List<ComboBoxItem<Machine>> machineNames = machines.stream().sorted(comparing(x -> x.getMachineNo()))
                .map(x -> ComboBoxItemConvertor.ConvertToComboBoxItem(x, x.getMachineNo(), x.getId()))
                .collect(Collectors.toList());
        Machine machine = new Machine();
        machine.setId(0);//from w w w .java2 s.c o  m
        machine.setMachineNo("- Select -");
        machineNames.add(0, new ComboBoxItem<Machine>(machine, machine.getMachineNo(), machine.getId()));
        ComboBoxItem[] machineNamesArray = machineNames.toArray(new ComboBoxItem[machineNames.size()]);
        comboBox.setModel(new DefaultComboBoxModel(machineNamesArray));
        if (id != 0) {
            ComboBoxItem<Machine> currentMachineName = machineNames.stream().filter(x -> x.getId() == id)
                    .findFirst().get();
            result = machineNames.indexOf(currentMachineName);
        } else {
            result = 0;
        }
        comboBox.setSelectedIndex(result);
    }
    return result;
}

From source file:com.t3.macro.api.functions.input.ColumnPanel.java

/** Creates a dropdown list control. */
public JComponent createListControl(VarSpec vs) {
    JComboBox combo;
    boolean showText = vs.optionValues.optionEquals("TEXT", "TRUE");
    boolean showIcons = vs.optionValues.optionEquals("ICON", "TRUE");
    int iconSize = vs.optionValues.getNumeric("ICONSIZE", 0);
    if (iconSize <= 0)
        showIcons = false;//from w  w  w  .  ja va  2s .c o  m

    // Build the combo box
    for (int j = 0; j < vs.valueList.size(); j++) {
        if (StringUtils.isEmpty(vs.valueList.get(j))) {
            // Using a non-empty string prevents the list entry from having zero height.
            vs.valueList.set(j, " ");
        }
    }
    if (!showIcons) {
        // Swing has an UNBELIEVABLY STUPID BUG when multiple items in a JComboBox compare as equal.
        // The combo box then stops supporting navigation with arrow keys, and
        // no matter which of the identical items is chosen, it returns the index
        // of the first one.  Sun closed this bug as "by design" in 1998.
        // A workaround found on the web is to use this alternate string class (defined below)
        // which never reports two items as being equal.
        NoEqualString[] nesValues = new NoEqualString[vs.valueList.size()];
        for (int i = 0; i < nesValues.length; i++)
            nesValues[i] = new NoEqualString(vs.valueList.get(i));
        combo = new JComboBox(nesValues);
    } else {
        combo = new JComboBox();
        combo.setRenderer(new ComboBoxRenderer());
        Pattern pattern = ASSET_PATTERN;

        for (String value : vs.valueList) {
            Matcher matcher = pattern.matcher(value);
            String valueText, assetID;
            Icon icon = null;

            // See if the value string for this item has an image URL inside it
            if (matcher.find()) {
                valueText = matcher.group(1);
                assetID = matcher.group(2);
            } else {
                valueText = value;
                assetID = null;
            }

            // Assemble a JLabel and put it in the list
            UpdatingLabel label = new UpdatingLabel();
            icon = InputFunctions.getIcon(assetID, iconSize, label);
            label.setOpaque(true); // needed to make selection highlighting show up
            if (showText)
                label.setText(valueText);
            if (icon != null)
                label.setIcon(icon);
            combo.addItem(label);
        }
    }
    int listIndex = vs.optionValues.getNumeric("SELECT");
    if (listIndex < 0 || listIndex >= vs.valueList.size())
        listIndex = 0;
    combo.setSelectedIndex(listIndex);
    combo.setMaximumRowCount(20);
    return combo;
}

From source file:com.cch.aj.entryrecorder.frame.EntryJFrame.java

private int FillProductComboBox(JComboBox comboBox, int id, int mouldId) {
    int result = -1;
    comboBox.removeAll();/*  ww  w .  j a  va2s.  c om*/
    List<Product> allProducts = this.productService.GetAllEntities();
    if (allProducts.size() > 0) {
        List<Product> products = allProducts.stream()
                .filter(x -> x.getMouldId() != null && x.getMouldId().getId() == mouldId)
                .collect(Collectors.toList());
        if (products.size() > 0) {
            List<ComboBoxItem<Product>> productNames = products.stream().sorted(comparing(x -> x.getCode()))
                    .map(x -> ComboBoxItemConvertor.ConvertToComboBoxItem(x, x.getCode(), x.getId()))
                    .collect(Collectors.toList());
            Product product = new Product();
            product.setId(0);
            product.setCode("- Select -");
            productNames.add(0, new ComboBoxItem<Product>(product, product.getCode(), product.getId()));
            ComboBoxItem[] productNamesArray = productNames.toArray(new ComboBoxItem[productNames.size()]);
            comboBox.setModel(new DefaultComboBoxModel(productNamesArray));
            if (id != 0) {
                ComboBoxItem<Product> currentProductName = productNames.stream().filter(x -> x.getId() == id)
                        .findFirst().get();
                result = productNames.indexOf(currentProductName);
            } else {
                result = 0;
            }
            comboBox.setSelectedIndex(result);
        }
    }
    return result;
}

From source file:com.cch.aj.entryrecorder.frame.EntryJFrame.java

private int FillEntryComboBox(JComboBox comboBox, int id) {
    int result = -1;
    List<Entry> allEntrys = this.entryService.GetAllEntities();
    if (allEntrys.size() > 0) {
        List<Entry> entrys = allEntrys.stream().filter(x -> x.getShift().equals(this.txtEntrySearch.getText()))
                .collect(Collectors.toList());
        if (entrys.size() > 0) {
            List<ComboBoxItem<Entry>> entryNames = entrys.stream().sorted(comparing(x -> x.getCreateDate()))
                    .map(x -> ComboBoxItemConvertor.ConvertToComboBoxItem(x,
                            (x.getMachineId() != null ? x.getMachineId().getMachineNo() : "New") + " / "
                                    + (x.getProductId() != null ? x.getProductId().getCode() : "NA"),
                            x.getId()))//from   w  w w .  ja  v a2 s  . c o m
                    .collect(Collectors.toList());
            Entry entry = new Entry();
            entry.setId(0);
            entry.setShift("- Select -");
            entryNames.add(0, new ComboBoxItem<Entry>(entry, entry.getShift(), entry.getId()));
            ComboBoxItem[] entryNamesArray = entryNames.toArray(new ComboBoxItem[entryNames.size()]);
            comboBox.setModel(new DefaultComboBoxModel(entryNamesArray));
            if (id != 0) {
                ComboBoxItem<Entry> currentEntryName = entryNames.stream().filter(x -> x.getId() == id)
                        .findFirst().get();
                result = entryNames.indexOf(currentEntryName);
            } else {
                result = 0;
            }
            comboBox.setSelectedIndex(result);
        } else {
            JOptionPane.showMessageDialog(this, "No entry has been found.", "Info", JOptionPane.OK_OPTION);
        }
    }
    return result;
}

From source file:it.imtech.metadata.MetaUtility.java

/**
 * Metodo adibito alla creazione dinamica ricorsiva dell'interfaccia dei
 * metadati/* www .j  a va 2 s.  c o  m*/
 *
 * @param submetadatas Map contente i metadati e i sottolivelli di metadati
 * @param vocabularies Map contenente i dati contenuti nel file xml
 * vocabulary.xml
 * @param parent Jpanel nel quale devono venir inseriti i metadati
 * @param level Livello corrente
 */
public void create_metadata_view(Map<Object, Metadata> submetadatas, JPanel parent, int level,
        final String panelname) throws Exception {
    ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader);
    int lenght = submetadatas.size();
    int labelwidth = 220;
    int i = 0;
    JButton addcontribute = null;

    for (Map.Entry<Object, Metadata> kv : submetadatas.entrySet()) {
        ArrayList<Component> tabobjects = new ArrayList<Component>();

        if (kv.getValue().MID == 17 || kv.getValue().MID == 23 || kv.getValue().MID == 18
                || kv.getValue().MID == 137) {
            continue;
        }

        //Crea un jpanel nuovo e fa appen su parent
        JPanel innerPanel = new JPanel(new MigLayout("fillx, insets 1 1 1 1"));
        innerPanel.setName("pannello" + level + i);

        i++;
        String datatype = kv.getValue().datatype.toString();

        if (kv.getValue().MID == 45) {
            JPanel choice = new JPanel(new MigLayout());

            JComboBox combo = addClassificationChoice(choice, kv.getValue().sequence, panelname);

            JLabel labelc = new JLabel();
            labelc.setText(Utility.getBundleString("selectclassif", bundle));
            labelc.setPreferredSize(new Dimension(100, 20));

            choice.add(labelc);

            findLastClassification(panelname);
            if (last_classification != 0 && classificationRemoveButton == null) {
                logger.info("Removing last clasification");
                classificationRemoveButton = new JButton("-");

                classificationRemoveButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent event) {
                        BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                        removeClassificationToMetadata(panelname);
                        BookImporter.getInstance().refreshMetadataTab(false, panelname);
                        findLastClassification(panelname); //update last_classification
                        BookImporter.getInstance().setCursor(null);
                    }
                });
                if (Integer.parseInt(kv.getValue().sequence) == last_classification) {
                    choice.add(classificationRemoveButton, "wrap, width :50:");
                }
            }

            if (classificationAddButton == null) {
                logger.info("Adding a new classification");
                choice.add(combo, "width 100:600:600");

                classificationAddButton = new JButton("+");

                classificationAddButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent event) {
                        BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                        addClassificationToMetadata(panelname);
                        BookImporter.getInstance().refreshMetadataTab(false, panelname);
                        BookImporter.getInstance().setCursor(null);
                    }
                });

                choice.add(classificationAddButton, "width :50:");
            } else {
                //choice.add(combo, "wrap,width 100:700:700");
                choice.add(combo, "width 100:700:700");
                if (Integer.parseInt(kv.getValue().sequence) == last_classification) {
                    choice.add(classificationRemoveButton, "wrap, width :50");
                }
            }
            parent.add(choice, "wrap,width 100:700:700");
            classificationMID = kv.getValue().MID;

            innerPanel.setName(panelname + "---ImPannelloClassif---" + kv.getValue().sequence);
            try {

                addClassification(innerPanel, classificationMID, kv.getValue().sequence, panelname);
            } catch (Exception ex) {
                logger.error("Errore nell'aggiunta delle classificazioni");
            }
            parent.add(innerPanel, "wrap, growx");
            BookImporter.policy.addIndexedComponent(combo);

            continue;
        }

        if (datatype.equals("Node")) {
            JLabel label = new JLabel();
            label.setText(kv.getValue().description);
            label.setPreferredSize(new Dimension(100, 20));

            int size = 16 - (level * 2);
            Font myFont = new Font("MS Sans Serif", Font.PLAIN, size);
            label.setFont(myFont);

            if (Integer.toString(kv.getValue().MID).equals("11")) {
                JPanel temppanel = new JPanel(new MigLayout());

                //update last_contribute
                findLastContribute(panelname);

                if (last_contribute != 0 && removeContribute == null) {
                    logger.info("Removing last contribute");
                    removeContribute = new JButton("-");

                    removeContribute.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent event) {
                            BookImporter.getInstance()
                                    .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                            removeContributorToMetadata(panelname);
                            BookImporter.getInstance().refreshMetadataTab(false, panelname);
                            BookImporter.getInstance().setCursor(null);
                        }
                    });

                    if (!kv.getValue().sequence.equals("")) {
                        if (Integer.parseInt(kv.getValue().sequence) == last_contribute) {
                            innerPanel.add(removeContribute, "width :50:");
                        }
                    }
                }

                if (addcontribute == null) {
                    logger.info("Adding a new contribute");
                    addcontribute = new JButton("+");

                    addcontribute.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent event) {
                            BookImporter.getInstance()
                                    .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                            addContributorToMetadata(panelname);
                            BookImporter.getInstance().refreshMetadataTab(false, panelname);
                            BookImporter.getInstance().setCursor(null);
                        }
                    });

                    temppanel.add(label, " width :200:");
                    temppanel.add(addcontribute, "width :50:");
                    innerPanel.add(temppanel, "wrap, growx");
                } else {
                    temppanel.add(label, " width :200:");
                    findLastContribute(panelname);
                    if (!kv.getValue().sequence.equals("")) {
                        if (Integer.parseInt(kv.getValue().sequence) == last_contribute) {
                            temppanel.add(removeContribute, "width :50:");
                        }
                    }
                    innerPanel.add(temppanel, "wrap, growx");
                }
            } else if (Integer.toString(kv.getValue().MID).equals("115")) {
                logger.info("Devo gestire una provenience!");
            }
        } else {
            String title = "";

            if (kv.getValue().mandatory.equals("Y") || kv.getValue().MID == 14 || kv.getValue().MID == 15) {
                title = kv.getValue().description + " *";
            } else {
                title = kv.getValue().description;
            }

            innerPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), title,
                    TitledBorder.LEFT, TitledBorder.TOP));

            if (datatype.equals("Vocabulary")) {
                TreeMap<String, String> entryCombo = new TreeMap<String, String>();
                int index = 0;
                String selected = null;

                if (!Integer.toString(kv.getValue().MID).equals("8"))
                    entryCombo.put(Utility.getBundleString("comboselect", bundle),
                            Utility.getBundleString("comboselect", bundle));

                for (Map.Entry<String, TreeMap<String, VocEntry>> vc : vocabularies.entrySet()) {
                    String tempmid = Integer.toString(kv.getValue().MID);

                    if (Integer.toString(kv.getValue().MID_parent).equals("11")
                            || Integer.toString(kv.getValue().MID_parent).equals("13")) {
                        String[] testmid = tempmid.split("---");
                        tempmid = testmid[0];
                    }

                    if (vc.getKey().equals(tempmid)) {
                        TreeMap<String, VocEntry> iEntry = vc.getValue();

                        for (Map.Entry<String, VocEntry> ivc : iEntry.entrySet()) {
                            entryCombo.put(ivc.getValue().description, ivc.getValue().ID);
                            if (kv.getValue().value != null) {
                                if (kv.getValue().value.equals(ivc.getValue().ID)) {
                                    selected = ivc.getValue().ID;
                                }
                            }
                            index++;
                        }
                    }
                }

                final ComboMapImpl model = new ComboMapImpl();
                model.setVocabularyCombo(true);
                model.putAll(entryCombo);

                final JComboBox voc = new javax.swing.JComboBox(model);
                model.specialRenderCombo(voc);

                if (Integer.toString(kv.getValue().MID_parent).equals("11")
                        || Integer.toString(kv.getValue().MID_parent).equals("13")) {
                    voc.setName("MID_" + Integer.toString(kv.getValue().MID) + "---" + kv.getValue().sequence);
                } else {
                    voc.setName("MID_" + Integer.toString(kv.getValue().MID));
                }

                if (Integer.toString(kv.getValue().MID).equals("8") && selected == null)
                    selected = "44";

                selected = (selected == null) ? Utility.getBundleString("comboselect", bundle) : selected;

                for (int k = 0; k < voc.getItemCount(); k++) {
                    Map.Entry<String, String> el = (Map.Entry<String, String>) voc.getItemAt(k);
                    if (el.getValue().equals(selected))
                        voc.setSelectedIndex(k);
                }

                voc.setPreferredSize(new Dimension(150, 30));
                innerPanel.add(voc, "wrap, width :400:");
                tabobjects.add(voc);
            } else if (datatype.equals("CharacterString") || datatype.equals("GPS")) {
                final JTextArea textField = new javax.swing.JTextArea();

                if (Integer.toString(kv.getValue().MID_parent).equals("11")
                        || Integer.toString(kv.getValue().MID_parent).equals("13")) {
                    textField.setName(
                            "MID_" + Integer.toString(kv.getValue().MID) + "---" + kv.getValue().sequence);
                } else {
                    textField.setName("MID_" + Integer.toString(kv.getValue().MID));
                }

                textField.setPreferredSize(new Dimension(230, 0));
                textField.setText(kv.getValue().value);
                textField.setLineWrap(true);
                textField.setWrapStyleWord(true);

                innerPanel.add(textField, "wrap, width :300:");

                textField.addKeyListener(new KeyAdapter() {
                    @Override
                    public void keyPressed(KeyEvent e) {
                        if (e.getKeyCode() == KeyEvent.VK_TAB) {
                            if (e.getModifiers() > 0) {
                                textField.transferFocusBackward();
                            } else {
                                textField.transferFocus();
                            }
                            e.consume();
                        }
                    }
                });

                tabobjects.add(textField);
            } else if (datatype.equals("LangString")) {
                JScrollPane inner_scroll = new javax.swing.JScrollPane();
                inner_scroll.setHorizontalScrollBarPolicy(
                        javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
                inner_scroll.setVerticalScrollBarPolicy(
                        javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
                inner_scroll.setPreferredSize(new Dimension(240, 80));
                inner_scroll.setName("langStringScroll");
                final JTextArea jTextArea1 = new javax.swing.JTextArea();
                jTextArea1.setName("MID_" + Integer.toString(kv.getValue().MID));
                jTextArea1.setText(kv.getValue().value);

                jTextArea1.setSize(new Dimension(350, 70));
                jTextArea1.setLineWrap(true);
                jTextArea1.setWrapStyleWord(true);

                inner_scroll.setViewportView(jTextArea1);
                innerPanel.add(inner_scroll, "width :300:");

                //Add combo language box
                JComboBox voc = getComboLangBox(kv.getValue().language);
                voc.setName("MID_" + Integer.toString(kv.getValue().MID) + "_lang");

                voc.setPreferredSize(new Dimension(200, 20));
                innerPanel.add(voc, "wrap, width :300:");

                jTextArea1.addKeyListener(new KeyAdapter() {
                    @Override
                    public void keyPressed(KeyEvent e) {
                        if (e.getKeyCode() == KeyEvent.VK_TAB) {
                            if (e.getModifiers() > 0) {
                                jTextArea1.transferFocusBackward();
                            } else {
                                jTextArea1.transferFocus();
                            }
                            e.consume();
                        }
                    }
                });
                tabobjects.add(jTextArea1);
                tabobjects.add(voc);
            } else if (datatype.equals("Language")) {
                final JComboBox voc = getComboLangBox(kv.getValue().value);
                voc.setName("MID_" + Integer.toString(kv.getValue().MID));

                voc.setPreferredSize(new Dimension(150, 20));
                voc.setBounds(5, 5, 150, 20);
                innerPanel.add(voc, "wrap, width :500:");

                //BookImporter.policy.addIndexedComponent(voc);
                tabobjects.add(voc);

            } else if (datatype.equals("Boolean")) {
                int selected = 0;
                TreeMap bin = new TreeMap<String, String>();
                bin.put("yes", Utility.getBundleString("voc1", bundle));
                bin.put("no", Utility.getBundleString("voc2", bundle));

                if (kv.getValue().value == null) {
                    switch (kv.getValue().MID) {
                    case 35:
                        selected = 0;
                        break;
                    case 36:
                        selected = 1;
                        break;
                    }
                } else if (kv.getValue().value.equals("yes")) {
                    selected = 1;
                } else {
                    selected = 0;
                }

                final ComboMapImpl model = new ComboMapImpl();
                model.putAll(bin);

                final JComboBox voc = new javax.swing.JComboBox(model);
                model.specialRenderCombo(voc);

                voc.setName("MID_" + Integer.toString(kv.getValue().MID));
                voc.setSelectedIndex(selected);

                voc.setPreferredSize(new Dimension(150, 20));
                voc.setBounds(5, 5, 150, 20);
                innerPanel.add(voc, "wrap, width :300:");
                //BookImporter.policy.addIndexedComponent(voc);
                tabobjects.add(voc);
            } else if (datatype.equals("License")) {
                String selectedIndex = null;
                int vindex = 0;
                int defaultIndex = 0;

                TreeMap<String, String> entryCombo = new TreeMap<String, String>();

                for (Map.Entry<String, TreeMap<String, VocEntry>> vc : vocabularies.entrySet()) {
                    if (vc.getKey().equals(Integer.toString(kv.getValue().MID))) {
                        TreeMap<String, VocEntry> iEntry = vc.getValue();

                        for (Map.Entry<String, VocEntry> ivc : iEntry.entrySet()) {
                            entryCombo.put(ivc.getValue().description, ivc.getValue().ID);

                            if (ivc.getValue().ID.equals("1"))
                                defaultIndex = vindex;

                            if (kv.getValue().value != null) {
                                if (ivc.getValue().ID.equals(kv.getValue().value)) {
                                    selectedIndex = Integer.toString(vindex);
                                }
                            }
                            vindex++;
                        }
                    }
                }

                if (selectedIndex == null)
                    selectedIndex = Integer.toString(defaultIndex);

                ComboMapImpl model = new ComboMapImpl();
                model.putAll(entryCombo);
                model.setVocabularyCombo(true);

                JComboBox voc = new javax.swing.JComboBox(model);
                model.specialRenderCombo(voc);

                voc.setName("MID_" + Integer.toString(kv.getValue().MID));
                voc.setSelectedIndex(Integer.parseInt(selectedIndex));
                voc.setPreferredSize(new Dimension(150, 20));

                voc.setBounds(5, 5, 150, 20);
                innerPanel.add(voc, "wrap, width :500:");
                //BookImporter.policy.addIndexedComponent(voc);
                tabobjects.add(voc);
            } else if (datatype.equals("DateTime")) {
                //final JXDatePicker datePicker = new JXDatePicker();
                JDateChooser datePicker = new JDateChooser();
                datePicker.setName("MID_" + Integer.toString(kv.getValue().MID));

                JPanel test = new JPanel(new MigLayout());
                JLabel lbefore = new JLabel(Utility.getBundleString("beforechristlabel", bundle));
                JCheckBox beforechrist = new JCheckBox();
                beforechrist.setName("MID_" + Integer.toString(kv.getValue().MID) + "_check");

                if (kv.getValue().value != null) {
                    try {
                        if (kv.getValue().value.charAt(0) == '-') {
                            beforechrist.setSelected(true);
                        }

                        Date date1 = new Date();
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                        if (kv.getValue().value.charAt(0) == '-') {
                            date1 = sdf.parse(adjustDate(kv.getValue().value));
                        } else {
                            date1 = sdf.parse(kv.getValue().value);
                        }
                        datePicker.setDate(date1);
                    } catch (Exception e) {
                        //Console.WriteLine("ERROR import date:" + ex.Message);
                    }
                }

                test.add(datePicker, "width :200:");
                test.add(lbefore, "gapleft 30");
                test.add(beforechrist, "wrap");

                innerPanel.add(test, "wrap");
            }
        }

        //Recursive call
        create_metadata_view(kv.getValue().submetadatas, innerPanel, level + 1, panelname);

        if (kv.getValue().editable.equals("Y")
                || (datatype.equals("Node") && kv.getValue().hidden.equals("0"))) {
            parent.add(innerPanel, "wrap, growx");

            for (Component tabobject : tabobjects) {
                BookImporter.policy.addIndexedComponent(tabobject);
            }
        }
    }
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private JComponent initializeJComponentForSubmodelParameter(final String type, final SubmodelInfo submodelInfo)
        throws ModelInformationException {
    try {//  w  ww  .j av a  2  s . c  o m
        final Class<?> clazz = Class.forName(type, true, currentModelHandler.getCustomClassLoader());
        final Object value = new ClassElement(clazz, null);
        submodelInfo.setActualType(clazz, null);
        final Object[] elements = new Object[] { value };
        final JComboBox list = new JComboBox(elements);
        list.setSelectedIndex(0);
        JPanel panel = new JPanel();
        panel.add(list);

        return panel;
    } catch (final ClassNotFoundException e) {
        throw new ModelInformationException(
                "Invalid actual type " + type + " for submodel parameter: " + submodelInfo.getName(), e);
    }
}

From source file:com.nikonhacker.gui.EmulatorUI.java

private void openChipOptionsDialog(final int chip) {

    // ------------------------ Disassembly options

    JPanel disassemblyOptionsPanel = new JPanel(new MigLayout("", "[left,grow][left,grow]"));

    // Prepare sample code area
    final RSyntaxTextArea listingArea = new RSyntaxTextArea(20, 90);
    SourceCodeFrame.prepareAreaFormat(chip, listingArea);

    final List<JCheckBox> outputOptionsCheckBoxes = new ArrayList<JCheckBox>();
    ActionListener areaRefresherListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                Set<OutputOption> sampleOptions = EnumSet.noneOf(OutputOption.class);
                dumpOptionCheckboxes(outputOptionsCheckBoxes, sampleOptions);
                int baseAddress = framework.getPlatform(chip).getCpuState().getResetAddress();
                int lastAddress = baseAddress;
                Memory sampleMemory = new DebuggableMemory(false);
                sampleMemory.map(baseAddress, 0x100, true, true, true);
                StringWriter writer = new StringWriter();
                Disassembler disassembler;
                if (chip == Constants.CHIP_FR) {
                    sampleMemory.store16(lastAddress, 0x1781); // PUSH    RP
                    lastAddress += 2;//  ww w . j av  a  2 s.co  m
                    sampleMemory.store16(lastAddress, 0x8FFE); // PUSH    (FP,AC,R12,R11,R10,R9,R8)
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x83EF); // ANDCCR  #0xEF
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x9F80); // LDI:32  #0x68000000,R0
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x6800);
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x0000);
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x2031); // LD      @(FP,0x00C),R1
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0xB581); // LSL     #24,R1
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x1A40); // DMOVB   R13,@0x40
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x9310); // ORCCR   #0x10
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x8D7F); // POP     (R8,R9,R10,R11,R12,AC,FP)
                    lastAddress += 2;
                    sampleMemory.store16(lastAddress, 0x0781); // POP    RP
                    lastAddress += 2;

                    disassembler = new Dfr();
                    disassembler.setDebugPrintWriter(new PrintWriter(new StringWriter())); // Ignore
                    disassembler.setOutputFileName(null);
                    disassembler.processOptions(new String[] { "-m", "0x" + Format.asHex(baseAddress, 8) + "-0x"
                            + Format.asHex(lastAddress, 8) + "=CODE" });
                } else {
                    sampleMemory.store32(lastAddress, 0x340B0001); // li      $t3, 0x0001
                    lastAddress += 4;
                    sampleMemory.store32(lastAddress, 0x17600006); // bnez    $k1, 0xBFC00020
                    lastAddress += 4;
                    sampleMemory.store32(lastAddress, 0x00000000); //  nop
                    lastAddress += 4;
                    sampleMemory.store32(lastAddress, 0x54400006); // bnezl   $t4, 0xBFC00028
                    lastAddress += 4;
                    sampleMemory.store32(lastAddress, 0x3C0C0000); //  ?lui   $t4, 0x0000
                    lastAddress += 4;

                    int baseAddress16 = lastAddress;
                    int lastAddress16 = baseAddress16;
                    sampleMemory.store32(lastAddress16, 0xF70064F6); // save    $ra,$s0,$s1,$s2-$s7,$fp, 0x30
                    lastAddress16 += 4;
                    sampleMemory.store16(lastAddress16, 0x6500); // nop
                    lastAddress16 += 2;
                    sampleMemory.store32(lastAddress16, 0xF7006476); // restore $ra,$s0,$s1,$s2-$s7,$fp, 0x30
                    lastAddress16 += 4;
                    sampleMemory.store16(lastAddress16, 0xE8A0); // ret
                    lastAddress16 += 2;

                    disassembler = new Dtx();
                    disassembler.setDebugPrintWriter(new PrintWriter(new StringWriter())); // Ignore
                    disassembler.setOutputFileName(null);
                    disassembler.processOptions(new String[] { "-m",
                            "0x" + Format.asHex(baseAddress, 8) + "-0x" + Format.asHex(lastAddress, 8)
                                    + "=CODE:32",
                            "-m", "0x" + Format.asHex(baseAddress16, 8) + "-0x" + Format.asHex(lastAddress16, 8)
                                    + "=CODE:16" });
                }
                disassembler.setOutputOptions(sampleOptions);
                disassembler.setMemory(sampleMemory);
                disassembler.initialize();
                disassembler.setOutWriter(writer);
                disassembler.disassembleMemRanges();
                disassembler.cleanup();
                listingArea.setText("");
                listingArea.append(writer.toString());
                listingArea.setCaretPosition(0);

            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    };

    int i = 1;
    for (OutputOption outputOption : OutputOption.allFormatOptions) {
        JCheckBox checkBox = makeOutputOptionCheckBox(chip, outputOption, prefs.getOutputOptions(chip), false);
        if (checkBox != null) {
            outputOptionsCheckBoxes.add(checkBox);
            disassemblyOptionsPanel.add(checkBox, (i % 2 == 0) ? "wrap" : "");
            checkBox.addActionListener(areaRefresherListener);
            i++;
        }
    }
    if (i % 2 == 0) {
        disassemblyOptionsPanel.add(new JLabel(), "wrap");
    }

    // Force a refresh
    areaRefresherListener.actionPerformed(new ActionEvent(outputOptionsCheckBoxes.get(0), 0, ""));

    //        disassemblyOptionsPanel.add(new JLabel("Sample output:", SwingConstants.LEADING), "gapbottom 1, span, split 2, aligny center");
    //        disassemblyOptionsPanel.add(new JSeparator(), "span 2,wrap");
    disassemblyOptionsPanel.add(new JSeparator(), "span 2, gapleft rel, growx, wrap");
    disassemblyOptionsPanel.add(new JLabel("Sample output:"), "span 2,wrap");
    disassemblyOptionsPanel.add(new JScrollPane(listingArea), "span 2,wrap");
    disassemblyOptionsPanel.add(new JLabel("Tip: hover over the option checkboxes for help"),
            "span 2, center, wrap");

    // ------------------------ Emulation options

    JPanel emulationOptionsPanel = new JPanel(new VerticalLayout(5, VerticalLayout.LEFT));
    emulationOptionsPanel.add(new JLabel());
    JLabel warningLabel = new JLabel(
            "NOTE: these options only take effect after reloading the firmware (or performing a 'Stop and reset')");
    warningLabel.setBackground(Color.RED);
    warningLabel.setOpaque(true);
    warningLabel.setForeground(Color.WHITE);
    warningLabel.setHorizontalAlignment(SwingConstants.CENTER);
    emulationOptionsPanel.add(warningLabel);
    emulationOptionsPanel.add(new JLabel());

    final JCheckBox writeProtectFirmwareCheckBox = new JCheckBox("Write-protect firmware");
    writeProtectFirmwareCheckBox.setSelected(prefs.isFirmwareWriteProtected(chip));
    emulationOptionsPanel.add(writeProtectFirmwareCheckBox);
    emulationOptionsPanel.add(new JLabel(
            "If checked, any attempt to write to the loaded firmware area will result in an Emulator error. This can help trap spurious writes"));

    final JCheckBox dmaSynchronousCheckBox = new JCheckBox("Make DMA synchronous");
    dmaSynchronousCheckBox.setSelected(prefs.isDmaSynchronous(chip));
    emulationOptionsPanel.add(dmaSynchronousCheckBox);
    emulationOptionsPanel.add(new JLabel(
            "If checked, DMA operations will be performed immediately, pausing the CPU. Otherwise they are performed in a separate thread."));

    final JCheckBox autoEnableTimersCheckBox = new JCheckBox("Auto enable timers");
    autoEnableTimersCheckBox.setSelected(prefs.isAutoEnableTimers(chip));
    emulationOptionsPanel.add(autoEnableTimersCheckBox);
    emulationOptionsPanel
            .add(new JLabel("If checked, timers will be automatically enabled upon reset or firmware load."));

    // Log memory messages
    final JCheckBox logMemoryMessagesCheckBox = new JCheckBox("Log memory messages");
    logMemoryMessagesCheckBox.setSelected(prefs.isLogMemoryMessages(chip));
    emulationOptionsPanel.add(logMemoryMessagesCheckBox);
    emulationOptionsPanel
            .add(new JLabel("If checked, messages related to memory will be logged to the console."));

    // Log serial messages
    final JCheckBox logSerialMessagesCheckBox = new JCheckBox("Log serial messages");
    logSerialMessagesCheckBox.setSelected(prefs.isLogSerialMessages(chip));
    emulationOptionsPanel.add(logSerialMessagesCheckBox);
    emulationOptionsPanel.add(
            new JLabel("If checked, messages related to serial interfaces will be logged to the console."));

    // Log register messages
    final JCheckBox logRegisterMessagesCheckBox = new JCheckBox("Log register messages");
    logRegisterMessagesCheckBox.setSelected(prefs.isLogRegisterMessages(chip));
    emulationOptionsPanel.add(logRegisterMessagesCheckBox);
    emulationOptionsPanel.add(new JLabel(
            "If checked, warnings related to unimplemented register addresses will be logged to the console."));

    // Log pin messages
    final JCheckBox logPinMessagesCheckBox = new JCheckBox("Log pin messages");
    logPinMessagesCheckBox.setSelected(prefs.isLogPinMessages(chip));
    emulationOptionsPanel.add(logPinMessagesCheckBox);
    emulationOptionsPanel.add(new JLabel(
            "If checked, warnings related to unimplemented I/O pins will be logged to the console."));

    emulationOptionsPanel.add(new JSeparator(JSeparator.HORIZONTAL));

    // Alt mode upon Debug
    JPanel altDebugPanel = new JPanel(new FlowLayout());
    Object[] altDebugMode = EnumSet.allOf(EmulationFramework.ExecutionMode.class).toArray();
    final JComboBox altModeForDebugCombo = new JComboBox(new DefaultComboBoxModel(altDebugMode));
    for (int j = 0; j < altDebugMode.length; j++) {
        if (altDebugMode[j].equals(prefs.getAltExecutionModeForSyncedCpuUponDebug(chip))) {
            altModeForDebugCombo.setSelectedIndex(j);
        }
    }
    altDebugPanel.add(new JLabel(Constants.CHIP_LABEL[1 - chip] + " mode when " + Constants.CHIP_LABEL[chip]
            + " runs in sync Debug: "));
    altDebugPanel.add(altModeForDebugCombo);
    emulationOptionsPanel.add(altDebugPanel);
    emulationOptionsPanel
            .add(new JLabel("If 'sync mode' is selected, this is the mode the " + Constants.CHIP_LABEL[1 - chip]
                    + " chip will run in when running the " + Constants.CHIP_LABEL[chip] + " in Debug mode"));

    // Alt mode upon Step
    JPanel altStepPanel = new JPanel(new FlowLayout());
    Object[] altStepMode = EnumSet.allOf(EmulationFramework.ExecutionMode.class).toArray();
    final JComboBox altModeForStepCombo = new JComboBox(new DefaultComboBoxModel(altStepMode));
    for (int j = 0; j < altStepMode.length; j++) {
        if (altStepMode[j].equals(prefs.getAltExecutionModeForSyncedCpuUponStep(chip))) {
            altModeForStepCombo.setSelectedIndex(j);
        }
    }
    altStepPanel.add(new JLabel(Constants.CHIP_LABEL[1 - chip] + " mode when " + Constants.CHIP_LABEL[chip]
            + " runs in sync Step: "));
    altStepPanel.add(altModeForStepCombo);
    emulationOptionsPanel.add(altStepPanel);
    emulationOptionsPanel
            .add(new JLabel("If 'sync mode' is selected, this is the mode the " + Constants.CHIP_LABEL[1 - chip]
                    + " chip will run in when running the " + Constants.CHIP_LABEL[chip] + " in Step mode"));

    // ------------------------ Prepare tabbed pane

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab(Constants.CHIP_LABEL[chip] + " Disassembly Options", null, disassemblyOptionsPanel);
    tabbedPane.addTab(Constants.CHIP_LABEL[chip] + " Emulation Options", null, emulationOptionsPanel);

    if (chip == Constants.CHIP_TX) {
        JPanel chipSpecificOptionsPanel = new JPanel(new VerticalLayout(5, VerticalLayout.LEFT));

        chipSpecificOptionsPanel.add(new JLabel("Eeprom status upon startup:"));

        ActionListener eepromInitializationRadioActionListener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                prefs.setEepromInitMode(Prefs.EepromInitMode.valueOf(e.getActionCommand()));
            }
        };
        JRadioButton blank = new JRadioButton("Blank");
        blank.setActionCommand(Prefs.EepromInitMode.BLANK.name());
        blank.addActionListener(eepromInitializationRadioActionListener);
        if (Prefs.EepromInitMode.BLANK.equals(prefs.getEepromInitMode()))
            blank.setSelected(true);
        JRadioButton persistent = new JRadioButton("Persistent across sessions");
        persistent.setActionCommand(Prefs.EepromInitMode.PERSISTENT.name());
        persistent.addActionListener(eepromInitializationRadioActionListener);
        if (Prefs.EepromInitMode.PERSISTENT.equals(prefs.getEepromInitMode()))
            persistent.setSelected(true);
        JRadioButton lastLoaded = new JRadioButton("Last Loaded");
        lastLoaded.setActionCommand(Prefs.EepromInitMode.LAST_LOADED.name());
        lastLoaded.addActionListener(eepromInitializationRadioActionListener);
        if (Prefs.EepromInitMode.LAST_LOADED.equals(prefs.getEepromInitMode()))
            lastLoaded.setSelected(true);

        ButtonGroup group = new ButtonGroup();
        group.add(blank);
        group.add(persistent);
        group.add(lastLoaded);

        chipSpecificOptionsPanel.add(blank);
        chipSpecificOptionsPanel.add(persistent);
        chipSpecificOptionsPanel.add(lastLoaded);

        chipSpecificOptionsPanel.add(new JLabel("Front panel type:"));
        final JComboBox frontPanelNameCombo = new JComboBox(new String[] { "D5100_small", "D5100_large" });
        if (prefs.getFrontPanelName() != null) {
            frontPanelNameCombo.setSelectedItem(prefs.getFrontPanelName());
        }
        frontPanelNameCombo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                prefs.setFrontPanelName((String) frontPanelNameCombo.getSelectedItem());
            }
        });
        chipSpecificOptionsPanel.add(frontPanelNameCombo);

        emulationOptionsPanel.add(new JSeparator(JSeparator.HORIZONTAL));

        tabbedPane.addTab(Constants.CHIP_LABEL[chip] + " specific options", null, chipSpecificOptionsPanel);
    }

    // ------------------------ Show it

    if (JOptionPane.OK_OPTION == JOptionPane.showOptionDialog(this, tabbedPane,
            Constants.CHIP_LABEL[chip] + " options", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
            null, null, JOptionPane.DEFAULT_OPTION)) {
        // save output options
        dumpOptionCheckboxes(outputOptionsCheckBoxes, prefs.getOutputOptions(chip));
        // apply
        TxCPUState.initRegisterLabels(prefs.getOutputOptions(chip));

        // save other prefs
        prefs.setFirmwareWriteProtected(chip, writeProtectFirmwareCheckBox.isSelected());
        prefs.setDmaSynchronous(chip, dmaSynchronousCheckBox.isSelected());
        prefs.setAutoEnableTimers(chip, autoEnableTimersCheckBox.isSelected());
        prefs.setLogRegisterMessages(chip, logRegisterMessagesCheckBox.isSelected());
        prefs.setLogSerialMessages(chip, logSerialMessagesCheckBox.isSelected());
        prefs.setLogPinMessages(chip, logPinMessagesCheckBox.isSelected());
        prefs.setLogMemoryMessages(chip, logMemoryMessagesCheckBox.isSelected());
        prefs.setAltExecutionModeForSyncedCpuUponDebug(chip,
                (EmulationFramework.ExecutionMode) altModeForDebugCombo.getSelectedItem());
        prefs.setAltExecutionModeForSyncedCpuUponStep(chip,
                (EmulationFramework.ExecutionMode) altModeForStepCombo.getSelectedItem());

    }
}