List of usage examples for javax.swing JComboBox getSelectedItem
public Object getSelectedItem()
From source file:de.dmarcini.submatix.pclogger.gui.spx42LogGraphPanel.java
@Override public void actionPerformed(ActionEvent ev) { String cmd = ev.getActionCommand(); String entry = null;// w w w . j a va 2 s .c o m int dbId; String device; // // ///////////////////////////////////////////////////////////////////////// // Button if (ev.getSource() instanceof JButton) { // JButton srcButton = ( JButton )ev.getSource(); // ///////////////////////////////////////////////////////////////////////// // Anzeigebutton? if (cmd.equals("show_log_graph")) { lg.debug("show log graph initiated."); // welches Device ? if (deviceComboBox.getSelectedIndex() < 0) { // kein Gert ausgewhlt lg.warn("no device selected."); return; } // welchen Tauchgang? if (diveSelectComboBox.getSelectedIndex() < 0) { lg.warn("no dive selected."); return; } device = ((DeviceComboBoxModel) deviceComboBox.getModel()) .getDeviceSerialAt(deviceComboBox.getSelectedIndex()); dbId = ((LogListComboBoxModel) diveSelectComboBox.getModel()) .getDatabaseIdAt(diveSelectComboBox.getSelectedIndex()); lg.debug("Select Device-Serial: " + device + ", DBID: " + dbId); if (dbId < 0) { lg.error("can't find database id for dive."); return; } makeGraphForLog(dbId, device); return; } else if (cmd.equals("set_detail_for_show_graph")) { lg.debug("select details for log selected."); SelectGraphDetailsDialog sgd = new SelectGraphDetailsDialog(); if (sgd.showModal()) { lg.debug("dialog returned 'true' => change propertys..."); computeGraphButton.doClick(); } } else if (cmd.equals("edit_notes_for_dive")) { if (chartPanel == null || showingDbIdForDiveWasShowing == -1) { lg.warn("it was not showing a dive! do nothing!"); return; } lg.debug("edit a note for this dive..."); showNotesEditForm(showingDbIdForDiveWasShowing); } else { lg.warn("unknown button command <" + cmd + "> recived."); } return; } // ///////////////////////////////////////////////////////////////////////// // Combobox else if (ev.getSource() instanceof JComboBox<?>) { @SuppressWarnings("unchecked") JComboBox<String> srcBox = (JComboBox<String>) ev.getSource(); // ///////////////////////////////////////////////////////////////////////// // Gert zur Grafischen Darstellung auswhlen if (cmd.equals("change_device_to_display")) { if (srcBox.getModel() instanceof DeviceComboBoxModel) { entry = ((DeviceComboBoxModel) srcBox.getModel()).getDeviceSerialAt(srcBox.getSelectedIndex()); lg.debug("device <" + entry + ">...Index: <" + srcBox.getSelectedIndex() + ">"); fillDiveComboBox(entry); } } // ///////////////////////////////////////////////////////////////////////// // Dive zur Grafischen Darstellung auswhlen else if (cmd.equals("change_dive_to_display")) { entry = (String) srcBox.getSelectedItem(); lg.debug("dive <" + entry + ">...Index: <" + srcBox.getSelectedIndex() + ">"); // fillDiveComboBox( entry ); } else { lg.warn("unknown combobox command <" + cmd + "> recived."); } return; } else { lg.warn("unknown action command <" + cmd + "> recived."); } }
From source file:erigo.ctstream.CTstream.java
/** * Callback for menu items and "run time" controls in controlsPanel. * //from w w w . j av a 2 s . co m * @param eventI The ActionEvent which has occurred. */ @Override public void actionPerformed(ActionEvent eventI) { Object source = eventI.getSource(); if (source == null) { return; } else if (source instanceof JComboBox) { JComboBox<?> fpsCB = (JComboBox<?>) source; framesPerSec = ((Double) fpsCB.getSelectedItem()).doubleValue(); // Even when "change detect" is turned on, we always save an image at a rate which is // the slower of 1.0fps or the current frame rate; this is kind of a "key frame" of // sorts. Because of this, the "change detect" checkbox is meaningless when images/sec // is 1.0 and lower. if (framesPerSec <= 1.0) { changeDetectCheck.setEnabled(false); // A nice side benefit of processing JCheckBox events using an Action listener // is that calling "changeDetectCheck.setSelected(false)" will NOT fire an // event; thus, we maintain our original value of bChangeDetect. changeDetectCheck.setSelected(false); } else { changeDetectCheck.setEnabled(true); changeDetectCheck.setSelected(bChangeDetect); } } else if ((source instanceof JCheckBox) && (((JCheckBox) source) == screencapCheck)) { bScreencap = screencapCheck.isSelected(); if ((writeTask != null) && (writeTask.bIsRunning)) { if (bScreencap) { startScreencapCapture(); } else if (!bScreencap) { stopScreencapCapture(); } } } else if ((source instanceof JCheckBox) && (((JCheckBox) source) == webcamCheck)) { bWebcam = webcamCheck.isSelected(); if ((writeTask != null) && (writeTask.bIsRunning)) { if (bWebcam) { startWebcamCapture(); } else if (!bWebcam) { stopWebcamCapture(); } } } else if ((source instanceof JCheckBox) && (((JCheckBox) source) == audioCheck)) { bAudio = audioCheck.isSelected(); if ((writeTask != null) && (writeTask.bIsRunning)) { if (bAudio) { startAudioCapture(); } else if (!bAudio) { stopAudioCapture(); } } } else if ((source instanceof JCheckBox) && (((JCheckBox) source) == textCheck)) { bText = textCheck.isSelected(); if ((writeTask != null) && (writeTask.bIsRunning)) { if (bText) { startTextCapture(); } else if (!bText) { stopTextCapture(); } } } else if ((source instanceof JCheckBox) && (((JCheckBox) source) == includeMouseCursorCheck)) { if (includeMouseCursorCheck.isSelected()) { bIncludeMouseCursor = true; } else { bIncludeMouseCursor = false; } } else if ((source instanceof JCheckBox) && (((JCheckBox) source) == changeDetectCheck)) { if (changeDetectCheck.isSelected()) { bChangeDetect = true; } else { bChangeDetect = false; } } else if ((source instanceof JCheckBox) && (((JCheckBox) source) == fullScreenCheck)) { if (fullScreenCheck.isSelected()) { bFullScreen = true; // Save the original height guiFrameOrigHeight = guiFrame.getHeight(); // Shrink the GUI down to just controlsPanel Rectangle guiFrameBounds = guiFrame.getBounds(); Rectangle updatedGUIFrameBounds = new Rectangle(guiFrameBounds.x, guiFrameBounds.y, guiFrameBounds.width, controlsPanel.getHeight() + 22); guiFrame.setBounds(updatedGUIFrameBounds); } else { bFullScreen = false; // Expand the GUI to its original height Rectangle guiFrameBounds = guiFrame.getBounds(); int updatedHeight = guiFrameOrigHeight; if (guiFrameOrigHeight == -1) { updatedHeight = controlsPanel.getHeight() + 450; } Rectangle updatedGUIFrameBounds = new Rectangle(guiFrameBounds.x, guiFrameBounds.y, guiFrameBounds.width, updatedHeight); guiFrame.setBounds(updatedGUIFrameBounds); } // To display or not display screencap preview is dependent on whether we are in full screen mode or not. if (screencapStream != null) { screencapStream.updatePreview(); } } else if ((source instanceof JCheckBox) && (((JCheckBox) source) == previewCheck)) { if (previewCheck.isSelected()) { bPreview = true; } else { bPreview = false; } } else if (eventI.getActionCommand().equals("Start")) { // Make sure all needed values have been set String errStr = canCTrun(); if (!errStr.isEmpty()) { JOptionPane.showMessageDialog(guiFrame, errStr, "CTstream settings error", JOptionPane.ERROR_MESSAGE); return; } ((JButton) source).setText("Starting..."); bContinueMode = false; firstCTtime = 0; continueWallclockInitTime = 0; startCapture(); ((JButton) source).setText("Stop"); ((JButton) source).setBackground(Color.RED); continueButton.setEnabled(false); } else if (eventI.getActionCommand().equals("Stop")) { ((JButton) source).setText("Stopping..."); stopCapture(); ((JButton) source).setText("Start"); ((JButton) source).setBackground(Color.GREEN); continueButton.setEnabled(true); } else if (eventI.getActionCommand().equals("Continue")) { // This is just like "Start" except we pick up in time just where we left off bContinueMode = true; firstCTtime = 0; continueWallclockInitTime = 0; startCapture(); startStopButton.setText("Stop"); startStopButton.setBackground(Color.RED); continueButton.setEnabled(false); } else if (eventI.getActionCommand().equals("Settings...")) { boolean bBeenRunning = false; if (startStopButton.getText().equals("Stop")) { bBeenRunning = true; } // Stop capture (if it is running) stopCapture(); startStopButton.setText("Start"); startStopButton.setBackground(Color.GREEN); // Only want to enable the Continue button if the user had in fact been running if (bBeenRunning) { continueButton.setEnabled(true); } // Let user edit settings; the following function will not // return until the user clicks the OK or Cancel button. ctSettings.popupSettingsDialog(); } else if (eventI.getActionCommand().equals("Launch CTweb server...")) { // Pop up dialog to launch the CTweb server new LaunchCTweb(this, guiFrame); } else if (eventI.getActionCommand().equals("CloudTurbine website") || eventI.getActionCommand().equals("View data")) { if (!Desktop.isDesktopSupported()) { System.err.println("\nNot able to launch URL in a browser window, feature not supported."); return; } Desktop desktop = Desktop.getDesktop(); String urlStr = "http://cloudturbine.com"; if (eventI.getActionCommand().equals("View data")) { // v=1 specifies to view 1 sec of data // y=4 specifies 4 grids in y-direction // n=X specifies the number of channels // Setup the channel list String chanListStr = ""; int chanIdx = 0; NumberFormat formatter = new DecimalFormat("00"); if (bWebcam) { chanListStr = chanListStr + "&p" + formatter.format(chanIdx * 10) + "=" + sourceName + "/" + webcamStreamName; ++chanIdx; } if (bAudio) { chanListStr = chanListStr + "&p" + formatter.format(chanIdx * 10) + "=" + sourceName + "/" + audioStreamName; ++chanIdx; } if (bScreencap) { chanListStr = chanListStr + "&p" + formatter.format(chanIdx * 10) + "=" + sourceName + "/" + screencapStreamName; ++chanIdx; } if (bText) { chanListStr = chanListStr + "&p" + formatter.format(chanIdx * 10) + "=" + sourceName + "/" + textStreamName; ++chanIdx; } if (chanIdx == 0) { urlStr = "http://localhost:" + Integer.toString(webScanPort); } else { urlStr = "http://localhost:" + Integer.toString(webScanPort) + "/?dt=1000&c=0&f=false&sm=false&y=4&n=" + Integer.toString(chanIdx) + "&v=1" + chanListStr; } } URI uri = null; try { uri = new URI(urlStr); } catch (URISyntaxException e) { System.err.println("\nURISyntaxException:\n" + e); return; } try { desktop.browse(uri); } catch (IOException e) { System.err.println("\nCaught IOException trying to go to " + urlStr + ":\n" + e); } } else if (eventI.getActionCommand().equals("Exit")) { exit(false); } }
From source file:it.imtech.metadata.MetaUtility.java
private JComboBox addClassificationChoice(JPanel choice, final String sequence, final String panelname) { int selected = 0; int index = 0; int count = 1; for (Map.Entry<String, String> vc : availableClassifications.entrySet()) { if (count == 1 && !selectedClassificationList.containsKey(panelname + "---" + sequence)) { selected = index;/* w w w. j av a 2 s. c om*/ selectedClassificationList.put(panelname + "---" + sequence, vc.getKey()); } if (selectedClassificationList.containsKey(panelname + "---" + sequence)) { if (selectedClassificationList.get(panelname + "---" + sequence).equals(vc.getKey())) { selected = index; } } index++; } try { classifications_reader(sequence, panelname); } catch (Exception ex) { logger.error(ex.getMessage()); } final ComboMapImpl model = new ComboMapImpl(); model.putAllLinked(availableClassifications); JComboBox result = new javax.swing.JComboBox(model); result.setSelectedIndex(selected); model.specialRenderCombo(result); result.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); JComboBox comboBox = (JComboBox) event.getSource(); Map.Entry<String, String> c = (Map.Entry<String, String>) comboBox.getSelectedItem(); selectedClassificationList.put(panelname + "---" + sequence, c.getKey()); BookImporter.getInstance() .createComponentMap(BookImporter.getInstance().metadatapanels.get(panelname).getPanel()); JPanel innerPanel = (JPanel) BookImporter.getInstance() .getComponentByName(panelname + "---ImPannelloClassif---" + sequence); innerPanel.removeAll(); try { classifications_reader(sequence, panelname); addClassification(innerPanel, classificationMID, sequence, panelname); } catch (Exception ex) { logger.error(ex.getMessage()); } innerPanel.revalidate(); BookImporter.getInstance().setCursor(null); } }); return result; }
From source file:it.imtech.metadata.MetaUtility.java
private String check_and_save_metadata_recursive(Map<Object, Metadata> submetadatas, boolean checkMandatory) { ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader); String error = ""; for (Map.Entry<Object, Metadata> field : submetadatas.entrySet()) { if (!field.getValue().datatype.equals("Node") && field.getValue().editable.equals("Y")) { Component element = null; String midp = Integer.toString(field.getValue().MID_parent); if (midp.equals("11") || midp.equals("13")) element = BookImporter.getInstance().getComponentByName( "MID_" + Integer.toString(field.getValue().MID) + "---" + field.getValue().sequence); else { element = BookImporter.getInstance() .getComponentByName("MID_" + Integer.toString(field.getValue().MID)); }// w w w .j a va 2s.c o m if (element != null) { if (field.getValue().datatype.equals("CharacterString") || field.getValue().datatype.equals("LangString") || field.getValue().datatype.equals("GPS")) { JTextArea textTemp = (JTextArea) element; field.getValue().value = textTemp.getText(); if (checkMandatory && field.getValue().value.length() < 1 && (field.getValue().mandatory.equals("Y") || field.getValue().MID == 14 || field.getValue().MID == 15)) { error += Utility.getBundleString("error10", bundle) + " " + field.getValue().description.toString() + " " + Utility.getBundleString("error11", bundle) + "!\n"; } } if (field.getValue().datatype.equals("LangString")) { Component combobox = BookImporter.getInstance() .getComponentByName("MID_" + Integer.toString(field.getValue().MID) + "_lang"); JComboBox tmp = (JComboBox) combobox; Map.Entry tmp2 = (Map.Entry) tmp.getSelectedItem(); field.getValue().language = tmp2.getKey().toString(); } else if (field.getValue().datatype.equals("DateTime")) { Component combobox = BookImporter.getInstance() .getComponentByName("MID_" + Integer.toString(field.getValue().MID) + "_check"); JCheckBox beforechrist = (JCheckBox) combobox; JDateChooser datePicker = (JDateChooser) element; Date data = datePicker.getDate(); field.getValue().value = ""; if (data != null) { Format formatter = new SimpleDateFormat("yyyy-MM-dd"); String stDate = formatter.format(data); if (!stDate.equals("")) { if (beforechrist.isSelected()) { stDate = "-" + stDate; } field.getValue().value = stDate; } } } else if (field.getValue().datatype.equals("Language") || field.getValue().datatype.equals("Boolean") || field.getValue().datatype.equals("License") || field.getValue().datatype.equals("Vocabulary")) { Component combobox = null; if (midp.equals("11") || midp.equals("13")) combobox = BookImporter.getInstance().getComponentByName("MID_" + Integer.toString(field.getValue().MID) + "---" + field.getValue().sequence); else combobox = BookImporter.getInstance() .getComponentByName("MID_" + Integer.toString(field.getValue().MID)); JComboBox tmp = (JComboBox) combobox; Map.Entry tmp2 = (Map.Entry) tmp.getSelectedItem(); if (field.getValue().datatype.equals("License") || field.getValue().datatype.equals("Vocabulary")) { ResourceBundle tmpBundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader); if (checkMandatory && tmp2.getValue().toString() .equals(Utility.getBundleString("comboselect", tmpBundle)) && field.getValue().mandatory.equals("Y")) error += Utility.getBundleString("error10", bundle) + " " + field.getValue().description.toString() + " " + Utility.getBundleString("error11", bundle) + "!\n"; else if (tmp2.getValue().toString() .equals(Utility.getBundleString("comboselect", tmpBundle))) field.getValue().value = ""; else field.getValue().value = tmp2.getValue().toString(); } else field.getValue().value = tmp2.getKey().toString(); } } else { if (midp.equals("11") || midp.equals("13")) { field.getValue().value = ""; } } } error += check_and_save_metadata_recursive(field.getValue().submetadatas, checkMandatory); } return error; }
From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_node.java
private List<JComponent> getExtraOptions(final int row, final Object itemId) { List<JComponent> options = new LinkedList<JComponent>(); final int numRows = model.getRowCount(); final List<Node> tableVisibleNodes = getVisibleElementsInTable(); if (itemId != null) { JMenuItem switchCoordinates_thisNode = new JMenuItem("Switch node coordinates from (x,y) to (y,x)"); switchCoordinates_thisNode.addActionListener(new ActionListener() { @Override/*from ww w. j a v a 2s .c om*/ public void actionPerformed(ActionEvent e) { NetPlan netPlan = callback.getDesign(); Node node = netPlan.getNodeFromId((long) itemId); Point2D currentPosition = node.getXYPositionMap(); node.setXYPositionMap(new Point2D.Double(currentPosition.getY(), currentPosition.getX())); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE)); callback.runCanvasOperation(ITopologyCanvas.CanvasOperation.ZOOM_ALL); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(switchCoordinates_thisNode); JMenuItem xyPositionFromAttributes_thisNode = new JMenuItem("Set node coordinates from attributes"); xyPositionFromAttributes_thisNode.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NetPlan netPlan = callback.getDesign(); Set<String> attributeSet = new LinkedHashSet<String>(); Node node = netPlan.getNodeFromId((long) itemId); attributeSet.addAll(node.getAttributes().keySet()); try { if (attributeSet.isEmpty()) throw new Exception("No attribute to select"); final JComboBox latSelector = new WiderJComboBox(); final JComboBox lonSelector = new WiderJComboBox(); for (String attribute : attributeSet) { latSelector.addItem(attribute); lonSelector.addItem(attribute); } JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[][]")); pane.add(new JLabel("X-coordinate / Longitude: ")); pane.add(lonSelector, "growx, wrap"); pane.add(new JLabel("Y-coordinate / Latitude: ")); pane.add(latSelector, "growx, wrap"); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please select the attributes for coordinates", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { String latAttribute = latSelector.getSelectedItem().toString(); String lonAttribute = lonSelector.getSelectedItem().toString(); node.setXYPositionMap( new Point2D.Double(Double.parseDouble(node.getAttribute(lonAttribute)), Double.parseDouble(node.getAttribute(latAttribute)))); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving coordinates from attributes"); break; } } callback.runCanvasOperation(ITopologyCanvas.CanvasOperation.ZOOM_ALL); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving coordinates from attributes"); } } }); options.add(xyPositionFromAttributes_thisNode); JMenuItem nameFromAttribute_thisNode = new JMenuItem("Set node name from attribute"); nameFromAttribute_thisNode.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NetPlan netPlan = callback.getDesign(); Set<String> attributeSet = new LinkedHashSet<String>(); long nodeId = (long) itemId; attributeSet.addAll(netPlan.getNodeFromId(nodeId).getAttributes().keySet()); try { if (attributeSet.isEmpty()) throw new Exception("No attribute to select"); final JComboBox selector = new WiderJComboBox(); for (String attribute : attributeSet) selector.addItem(attribute); JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[]")); pane.add(new JLabel("Name: ")); pane.add(selector, "growx, wrap"); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please select the attribute for name", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { String name = selector.getSelectedItem().toString(); netPlan.getNodeFromId(nodeId) .setName(netPlan.getNodeFromId(nodeId).getAttribute(name)); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving name from attribute"); break; } } } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving name from attribute"); } } }); options.add(nameFromAttribute_thisNode); } if (numRows > 1) { if (!options.isEmpty()) options.add(new JPopupMenu.Separator()); JMenuItem switchCoordinates_allNodes = new JMenuItem( "Switch all table node coordinates from (x,y) to (y,x)"); switchCoordinates_allNodes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (Node n : tableVisibleNodes) { Point2D currentPosition = n.getXYPositionMap(); double newX = currentPosition.getY(); double newY = currentPosition.getX(); Point2D newPosition = new Point2D.Double(newX, newY); n.setXYPositionMap(newPosition); } callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE)); callback.runCanvasOperation(ITopologyCanvas.CanvasOperation.ZOOM_ALL); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(switchCoordinates_allNodes); JMenuItem xyPositionFromAttributes_allNodes = new JMenuItem( "Set all table node coordinates from attributes"); xyPositionFromAttributes_allNodes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Set<String> attributeSet = new LinkedHashSet<String>(); for (Node node : tableVisibleNodes) attributeSet.addAll(node.getAttributes().keySet()); try { if (attributeSet.isEmpty()) throw new Exception("No attribute to select"); final JComboBox latSelector = new WiderJComboBox(); final JComboBox lonSelector = new WiderJComboBox(); for (String attribute : attributeSet) { latSelector.addItem(attribute); lonSelector.addItem(attribute); } JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[][]")); pane.add(new JLabel("X-coordinate / Longitude: ")); pane.add(lonSelector, "growx, wrap"); pane.add(new JLabel("Y-coordinate / Latitude: ")); pane.add(latSelector, "growx, wrap"); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please select the attributes for coordinates", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { String latAttribute = latSelector.getSelectedItem().toString(); String lonAttribute = lonSelector.getSelectedItem().toString(); for (Node node : tableVisibleNodes) node.setXYPositionMap( new Point2D.Double(Double.parseDouble(node.getAttribute(lonAttribute)), Double.parseDouble(node.getAttribute(latAttribute)))); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving coordinates from attributes"); break; } } callback.runCanvasOperation(ITopologyCanvas.CanvasOperation.ZOOM_ALL); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving coordinates from attributes"); } } }); options.add(xyPositionFromAttributes_allNodes); JMenuItem nameFromAttribute_allNodes = new JMenuItem("Set all table node names from attribute"); nameFromAttribute_allNodes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Set<String> attributeSet = new LinkedHashSet<String>(); for (Node node : tableVisibleNodes) attributeSet.addAll(node.getAttributes().keySet()); try { if (attributeSet.isEmpty()) throw new Exception("No attribute to select"); final JComboBox selector = new WiderJComboBox(); for (String attribute : attributeSet) selector.addItem(attribute); JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[]")); pane.add(new JLabel("Name: ")); pane.add(selector, "growx, wrap"); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please select the attribute for name", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { String name = selector.getSelectedItem().toString(); for (Node node : tableVisibleNodes) node.setName(node.getAttribute(name) != null ? node.getAttribute(name) : ""); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.NODE)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving name from attribute"); break; } } } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error retrieving name from attribute"); } } }); options.add(nameFromAttribute_allNodes); } return options; }
From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java
private JComboBox createFilterCombo(JComboBox filtersCombo) { FiltersType filtersType = viewerConfig.getFilters(); // filtersCombo = new JComboBox(); if (filtersType == null) return filtersCombo; java.util.List<FilterType> filters = filtersType.getFilter(); final Map<String, FilterType> filterName2FilterType = new HashMap<String, FilterType>(); for (FilterType filter : filters) { filtersCombo.addItem(filter.getName()); filterName2FilterType.put(filter.getName(), filter); }//ww w. j ava 2 s. co m filtersCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String filterName = (String) ((JComboBox) e.getSource()).getSelectedItem(); currentFilter = filterName2FilterType.get(filterName); vv.setCurrentFilter(currentFilter); // Set<String> vertexes = new HashSet<String>(currentGraph.getVertices()); Set<String> pickedVertexes = getPickedVerteces(); if (pickedVertexes != null) { applyFilter(currentFilter, currentHops, pickedVertexes); } else { applyFilter(currentFilter, currentHops); } } }); final String filterName = (String) filtersCombo.getSelectedItem(); currentFilter = filterName2FilterType.get(filterName); vv.setCurrentFilter(currentFilter); return filtersCombo; }
From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_multicastDemand.java
private List<JComponent> getExtraOptions(final int row, final Object itemId) { List<JComponent> options = new LinkedList<JComponent>(); final int numRows = model.getRowCount(); final NetPlan netPlan = callback.getDesign(); final List<MulticastDemand> visibleRows = getVisibleElementsInTable(); JMenuItem offeredTrafficToAll = new JMenuItem("Set offered traffic to all"); offeredTrafficToAll.addActionListener(new ActionListener() { @Override//from w ww . j ava 2 s .c om public void actionPerformed(ActionEvent e) { double h_d; while (true) { String str = JOptionPane.showInputDialog(null, "Offered traffic volume", "Set traffic value to all table multicast demands", JOptionPane.QUESTION_MESSAGE); if (str == null) return; try { h_d = Double.parseDouble(str); if (h_d < 0) throw new RuntimeException(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog( "Non-valid multicast demand offered traffic value. Please, introduce a non-negative number", "Error setting link length"); } } try { for (MulticastDemand demand : visibleRows) demand.setOfferedTraffic(h_d); callback.updateVisualizationAfterChanges( Collections.singleton(NetworkElementType.MULTICAST_DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set offered traffic to all multicast demands"); } } }); options.add(offeredTrafficToAll); if (itemId != null && netPlan.isMultilayer()) { final long demandId = (long) itemId; final MulticastDemand demand = netPlan.getMulticastDemandFromId(demandId); if (demand.isCoupled()) { JMenuItem decoupleDemandItem = new JMenuItem("Decouple multicast demand"); decoupleDemandItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { demand.decouple(); model.setValueAt("", row, COLUMN_COUPLEDTOLINKS); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.MULTICAST_DEMAND, NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(decoupleDemandItem); } if (numRows > 1) { JMenuItem decoupleAllDemandsItem = null; JMenuItem createUpperLayerLinksFromDemandsItem = null; final Set<MulticastDemand> coupledDemands = visibleRows.stream().filter(e -> e.isCoupled()) .collect(Collectors.toSet()); if (!coupledDemands.isEmpty()) { decoupleAllDemandsItem = new JMenuItem("Decouple all table demands"); decoupleAllDemandsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (MulticastDemand d : coupledDemands) d.decouple(); int numRows = model.getRowCount(); for (int i = 0; i < numRows; i++) model.setValueAt("", i, COLUMN_COUPLEDTOLINKS); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.MULTICAST_DEMAND, NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); } if (coupledDemands.size() < visibleRows.size()) { createUpperLayerLinksFromDemandsItem = new JMenuItem( "Create upper layer links from uncoupled demands"); createUpperLayerLinksFromDemandsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { List<Long> layerIds = netPlan.getNetworkLayerIds(); final JComboBox layerSelector = new WiderJComboBox(); for (long layerId : layerIds) { if (layerId == netPlan.getNetworkLayerDefault().getId()) continue; final String layerName = netPlan.getNetworkLayerFromId(layerId).getName(); String layerLabel = "Layer " + layerId; if (!layerName.isEmpty()) layerLabel += " (" + layerName + ")"; layerSelector.addItem(StringLabeller.of(layerId, layerLabel)); } layerSelector.setSelectedIndex(0); JPanel pane = new JPanel(); pane.add(new JLabel("Select layer: ")); pane.add(layerSelector); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please select the upper layer to create links", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { long layerId = (long) ((StringLabeller) layerSelector.getSelectedItem()) .getObject(); NetworkLayer layer = netPlan.getNetworkLayerFromId(layerId); for (MulticastDemand demand : visibleRows) if (!demand.isCoupled()) demand.coupleToNewLinksCreated(layer); callback.getVisualizationState() .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals(); callback.updateVisualizationAfterChanges(Sets.newHashSet( NetworkElementType.MULTICAST_DEMAND, NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error creating upper layer links"); } } } }); } if (!options.isEmpty() && (decoupleAllDemandsItem != null || createUpperLayerLinksFromDemandsItem != null)) { options.add(new JPopupMenu.Separator()); if (decoupleAllDemandsItem != null) options.add(decoupleAllDemandsItem); if (createUpperLayerLinksFromDemandsItem != null) options.add(createUpperLayerLinksFromDemandsItem); } } } return options; }
From source file:search2go.UIFrame.java
private void blast(JTextField queries, JFormattedTextField eValue, JTextField db, JTextField threads, JComboBox type, JTextArea output, boolean fullProcess) throws IOException { Path queriesPath = new Path(queries.getText()); Path dbPath = new Path(db.getText()); String threadNo = threads.getText(); String blastType = type.getSelectedItem().toString().replace("BLAST", ""); currentProj.setQueries(queriesPath.toEscString()); currentProj.setPathToDB(dbPath.toEscString()); currentProj.setThreadNo(Integer.parseInt(threadNo)); currentProj.setBlastTypeIndex(type.getSelectedIndex()); currentProj.setEthreshold(Integer.parseInt(txtBlastE.getText())); blastSequence = new ProcessSequence(currentProj, new ProcessSequenceEnd() { @Override//from w w w .j a v a 2 s . co m public void run() { output.append("BLAST Done! Please proceed to Mapping\n"); prgBlast.setIndeterminate(false); currentProj.setAvailable(true); currentProj.setStage(1); if (fullProcess) { map(txtBitScoreFP, eValue, cbxDBIDFP, txtFullOutput, true); } blastButton.restore(); } }); Path outLoc = new Path(currentProj.getPath()); outLoc.append("BLAST_Results.xml"); Process blastProcess = new Process(output, outLoc); blastProcess.setBaseCommand(""); blastProcess.setScriptCommand(type.getSelectedItem().toString().toLowerCase()); blastProcess.addParameter("query", queriesPath.toEscString()); blastProcess.addParameter("db", dbPath.toEscString()); blastProcess.addParameter("num_threads", threadNo); if (!eValue.getText().equals("")) blastProcess.addParameter("evalue", eValue.getText()); blastProcess.addParameter("outfmt", Integer.toString(5)); blastSequence.addProcess(blastProcess); try { blastSequence.start(); blastButton.setStopTargets(blastSequence); if (!fullProcess) blastButton.activate(); currentProj.setStage(0); output.setText("Searching...\n"); prgBlast.setIndeterminate(true); } catch (IOException ex) { javax.swing.JOptionPane.showMessageDialog(this, "Error running BLAST search."); } }
From source file:de.dmarcini.submatix.pclogger.gui.MainCommGUI.java
/** * Bearbeitet Combobox actions Project: SubmatixBTConfigPC Package: de.dmarcini.submatix.pclogger.gui * /* w ww.j av a 2 s . co m*/ * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 07.01.2012 * @param ev * Avtion event */ private void processComboBoxActions(ActionEvent ev) { String cmd = ev.getActionCommand(); String entry = null; JComboBox<?> srcBox = (JComboBox<?>) ev.getSource(); // ///////////////////////////////////////////////////////////////////////// // Letzter Decostop auf 3 oder 6 Meter if (cmd.equals("deco_last_stop")) { entry = (String) srcBox.getSelectedItem(); lg.debug("deco last stop <" + entry + ">..."); currentConfig.setLastStop(srcBox.getSelectedIndex()); } // ///////////////////////////////////////////////////////////////////////// // Preset fr Deco-Gradienten ausgewhlt else if (cmd.equals("deco_gradient_preset")) { entry = (String) srcBox.getSelectedItem(); lg.debug("gradient preset <" + entry + ">, Index: <" + srcBox.getSelectedIndex() + ">..."); currentConfig.setDecoGfPreset(srcBox.getSelectedIndex()); // Spinner setzen setGradientSpinnersAfterPreset(srcBox.getSelectedIndex()); } // ///////////////////////////////////////////////////////////////////////// // Autosetpoint Voreinstellung else if (cmd.equals("set_autosetpoint")) { entry = (String) srcBox.getSelectedItem(); lg.debug("autosetpoint preset <" + entry + ">..."); currentConfig.setAutoSetpoint(srcBox.getSelectedIndex()); } // ///////////////////////////////////////////////////////////////////////// // Setpoint fr hchsten PPO2 Wert einstellen else if (cmd.equals("set_highsetpoint")) { entry = (String) srcBox.getSelectedItem(); lg.debug("hightsetpoint <" + entry + ">..."); currentConfig.setMaxSetpoint(srcBox.getSelectedIndex()); } // ///////////////////////////////////////////////////////////////////////// // Helligkeit des Displays else if (cmd.equals("set_disp_brightness")) { entry = (String) srcBox.getSelectedItem(); lg.debug("brightness <" + entry + ">..."); currentConfig.setDisplayBrithtness(srcBox.getSelectedIndex()); } // ///////////////////////////////////////////////////////////////////////// // Ausrichtung des Displays else if (cmd.equals("set_display_orientation")) { entry = (String) srcBox.getSelectedItem(); lg.debug("orientation <" + entry + ">..."); currentConfig.setDisplayOrientation(srcBox.getSelectedIndex()); } // ///////////////////////////////////////////////////////////////////////// // Grad Celsius oder Fahrenheit einstellen else if (cmd.equals("set_temperature_unit")) { entry = (String) srcBox.getSelectedItem(); lg.debug("temperature unit <" + entry + ">..."); currentConfig.setUnitTemperature(srcBox.getSelectedIndex()); } // ///////////////////////////////////////////////////////////////////////// // Maeinheit fr Tiefe festlegen else if (cmd.equals("set_depth_unit")) { entry = (String) srcBox.getSelectedItem(); lg.debug("depth unit <" + entry + ">..."); currentConfig.setUnitDepth(srcBox.getSelectedIndex()); configPanel.setUnitDepth(srcBox.getSelectedIndex()); } // ///////////////////////////////////////////////////////////////////////// // Swasser oder Salzwasser else if (cmd.equals("set_salnity")) { entry = (String) srcBox.getSelectedItem(); lg.debug("salnity <" + entry + ">..."); currentConfig.setUnitSalnyty(srcBox.getSelectedIndex()); } // ///////////////////////////////////////////////////////////////////////// // Loginterval einstellen else if (cmd.equals("set_loginterval")) { entry = (String) srcBox.getSelectedItem(); lg.debug("loginterval <" + entry + ">..."); currentConfig.setLogInterval(srcBox.getSelectedIndex()); } // ///////////////////////////////////////////////////////////////////////// // Anzahl der sensoren fr Messung/Warung einstellen else if (cmd.equals("set_sensorwarnings")) { entry = (String) srcBox.getSelectedItem(); lg.debug("sensorwarnings <" + entry + ">...Index: <" + srcBox.getSelectedIndex() + ">"); currentConfig.setSensorsCount(srcBox.getSelectedIndex()); } // ///////////////////////////////////////////////////////////////////////// // Temperatur Sensor Version umstellen else if (cmd.equals("set_tempstickversion")) { entry = (String) srcBox.getSelectedItem(); lg.debug("tempstickversion <" + entry + ">...Index: <" + srcBox.getSelectedIndex() + ">"); currentConfig.setTempStickVersion(srcBox.getSelectedIndex()); } else { lg.warn("unknown combobox command <" + cmd + "> recived."); } }
From source file:com.alvermont.terraj.fracplanet.ui.ControlsDialog.java
private void terrainTypeComboActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_terrainTypeComboActionPerformed {//GEN-HEADEREND:event_terrainTypeComboActionPerformed final JComboBox box = (JComboBox) evt.getSource(); final TerrainParameters params = this.parent.getParameters().getTerrainParameters(); final String selected = (String) box.getSelectedItem(); if (selected.equals("Planet")) { params.setObjectType(TerrainParameters.ObjectTypeEnum.PLANET); } else if (selected.equals("Triangular Terrain")) { params.setObjectType(TerrainParameters.ObjectTypeEnum.TERRAIN_TRIANGLE); } else if (selected.equals("Square Terrain")) { params.setObjectType(TerrainParameters.ObjectTypeEnum.TERRAIN_SQUARE); } else {/* w w w .j a v a 2 s . co m*/ params.setObjectType(TerrainParameters.ObjectTypeEnum.TERRAIN_HEXAGON); } }