Example usage for javax.swing Box add

List of usage examples for javax.swing Box add

Introduction

In this page you can find the example usage for javax.swing Box add.

Prototype

public Component add(Component comp) 

Source Link

Document

Appends the specified component to the end of this container.

Usage

From source file:com.diversityarrays.kdxplore.boxplot.BoxPlotPanel.java

private Box generateControls() {

    for (JCheckBox jcb : Arrays.asList(showOutliers, showMean, showMedian)) {
        ActionListener optionsActionListener = new ActionListener() {
            @Override/*from  ww w.jav  a2s.c  o  m*/
            public void actionPerformed(ActionEvent e) {
                generateGraph(Why.OPTION_CHANGED);
                setSpinnerRanges();
            }
        };
        jcb.addActionListener(optionsActionListener);
        jcb.setSelected(true);
    }

    JLabel infoLabel = new JLabel(Msg.LABEL_SHOW_PARAMETERS());
    infoLabel.setBorder(new EmptyBorder(3, 3, 3, 3));

    Box hbox = Box.createHorizontalBox();
    hbox.add(syncedOption);
    hbox.add(minSpinner);
    hbox.add(new JLabel(" - ")); //$NON-NLS-1$
    hbox.add(maxSpinner);
    hbox.add(infoLabel);
    hbox.add(showOutliers);
    hbox.add(showMean);
    hbox.add(showMedian);

    return hbox;
}

From source file:com.diversityarrays.kdxplore.heatmap.HeatMapPanel.java

public HeatMapPanel(VisualisationTool vtool, int unique, SelectedValueStore svs, PlotInfoProvider pip,
        String title,/*from www  . ja va  2s  .  c  o  m*/

        HeatMapModelData<T> heatMapModelData, SuppressionHandler suppressionHandler) {
    super(title, svs, vtool.getVisualisationToolId(), unique, Arrays.asList(heatMapModelData.zTraitInstance),
            suppressionHandler);

    context = heatMapModelData.context;
    xValueRetriever = heatMapModelData.xValueRetriever;
    yValueRetriever = heatMapModelData.yValueRetriever;

    askAboutValueForUnscored = !ValueRetriever.isEitherOneXorY(xValueRetriever, yValueRetriever);

    traitInstanceValueRetriever = heatMapModelData.traitInstanceValueRetriever;
    this.zTraitInstance = heatMapModelData.zTraitInstance;
    //      this.plotSpecimensByPoint = heatMapModelData.model.getCellLegend();

    this.plotInfoProvider = pip;
    this.title = title;

    if (heatMapModelData.plotPointsByMark.isEmpty()) {
        markInfo = null;
    } else {
        markInfo = new MarkInfo(Msg.LABEL_MARK_INFO_PLOT_TYPE(), heatMapModelData.plotPointsByMark);
    }

    this.heatMap = createHeatMap(heatMapModelData);

    this.heatMap.addPropertyChangeListener(HeatMapPane.PROPERTY_SELECTION_CHANGE,
            heatMapPaneSelectionChangeListener);

    messagesTextArea.setEditable(false);
    tabbedPane.addTab(TAB_MESSAGES, new JScrollPane(messagesTextArea));
    tabbedPane.addTab(TAB_CURATION, createCurationControls());

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tabbedPane, heatMap);

    splitPane.setOneTouchExpandable(true);
    splitPane.setResizeWeight(0.0);
    add(splitPane, BorderLayout.CENTER);

    int cellValueCount = heatMap.getValueModel().getUniqueCellValueCount();
    Gradient[] gradients = Gradient.createBuiltins(cellValueCount);
    Gradient initial = null;
    for (Gradient g : gradients) {
        if (Gradient.RAINBOW_NAME.equals(g.getName())) {
            initial = g;
            break;
        }
    }

    gradientComboBox = new JComboBox<Gradient>(gradients);
    gradientComboBox.setRenderer(new GradientComboBoxRenderer());
    gradientComboBox.addItemListener(gradientItemListener);

    // gradientItemListener will to model.setGradient()
    gradientComboBox.setSelectedItem(initial);

    Box box = Box.createHorizontalBox();
    box.add(syncedOption);
    box.add(gradientComboBox);
    box.add(Box.createHorizontalGlue());
    //      if (RunMode.getRunMode().isDeveloper()) {
    //           box.add(useBlankTilesOption);
    //      }
    box.add(new JSeparator(JSeparator.VERTICAL));
    box.add(opacityLabel);
    box.add(unselectedOpacitySpinner);

    add(box, BorderLayout.SOUTH);

    opacityLabel.setToolTipText("Sets the opacity of unselected cells");
    unselectedOpacitySpinner.setToolTipText("Sets the opacity of unselected cells");

    //      useBlankTilesOption.setSelected(heatMap.getUseBlankTiles());
    unselectedOpacityModel.setValue(heatMap.getUnselectedOpacity());

    //      useBlankTilesOption.addActionListener(new ActionListener() {
    //            @Override
    //            public void actionPerformed(ActionEvent e) {
    //                handleUseBlankTilesChanged();
    //            }
    //        });

    unselectedOpacityModel.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            handleOpacityChange();
        }
    });

    updateMessagesWithMissingOrBad(null, heatMapModelData);

    applyDecoratorsToHeatMap(heatMapModelData);
}

From source file:com.diversityarrays.kdxplore.importdata.ImportSourceChoiceDialog.java

public ImportSourceChoiceDialog(SourceChoice sc, Window owner, KdxploreDatabase kdxdb, MessagePrinter mp,
        Closure<List<Trial>> onTrialsLoaded, BackgroundRunner backgroundRunner)
        throws IOException, KdxploreConfigException {
    super(owner, "Load Trial Data", ModalityType.APPLICATION_MODAL);

    this.sourceChoice = sc;
    this.kdxDatabase = kdxdb;
    this.databaseDeviceIdentifier = kdxDatabase.getDatabaseDeviceIdentifier();
    this.database = kdxDatabase.getKDXploreKSmartDatabase();
    this.backgroundRunner = backgroundRunner;
    this.messagePrinter = new CompoundMessagePrinter(mp, messagePanel);
    this.onTrialsLoaded = onTrialsLoaded;

    DevicesAndOperators devsAndOps = new DevicesAndOperators(System.getProperty("user.name")); //$NON-NLS-1$
    devAndOpPanel = new DeviceAndOperatorPanel(kdxdb, devsAndOps, true);
    devAndOpPanel.addChangeListener(devAndOpChangeListener);
    // Note: devAndOpPanel.initialise() is done in WindowListener.windowOpened() below 

    StringBuilder sb = new StringBuilder("Drag/Drop ");
    ImportType[] tmp = null;// ww  w.  j  a va2  s .  c o  m

    switch (sourceChoice) {
    case CSV:
        predicate = new Predicate<DeviceIdentifier>() {
            @Override
            public boolean evaluate(DeviceIdentifier devid) {
                return devid != null && DeviceIdentifier.PLEASE_SELECT_DEVICE_TYPE != devid.getDeviceType();
            }
        };
        sb.append("CSV");
        tmp = new ImportType[] { ImportType.CSV };
        break;
    case KDX:
        predicate = new Predicate<DeviceIdentifier>() {
            @Override
            public boolean evaluate(DeviceIdentifier devid) {
                if (devid == null || DeviceIdentifier.PLEASE_SELECT_DEVICE_TYPE == devid.getDeviceType()) {
                    return false;
                }
                return DeviceType.KDSMART.equals(devid.getDeviceType());
            }
        };
        sb.append(".KDX");
        tmp = new ImportType[] { ImportType.KDX };
        break;
    case XLS:
        devAndOpPanel.disableAddDevice();
        predicate = new Predicate<DeviceIdentifier>() {
            @Override
            public boolean evaluate(DeviceIdentifier devid) {
                if (devid == null || DeviceIdentifier.PLEASE_SELECT_DEVICE_TYPE == devid.getDeviceType()) {
                    return false;
                }
                return DeviceType.DATABASE.equals(devid.getDeviceType());
            }
        };
        sb.append("Excel");
        tmp = new ImportType[] { ImportType.KDXPLORE_EXCEL, ImportType.BMS_EXCEL };
        break;
    case DATABASE:
    default:
        throw new IllegalStateException("sourceChoice=" + sourceChoice.name());
    }
    importTypes = tmp;
    if (importTypes == null) {
        throw new IllegalArgumentException(sourceChoice.name());
    }

    sb.append(" files here");
    String prompt = sb.toString();

    setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

    Container cp = getContentPane();

    PromptScrollPane pscrollPane = new PromptScrollPane(fileImportTable, prompt);
    pscrollPane.setTransferHandler(flth);
    fileImportTable.setTransferHandler(flth);

    fileImportTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //      fileImportTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    fileImportTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                updateImportAction();
            }
        }
    });

    final JSplitPane vSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pscrollPane, messagePanel);

    updateImportAction();

    Box buttons = Box.createHorizontalBox();
    buttons.add(Box.createHorizontalStrut(4));
    buttons.add(new JButton(importAction));
    buttons.add(Box.createHorizontalGlue());
    buttons.add(errorMessage);
    buttons.add(Box.createHorizontalGlue());
    buttons.add(new JButton(browseAction));
    buttons.add(Box.createHorizontalStrut(4));

    errorMessage.setForeground(Color.RED);

    JPanel top = new JPanel();
    GBH gbh = new GBH(top, 2, 2, 2, 2);
    int y = 0;

    gbh.add(0, y, 1, 1, GBH.BOTH, 1, 1, GBH.CENTER, devAndOpPanel);
    ++y;

    if (RunMode.getRunMode().isDeveloper()) {
        // Only Developer gets to see the Excel options panel (for now).
        gbh.add(0, y, 3, 1, GBH.BOTH, 2, 2, GBH.CENTER, bmsOptionsPanel);
        ++y;
    }

    gbh.add(0, y, 3, 1, GBH.HORZ, 1, 1, GBH.CENTER, buttons);
    ++y;

    cp.add(top, BorderLayout.NORTH);
    cp.add(vSplit, BorderLayout.CENTER);

    pack();

    GuiUtil.centreOnOwner(ImportSourceChoiceDialog.this);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            vSplit.setDividerLocation(0.5);

            // NO_BMS
            bmsOptionsPanel.setVisible(false /* SourceChoice.XLS == sourceChoice */);

            List<Pair<String, Exception>> errors = devAndOpPanel.initialise(predicate);
            if (errors.isEmpty()) {
                List<String> kdxFileNamesWithoutSuffix = new ArrayList<>();
                for (int rowIndex = fileImportTableModel.getRowCount(); --rowIndex >= 0;) {
                    File file = fileImportTableModel.getFileAt(rowIndex);
                    String fname = file.getName();
                    int dotpos = fname.lastIndexOf('.');
                    if (dotpos > 0) {
                        String sfx = fname.substring(dotpos);
                        if (ExportFor.KDX_SUFFIX.equalsIgnoreCase(sfx)) {
                            kdxFileNamesWithoutSuffix.add(fname.substring(0, dotpos));
                        }
                    }
                }

                if (!kdxFileNamesWithoutSuffix.isEmpty()) {
                    devAndOpPanel.selectInitialDeviceIdentifier(kdxFileNamesWithoutSuffix);
                }
            } else {
                for (Pair<String, Exception> pair : errors) {
                    messagePrinter.println(pair.first + ":");
                    messagePrinter.println(pair.second.getMessage());
                }
            }
        }

        @Override
        public void windowClosing(WindowEvent e) {
            if (busy) {
                GuiUtil.beep();
            } else {
                dispose();
            }
        }
    });
}

From source file:org.kepler.gui.DialogGeneralTab.java

/**
 * getBottomPanel//from  w w w  .  j a v  a  2 s .c  o m
 * 
 * @return Component
 */
protected Component getBottomPanel() {
    final Box bottomPanel = Box.createVerticalBox();
    final Border bottomPanelTitledBorder = BorderFactory.createTitledBorder(
            StaticResources.getDisplayString("dialogs." + _targetType + ".general.NamesNotesBorderTitle", ""));

    bottomPanel.setBorder(bottomPanelTitledBorder);

    cbName = new JCheckBox(
            StaticResources.getDisplayString("dialogs." + _targetType + ".general.showNameCheckbox", ""));
    cbNotes = new JCheckBox(
            StaticResources.getDisplayString("dialogs." + _targetType + ".general.showNoteCheckbox", ""));
    cbPorts = new JCheckBox(
            StaticResources.getDisplayString("dialogs." + _targetType + ".general.showPortNamesCheckbox", ""));

    bottomPanel.add(cbName);
    bottomPanel.add(cbNotes);
    bottomPanel.add(cbPorts);
    return bottomPanel;
}

From source file:com.diversityarrays.dal.server.AskServerParams.java

public AskServerParams(Image serverIconImage, final Window owner, String title, File www,
        DalServerPreferences prefs) {//from   ww  w . j a  v a2s . c  om
    super(owner, title, ModalityType.APPLICATION_MODAL);

    this.wwwRoot = www;
    this.preferences = prefs;

    if (serverIconImage != null) {
        setIconImage(serverIconImage);
    }

    Iterator<DalDbProviderService> iter = ServiceRegistry.lookupProviders(DalDbProviderService.class);
    while (iter.hasNext()) {
        DalDbProviderService s = iter.next();
        factoryTabbedPane.addTab(s.getProviderName(), new ProviderPanel(s));
    }

    List<String> hostnames = DalServerUtil.collectHostnamesForChoice(true);
    hostnameChoice = new JComboBox<String>(hostnames.toArray(new String[hostnames.size()]));

    wwwRootPath.setText(wwwRoot.getPath());

    Box buttons = Box.createHorizontalBox();
    buttons.add(Box.createHorizontalStrut(10));
    buttons.add(okButton);
    buttons.add(Box.createHorizontalGlue());
    buttons.add(cancelButton);
    buttons.add(Box.createHorizontalStrut(10));

    getContentPane().add(BorderLayout.NORTH, initGui());
    getContentPane().add(BorderLayout.SOUTH, buttons);
    pack();

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            removeWindowListener(this);
            if (owner != null) {
                GuiUtil.centreOnOwner(AskServerParams.this);
            } else {
                GuiUtil.centreOnScreen(AskServerParams.this);
            }
            okButton.requestFocus(); // unless it is disabled !
        }
    });
}

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

/** Creates a group of radio buttons. */
public JComponent createRadioControl(VarSpec vs) {
    int listIndex = vs.optionValues.getNumeric("SELECT");
    if (listIndex < 0 || listIndex >= vs.valueList.size())
        listIndex = 0;//from w  w w  .  j  a  v a  2 s  . c om
    ButtonGroup bg = new ButtonGroup();
    Box box = (vs.optionValues.optionEquals("ORIENT", "H")) ? Box.createHorizontalBox()
            : Box.createVerticalBox();

    // If the prompt is suppressed by SPAN=TRUE, use it as the border title
    String title = "";
    if (vs.optionValues.optionEquals("SPAN", "TRUE"))
        title = vs.prompt;
    box.setBorder(new TitledBorder(new EtchedBorder(), title));

    int radioCount = 0;
    for (String value : vs.valueList) {
        JRadioButton radio = new JRadioButton(value, false);
        bg.add(radio);
        box.add(radio);
        if (listIndex == radioCount)
            radio.setSelected(true);
        radioCount++;
    }
    return box;
}

From source file:com.diversityarrays.kdxplore.field.FieldViewPanel.java

public FieldViewPanel(PlotVisitList plotVisitList, Map<Integer, Trait> traitMap,
        SeparatorVisibilityOption visible, SimplePlotCellRenderer plotRenderer, Component... extras) {
    super(new BorderLayout());

    this.plotVisitList = plotVisitList;
    this.traitMap = traitMap;

    trial = plotVisitList.getTrial();/*w ww . j  a v a 2s . c o m*/

    fieldLayoutTableModel.setTrial(trial);

    int rowHeight = fieldLayoutTable.getRowHeight();
    fieldLayoutTable.setRowHeight(4 * rowHeight);

    fieldLayoutTable.setCellSelectionEnabled(true);

    fieldLayoutTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

    // IMPORTANT: DO NOT SORT THE FIELD LAYOUT TABLE
    fieldLayoutTable.setAutoCreateRowSorter(false);

    Map<Integer, Plot> plotById = new HashMap<>();
    FieldLayout<Integer> plotIdLayout = FieldLayoutUtil.createPlotIdLayout(trial.getTrialLayout(),
            trial.getPlotIdentSummary(), plotVisitList.getPlots(), plotById);

    KdxploreFieldLayout<Plot> kdxFieldLayout = new KdxploreFieldLayout<Plot>(Plot.class, plotIdLayout.imageId,
            plotIdLayout.xsize, plotIdLayout.ysize);
    kdxFieldLayout.warning = plotIdLayout.warning;

    String displayName = null;
    for (VisitOrder2D vo : VisitOrder2D.values()) {
        if (vo.imageId == plotIdLayout.imageId) {
            displayName = vo.displayName;
            break;
        }
    }
    //      VisitOrder2D vo = plotVisitList.getVisitOrder();
    KDClientUtils.initAction(plotIdLayout.imageId, changeCollectionOrder, displayName);

    hasUserPlotId = lookForUserPlotIdPresent(plotById, plotIdLayout, kdxFieldLayout);

    this.plotCellRenderer = plotRenderer;
    plotCellRenderer.setShowUserPlotId(hasUserPlotId);

    plotCellRenderer.setPlotXYprovider(getXYprovider());

    plotCellRenderer.setPlotVisitList(plotVisitList);

    fieldLayoutTable.setDefaultRenderer(Plot.class, plotCellRenderer);
    fieldLayoutTable.setCellSelectionEnabled(true);

    fieldLayoutTableModel.setFieldLayout(kdxFieldLayout);

    if (kdxFieldLayout.warning != null && !kdxFieldLayout.warning.isEmpty()) {
        warningMessage.setText(kdxFieldLayout.warning);
    } else {
        warningMessage.setText("");
    }

    fieldLayoutTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    fieldLayoutTable.getTableHeader().setReorderingAllowed(false);
    fieldLayoutTable.setCellSelectionEnabled(true);

    StringBuilder naming = new StringBuilder();
    String nameForRow = plotVisitList.getTrial().getNameForRow();
    if (!Check.isEmpty(nameForRow)) {
        naming.append(nameForRow);
    }
    String nameForCol = plotVisitList.getTrial().getNameForColumn();
    if (!Check.isEmpty(nameForCol)) {
        if (naming.length() > 0) {
            naming.append('/');
        }
        naming.append(nameForCol);
    }
    fieldTableScrollPane = new JScrollPane(fieldLayoutTable);
    if (naming.length() > 0) {
        JLabel cornerLabel = new JLabel(naming.toString());
        fieldTableScrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, cornerLabel);
    }
    fieldTableScrollPane.setRowHeaderView(rowHeaderTable);

    //      fieldLayoutTable.setRowHeaderTable(rowHeaderTable);

    //      Box extra = Box.createHorizontalBox();
    //      extra.add(new JButton(changeCollectionOrder));
    //      if (extras != null && extras.length > 0) {
    //         extra.add(Box.createHorizontalStrut(8));
    //         for (Component c : extras) {
    //            extra.add(c);
    //         }
    //      }
    //      extra.add(Box.createHorizontalGlue());

    switch (visible) {
    case NOTVISIBLE:
        break;

    case VISIBLE:
    default:
        Box top = Box.createHorizontalBox();
        top.setOpaque(true);
        top.setBackground(Color.LIGHT_GRAY);
        top.setBorder(new MatteBorder(0, 0, 1, 0, Color.GRAY));
        JLabel label = new JLabel("Field");
        label.setForeground(Color.DARK_GRAY);
        label.setFont(label.getFont().deriveFont(Font.BOLD));
        top.add(label);
        top.add(new JButton(changeCollectionOrder));

        if (extras != null && extras.length > 0) {
            top.add(Box.createHorizontalStrut(8));
            for (Component c : extras) {
                top.add(c);
            }
        }
        add(top, BorderLayout.NORTH);
        break;
    }

    add(fieldTableScrollPane, BorderLayout.CENTER);
    add(warningMessage, BorderLayout.SOUTH);
}

From source file:cloud.gui.CloudGUI.java

private JPanel createCurrentInstancesPanel() {
    JPanel currentInstancesPanel = new JPanel();
    currentInstancesPanel.setBorder(BorderFactory.createTitledBorder("Current Instances"));
    currentInstancesPanel.setLayout(new BoxLayout(currentInstancesPanel, BoxLayout.Y_AXIS));
    Box layout = Box.createVerticalBox();

    createNumberOfInstancesStatus(layout);
    createTotalCost(layout);//from   w w  w . j  a v  a  2 s . c o  m
    createInstanceTable(layout);

    removeInstanceButton = new JButton("Remove instance");

    layout.add(removeInstanceButton);
    currentInstancesPanel.add(layout);
    return currentInstancesPanel;
}

From source file:org.genedb.jogra.plugins.TermRationaliser.java

/**
 * Supplies the JPanel which is displayed in the main Jogra window.
 *//*  w  w  w. j a v a  2s  .c  o m*/
public JPanel getMainWindowPlugin() {

    final JPanel ret = new JPanel();
    final JButton loadButton = new JButton("Load Term Rationaliser");
    final JLabel chooseType = new JLabel("Select term: ");
    final JComboBox termTypeBox = new JComboBox(instances.keySet().toArray());
    final JCheckBox showEVCFilter = new JCheckBox("Highlight terms with evidence codes", true);

    loadButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent ae) {

            new SwingWorker<JFrame, Void>() {
                @Override
                protected JFrame doInBackground() throws Exception {
                    ret.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    setTermType(instances.get((String) termTypeBox.getSelectedItem()));
                    setShowEVC(showEVCFilter.isSelected());
                    return makeWindow();
                }

                @Override
                public void done() {
                    try {
                        final GeneDBMessage e = new OpenWindowEvent(TermRationaliser.this, get());
                        EventBus.publish(e);
                    } catch (final InterruptedException exp) {
                        exp.printStackTrace();
                    } catch (final ExecutionException exp) {
                        exp.printStackTrace();
                    }
                    ret.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                }
            }.execute();
        }
    });
    Box verticalBox = Box.createVerticalBox();
    Box horizontalBox = Box.createHorizontalBox();
    horizontalBox.add(chooseType);
    horizontalBox.add(termTypeBox);
    verticalBox.add(horizontalBox);
    verticalBox.add(loadButton);
    verticalBox.add(showEVCFilter);
    ret.add(verticalBox);
    return ret;
}

From source file:com.diversityarrays.kdxplore.trials.SampleGroupExportDialog.java

public SampleGroupExportDialog(Window owner, String title, Trial trial, KdxploreDatabase kdxploreDatabase,
        DeviceType deviceType, DeviceIdentifier devid, SampleGroup sampleGroup,
        Set<Integer> excludeTheseTraitIds, Map<Integer, Trait> allTraitIds, Set<Integer> excludeThesePlotIds) {
    super(owner, title, ModalityType.APPLICATION_MODAL);

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    setGlassPane(backgroundRunner.getBlockingPane());

    this.allTraits = allTraitIds;
    this.trial = trial;
    this.kdxploreDatabase = kdxploreDatabase;
    this.sampleGroup = sampleGroup;
    this.excludeTheseTraitIds = excludeTheseTraitIds;
    this.excludeThesePlotIds = excludeThesePlotIds;

    String deviceName = devid == null ? "Unknown_" + deviceType.name() : devid.getDeviceName();

    if (DeviceType.FOR_SCORING.equals(deviceType)) {
        if (!Check.isEmpty(sampleGroup.getOperatorName())) {
            deviceName = sampleGroup.getOperatorName();
        }/*from  w  w w . j av a  2  s .com*/
    }

    File directory = KdxplorePreferences.getInstance().getOutputDirectory();
    if (directory == null) {
        directory = new File(System.getProperty("user.home"));
    }
    String filename = Util.getTimestampedOutputFileName(trial.getTrialName(), deviceName);

    File outfile = new File(directory, filename);

    filepathText.setText(outfile.getPath());

    filepathText.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            updateButtons();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateButtons();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateButtons();
        }
    });
    updateButtons();

    boolean developer = RunMode.getRunMode().isDeveloper();
    oldKdsmartOption.setForeground(Color.BLUE);
    oldKdsmartOption.setToolTipText("For ElapsedDays value compatiblity with older versions of KDSmart");

    Box exportForOptionsBox = Box.createHorizontalBox();
    for (JComponent comp : exportForOptions) {
        if (developer || comp != oldKdsmartOption) {
            exportForOptionsBox.add(comp);
        }
    }

    Map<JRadioButton, OutputOption> optionByRb = new HashMap<>();
    ActionListener rbListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            selectedOutputOption = optionByRb.get(e.getSource());
            boolean enb = selectedOutputOption.exportFor != null;
            for (JComponent comp : exportForOptions) {
                if (comp == wantMediaFilesOption) {
                    comp.setEnabled(enb && selectedOutputOption.supportsMediaFiles());
                } else if (comp == kdsmartVersion3option) {
                    comp.setEnabled(enb && selectedOutputOption.usesWorkPackage());
                } else {
                    comp.setEnabled(enb);
                }
            }
        }
    };

    boolean anySamplesForIndividuals = true;
    try {
        anySamplesForIndividuals = kdxploreDatabase.getAnySamplesForIndividuals(sampleGroup);
    } catch (IOException e) {
        Shared.Log.w("SampleGroupExportDialog", "getAnySamplesForIndividuals", e);
    }

    ButtonGroup bg = new ButtonGroup();
    Box radioButtons = Box.createHorizontalBox();

    List<OutputOption> options = new ArrayList<>();
    Collections.addAll(options, OutputOption.values());

    if (!anySamplesForIndividuals) {
        // No relevant samples so don't bother offering the option.
        options.remove(OutputOption.CSV_FULL);
    }

    for (OutputOption oo : options) {
        if (!developer && OutputOption.JSON == oo) {
            continue;
        }

        JRadioButton rb = new JRadioButton(oo.displayName);
        if (OutputOption.KDX == oo) {
            kdxExportButton = rb;
        }

        if (OutputOption.ZIP == oo) {
            zipExportButton = rb;
        }

        rb.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                exportExclusionBox.selectAndDeactivateButtons(
                        kdxExportButton.isSelected() || zipExportButton.isSelected());
            }
        });

        if (OutputOption.JSON == oo) {
            rb.setForeground(Color.BLUE);
            rb.setToolTipText("Developer Only");
        }
        bg.add(rb);
        optionByRb.put(rb, oo);
        radioButtons.add(rb);
        rb.addActionListener(rbListener);
        if (bg.getButtonCount() == 1) {
            rb.doClick();
        }
    }

    Box additionalOptionsBox = Box.createHorizontalBox();
    additionalOptionsBox.add(this.wantMediaFilesOption);
    additionalOptionsBox.add(this.kdsmartVersion3option);

    dbVersionLabel.setToolTipText(TTT_DATABASE_VERSION_FOR_EXPORT);
    databaseVersionChoices.setToolTipText(TTT_DATABASE_VERSION_FOR_EXPORT);

    JPanel panel = new JPanel();
    GBH gbh = new GBH(panel);
    int y = 0;

    gbh.add(0, y, 1, 1, GBH.NONE, 0, 1, GBH.EAST, "Output File:");
    gbh.add(1, y, 1, 1, GBH.HORZ, 1, 1, GBH.CENTER, filepathText);
    gbh.add(2, y, 1, 1, GBH.NONE, 1, 1, GBH.WEST, new JButton(browseFileAction));
    ++y;

    gbh.add(0, y, 1, 1, GBH.NONE, 0, 1, GBH.EAST, "Options:");
    gbh.add(1, y, 2, 1, GBH.HORZ, 1, 1, GBH.CENTER, radioButtons);
    ++y;

    gbh.add(0, y, 3, 1, GBH.HORZ, 1, 1, GBH.CENTER, exportExclusionBox);
    ++y;

    gbh.add(0, y, 3, 1, GBH.HORZ, 1, 1, GBH.CENTER, additionalOptionsBox);
    ++y;

    gbh.add(0, y, 1, 1, GBH.NONE, 0, 1, GBH.EAST, dbVersionLabel);
    gbh.add(1, y, 2, 1, GBH.HORZ, 1, 1, GBH.CENTER, BoxBuilder.horizontal().add(databaseVersionChoices).get());

    gbh.add(1, y, 2, 1, GBH.HORZ, 1, 1, GBH.CENTER, exportForOptionsBox);
    ++y;

    Box buttons = Box.createHorizontalBox();
    buttons.add(Box.createHorizontalGlue());
    buttons.add(new JButton(cancelAction));
    buttons.add(new JButton(exportAction));
    buttons.add(new JButton(exportAndCloseAction));

    Container cp = getContentPane();

    cp.add(panel, BorderLayout.CENTER);
    cp.add(buttons, BorderLayout.SOUTH);

    pack();
}