List of usage examples for javax.swing MutableComboBoxModel getSelectedItem
Object getSelectedItem();
From source file:com.anrisoftware.prefdialog.miscswing.comboboxhistory.HistoryComboBoxModel.java
/** * @see HistoryComboBoxModelFactory#create(MutableComboBoxModel, Collection) *//*w w w . j ava2 s. c o m*/ @Inject HistoryComboBoxModel(ItemDefaultFactory itemDefaultFactory, @Assisted MutableComboBoxModel model, @Assisted Collection defaultItems) { this.maximum = 5; this.model = model; this.itemDefaultFactory = itemDefaultFactory; Collection<Object> defaultItemsCollection = convertDefaultItems(defaultItems); this.defaultItems = new HashSet<Object>(defaultItemsCollection); this.items = synchronizedSet(fromModel(model)); insertDefaultItems(defaultItemsCollection); setSelectedItem(model.getSelectedItem()); }
From source file:com.diversityarrays.kdxplore.curate.fieldview.FieldLayoutViewPanel.java
@SuppressWarnings("unchecked") public FieldLayoutViewPanel(@SuppressWarnings("rawtypes") MutableComboBoxModel comboBoxModel, JCheckBox alwaysOnTopOption, CurationData cd, CurationTableModel ctm, SelectedValueStore svs, PlotCellChoicesPanel pccp, JPopupMenu popuMenu, Font fontForResizeControls, Action curationHelpAction, MessagePrinter mp, Closure<String> selectionClosure, CurationContext curationContext, CurationMenuProvider curationMenuProvider, FieldLayoutTableModel fieldLayoutTableModel, CellSelectableTable fieldLayoutTable, FieldViewSelectionModel fvsm,//from w w w . j a v a 2s .co m JButton undockButton) { super(new BorderLayout()); this.traitInstanceCombo.setModel(comboBoxModel); this.curationData = cd; this.messagePrinter = mp; this.selectionClosure = selectionClosure; this.curationTableModel = ctm; this.fieldLayoutTableModel = fieldLayoutTableModel; this.fieldLayoutTable = fieldLayoutTable; this.fieldViewSelectionModel = fvsm; traitInstanceCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Object item = comboBoxModel.getSelectedItem(); if (item instanceof TraitInstance) { TraitInstance ti = (TraitInstance) item; plotCellRenderer.setActiveInstance(ti); } } }); rhtm = new RowHeaderTableModel(true, fieldLayoutTable, rowRemovable) { public String getRowLabel(int rowIndex) { int yCoord = FieldLayoutUtil.convertRowIndexToYCoord(rowIndex, trial, fieldLayoutTableModel.getFieldLayout()); return String.valueOf(yCoord); } }; rowHeaderTable = new RowHeaderTable(SwingConstants.CENTER, false, fieldLayoutTable, rowRemovable, rhtm, RowHeaderTable.createDefaultColumnModel("X/Y")) { public String getMarkerIndexName(int viewRow) { return "MIN-" + viewRow; //$NON-NLS-1$ } }; rhtTableRowResizer = new TableRowResizer(rowHeaderTable, true); curationData.addCurationDataChangeListener(plotActivationListener); curationTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { fieldLayoutTable.repaint(); } }); plotCellRenderer = new PlotCellRenderer(plotAttributeProvider, curationTableModel); TraitInstanceCellRenderer tiCellRenderer = new TraitInstanceCellRenderer( curationData.getTraitColorProvider(), instanceNameProvider); traitInstanceCombo.setRenderer(tiCellRenderer); traitInstanceCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateActiveTraitInstance(); } }); traitInstanceCombo.getModel().addListDataListener(new ListDataListener() { @Override public void intervalRemoved(ListDataEvent e) { updateActiveTraitInstance(); } @Override public void intervalAdded(ListDataEvent e) { updateActiveTraitInstance(); } @Override public void contentsChanged(ListDataEvent e) { updateActiveTraitInstance(); } }); this.trial = curationData.getTrial(); this.plotCellChoicesPanel = pccp; for (TraitInstance t : curationData.getTraitInstances()) { String id = InstanceIdentifierUtil.getInstanceIdentifier(t); traitById.put(id, t); } // fieldViewSelectionModel = new FieldViewSelectionModel( // fieldLayoutTable, // fieldLayoutTableModel, // svs); fieldLayoutTable.setSelectionModel(fieldViewSelectionModel); plotCellRenderer.setCurationData(curationData); plotCellRenderer.setSelectionModel(fieldViewSelectionModel); plotCellChoicesPanel.addPlotCellChoicesListener(plotCellChoicesListener); fieldLayoutTableModel.setTrial(trial); // IMPORTANT: DO NOT SORT THE FIELD LAYOUT TABLE fieldLayoutTable.setAutoCreateRowSorter(false); JScrollPane fieldTableScrollPane = new JScrollPane(fieldLayoutTable); if (undockButton != null) { fieldTableScrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, undockButton); } fieldTableScrollPane.setRowHeaderView(rowHeaderTable); ChangeListener scrollBarChangeListener = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { fireRefreshRequired(); } }; fieldTableScrollPane.getVerticalScrollBar().getModel().addChangeListener(scrollBarChangeListener); fieldTableScrollPane.getHorizontalScrollBar().getModel().addChangeListener(scrollBarChangeListener); fieldLayoutTable.setRowHeaderTable(rowHeaderTable); // fieldLayoutTable.setComponentPopupMenu(popuMenu); initFieldLayoutTable(); Map<Integer, Plot> plotById = new HashMap<>(); FieldLayout<Integer> plotIdLayout = FieldLayoutUtil.createPlotIdLayout(trial.getTrialLayout(), trial.getPlotIdentSummary(), curationData.getPlots(), plotById); KdxploreFieldLayout<Plot> kdxFieldLayout = new KdxploreFieldLayout<Plot>(Plot.class, plotIdLayout.imageId, plotIdLayout.xsize, plotIdLayout.ysize); kdxFieldLayout.warning = plotIdLayout.warning; for (int y = 0; y < plotIdLayout.ysize; ++y) { for (int x = 0; x < plotIdLayout.xsize; ++x) { Integer id = plotIdLayout.cells[y][x]; if (id != null) { Plot plot = plotById.get(id); kdxFieldLayout.store_xy(plot, x, y); } } } fieldLayoutTableModel.setFieldLayout(kdxFieldLayout); if (kdxFieldLayout.warning != null && !kdxFieldLayout.warning.isEmpty()) { warningMessage.setText(kdxFieldLayout.warning); } else { warningMessage.setText(""); //$NON-NLS-1$ } changeVisitOrderAction.putValue(Action.SMALL_ICON, KDClientUtils.getIcon(kdxFieldLayout.imageId)); List<Component> components = new ArrayList<>(); components.add(alwaysOnTopOption); Collections.addAll(components, new JButton(changeVisitOrderAction), new JButton(curationHelpAction), traitInstanceCombo); Box resizeControls = KDClientUtils.createResizeControls(fieldLayoutTable, fontForResizeControls, components.toArray(new Component[components.size()])); resizeCombo = KDClientUtils.findResizeCombo(resizeControls); if (RunMode.getRunMode().isDeveloper()) { new FieldLayoutViewPanel.DebugSettings(resizeControls, messagePrinter); } JPanel fieldPanel = new JPanel(new BorderLayout()); // if (useSeparator) { // SeparatorPanel separator = GuiUtil.createLabelSeparator("Field Layout:", resizeControls); // fieldPanel.add(separator, BorderLayout.NORTH); // fieldPanel.add(fieldTableScrollPane, BorderLayout.CENTER); // } // else { fieldPanel.add(resizeControls, BorderLayout.NORTH); fieldPanel.add(fieldTableScrollPane, BorderLayout.CENTER); // } // splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, // plotCellChoicesPanel, // fieldPanel); // splitPane.setResizeWeight(0.0); // splitPane.setOneTouchExpandable(true); add(warningMessage, BorderLayout.NORTH); add(fieldPanel, BorderLayout.CENTER); // splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, // plotCellChoicesPanel, // fieldPanel); // splitPane.setResizeWeight(0.0); // splitPane.setOneTouchExpandable(true); // // add(warningMessage, BorderLayout.NORTH); // add(splitPane, BorderLayout.CENTER); fieldLayoutTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { if (SwingUtilities.isRightMouseButton(me) && 1 == me.getClickCount()) { me.consume(); List<Plot> plots = getSelectedPlots(); List<TraitInstance> checkedInstances = new ArrayList<>(); for (int index = traitInstanceCombo.getItemCount(); --index >= 1;) { Object item = traitInstanceCombo.getItemAt(index); if (item instanceof TraitInstance) { checkedInstances.add((TraitInstance) item); } } TraitInstance ti = fieldViewSelectionModel.getActiveTraitInstance(true); List<PlotOrSpecimen> plotSpecimens = new ArrayList<>(); plotSpecimens.addAll(plots); curationMenuProvider.showFieldViewToolMenu(me, plotSpecimens, ti, checkedInstances); } } }); }