Example usage for javax.swing Box createHorizontalBox

List of usage examples for javax.swing Box createHorizontalBox

Introduction

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

Prototype

public static Box createHorizontalBox() 

Source Link

Document

Creates a Box that displays its components from left to right.

Usage

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;/*  w  w w. j ava  2 s .com*/

    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:com.diversityarrays.kdxplore.heatmap.HeatMapPanel.java

private JComponent createCurationControls() {

    rejectSamplesAction.setEnabled(false);
    acceptSamplesAction.setEnabled(false);

    deActivatePlotsAction.setEnabled(false);
    reActivatePlotsAction.setEnabled(false);

    //                      | deactivate
    //   accept  suppress   | reactivate

    JPanel panel = new JPanel();
    GBH gbh = new GBH(panel, 2, 2, 2, 2);

    gbh.add(0, 0, 1, 1, GBH.NONE, 1, 1, GBH.WEST, new JButton(acceptSamplesAction));
    gbh.add(1, 0, 1, 1, GBH.NONE, 1, 1, GBH.WEST, new JButton(rejectSamplesAction));
    //        if (! askAboutValueForUnscored) {
    //            // TODO i18n
    //            gbh.add(0,1, 2,1, GBH.HORZ, 1,1, GBH.CENTER, "Unscored samples ignored");
    //        }//w  ww.j a va  2s  . c o  m

    if (xValueRetriever.isPlotColumn() && yValueRetriever.isPlotRow()) {
        gbh.add(2, 0, 1, 2, GBH.VERT, 1, 1, GBH.CENTER, new JSeparator(JSeparator.VERTICAL));
        gbh.add(3, 0, 1, 1, GBH.NONE, 1, 1, GBH.EAST, new JButton(deActivatePlotsAction));
        gbh.add(3, 1, 1, 1, GBH.NONE, 1, 1, GBH.EAST, new JButton(reActivatePlotsAction));
    }

    if (markInfo != null) {
        JComboBox<String> combo = new JComboBox<>();
        combo.addItem(NO_MARK);
        for (String s : markInfo.plotPointsByMark.keySet()) {
            combo.addItem(s);
        }
        combo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                List<Point> points = null;
                Object item = combo.getSelectedItem();
                if (item != null && !NO_MARK.equals(item)) {
                    points = markInfo.plotPointsByMark.get(item);
                    markName = item.toString();
                }

                if (Check.isEmpty(points)) {
                    heatMap.removeDecoratedPoints(markInfoRenderer);
                } else {
                    heatMap.setDecoratedPoints(markInfoRenderer, points.toArray(new Point[points.size()]));
                }
            }
        });

        Box newBox = Box.createHorizontalBox();
        newBox.add(new JLabel(markInfo.label));
        newBox.add(combo);

        gbh.add(0, 2, 4, 1, GBH.HORZ, 1, 1, GBH.CENTER, newBox);
    }

    return panel;
}

From source file:jchrest.gui.VisualSearchPane.java

private JPanel logPanel() {
    _logScreen = new JTextArea();
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(new JScrollPane(_logScreen));

    Box buttons = Box.createHorizontalBox();
    buttons.add(new JButton(new SaveAction(_logScreen)));
    buttons.add(new JButton(new ClearAction(_logScreen)));
    panel.add(buttons, BorderLayout.SOUTH);

    return panel;
}

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

public TrialOverviewPanel(String title, OfflineData offdata, TrialExplorerManager manager,
        FileListTransferHandler flth, MessagePrinter mp, final Closure<List<Trial>> onTrialSelected) {
    super(new BorderLayout());

    offlineData = offdata;/*from   w w w.  j a v  a 2s  .  co  m*/
    KdxploreDatabase kdxdb = offlineData.getKdxploreDatabase();
    if (kdxdb != null) {
        kdxdb.addEntityChangeListener(trialChangeListener);
        kdxdb.addEntityChangeListener(traitChangeListener);
    }

    this.messagePrinter = mp;

    TableTransferHandler tth = TableTransferHandler.initialiseForCopySelectAll(trialsTable, true);
    trialsTable.setTransferHandler(new ChainingTransferHandler(flth, tth));
    trialsTable.setAutoCreateRowSorter(true);

    trialsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                List<Trial> selectedTrials = getSelectedTrials();
                if (selectedTrials.size() == 1) {
                    trialTraitsTableModel.setSelectedTrial(selectedTrials.get(0));
                } else {
                    trialTraitsTableModel.setSelectedTrial(null);
                }
                onTrialSelected.execute(selectedTrials);
            }
        }
    });
    trialsTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
                fireEditCommand(e);
            }
        }
    });

    GuiUtil.setVisibleRowCount(trialsTable, MAX_INITIAL_VISIBLE_TRIAL_ROWS);

    offlineData.addOfflineDataChangeListener(offlineDataChangeListener);

    trialTableModel.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            updateRefreshAction();
        }
    });
    trialTraitsTableModel.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            updateAddTraitAction();
            updateRemoveTraitAction();
            updateScoringOrderAction();
        }
    });
    trialTraitsTable.addMouseListener(new MouseAdapter() {

        List<Trait> selectedTraits;
        JPopupMenu popupMenu;
        Action showTraitsAction = new AbstractAction("Select in Trait Explorer") {
            @Override
            public void actionPerformed(ActionEvent e) {
                manager.showTraitsInTraitExplorer(selectedTraits);
            }
        };

        @Override
        public void mouseClicked(MouseEvent e) {

            if (SwingUtilities.isLeftMouseButton(e) && 2 == e.getClickCount()) {
                // Start editing the Trait
                e.consume();
                int vrow = trialTraitsTable.rowAtPoint(e.getPoint());
                if (vrow >= 0) {
                    int mrow = trialTraitsTable.convertRowIndexToModel(vrow);
                    if (mrow >= 0) {
                        Trait trait = trialTraitsTableModel.getTraitAt(mrow);
                        if (trait != null) {
                            traitExplorer.startEditing(trait);
                            ;
                        }
                    }
                }
            } else if (SwingUtilities.isRightMouseButton(e) && 1 == e.getClickCount()) {
                // Select the traits in the traitExplorer
                e.consume();
                List<Integer> modelRows = GuiUtil.getSelectedModelRows(trialTraitsTable);
                if (!modelRows.isEmpty()) {
                    selectedTraits = modelRows.stream().map(trialTraitsTableModel::getTraitAt)
                            .collect(Collectors.toList());

                    if (popupMenu == null) {
                        popupMenu = new JPopupMenu();
                        popupMenu.add(showTraitsAction);
                    }
                    Point pt = e.getPoint();
                    popupMenu.show(trialTraitsTable, pt.x, pt.y);
                }
            }
        }
    });
    trialTraitsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                updateRemoveTraitAction();
            }
        }
    });
    updateAddTraitAction();
    updateRemoveTraitAction();
    updateScoringOrderAction();
    updateRefreshAction();

    KDClientUtils.initAction(ImageId.REFRESH_24, refreshTrialTraitsAction, "Refresh");
    KDClientUtils.initAction(ImageId.MINUS_GOLD_24, removeTraitAction, "Remove selected Traits");
    KDClientUtils.initAction(ImageId.PLUS_BLUE_24, addTraitAction, "Add Traits to Trial");
    KDClientUtils.initAction(ImageId.TRAIT_ORDER_24, setScoringOrderAction, "Define Trait Scoring Order");

    Box buttons = Box.createHorizontalBox();

    buttons.add(new JButton(setScoringOrderAction));
    buttons.add(Box.createHorizontalGlue());
    buttons.add(new JButton(addTraitAction));
    buttons.add(new JButton(removeTraitAction));
    buttons.add(Box.createHorizontalStrut(10));
    buttons.add(refreshTrialTraitsButton);

    JPanel traitsPanel = new JPanel(new BorderLayout());
    traitsPanel.add(GuiUtil.createLabelSeparator("Uses Traits", buttons), BorderLayout.NORTH);
    traitsPanel.add(new PromptScrollPane(trialTraitsTable,
            "If the (single) selected Trial has Traits they will appear here"), BorderLayout.CENTER);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(trialsTable), traitsPanel);
    splitPane.setResizeWeight(0.5);

    add(splitPane, BorderLayout.CENTER);
}

From source file:jchrest.gui.VisualSearchPane.java

private JPanel analysePanel() {
    _analysisScreen = new JTextArea();

    Box buttons = Box.createVerticalBox();
    buttons.add(new JLabel("Find frequency of nodes used by model when scanning scenes"));

    JSpinner numFixations = new JSpinner(new SpinnerNumberModel(20, 1, 1000, 1));

    JPanel labelledSpinner = new JPanel();
    labelledSpinner.setLayout(new GridLayout(1, 2));
    labelledSpinner.add(new JLabel("Number of fixations: ", SwingConstants.RIGHT));
    labelledSpinner.add(numFixations);//from   w ww .  j a v  a  2 s  .  c  o m

    buttons.add(labelledSpinner);
    buttons.add(runAnalysisButtons(numFixations));

    // main panel
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    panel.add(buttons, BorderLayout.NORTH);

    panel.add(new JScrollPane(_analysisScreen));

    Box displayButtons = Box.createHorizontalBox();
    displayButtons.add(new JButton(new SaveAction(_analysisScreen)));
    displayButtons.add(new JButton(new ClearAction(_analysisScreen)));
    panel.add(displayButtons, BorderLayout.SOUTH);

    return panel;
}

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

public TrialViewPanel(WindowOpener<JFrame> windowOpener, OfflineData od,
        Transformer<Trial, Boolean> checkIfEditorActive, Consumer<Trial> onTraitInstancesRemoved,
        MessagePrinter mp) {//from  w  w w  . j  av  a2 s.  c  o  m
    super(new BorderLayout());

    this.windowOpener = windowOpener;
    this.checkIfEditorActive = checkIfEditorActive;
    this.onTraitInstancesRemoved = onTraitInstancesRemoved;
    this.messagePrinter = mp;

    this.offlineData = od;
    this.offlineData.addOfflineDataChangeListener(offlineDataChangeListener);
    KdxploreDatabase db = offlineData.getKdxploreDatabase();
    if (db != null) {
        db.addEntityChangeListener(trialChangeListener);
    }

    trialDataTable.setTransferHandler(TableTransferHandler.initialiseForCopySelectAll(trialDataTable, true));
    trialPropertiesTable
            .setTransferHandler(TableTransferHandler.initialiseForCopySelectAll(trialPropertiesTable, true));

    // Note: Can't use renderers because the TM always returns String.class
    // for getColumnClass()
    // trialPropertiesTable.setDefaultRenderer(TrialLayout.class, new
    // TrialLayoutRenderer(trialPropertiesTableModel));
    // trialPropertiesTable.setDefaultRenderer(PlotIdentOption.class, new
    // PlotIdentOptionRenderer(trialPropertiesTableModel));

    trialPropertiesTableModel.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            if (trialPropertiesTableModel.getRowCount() > 0) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        GuiUtil.initialiseTableColumnWidths(trialPropertiesTable);
                    }
                });
                trialPropertiesTableModel.removeTableModelListener(this);
            }
        }
    });

    //      int tnsColumnIndex = -1;
    //      for (int col = trialPropertiesTableModel.getColumnCount(); --col >= 0; ) {
    //         if (TraitNameStyle.class == trialPropertiesTableModel.getColumnClass(col)) {
    //            tnsColumnIndex = col;
    //            break;
    //         }
    //      }

    editAction.setEnabled(false);
    trialPropertiesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                int vrow = trialPropertiesTable.getSelectedRow();
                editAction.setEnabled(vrow >= 0 && trialPropertiesTableModel.isCellEditable(vrow, 1));
            }
        }
    });

    errorMessage.setForeground(Color.RED);
    Box top = Box.createHorizontalBox();
    top.add(errorMessage);
    top.add(Box.createHorizontalGlue());
    top.add(new JButton(editAction));

    JPanel main = new JPanel(new BorderLayout());
    main.add(new JScrollPane(trialPropertiesTable), BorderLayout.CENTER);
    main.add(legendPanel, BorderLayout.SOUTH);

    JScrollPane trialDataTableScrollPane = new JScrollPane(trialDataTable);

    // The preferred height of the viewport is determined
    // by whether or not we need to use hh:mm:ss in the name of any of
    // the scoring data sets.
    JViewport viewPort = new JViewport() {
        @Override
        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.height = 32;
            TableModel model = trialDataTable.getModel();
            if (model instanceof TrialData) {
                if (((TrialData) model).isUsingHMSformat()) {
                    d.height = 48;
                }
            }
            return d;
        }
    };
    trialDataTableScrollPane.setColumnHeader(viewPort);

    JTableHeader th = trialDataTable.getTableHeader();
    th.setDefaultRenderer(trialDataTableHeaderRenderer);
    th.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            int column = th.columnAtPoint(e.getPoint());
            trialDataTableHeaderRenderer.columnSelected = column;
            boolean shifted = 0 != (MouseEvent.SHIFT_MASK & e.getModifiers());
            boolean right = SwingUtilities.isRightMouseButton(e);
            updateDeleteSamplesAction(shifted, right);
            e.consume();
        }
    });

    trialDataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                removeTraitInstancesAction.setEnabled(trialDataTable.getSelectedRowCount() > 0);
            }
        }
    });
    removeTraitInstancesAction.setEnabled(false);

    KDClientUtils.initAction(ImageId.PLUS_BLUE_24, addSampleGroupAction, Msg.TOOLTIP_ADD_SAMPLES_FOR_SCORING());
    KDClientUtils.initAction(ImageId.TRASH_24, deleteSamplesAction, Msg.TOOLTIP_DELETE_COLLECTED_SAMPLES());
    KDClientUtils.initAction(ImageId.EXPORT_24, exportSamplesAction, Msg.TOOLTIP_EXPORT_SAMPLES_OR_TRAITS());
    KDClientUtils.initAction(ImageId.MINUS_GOLD_24, removeTraitInstancesAction,
            Msg.TOOLTIP_REMOVE_TRAIT_INSTANCES_WITH_NO_DATA());

    JPanel trialDataPanel = new JPanel(new BorderLayout());
    Box buttons = Box.createHorizontalBox();

    buttons.add(new JButton(removeTraitInstancesAction));
    buttons.add(Box.createHorizontalGlue());
    buttons.add(new JButton(exportSamplesAction));
    buttons.add(Box.createHorizontalGlue());
    buttons.add(new JButton(addSampleGroupAction));
    buttons.add(Box.createHorizontalStrut(8));
    buttons.add(new JButton(deleteSamplesAction));
    trialDataPanel.add(GuiUtil.createLabelSeparator("Measurements by Source", buttons), BorderLayout.NORTH);
    trialDataPanel.add(trialDataTableScrollPane, BorderLayout.CENTER);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, main, trialDataPanel);
    splitPane.setResizeWeight(0.5);

    add(top, BorderLayout.NORTH);
    add(splitPane, BorderLayout.CENTER);

    trialDataTable.setDefaultRenderer(Object.class, new TrialDataCellRenderer());

    trialDataTable.addPropertyChangeListener("model", new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            trialDataTableHeaderRenderer.columnSelected = -1;
            updateDeleteSamplesAction(false, false);
        }
    });
}

From source file:ffx.ui.ModelingPanel.java

private JPanel getNucleicAcidPanel() {
    if (nucleicPanel != null) {
        return nucleicPanel;
    }/*  ww w.  j  ava  2s .  c  om*/
    nucleicPanel = new JPanel(new GridLayout(3, 4, 2, 2));
    Residue.NA3 a[] = Residue.NA3.values();
    for (int i = 0; i < 8; i++) {
        JButton button = new JButton(a[i].name());
        button.setActionCommand("NUCLEIC");
        button.addActionListener(this);
        nucleicPanel.add(button);
    }
    JButton button = new JButton("MOL");
    button.setActionCommand("NUCLEIC");
    button.addActionListener(this);
    nucleicPanel.add(button);
    nucleicPanel.add(Box.createHorizontalBox());
    nucleicPanel.add(Box.createHorizontalBox());
    nucleicPanel.add(Box.createHorizontalBox());
    nucleicPanel.setMaximumSize(nucleicPanel.getPreferredSize());
    return nucleicPanel;
}

From source file:io.heming.accountbook.ui.MainFrame.java

private void initToolBar() {
    toolbar = new JToolBar("ToolBar", JToolBar.HORIZONTAL);

    // Add Button
    addButton = new JButton();
    addButton.setActionCommand("");
    addButton.setToolTipText("");
    addButton.setIcon(new ImageIcon(getClass().getResource("edit-add-3.png")));

    // Search date range radio buttons
    ButtonGroup group = new ButtonGroup();
    yearToggleButton = new JToggleButton();
    yearToggleButton.setToolTipText("");
    yearToggleButton.setIcon(new ImageIcon(getClass().getResource("year-s.png")));
    group.add(yearToggleButton);//from   ww w .j a  v  a2s.  c o  m
    monthToggleButton = new JToggleButton();
    monthToggleButton.setToolTipText("");
    monthToggleButton.setIcon(new ImageIcon(getClass().getResource("month-s.png")));
    group.add(monthToggleButton);
    dayToggleButton = new JToggleButton();
    dayToggleButton.setToolTipText("");
    dayToggleButton.setIcon(new ImageIcon(getClass().getResource("day-s.png")));
    group.add(dayToggleButton);
    customToggleButton = new JToggleButton();
    customToggleButton.setToolTipText("");
    customToggleButton.setIcon(new ImageIcon(getClass().getResource("all-s.png")));
    group.add(customToggleButton);

    // ??Checkbox
    monthToggleButton.setSelected(true);

    Calendar earliestCalendar = Calendar.getInstance();
    earliestCalendar.add(Calendar.YEAR, -100);
    java.util.Date earliestDate = earliestCalendar.getTime();

    Calendar latestCalendar = Calendar.getInstance();
    latestCalendar.add(Calendar.YEAR, 100);
    java.util.Date latestDate = latestCalendar.getTime();
    // 3?
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MONTH, -1);
    calendar.add(Calendar.DAY_OF_MONTH, 1);
    java.util.Date initDate = calendar.getTime();

    SpinnerDateModel startDateModel = new SpinnerDateModel(DateUtil.getStartOfWeek(), earliestDate, latestDate,
            Calendar.MONTH);
    startDateSpinner = new JSpinner(startDateModel);
    JSpinner.DateEditor startDateEditor = new JSpinner.DateEditor(startDateSpinner, "yyyy-MM-dd");
    startDateSpinner.setEditor(startDateEditor);

    calendar.add(Calendar.MONTH, 1);
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    initDate = calendar.getTime();
    SpinnerDateModel endDateModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.MONTH);
    endDateSpinner = new JSpinner(endDateModel);
    JSpinner.DateEditor endDateEditor = new JSpinner.DateEditor(endDateSpinner, "yyyy-MM-dd");
    endDateSpinner.setEditor(endDateEditor);

    // Keyword text field
    keywordTextField = new JTextField();
    keywordTextField.setPreferredSize(new Dimension(250, 20));
    keywordTextField.setMaximumSize(keywordTextField.getPreferredSize());

    // Search Button
    searchButton = new JButton();
    searchButton.setActionCommand("?");
    searchButton.setToolTipText("?");
    searchButton.setIcon(new ImageIcon(getClass().getResource("edit-find-5.png")));

    // Layout
    cards = new JPanel();
    cards.setLayout(new CardLayout());
    Box box = Box.createHorizontalBox();
    box.add(Box.createHorizontalGlue());

    startDateSpinner.setPreferredSize(new Dimension(90, 20));
    startDateSpinner.setMaximumSize(startDateSpinner.getPreferredSize());
    box.add(startDateSpinner);

    box.add(Box.createHorizontalStrut(6));

    endDateSpinner.setPreferredSize(new Dimension(90, 20));
    endDateSpinner.setMaximumSize(endDateSpinner.getPreferredSize());
    box.add(endDateSpinner);

    cards.add(new JPanel(), HIDE_DATE_CHOOSER);
    cards.add(box, SHOW_DATE_CHOOSER);

    Box dateRangeBox = Box.createHorizontalBox();
    dateRangeBox.add(Box.createHorizontalGlue());
    dateRangeBox.add(cards);

    toolbar.add(addButton);
    toolbar.add(dateRangeBox);
    toolbar.add(customToggleButton);
    toolbar.add(yearToggleButton);
    toolbar.add(monthToggleButton);
    toolbar.add(dayToggleButton);
    toolbar.add(keywordTextField);
    toolbar.add(searchButton);

    add(toolbar, BorderLayout.NORTH);

    // Event listener
    addButton.addActionListener(e -> showAddRecordDialog());

    ActionListener listener = e -> searchRecords();
    yearToggleButton.addActionListener(listener);
    monthToggleButton.addActionListener(listener);
    dayToggleButton.addActionListener(listener);
    customToggleButton.addActionListener(listener);
    keywordTextField.addActionListener(listener);
    searchButton.addActionListener(listener);

    customToggleButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                chooseDateRange();
            }
        }
    });
}

From source file:com.diversityarrays.kdxplore.trialmgr.trait.TraitExplorerPanel.java

public TraitExplorerPanel(MessagePrinter mp, OfflineData od, DALClientProvider clientProvider,
        // KdxUploadHandler uploadHandler,
        BackgroundRunner backgroundRunner, ImageIcon addBarcodeIcon,
        Transformer<Trial, Boolean> checkIfEditorActive) {
    super(new BorderLayout());

    this.backgroundRunner = backgroundRunner;
    this.clientProvider = clientProvider;
    // this.uploadHandler = uploadHandler;
    this.messagePrinter = mp;
    this.offlineData = od;
    this.checkIfEditorActive = checkIfEditorActive;

    offlineData.addOfflineDataChangeListener(offlineDataListener);

    editingLocked.setIcon(KDClientUtils.getIcon(ImageId.LOCKED));
    editingLocked.addActionListener(new ActionListener() {
        @Override//from   w  w w  .ja  v  a2s . c o m
        public void actionPerformed(ActionEvent e) {
            changeEditable(editingLocked.isSelected(), DONT_OVERRIDE);
        }
    });

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

    KDClientUtils.initAction(ImageId.TRASH_24, deleteTraitsAction, "Remove Trait");
    deleteTraitsAction.setEnabled(false);

    KDClientUtils.initAction(ImageId.REFRESH_24, refreshAction, "Refresh Data");

    KDClientUtils.initAction(ImageId.PLUS_BLUE_24, addNewTraitAction, "Add Trait");

    KDClientUtils.initAction(ImageId.UPLOAD_24, uploadTraitsAction, "Upload Traits");

    KDClientUtils.initAction(ImageId.ADD_TRIALS_24, importTraitsAction, "Import Traits");

    KDClientUtils.initAction(ImageId.EXPORT_24, exportTraitsAction, "Export Traits");

    try {
        Class.forName("com.diversityarrays.kdxplore.upload.TraitUploadTask");
    } catch (ClassNotFoundException e1) {
        uploadTraitsAction.setEnabled(false);
        if (RunMode.getRunMode().isDeveloper()) {
            new Toast((JComponent) null,
                    "<HTML>Developer Warning<BR>" + "Trait Upload currently unavailable<BR>", 4000)
                            .showAsError();
        }
    }

    traitPropertiesTable
            .setTransferHandler(TableTransferHandler.initialiseForCopySelectAll(traitPropertiesTable, true));
    traitPropertiesTableModel.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            if (traitPropertiesTableModel.getRowCount() > 0) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        GuiUtil.initialiseTableColumnWidths(traitPropertiesTable);
                    }
                });
                traitPropertiesTableModel.removeTableModelListener(this);
            }
        }
    });

    traitTableModel.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            showCorrectCard();
        }
    });

    TrialManagerPreferences preferences = TrialManagerPreferences.getInstance();
    preferences.addChangeListener(TrialManagerPreferences.BAD_FOR_CALC, badForCalcColorChangeListener);
    badForCalc.setForeground(preferences.getBadForCalcColor());
    badForCalc.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e)) {
                KdxPreference<Color> pref = TrialManagerPreferences.BAD_FOR_CALC;
                String title = pref.getName();
                KdxplorePreferenceEditor.startEditorDialog(TraitExplorerPanel.this, title, pref);
            }
        }
    });

    traitsTable.setAutoCreateRowSorter(true);
    int index = traitTableModel.getTraitNameColumnIndex();
    if (index >= 0) {
        traitsTable.getColumnModel().getColumn(index).setCellRenderer(traitNameCellRenderer);
    }

    traitsTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e) && 2 == e.getClickCount()) {
                e.consume();

                int vrow = traitsTable.rowAtPoint(e.getPoint());
                if (vrow >= 0) {
                    int mrow = traitsTable.convertRowIndexToModel(vrow);
                    if (mrow >= 0) {
                        Trait trait = traitTableModel.getTraitAtRow(mrow);
                        Integer selectViewRow = null;
                        if (!traitTrialsTableModel.isSelectedTrait(trait)) {
                            selectViewRow = vrow;
                        }
                        if (traitsEditable) {
                            startEditingTraitInternal(trait, selectViewRow, null);
                        } else {
                            warnEditingLocked();
                        }
                    }
                }
            }
        }
    });

    traitsTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    traitsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {

                List<Trait> selectedTraits = getSelectedTraits();
                traitTrialsTableModel.setSelectedTraits(selectedTraits);

                if (selectedTraits.size() == 1) {
                    Trait trait = null;
                    int vrow = traitsTable.getSelectedRow();
                    if (vrow >= 0) {
                        int mrow = traitsTable.convertRowIndexToModel(vrow);
                        if (mrow >= 0) {
                            trait = traitTableModel.getEntityAt(mrow);
                        }
                    }
                    showTraitDetails(trait);
                }

                deleteTraitsAction.setEnabled(selectedTraits.size() > 0);

                showCorrectCard();
            }
        }
    });

    TraitTableModel.initValidationExpressionRenderer(traitsTable);
    if (RunMode.getRunMode().isDeveloper()) {
        TraitTableModel.initTableForRawExpression(traitsTable);
    }
    cardPanel.add(noTraitsComponent, CARD_NO_TRAITS);
    cardPanel.add(selectTraitComponent, CARD_SELECT_TO_EDIT);
    cardPanel.add(new JScrollPane(traitPropertiesTable), CARD_TRAIT_EDITOR);

    JButton undoButton = initAction(undoAction, ImageId.UNDO_24, "Undo",
            KeyStroke.getKeyStroke('Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    JButton redoButton = initAction(redoAction, ImageId.REDO_24, "Redo",
            KeyStroke.getKeyStroke('Y', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    Box undoRedoButtons = Box.createHorizontalBox();
    undoRedoButtons.add(undoButton);
    undoRedoButtons.add(redoButton);

    JPanel detailsPanel = new JPanel(new BorderLayout());
    detailsPanel.add(GuiUtil.createLabelSeparator("Details", undoRedoButtons), BorderLayout.NORTH);
    detailsPanel.add(cardPanel, BorderLayout.CENTER);
    detailsPanel.add(legendPanel, BorderLayout.SOUTH);

    PromptScrollPane scrollPane = new PromptScrollPane(traitsTable,
            "Drag/Drop Traits CSV file or use 'Import Traits'");

    TableTransferHandler tth = TableTransferHandler.initialiseForCopySelectAll(traitsTable, true);
    traitsTable.setTransferHandler(new ChainingTransferHandler(flth, tth));

    scrollPane.setTransferHandler(flth);

    if (addBarcodeIcon == null) {
        barcodesMenuAction.putValue(Action.NAME, "Barcodes...");
    } else {
        barcodesMenuAction.putValue(Action.SMALL_ICON, addBarcodeIcon);
    }

    italicsForProtectedCheckbox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            traitNameCellRenderer.setUseItalicsForProtected(italicsForProtectedCheckbox.isSelected());
            traitsTable.repaint();
        }
    });

    Box leftTopControls = Box.createHorizontalBox();
    leftTopControls.add(importTraitsButton);
    leftTopControls.add(barcodesMenuButton);
    leftTopControls.add(new JButton(addNewTraitAction));
    leftTopControls.add(new JButton(uploadTraitsAction));
    leftTopControls.add(new JButton(exportTraitsAction));

    leftTopControls.add(Box.createHorizontalGlue());

    leftTopControls.add(editingLocked);
    leftTopControls.add(fixTraitLevelsButton);
    leftTopControls.add(refreshButton);
    leftTopControls.add(Box.createHorizontalStrut(8));
    leftTopControls.add(new JButton(deleteTraitsAction));
    // leftTopControls.add(Box.createHorizontalStrut(4));

    Box explanations = Box.createHorizontalBox();
    explanations.add(italicsForProtectedCheckbox);
    explanations.add(badForCalc);
    explanations.add(Box.createHorizontalGlue());

    fixTraitLevelsButton.setToolTipText("Fix Traits with " + TraitLevel.UNDECIDABLE.visible + " 'Level'");
    fixTraitLevelsButton.setVisible(false);

    JPanel leftTop = new JPanel(new BorderLayout());
    leftTop.add(leftTopControls, BorderLayout.NORTH);
    leftTop.add(scrollPane, BorderLayout.CENTER);
    leftTop.add(explanations, BorderLayout.SOUTH);

    JPanel leftBot = new JPanel(new BorderLayout());
    leftBot.add(GuiUtil.createLabelSeparator("Used by Trials"), BorderLayout.NORTH);
    leftBot.add(new PromptScrollPane(traitTrialsTable, "Any Trials using selected Traits appear here"));

    JSplitPane leftSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, leftTop, leftBot);
    leftSplit.setResizeWeight(0.5);

    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftSplit, detailsPanel);
    splitPane.setOneTouchExpandable(true);
    splitPane.setResizeWeight(0.5);

    add(splitPane, BorderLayout.CENTER);
}

From source file:org.forester.archaeopteryx.ControlPanel.java

void addSecondLevelJCheckBox(final JCheckBox jcb, final JPanel p) {
    jcb.setFocusPainted(false);/* w w w  . j  a v a2s .  c  om*/
    jcb.setFont(ControlPanel.jcb_font);
    if (!_configuration.isUseNativeUI()) {
        jcb.setBackground(ControlPanel.jcb_background_color);
        jcb.setForeground(ControlPanel.jcb_text_color);
    }
    Box box = Box.createHorizontalBox();
    p.setBackground(background_color);
    box.add(Box.createRigidArea(new Dimension(12, 0)));
    jcb.setVisible(_color_branches_cb.isSelected());
    box.add(jcb);
    p.add(box, "Center");
    jcb.addActionListener(this);
}