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.dal.server.ServerGui.java

public ServerGui(Image serverIconImage, IDalServer svr, DalServerFactory factory, File wwwRoot,
        DalServerPreferences prefs) {//from ww  w.ja v  a2 s  .c  o  m

    this.serverIconImage = serverIconImage;
    this.dalServerFactory = factory;
    this.wwwRoot = wwwRoot;
    this.preferences = prefs;

    JMenuBar menuBar = new JMenuBar();

    JMenu serverMenu = new JMenu("Server");
    menuBar.add(serverMenu);
    serverMenu.add(serverStartAction);
    serverMenu.add(serverStopAction);
    serverMenu.add(exitAction);

    JMenu commandMenu = new JMenu("Command");
    menuBar.add(commandMenu);
    commandMenu.add(doSql);

    JMenu urlMenu = new JMenu("URL");
    menuBar.add(urlMenu);
    urlMenu.add(new JMenuItem(copyDalUrlAction));
    urlMenu.add(new JMenuItem(showDalUrlQRcodeAction));

    setJMenuBar(menuBar);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    messages.setFont(GuiUtil.createMonospacedFont(12));
    messages.setEditable(false);

    setServer(svr);

    quietOption.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean q = quietOption.isSelected();
            if (server != null) {
                server.setQuiet(q);
            }
        }
    });

    JScrollPane scrollPane = new JScrollPane(messages, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    final JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();

    JButton clear = new JButton(new AbstractAction("Clear") {
        @Override
        public void actionPerformed(ActionEvent e) {
            messages.setText("");
        }
    });

    final boolean[] follow = new boolean[] { true };
    final JCheckBox followTail = new JCheckBox("Follow", follow[0]);

    followTail.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            follow[0] = followTail.isSelected();
        }
    });

    final OutputStream os = new OutputStream() {
        @Override
        public void write(int b) throws IOException {
            char ch = (char) b;
            messages.append(new Character(ch).toString());
            if (ch == '\n' && follow[0]) {
                verticalScrollBar.setValue(verticalScrollBar.getMaximum());
            }
        }
    };

    TeePrintStream pso = new TeePrintStream(System.out, os);
    TeePrintStream pse = new TeePrintStream(System.err, os);

    System.setErr(pse);
    System.setOut(pso);

    Box box = Box.createHorizontalBox();
    box.add(clear);
    box.add(followTail);
    box.add(quietOption);
    box.add(Box.createHorizontalGlue());

    JPanel bottom = new JPanel(new BorderLayout());
    bottom.add(BorderLayout.NORTH, box);
    bottom.add(BorderLayout.SOUTH, statusInfoLine);

    Container cp = getContentPane();
    cp.add(BorderLayout.CENTER, scrollPane);
    cp.add(BorderLayout.SOUTH, bottom);

    pack();
    setSize(640, 480);

    final MemoryUsageMonitor mum = new MemoryUsageMonitor();
    mum.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            statusInfoLine.setMessage(mum.getMemoryUsage());
        }
    });

    if (server == null) {
        // If initial server is null, allow user to specify
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowOpened(WindowEvent e) {
                removeWindowListener(this);
                serverStartAction.actionPerformed(null);
            }
        });
    } else {
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowOpened(WindowEvent e) {
                removeWindowListener(this);
                ensureDatabaseInitialisedThenStartServer();
            }
        });
    }
}

From source file:com.diversityarrays.kdxplore.design.EntryFileImportDialog.java

public EntryFileImportDialog(Window owner, String title, File inputFile, Predicate<Role> entryHeadingFilter) {
    super(owner, title, ModalityType.APPLICATION_MODAL);

    this.entryHeadingFilter = entryHeadingFilter;
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    setGlassPane(backgroundRunner.getBlockingPane());

    useScrollBarOption.addActionListener(new ActionListener() {
        @Override/*from www  . j av a2s  . co  m*/
        public void actionPerformed(ActionEvent e) {
            updateDataPreviewScrolling();
        }
    });

    headingRoleTableModel = createHeadingRoleTableModel();
    headingRoleTable = new HeadingRoleTable<>(headingRoleTableModel);
    headingTableScrollPane = new JScrollPane(headingRoleTable);
    GuiUtil.setVisibleRowCount(headingRoleTable, 10);

    JPanel roleAssignmentPanel = new JPanel(new BorderLayout());
    roleAssignmentPanel.add(headingTableScrollPane, BorderLayout.CENTER);

    headingRoleTable.setTransferHandler(flth);
    headingRoleTableModel.addChangeListener(headingRoleChangeListener);

    GuiUtil.setVisibleRowCount(dataPreviewTable, 10);
    dataPreviewTable.setTransferHandler(flth);
    dataPreviewScrollPane.setTransferHandler(flth);
    updateDataPreviewScrolling();

    dataPreviewScrollPane.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            //                boolean useScrollBar = useScrollBarOption.isSelected();
            GuiUtil.initialiseTableColumnWidths(dataPreviewTable, true);
        }
    });

    Box top = Box.createHorizontalBox();
    top.add(new JLabel("# rows to preview: "));
    top.add(new JSpinner(previewRowCountSpinnerModel));
    top.add(Box.createHorizontalGlue());
    top.add(useScrollBarOption);

    JPanel dataPreviewPanel = new JPanel(new BorderLayout());
    dataPreviewPanel.add(GuiUtil.createLabelSeparator("Data Preview", top), BorderLayout.NORTH);
    dataPreviewPanel.add(dataPreviewScrollPane, BorderLayout.CENTER);

    headingWarning.setForeground(Color.RED);
    JLabel instructions = new JLabel("<HTML>Please assign a <i>Role</i> for each of the headings in your data"
            + "<br>You must specify one as the <i>Entry Name</i>."
            + "<br>Click on one of the <i>Role</i> cells and select from the dropdown"
            + "<br>To assign multiple headings, select the rows for which you wish"
            + "<br>to set the <i>Role</i> then right-click and choose from the dropdown.");
    instructions.setHorizontalAlignment(JLabel.CENTER);
    instructions.setBackground(Toast.PALE_YELLOW);

    JScrollPane instScroll = new JScrollPane(instructions);
    instScroll.setBackground(Toast.PALE_YELLOW);

    normalEntryNameField.getDocument()
            .addDocumentListener(new DocumentChangeListener((e) -> updateAcceptButton()));
    normalEntryNameField.setText(TrialDesignPreferences.getInstance().getNormalEntryTypeName());

    JPanel rolesPanel = new JPanel();
    GBH gbh = new GBH(rolesPanel, 2, 2, 0, 0);
    int y = 0;
    gbh.add(0, y, 1, 1, GBH.NONE, 0, 1, GBH.EAST, "Entry Type Name for non-Checks:");
    gbh.add(1, y, 1, 1, GBH.NONE, 1, 1, GBH.WEST, normalEntryNameField);
    gbh.add(2, y, 1, 1, GBH.NONE, 1, 1, GBH.WEST, saveForFuture);
    ++y;

    gbh.add(0, y, 3, 1, GBH.BOTH, 2, 1, GBH.CENTER, roleAssignmentPanel);
    ++y;

    JSplitPane headingsAndInstructions = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, rolesPanel, instScroll);

    JPanel headingPanel = new JPanel(new BorderLayout());
    headingPanel.add(GuiUtil.createLabelSeparator("Assign Roles for Headings"), BorderLayout.NORTH);
    headingPanel.add(headingsAndInstructions, BorderLayout.CENTER);
    headingPanel.add(headingWarning, BorderLayout.SOUTH);

    errorMessage.setEditable(false);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, dataPreviewPanel, headingPanel);
    splitPane.setResizeWeight(0.5);

    cardPanel.add(new JScrollPane(errorMessage), CARD_ERROR);
    cardPanel.add(splitPane, CARD_DATA);

    Box bot = Box.createHorizontalBox();
    bot.add(Box.createHorizontalGlue());
    bot.add(new JButton(cancelAction));
    bot.add(new JButton(acceptAction));
    acceptAction.setEnabled(false);

    Container cp = getContentPane();
    cp.add(cardPanel, BorderLayout.CENTER);
    cp.add(bot, BorderLayout.SOUTH);
    pack();

    sheetNamesComboBox.addActionListener(sheetNamesActionListener);

    Timer timer = new Timer(true);

    previewRowCountSpinnerModel.addChangeListener(new ChangeListener() {
        int nPreview;
        TimerTask timerTask = null;

        @Override
        public void stateChanged(ChangeEvent e) {
            nPreview = previewRowCountSpinnerModel.getNumber().intValue();

            if (timerTask == null) {
                timerTask = new TimerTask() {
                    int lastPreviewCount = nPreview;

                    @Override
                    public void run() {
                        if (lastPreviewCount == nPreview) {
                            System.err.println("Stable at " + lastPreviewCount);
                            // No change, do it now
                            cancel();
                            try {
                                updateDataPreview(lastPreviewCount);
                            } finally {
                                timerTask = null;
                            }
                        } else {
                            System.err.println("Changing from " + lastPreviewCount + " to " + nPreview);
                            lastPreviewCount = nPreview;
                        }
                    }
                };
                timer.scheduleAtFixedRate(timerTask, 500, 100);
            }
        }
    });

    sheetNamesComboBox.setVisible(false);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            removeWindowListener(this);
            setFile(inputFile);
        }
    });
}

From source file:net.sf.firemox.DeckBuilder.java

/**
 * Creates new form DeckBuilder/*from w  ww .  j ava2s .c o  m*/
 */
private DeckBuilder() {
    super("DeckBuilder");
    form = this;
    timerPanel = new TimerGlassPane();
    cardLoader = new CardLoader(timerPanel);
    timer = new Timer(200, cardLoader);
    setGlassPane(timerPanel);
    try {
        setIconImage(Picture.loadImage(IdConst.IMAGES_DIR + "deckbuilder.gif"));
    } catch (Exception e) {
        // IGNORING
    }

    // Load settings
    loadSettings();

    // Initialize components
    final JMenuItem newItem = UIHelper.buildMenu("menu_db_new", 'n', this);
    newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));

    final JMenuItem loadItem = UIHelper.buildMenu("menu_db_load", 'o', this);
    loadItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));

    final JMenuItem saveAsItem = UIHelper.buildMenu("menu_db_saveas", 'a', this);
    saveAsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0));

    final JMenuItem saveItem = UIHelper.buildMenu("menu_db_save", 's', this);
    saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));

    final JMenuItem quitItem = UIHelper.buildMenu("menu_db_exit", this);
    quitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_MASK));

    final JMenuItem deckConstraintsItem = UIHelper.buildMenu("menu_db_constraints", 'c', this);
    deckConstraintsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0));

    final JMenuItem aboutItem = UIHelper.buildMenu("menu_help_about", 'a', this);
    aboutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, InputEvent.SHIFT_MASK));

    final JMenuItem convertDCK = UIHelper.buildMenu("menu_convert_DCK_MP", this);

    final JMenu mainMenu = UIHelper.buildMenu("menu_file");
    mainMenu.add(newItem);
    mainMenu.add(loadItem);
    mainMenu.add(saveAsItem);
    mainMenu.add(saveItem);
    mainMenu.add(new JSeparator());
    mainMenu.add(quitItem);

    super.optionMenu = new JMenu("Options");

    final JMenu convertMenu = UIHelper.buildMenu("menu_convert");
    convertMenu.add(convertDCK);

    final JMenuItem helpItem = UIHelper.buildMenu("menu_help_help", 'h', this);
    helpItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));

    final JMenu helpMenu = new JMenu("?");
    helpMenu.add(helpItem);
    helpMenu.add(deckConstraintsItem);
    helpMenu.add(aboutItem);

    final JMenuBar menuBar = new JMenuBar();
    menuBar.add(mainMenu);
    initAbstractMenu();
    menuBar.add(optionMenu);
    menuBar.add(convertMenu);
    menuBar.add(helpMenu);
    setJMenuBar(menuBar);
    addWindowListener(this);

    // Build the panel containing amount of available cards
    final JLabel amountLeft = new JLabel("<html>0/?", SwingConstants.RIGHT);

    // Build the left list
    allListModel = new MListModel<MCardCompare>(amountLeft, false);
    leftList = new ThreadSafeJList(allListModel);
    leftList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    leftList.setLayoutOrientation(JList.VERTICAL);
    leftList.getSelectionModel().addListSelectionListener(this);
    leftList.addMouseListener(this);
    leftList.setVisibleRowCount(10);

    // Initialize the text field containing the amount to add
    addQtyTxt = new JTextField("1");

    // Build the "Add" button
    addButton = new JButton(LanguageManager.getString("db_add"));
    addButton.setMnemonic('a');
    addButton.setEnabled(false);

    // Build the panel containing : "Add" amount and "Add" button
    final Box addPanel = Box.createHorizontalBox();
    addPanel.add(addButton);
    addPanel.add(addQtyTxt);
    addPanel.setMaximumSize(new Dimension(32010, 26));

    // Build the panel containing the selected card name
    cardNameTxt = new JTextField();
    new HireListener(cardNameTxt, addButton, this, leftList);

    final JLabel searchLabel = new JLabel(LanguageManager.getString("db_search") + " : ");
    searchLabel.setLabelFor(cardNameTxt);

    // Build the panel containing search label and card name text field
    final Box searchPanel = Box.createHorizontalBox();
    searchPanel.add(searchLabel);
    searchPanel.add(cardNameTxt);
    searchPanel.setMaximumSize(new Dimension(32010, 26));

    listScrollerLeft = new JScrollPane(leftList);
    MToolKit.addOverlay(listScrollerLeft);

    // Build the left panel containing : list, available amount, "Add" panel
    final JPanel srcPanel = new JPanel(null);
    srcPanel.add(searchPanel);
    srcPanel.add(listScrollerLeft);
    srcPanel.add(amountLeft);
    srcPanel.add(addPanel);
    srcPanel.setMinimumSize(new Dimension(220, 200));
    srcPanel.setLayout(new BoxLayout(srcPanel, BoxLayout.Y_AXIS));

    // Initialize constraints
    constraintsChecker = new ConstraintsChecker();
    constraintsChecker.setBorder(new EtchedBorder());
    final JScrollPane constraintsCheckerScroll = new JScrollPane(constraintsChecker);
    MToolKit.addOverlay(constraintsCheckerScroll);

    // create a pane with the oracle text for the present card
    oracleText = new JLabel();
    oracleText.setPreferredSize(new Dimension(180, 200));
    oracleText.setVerticalAlignment(SwingConstants.TOP);

    final JScrollPane oracle = new JScrollPane(oracleText, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    MToolKit.addOverlay(oracle);

    // build some Pie Charts and a panel to display it
    initSets();
    datasets = new ChartSets();
    final JTabbedPane tabbedPane = new JTabbedPane();
    for (ChartFilter filter : ChartFilter.values()) {
        final Dataset dataSet = filter.createDataSet(this);
        final JFreeChart chart = new JFreeChart(null, null,
                filter.createPlot(dataSet, painterMapper.get(filter)), false);
        datasets.addDataSet(filter, dataSet);
        ChartPanel pieChartPanel = new ChartPanel(chart, true);
        tabbedPane.add(pieChartPanel, filter.getTitle());
    }
    // add the Constraints scroll panel and Oracle text Pane to the tabbedPane
    tabbedPane.add(constraintsCheckerScroll, LanguageManager.getString("db_constraints"));
    tabbedPane.add(oracle, LanguageManager.getString("db_text"));
    tabbedPane.setSelectedComponent(oracle);

    // The toollBar for color filtering
    toolBar = new JToolBar();
    toolBar.setFloatable(false);
    final JButton clearButton = UIHelper.buildButton("clear");
    clearButton.addActionListener(this);
    toolBar.add(clearButton);
    final JToggleButton toggleColorlessButton = new JToggleButton(
            UIHelper.getTbsIcon("mana/colorless/small/" + MdbLoader.unknownSmlMana), true);
    toggleColorlessButton.setActionCommand("0");
    toggleColorlessButton.addActionListener(this);
    toolBar.add(toggleColorlessButton);
    for (int index = 1; index < IdCardColors.CARD_COLOR_NAMES.length; index++) {
        final JToggleButton toggleButton = new JToggleButton(
                UIHelper.getTbsIcon("mana/colored/small/" + MdbLoader.coloredSmlManas[index]), true);
        toggleButton.setActionCommand(String.valueOf(index));
        toggleButton.addActionListener(this);
        toolBar.add(toggleButton);
    }

    // sorted card type combobox creation
    final List<String> idCards = new ArrayList<String>(Arrays.asList(CardFactory.exportedIdCardNames));
    Collections.sort(idCards);
    final Object[] cardTypes = ArrayUtils.addAll(new String[] { LanguageManager.getString("db_types.any") },
            idCards.toArray());
    idCardComboBox = new JComboBox(cardTypes);
    idCardComboBox.setSelectedIndex(0);
    idCardComboBox.addActionListener(this);
    idCardComboBox.setActionCommand("cardTypeFilter");

    // sorted card properties combobox creation
    final List<String> properties = new ArrayList<String>(
            CardFactory.getPropertiesName(DeckConstraints.getMinProperty(), DeckConstraints.getMaxProperty()));
    Collections.sort(properties);
    final Object[] cardProperties = ArrayUtils
            .addAll(new String[] { LanguageManager.getString("db_properties.any") }, properties.toArray());
    propertiesComboBox = new JComboBox(cardProperties);
    propertiesComboBox.setSelectedIndex(0);
    propertiesComboBox.addActionListener(this);
    propertiesComboBox.setActionCommand("propertyFilter");

    final JLabel colors = new JLabel(" " + LanguageManager.getString("colors") + " : ");
    final JLabel types = new JLabel(" " + LanguageManager.getString("types") + " : ");
    final JLabel property = new JLabel(" " + LanguageManager.getString("properties") + " : ");

    // filter Panel with colors toolBar and card type combobox
    final Box filterPanel = Box.createHorizontalBox();
    filterPanel.add(colors);
    filterPanel.add(toolBar);
    filterPanel.add(types);
    filterPanel.add(idCardComboBox);
    filterPanel.add(property);
    filterPanel.add(propertiesComboBox);

    getContentPane().add(filterPanel, BorderLayout.NORTH);

    // Destination section :

    // Build the panel containing amount of available cards
    final JLabel rightAmount = new JLabel("0/?", SwingConstants.RIGHT);
    rightAmount.setMaximumSize(new Dimension(220, 26));

    // Build the right list
    rightListModel = new MCardTableModel(new MListModel<MCardCompare>(rightAmount, true));
    rightListModel.addTableModelListener(this);
    rightList = new JTable(rightListModel);
    rightList.setShowGrid(false);
    rightList.setTableHeader(null);
    rightList.getSelectionModel().addListSelectionListener(this);
    rightList.getColumnModel().getColumn(0).setMaxWidth(25);
    rightList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);

    // Build the panel containing the selected deck
    deckNameTxt = new JTextField("loading...");
    deckNameTxt.setEditable(false);
    deckNameTxt.setBorder(null);
    final JLabel deckLabel = new JLabel(LanguageManager.getString("db_deck") + " : ");
    deckLabel.setLabelFor(deckNameTxt);
    final Box deckNamePanel = Box.createHorizontalBox();
    deckNamePanel.add(deckLabel);
    deckNamePanel.add(deckNameTxt);
    deckNamePanel.setMaximumSize(new Dimension(220, 26));

    // Initialize the text field containing the amount to remove
    removeQtyTxt = new JTextField("1");

    // Build the "Remove" button
    removeButton = new JButton(LanguageManager.getString("db_remove"));
    removeButton.setMnemonic('r');
    removeButton.addMouseListener(this);
    removeButton.setEnabled(false);

    // Build the panel containing : "Remove" amount and "Remove" button
    final Box removePanel = Box.createHorizontalBox();
    removePanel.add(removeButton);
    removePanel.add(removeQtyTxt);
    removePanel.setMaximumSize(new Dimension(220, 26));

    // Build the right panel containing : list, available amount, constraints
    final JScrollPane deskListScroller = new JScrollPane(rightList);
    MToolKit.addOverlay(deskListScroller);
    deskListScroller.setBorder(BorderFactory.createLineBorder(Color.GRAY));
    deskListScroller.setMinimumSize(new Dimension(220, 200));
    deskListScroller.setMaximumSize(new Dimension(220, 32000));

    final Box destPanel = Box.createVerticalBox();
    destPanel.add(deckNamePanel);
    destPanel.add(deskListScroller);
    destPanel.add(rightAmount);
    destPanel.add(removePanel);
    destPanel.setMinimumSize(new Dimension(220, 200));
    destPanel.setMaximumSize(new Dimension(220, 32000));

    // Build the panel containing the name of card in picture
    cardPictureNameTxt = new JLabel("<html><i>no selected card</i>");
    final Box cardPictureNamePanel = Box.createHorizontalBox();
    cardPictureNamePanel.add(cardPictureNameTxt);
    cardPictureNamePanel.setMaximumSize(new Dimension(32010, 26));

    // Group the detail panels
    final JPanel viewCard = new JPanel(null);
    viewCard.add(cardPictureNamePanel);
    viewCard.add(CardView.getInstance());
    viewCard.add(tabbedPane);
    viewCard.setLayout(new BoxLayout(viewCard, BoxLayout.Y_AXIS));

    final Box mainPanel = Box.createHorizontalBox();
    mainPanel.add(destPanel);
    mainPanel.add(viewCard);

    // Add the main panel
    getContentPane().add(srcPanel, BorderLayout.WEST);
    getContentPane().add(mainPanel, BorderLayout.CENTER);

    // Size this frame
    getRootPane().setPreferredSize(new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT));
    getRootPane().setMinimumSize(getRootPane().getPreferredSize());
    pack();
}

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();/*from w w  w . j  av  a 2  s.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:com.diversityarrays.kdxplore.trialmgr.TrialManagerApp.java

public TrialManagerApp(KdxPluginInfo pluginInfo) throws IOException {
    super(new BorderLayout());

    this.messagesPanel = pluginInfo.getMessagePrinter();
    this.backgroundRunner = pluginInfo.getBackgroundRunner();
    this.userDataFolder = pluginInfo.getUserDataFolder();
    this.clientProvider = pluginInfo.getClientProvider();
    this.offlineData = pluginInfo.getSingletonSharedResource(OfflineData.class);

    KDSmartApplication.getInstance().setMessagePrinter(pluginInfo.getMessagePrintStream());

    this.driverType = DriverType.getDriverTypeFromSystemProperties(DriverType.H2);

    offlineData.addOfflineDataChangeListener(offlineDataChangeListener);

    linkedIcon = KDClientUtils.getIcon(ImageId.CONNECTED_24);
    unlinkedIcon = KDClientUtils.getIcon(ImageId.DISCONNECTED_24);
    barcodeIcon = KDClientUtils.getIcon(ImageId.BARCODE_PAGE);

    updateDatabaseUrlLabel();//from  ww w  . j a va2 s  . com

    this.clientProvider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            handleClientChanged();
        }
    });

    explorerProperties = ExplorerProperties.getInstance();

    PreferenceCollection pc = TrialManagerPreferences.getInstance().getPreferenceCollection(this,
            Msg.APPNAME_TRIAL_MANAGER());
    KdxplorePreferences.getInstance().addPreferenceCollection(pc);

    TraitValue.DISPLAY_DATE_DIFF_AS_NDAYS = explorerProperties.getDisplayElapsedDaysAsCount();

    ExplorerServices explorerServices = new ExplorerServices(pluginInfo, offlineData
    //              , clientProvider
    );

    trialExplorerPanel = new TrialExplorerPanel(this, // KdxApp
            pluginInfo, explorerServices.getKdxDeviceService(), this, // as TrialExplorerManager
            offlineData, driverType, barcodeIcon, clientUrlChanger, trialsLoadedConsumer, traitRemovalHandler);

    tabbedPane.addTab(TAB_TRIALS, KDClientUtils.getIcon(ImageId.KDS_TRIALS), trialExplorerPanel);

    Transformer<Trial, Boolean> checkIfEditorIsActive = new Transformer<Trial, Boolean>() {
        @Override
        public Boolean transform(Trial trial) {
            return trialExplorerPanel.isEditorActiveForTrial(trial);
        }
    };
    traitExplorerPanel = new TraitExplorerPanel(messagesPanel, offlineData, clientProvider,
            //            uploadHandler,
            backgroundRunner, barcodeIcon, checkIfEditorIsActive);

    tabbedPane.addTab(TAB_TRAITS, KDClientUtils.getIcon(ImageId.KDS_TRAITS), traitExplorerPanel);

    tagExplorerPanel = new TagExplorerPanel(offlineData);
    tabbedPane.addTab(TAB_TAGS, KDClientUtils.getIcon(ImageId.BLACK_TAG), tagExplorerPanel);

    // Now tie together those panels that need to talk to each other
    trialExplorerPanel.setTraitExplorer(traitExplorerPanel);

    Box box = Box.createHorizontalBox();

    explorerServices.addActions(box);
    box.add(Box.createHorizontalGlue());
    box.add(databaseUrlLabel);
    box.add(Box.createHorizontalGlue());
    Action action = offlineData.getOfflineDataAction();
    if (action != null) {
        JButton button = new JButton(pluginInfo.getKdxploreIcon());
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (RunMode.getRunMode().isDeveloper()) {
                    if (0 != (ActionEvent.SHIFT_MASK & e.getModifiers())) {
                        openJdbcExplorer();
                        return;
                    }
                }
                action.actionPerformed(e);
            }
        });
        box.add(button);
    }

    add(box, BorderLayout.NORTH);
    add(tabbedPane, BorderLayout.CENTER);
}

From source file:com.diversityarrays.kdxplore.vistool.AskForTraitInstances.java

AskForTraitInstances(Window owner, String title, boolean xAndYaxes, String okLabel, TraitNameStyle tns,
        Map<TraitInstance, SimpleStatistics<?>> map, int[] minMax,
        Closure<List<TraitInstance>> onInstancesChosen) {
    super(owner, title, ModalityType.MODELESS);

    this.traitNameStyle = tns;
    this.minInstances = minMax[0];
    this.maxInstances = minMax[1];
    this.onInstancesChosen = onInstancesChosen;

    if (xAndYaxes) {
        tableModel = new TraitInstanceAxisChoiceTableModel();
    } else {/*from   w  w  w.  j  av a2  s . com*/
        tableModel = new TraitInstanceChoiceTableModel();
    }
    table = new JTable(tableModel);

    okAction.putValue(Action.NAME, okLabel);

    traitInstances = new ArrayList<TraitInstance>(map.keySet());
    Collections.sort(traitInstances, TraitHelper.COMPARATOR);

    table.setAutoCreateRowSorter(true);

    Box box = Box.createHorizontalBox();
    box.add(message);
    box.add(Box.createHorizontalGlue());
    box.add(new JButton(okAction));
    box.add(new JButton(cancelAction));

    getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
    getContentPane().add(box, BorderLayout.SOUTH);

    pack();

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

From source file:com.diversityarrays.kdxplore.scatterplot.ScatterPlotPanel.java

public ScatterPlotPanel(PlotInfoProvider infoProvider, VisualisationToolId<?> vtoolId, SelectedValueStore svs,
        String title, VisToolData data, Supplier<TraitColorProvider> colorProviderFactory,
        SuppressionHandler sh) {/*from w w  w  .j  a va2  s .  c  om*/
    super(title, vtoolId, svs, nextId++, data.traitInstances, data.context.getTrial(), sh);

    this.plotInfoProvider = infoProvider;

    if (data.plotSpecimensToGraph == null) {
        plotSpecimens = new ArrayList<>();
        VisToolUtil.collectPlotSpecimens(plotInfoProvider.getPlots(), new Consumer<PlotOrSpecimen>() {
            @Override
            public void accept(PlotOrSpecimen pos) {
                plotSpecimens.add(pos);
            }
        });
    } else {
        plotSpecimens = data.plotSpecimensToGraph;
    }

    List<List<Comparable<?>>> instanceValuesList = new ArrayList<>();

    this.colorProviderFactory = colorProviderFactory;

    Function<TraitInstance, List<KdxSample>> sampleProvider = new Function<TraitInstance, List<KdxSample>>() {
        @Override
        public List<KdxSample> apply(TraitInstance ti) {
            return infoProvider.getSampleMeasurements(ti);
        }
    };
    tivrByTi = VisToolUtil.buildTraitInstanceValueRetrieverMap(trial, traitInstances, sampleProvider);

    int plotLength = instanceValuesList.size();
    if (plotLength < 3) {
        plotLength = 3;
    }

    xInstance = traitInstances.get(0);
    TraitInstance firstValueInstance = null;

    for (int i = 1; i < traitInstances.size(); i++) {
        TraitInstance ti = traitInstances.get(i);
        if (firstValueInstance == null) {
            firstValueInstance = ti;
        }
        valueInstances.add(ti);
        valueInstanceByTraitIdAndNumber.put(InstanceIdentifierUtil.getInstanceIdentifier(ti), ti);
    }

    xAxisName = traitNameStyle.makeTraitInstanceName(xInstance);

    if (traitInstances.size() == 2) {
        yAxisName = traitNameStyle.makeTraitInstanceName(firstValueInstance);
    } else {
        yAxisName = "Sample Measurement Value";
    }

    chartPanel.addChartMouseListener(chartMouseListener);

    Bag<String> missingOrBad = new TreeBag<String>();
    Bag<String> suppressed = new TreeBag<String>();

    generateChart(true, missingOrBad, suppressed);

    ChangeListener listener = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            if (!stillChanging) {
                clearExternallySelectedPlots();

                setXYValues();
                drawRectangle();
                if (mouseDownPoint != null && mouseUpPoint != null) {
                    buildMinMaxPoints();
                    setSelectedTraitAndMeasurements();
                }
            }
        }
    };

    minxSpinner.addChangeListener(listener);
    minySpinner.addChangeListener(listener);
    maxxSpinner.addChangeListener(listener);
    maxySpinner.addChangeListener(listener);

    stillChanging = true;
    minxModel.setValue(dataxMin);
    maxxModel.setValue(dataxMax);

    minyModel.setValue(datayMin);
    maxyModel.setValue(datayMax);

    minxModel.setMinimum(dataxMin);
    minxModel.setMaximum(dataxMax);
    minyModel.setMinimum(datayMin);
    minyModel.setMaximum(datayMax);

    maxxModel.setMinimum(dataxMin);
    maxxModel.setMaximum(dataxMax);
    maxyModel.setMinimum(datayMin);
    maxyModel.setMaximum(datayMax);
    stillChanging = false;

    Box hbox = Box.createHorizontalBox();
    hbox.add(syncedOption);

    addSpinners(hbox, minxSpinner, minySpinner);
    hbox.add(new JLabel(" " + Msg.LABEL_MIN_TO_MAX_SEPARATOR() + " ")); //$NON-NLS-1$ //$NON-NLS-2$
    addSpinners(hbox, maxxSpinner, maxySpinner);

    List<TraitInstance> curationControlInstances = traitInstances;
    curationControlInstances.remove(xInstance);

    curationControls = new CurationControls(true, // askAboutValueForUnscored
            suppressionHandler, selectedValueStore,
            //              plotInfoProvider, 
            toolPanelId, null, traitNameStyle, curationControlInstances);

    reportTextArea = new JTextArea();
    reportTextArea.setEditable(false);

    tabMessages = Msg.TAB_MESSAGES();
    tabCuration = Msg.TAB_CURATION();
    tabbedPane.addTab(tabMessages, new JScrollPane(reportTextArea));
    tabbedPane.addTab(tabCuration, curationControls);

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

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

    splitPane.repaint(); // TODO why is this here?

    String msg = VisToolData.createReportText(missingOrBad, suppressed);
    if (Check.isEmpty(msg)) {
        tabbedPane.setSelectedIndex(tabbedPane.indexOfTab(tabCuration));
    } else {
        reportTextArea.setText(msg);
        tabbedPane.setSelectedIndex(tabbedPane.indexOfTab(tabMessages));
    }

    setPreferredSize(new Dimension(600, 500));
}

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  a2 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.trials.TrialDetailsPanel.java

TrialDetailsPanel(WindowOpener<JFrame> windowOpener, MessagePrinter mp, BackgroundRunner backgroundRunner,
        OfflineData offlineData, Action editTrialAction, Action seedPrepAction, Action harvestAction,
        Action uploadTrialAction, Action refreshTrialInfoAction, ImageIcon barcodeIcon,
        Transformer<Trial, Boolean> checkIfEditorActive, Consumer<Trial> onTraitInstancesRemoved) {
    super(new BorderLayout());

    this.editTrialAction = editTrialAction;
    this.uploadTrialAction = uploadTrialAction;
    this.refreshTrialInfoAction = refreshTrialInfoAction;
    this.onTraitInstancesRemoved = onTraitInstancesRemoved;

    this.messagePrinter = mp;
    this.backgroundRunner = backgroundRunner;
    this.offlineData = offlineData;

    if (barcodeIcon == null) {
        barcodesMenuButton = new JLabel("Barcodes"); //$NON-NLS-1$
    } else {// w  w  w. j  a v a  2 s.co  m
        barcodesMenuButton = new JLabel(barcodeIcon);
    }
    barcodesMenuButton.setBorder(BorderFactory.createRaisedSoftBevelBorder());

    barcodesMenuButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (trial != null) {
                barcodesMenuHandler.handleMouseClick(e.getPoint());
            }
        }
    });

    trialViewPanel = new TrialViewPanel(windowOpener, offlineData, checkIfEditorActive, onTraitInstancesRemoved,
            mp);

    Box buttons = Box.createHorizontalBox();
    buttons.add(new JButton(refreshTrialInfoAction));
    buttons.add(new JButton(seedPrepAction));
    buttons.add(new JButton(editTrialAction));
    buttons.add(new JButton(uploadTrialAction));
    buttons.add(new JButton(harvestAction));
    buttons.add(barcodesMenuButton);
    buttons.add(Box.createHorizontalGlue());

    //      JPanel trialPanel = new JPanel(new BorderLayout());
    //      trialPanel.add(buttons, BorderLayout.NORTH);
    //      trialPanel.add(fieldViewPanel, BorderLayout.CENTER);

    cardPanel.add(new JLabel(Msg.LABEL_NO_TRIAL_SELECTED()), CARD_NO_TRIAL);
    cardPanel.add(trialViewPanel, CARD_HAVE_TRIAL);

    setSelectedTrial(null);

    add(buttons, BorderLayout.NORTH);
    add(cardPanel, BorderLayout.CENTER);
}

From source file:cloud.gui.CloudGUI.java

private void createNumberOfInstancesStatus(Box layout) {
    JLabel nn = new JLabel("Number of current instances: ", JLabel.CENTER);
    Box horizonLayout = Box.createHorizontalBox();

    numberOfNodesLbl = new JLabel("0", JLabel.CENTER);
    horizonLayout.add(nn);/*from w ww  . j  a va 2  s . c o  m*/
    horizonLayout.add(numberOfNodesLbl);

    layout.add(horizonLayout);
}