List of usage examples for java.awt.event ItemEvent getItem
public Object getItem()
From source file:model.utilities.ExchangeNetwork.java
/** * Create the network: both the structure and the visualization */// www . j av a 2 s . com public ExchangeNetwork(GoodType type) { assert MacroII.hasGUI(); //don't bother with any of this if there is no inventory //create the graph! inventoryGraph = new DirectedSparseGraph<>(); //record your good type this.type = type; //create the layout used for vertices Layout<EconomicAgent, InventoryEdge> layout = new SpringLayout<EconomicAgent, InventoryEdge>( inventoryGraph); //new DAGLayout<EconomicAgent, InventoryEdge>(inventoryGraph); layout.setSize(new Dimension(600, 600)); //set size //create the viewer vv = new VisualizationViewer<>(layout); //tell it how to color the vertices vv.getRenderContext().setVertexFillPaintTransformer(vertexPainter); //tell it to print the name of the vertices vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<EconomicAgent>()); //call to string to label edges vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<InventoryEdge>()); //edges will have name //have the thickness of lines grow vv.getRenderContext().setEdgeStrokeTransformer(InventoryEdge.edgeStrokeTransformer); //now set up the visualization so that clicking on an agent gives you info about him //set up the mouse to select ModalGraphMouse mouse = new DefaultModalGraphMouse<>(); mouse.setMode(ModalGraphMouse.Mode.PICKING); vv.setGraphMouse(mouse); //make selection communicate to Mason through inspectors vv.getPickedVertexState().addItemListener(new ItemListener() { @Override //when you have a selection, this logEvent is fired public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) //if e is selected { EconomicAgent agent = (EconomicAgent) e.getItem(); //cast it to agent Inspector inspector = agent.getInspector(MacroII.getGUI()); //notice how you get back the outer instance //now for the moronic, let's talk to MASON in java 1.3 language because computer science people are too smart //to use generics or arraylists Bag inspectors = new Bag(1); inspectors.add(inspector); Bag names = new Bag(1); names.add(agent.toString()); MacroII.getGUI().controller.setInspectors(inspectors, names); } } }); }
From source file:org.smart.migrate.ui.UpdateRelatePKDialog.java
private void cbxFKTableItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbxFKTableItemStateChanged if (evt.getStateChange() == ItemEvent.SELECTED) { initFields(cbxFKLogic, (String) evt.getItem()); initFields(cbxFK, (String) evt.getItem()); }//from w w w .j a v a2s. c om }
From source file:org.smart.migrate.ui.UpdateRelatePKDialog.java
private void cbxPKTableItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbxPKTableItemStateChanged if (evt.getStateChange() == ItemEvent.SELECTED) { initFields(cbxPKLogic, (String) evt.getItem()); initFields(cbxPK, (String) evt.getItem()); }/*from w ww . j a v a 2 s . co m*/ }
From source file:de.cebitec.readXplorer.differentialExpression.plot.DeSeqGraphicsTopComponent.java
@Override public void itemStateChanged(ItemEvent e) { DeSeqAnalysisHandler.Plot plotType = (DeSeqAnalysisHandler.Plot) e.getItem(); if (plotType == DeSeqAnalysisHandler.Plot.MAplot) { iSymbol.setVisible(true);/* w w w. j a va 2 s. c om*/ } else { iSymbol.setVisible(false); } }
From source file:com.willwinder.ugs.nbp.core.windows.StateTopComponent.java
public StateTopComponent() { initComponents();/*from w w w .j a va2 s .c om*/ setName(LocalizingService.StateTitle); setToolTipText(LocalizingService.StateTooltip); backend = CentralLookup.getDefault().lookup(BackendAPI.class); backend.addUGSEventListener(this); statePollTimer = createTimer(); setLayout(new MigLayout("wrap 2, fillx")); add(new JLabel(Localization.getString("gcode.current-motion"))); add(motionBox, "growx"); motionBox.setEnabled(false); add(new JLabel(Localization.getString("gcode.setting.units"))); add(unitBox, "growx"); add(new JLabel(Localization.getString("gcode.distance-mode"))); add(distanceModeBox, "growx"); //add(new JLabel(Localization.getString("gcode.feed-rate-mode"))); //add(feedModeBox, "growx"); add(new JLabel(Localization.getString("gcode.work-offset"))); add(workOffsetBox, "growx"); add(new JLabel(Localization.getString("gcode.plane"))); add(planeBox, "growx"); add(new JLabel(Localization.getString("gcode.setting.feed"))); add(feedBox, "growx"); add(new JLabel(Localization.getString("overrides.spindle.short"))); add(speedBox, "growx"); ItemListener codeComboListener = (ItemEvent ie) -> { // Only interested in the new item, don't fire when programatically setting selection. if (loading || ie.getStateChange() == ItemEvent.DESELECTED) return; String item = ie.getItem().toString(); System.out.println("item"); String code = item; if (item.contains("(")) { code = item.substring(item.lastIndexOf('(') + 1, item.lastIndexOf(')')); } if (backend.isIdle()) { try { backend.sendGcodeCommand(code); } catch (Exception ex) { GUIHelpers.displayErrorDialog(ex.getLocalizedMessage()); } } }; motionBox.addItemListener(codeComboListener); unitBox.addItemListener(codeComboListener); feedModeBox.addItemListener(codeComboListener); distanceModeBox.addItemListener(codeComboListener); workOffsetBox.addItemListener(codeComboListener); planeBox.addItemListener(codeComboListener); feedBox.addActionListener((al) -> executeNumber('F', feedBox)); speedBox.addActionListener((al) -> executeNumber('S', speedBox)); }
From source file:storybook.export.DlgExport.java
private void cbReportItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbReportItemStateChanged if (evt.getStateChange() == ItemEvent.SELECTED) { if (evt.getItem().toString().equals(I18N.getMsg("msg.export.book.text"))) setOptions(cbFormat.getSelectedItem().toString()); }//from www. j a v a 2 s .c om }
From source file:storybook.export.DlgExport.java
private void cbFormatItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbFormatItemStateChanged if (evt.getStateChange() == ItemEvent.SELECTED) { setOptions(evt.getItem().toString()); }/*www . j a va2s . com*/ }
From source file:richtercloud.reflection.form.builder.components.AmountMoneyPanel.java
/** * Creates a new AmountMoneyPanel with {@link #DEFAULT_CURRENCIES} and * {@code additionalCurrencies}./*from w w w . ja v a 2 s . c o m*/ * @param amountMoneyCurrencyStorage * @param amountMoneyUsageStatisticsStorage * @param amountMoneyExchangeRateRetriever * @param messageHandler * @throws richtercloud.reflection.form.builder.components.AmountMoneyCurrencyStorageException */ public AmountMoneyPanel(AmountMoneyCurrencyStorage amountMoneyCurrencyStorage, AmountMoneyUsageStatisticsStorage amountMoneyUsageStatisticsStorage, AmountMoneyExchangeRateRetriever amountMoneyExchangeRateRetriever, MessageHandler messageHandler) throws AmountMoneyCurrencyStorageException { this.messageHandler = messageHandler; Set<Currency> exchangeRateRetrieverSupportedCurrencies = amountMoneyExchangeRateRetriever .getSupportedCurrencies(); for (Currency currency : amountMoneyCurrencyStorage.getCurrencies()) { if (!exchangeRateRetrieverSupportedCurrencies.contains(currency)) { try { currency.getExchangeRate(); } catch (ConversionException ex) { throw new IllegalArgumentException(String.format( "Currency %s isn't supported by exchange rate retriever and doesn't have an exchange rate set", currency)); } } currencyComboBoxModel.addElement(currency); } initComponents(); ((SpinnerNumberModel) amountIntegerSpinner.getModel()) .setMaximum(((long) (Double.MAX_VALUE * MINIMAL_STEP))); //cast to long is necessary to make ChangeListener of //amountIntegerSpinner be notified this.amountIntegerSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { for (AmountMoneyPanelUpdateListener updateListener : AmountMoneyPanel.this.updateListeners) { updateListener.onUpdate(new AmountMoneyPanelUpdateEvent(getValue())); } } }); this.amountDecimalSpinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { for (AmountMoneyPanelUpdateListener updateListener : AmountMoneyPanel.this.updateListeners) { updateListener.onUpdate(new AmountMoneyPanelUpdateEvent(getValue())); } } }); this.currencyComboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent itemEvent) { //convert after currency change (not necessary, but useful) Currency oldCurrency = (Currency) itemEvent.getItem(); Currency newCurrency = (Currency) itemEvent.getItemSelectable().getSelectedObjects()[0]; double newAmount; try { newAmount = oldCurrency.getConverterTo(newCurrency).convert(getAmount()); } catch (ConversionException ex) { try { //if the exchange rate isn't set AmountMoneyPanel.this.amountMoneyExchangeRateRetriever.retrieveExchangeRate(newCurrency); AmountMoneyPanel.this.amountMoneyExchangeRateRetriever.retrieveExchangeRate(oldCurrency); newAmount = oldCurrency.getConverterTo(newCurrency).convert(getAmount()); } catch (AmountMoneyCurrencyStorageException amountMoneyCurrencyStorageException) { throw new RuntimeException(amountMoneyCurrencyStorageException); } } AmountMoneyPanel.this.amountIntegerSpinner.setValue((int) newAmount); BigDecimal bd = new BigDecimal(newAmount * 100); bd = bd.setScale(0, //newScale RoundingMode.HALF_UP //the rounding mode "taught in school" ); AmountMoneyPanel.this.amountDecimalSpinner.setValue(bd.intValue() % 100); //notify registered update listeners for (AmountMoneyPanelUpdateListener updateListener : AmountMoneyPanel.this.updateListeners) { updateListener.onUpdate(new AmountMoneyPanelUpdateEvent(getValue())); } } }); this.amountMoneyCurrencyStorage = amountMoneyCurrencyStorage; this.amountMoneyUsageStatisticsStorage = amountMoneyUsageStatisticsStorage; this.amountMoneyExchangeRateRetriever = amountMoneyExchangeRateRetriever; }
From source file:de.cebitec.readXplorer.differentialExpression.plot.BaySeqGraphicsTopComponent.java
@Override public void itemStateChanged(ItemEvent e) { BaySeqAnalysisHandler.Plot item = (BaySeqAnalysisHandler.Plot) e.getItem(); if (item == BaySeqAnalysisHandler.Plot.Priors || item == BaySeqAnalysisHandler.Plot.MACD) { samplesAList.setEnabled(false);//from ww w . java2 s . c o m samplesALabel.setEnabled(false); samplesBList.setEnabled(false); samplesBLabel.setEnabled(false); groupComboBox.setEnabled(true); } if (item == BaySeqAnalysisHandler.Plot.Posteriors) { samplesAList.setEnabled(true); samplesALabel.setEnabled(true); samplesBList.setEnabled(true); samplesBLabel.setEnabled(true); groupComboBox.setEnabled(true); } iSymbol.setVisible(item == BaySeqAnalysisHandler.Plot.MACD); }
From source file:ro.nextreports.designer.querybuilder.SelectionColumnPanel.java
private void buildUI() { setLayout(new GridBagLayout()); final DBViewer viewer = Globals.getDBViewer(); schemaCombo = new JComboBox(); schemaCombo.setPreferredSize(comboDim); schemaCombo.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { String schema = (String) e.getItem(); shownColumnModel.clear();/* w ww . j a va 2s . c o m*/ columnModel.clear(); tableModel.clear(); try { DBInfo dbInfo = viewer.getDBInfo(schema, DBInfo.TABLES | DBInfo.VIEWS); List<DBTable> tables = dbInfo.getTables(); Collections.sort(tables); for (DBTable table : tables) { tableModel.addElement(table); } } catch (NextSqlException ex) { LOG.error(ex.getMessage(), ex); ex.printStackTrace(); } } }); try { List<String> schemas = viewer.getSchemas(); String schemaName = viewer.getUserSchema(); Collections.sort(schemas); boolean added = false; for (String schema : schemas) { if (DefaultSchemaManager.getInstance().isVisible( DefaultDataSourceManager.getInstance().getConnectedDataSource().getName(), schema)) { added = true; schemaCombo.addItem(schema); } } if ((schema == null) || schema.equals(DefaultDBViewer.NO_SCHEMA_NAME)) { schema = DefaultDBViewer.NO_SCHEMA_NAME;//viewer.getUserSchema(); } if (!added) { schemaCombo.addItem(schema); } schemaCombo.setSelectedItem(schema); } catch (NextSqlException e) { LOG.error(e.getMessage(), e); e.printStackTrace(); } // create table list tableList = new JXList(tableModel); tableList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tableList.setCellRenderer(new DBTableCellRenderer()); // create column list columnList = new JXList(columnModel); if (singleSelection) { columnList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else { columnList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } columnList.setCellRenderer(new DBColumnCellRenderer()); shownColumnList = new JXList(shownColumnModel); if (singleSelection) { shownColumnList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else { columnList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } addDoubleClick(); shownColumnList.setCellRenderer(new DBColumnCellRenderer()); shownColumnList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent mouseEvent) { if ((mouseEvent.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { JPopupMenu popupMenu = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(new DeselectListAction(shownColumnList)); popupMenu.add(menuItem); popupMenu.show((Component) mouseEvent.getSource(), mouseEvent.getX(), mouseEvent.getY()); } } }); tableList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { int index = tableList.getSelectedIndex(); if (index == -1) { return; } DBTable table = (DBTable) tableModel.getElementAt(index); try { List<DBColumn> columns = null; try { columns = viewer.getColumns(table.getSchema(), table.getName()); } catch (MalformedTableNameException e1) { Show.error("Malformed table name : " + table.getName()); return; } Collections.sort(columns); columnModel.clear(); shownColumnModel.clear(); for (DBColumn column : columns) { columnModel.addElement(column); shownColumnModel.addElement(column); } } catch (NextSqlException e1) { LOG.error(e1.getMessage(), e1); e1.printStackTrace(); Show.error(e1); } } } }); columnList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { shownColumnList.clearSelection(); } }); scrTable = new JScrollPane(tableList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrTable.setPreferredSize(scrDim); scrTable.setMinimumSize(scrDim); scrTable.setBorder(new TitledBorder(I18NSupport.getString("parameter.source.tables"))); scrColumn = new JScrollPane(columnList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrColumn.setPreferredSize(scrDim); scrColumn.setMinimumSize(scrDim); scrColumn.setBorder(new TitledBorder(I18NSupport.getString("parameter.source.columns"))); scrShownColumn = new JScrollPane(shownColumnList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrShownColumn.setPreferredSize(scrDim); scrShownColumn.setMinimumSize(scrDim); scrShownColumn.setBorder(new TitledBorder(I18NSupport.getString("parameter.source.shown.columns"))); JPanel schemaPanel = new JPanel(); schemaPanel.setLayout(new BoxLayout(schemaPanel, BoxLayout.X_AXIS)); schemaPanel.add(new JLabel("Schema")); schemaPanel.add(Box.createHorizontalStrut(5)); schemaPanel.add(schemaCombo); add(schemaPanel, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); add(scrTable, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0)); add(scrColumn, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0)); if (show) { add(scrShownColumn, new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); } }