Java Code Examples for javax.swing.JComboBox#getSelectedIndex()

The following examples show how to use javax.swing.JComboBox#getSelectedIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NextFunctionAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isEnabledForContext(ActionContext context) {
	if (!(context.getComponentProvider() instanceof MultiFunctionComparisonProvider)) {
		return false;
	}
	MultiFunctionComparisonProvider provider =
		(MultiFunctionComparisonProvider) context.getComponentProvider();

	Component comp = provider.getComponent();
	if (!(comp instanceof MultiFunctionComparisonPanel)) {
		return false;
	}

	MultiFunctionComparisonPanel panel = (MultiFunctionComparisonPanel) comp;
	JComboBox<Function> focusedComponent = panel.getFocusedComponent();
	return focusedComponent.getSelectedIndex() < (focusedComponent.getModel().getSize() - 1);
}
 
Example 2
Source File: PreviousFunctionAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isEnabledForContext(ActionContext context) {
	if (!(context.getComponentProvider() instanceof MultiFunctionComparisonProvider)) {
		return false;
	}
	MultiFunctionComparisonProvider provider =
		(MultiFunctionComparisonProvider) context.getComponentProvider();

	Component comp = provider.getComponent();
	if (!(comp instanceof MultiFunctionComparisonPanel)) {
		return false;
	}

	MultiFunctionComparisonPanel panel = (MultiFunctionComparisonPanel) comp;
	JComboBox<Function> focusedComponent = panel.getFocusedComponent();
	return focusedComponent.getSelectedIndex() > 0;
}
 
Example 3
Source File: RemoveFunctionsAction.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isEnabledForContext(ActionContext context) {
	if (!(context.getComponentProvider() instanceof MultiFunctionComparisonProvider)) {
		return false;
	}
	MultiFunctionComparisonProvider provider =
		(MultiFunctionComparisonProvider) context.getComponentProvider();

	Component comp = provider.getComponent();
	if (!(comp instanceof MultiFunctionComparisonPanel)) {
		return false;
	}
	MultiFunctionComparisonPanel panel = (MultiFunctionComparisonPanel) comp;
	JComboBox<Function> focusedComponent = panel.getFocusedComponent();

	return focusedComponent.getSelectedIndex() != -1;
}
 
Example 4
Source File: ActivitySequenceElementEditorPanel.java    From jclic with GNU General Public License v2.0 6 votes vote down vote up
protected JumpInfo checkJump(JumpInfo ji, JComboBox combo, boolean allowNull, boolean forcePrompt) {
  int offset = allowNull ? 1 : 0;
  int v = combo.getSelectedIndex();
  if (v == 0 && allowNull)
    ji = null;
  else {
    if (ji == null)
      ji = new ActivitySequenceJump(v - offset);
    else
      ji.action = v - offset;
    if (ji.action == JumpInfo.JUMP && (forcePrompt || (ji.sequence == null && ji.projectPath == null))) {
      boolean b = promptJumpParams(ji, this);
      if (!b || (ji.sequence == null && ji.projectPath == null)) {
        if (allowNull)
          ji = null;
        else
          ji.action = JumpInfo.RETURN;
        setInitializing(true);
        combo.setSelectedIndex(ji == null ? 0 : ji.action + offset);
        setInitializing(false);
      }
    }
  }
  return ji;
}
 
Example 5
Source File: QueryClientGui.java    From fosstrak-epcis with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Handles the event of a changed JComboBox in the query arguments section
 * Will add or remove JComboBoxes as necessary and resize the window.
 * 
 * @param i
 *            The index of the combo box.
 */
private void mwQuerySelectComboBoxesChanged(final int i) {
    JComboBox<String> cb = (JComboBox<String>) mwQuerySelectComboBoxes.get(i);

    if ((cb.getSelectedIndex() == 0) && (cb != mwQuerySelectComboBoxes.getLast())) {
        /*
         * the user selected "ignore" and this is not the last row, so
         * remove it
         */
        removeArgumentRow(i);
    } else if ((cb.getSelectedIndex() != 0) && (cb == mwQuerySelectComboBoxes.getLast())) {
        /* the user changed the value of the last row, so add a new row */
        addArgumentRow(i);
    } else {
        /* the user changed an existing row, so just update description */
        ((JTextFieldEnhanced) mwQueryArgumentTextFields.get(i)).setQueryItem(queryParamsUserText.get(queryParameterUsertext[cb.getSelectedIndex()]));
    }
}
 
Example 6
Source File: EditTeamService.java    From Shuffle-Move with GNU General Public License v3.0 6 votes vote down vote up
private void updateKeybindComboBoxes() {
   Team curTeam = getCurrentTeam();
   for (String name : curTeam.getNames()) {
      ItemListener itemListener = nameToItemListenerMap.get(name);
      JComboBox<Character> box = nameToKeybindComboboxMap.get(name);
      box.removeItemListener(itemListener);
      Character prevSelected = box.getItemAt(box.getSelectedIndex());
      box.removeAllItems();
      Character curBinding = curTeam.getBinding(name);
      LinkedHashSet<Character> availableBindings = new LinkedHashSet<Character>(Arrays.asList(curBinding));
      availableBindings.addAll(myData.getAllAvailableBindingsFor(name, curTeam));
      for (Character ch : availableBindings) {
         if (ch != null) {
            box.addItem(ch);
         }
      }
      box.setSelectedItem(prevSelected);
      if (box.getSelectedIndex() < 0) {
         LOG.warning(getString(KEY_NO_BINDINGS));
      }
      box.addItemListener(itemListener);
   }
}
 
Example 7
Source File: JWTInterceptTabController.java    From JWT4B with GNU General Public License v3.0 6 votes vote down vote up
private void algAttackChanged() {
	JComboBox<String> jCB = jwtST.getNoneAttackComboBox();
	switch (jCB.getSelectedIndex()) {
	default:
	case 0:
		algAttackMode = null;
		break;
	case 1:
		algAttackMode = "none";
		break;
	case 2:
		algAttackMode = "None";
		break;
	case 3:
		algAttackMode = "nOnE";
		break;
	case 4:
		algAttackMode = "NONE";
		break;
	}
}
 
Example 8
Source File: EditorPanel.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent event) {
    String command = event.getActionCommand();
    if (COMPARISON.equals(command)) {
        JComboBox<?>   combo          = (JComboBox<?>) event.getSource();
        int            selectedIndex  = combo.getSelectedIndex();
        StringCriteria stringCriteria = (StringCriteria) combo.getClientProperty(StringCriteria.class);
        if (stringCriteria != null) {
            stringCriteria.setType(StringCompareType.values()[selectedIndex]);
            notifyActionListeners();
        } else {
            NumericCriteria numericCriteria = (NumericCriteria) combo.getClientProperty(NumericCriteria.class);
            if (numericCriteria != null) {
                numericCriteria.setType(NumericCompareType.values()[selectedIndex]);
                notifyActionListeners();
            }
        }
    }
}
 
Example 9
Source File: ClusteringVisualTab.java    From moa with GNU General Public License v3.0 5 votes vote down vote up
private void comboXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboXActionPerformed
    JComboBox cb = (JComboBox)evt.getSource();
    int dim = cb.getSelectedIndex();
    streamPanel0.setActiveXDim(dim);
    streamPanel1.setActiveXDim(dim);
    if(visualizer!=null)
        visualizer.redraw();
}
 
Example 10
Source File: OutlierVisualTab.java    From moa with GNU General Public License v3.0 5 votes vote down vote up
private void comboYActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboYActionPerformed
    if (visualizer == null) return;
    JComboBox cb = (JComboBox)evt.getSource();
    int dim = cb.getSelectedIndex();
    streamPanel0.setActiveYDim(dim);
    streamPanel1.setActiveYDim(dim);
    if(visualizer!=null)
        visualizer.redraw();
}
 
Example 11
Source File: FrmSimulator.java    From drmips with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initializes/translates the specified data format selection combo box.
 * @param cmb The combo box.
 * @param formatPref The name of the preference for the saved previous format.
 * @param defaultFormat The default data format.
 */
private void initFormatComboBox(JComboBox cmb, String formatPref, int defaultFormat) {
	if(cmb.getSelectedIndex() >= 0)
		DrMIPS.prefs.putInt(formatPref, cmb.getSelectedIndex());
	cmb.removeAllItems();
	cmb.addItem(Lang.t("binary"));
	cmb.addItem(Lang.t("decimal"));
	cmb.addItem(Lang.t("hexadecimal"));
	cmb.setSelectedIndex(DrMIPS.prefs.getInt(formatPref, defaultFormat));
}
 
Example 12
Source File: SwingUtil.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Object value(JComboBox cb, Object[] val)
{
	int selIndex = cb.getSelectedIndex();
	if (selIndex == -1) 
		return null;
	return val[selIndex];
}
 
Example 13
Source File: ClusteringVisualTab.java    From moa with GNU General Public License v3.0 5 votes vote down vote up
private void comboYActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboYActionPerformed
    JComboBox cb = (JComboBox)evt.getSource();
    int dim = cb.getSelectedIndex();
    streamPanel0.setActiveYDim(dim);
    streamPanel1.setActiveYDim(dim);
    if(visualizer!=null)
        visualizer.redraw();
}
 
Example 14
Source File: JComboBoxJavaElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static String getSelectedItemText(JComboBox combo) {
    int selectedIndex = combo.getSelectedIndex();
    if (selectedIndex == -1) {
        return "";
    }
    return JComboBoxOptionJavaElement.getText(combo, selectedIndex, true);
}
 
Example 15
Source File: UIUtilities.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
/**
 * Since JComboBox.getSelectedItem() returns a plain Object, this allows us to get the
 * appropriate type of object instead.
 */
public static <E> E getTypedSelectedItemFromCombo(JComboBox<E> combo) {
    int index = combo.getSelectedIndex();
    return index == -1 ? null : combo.getItemAt(index);
}
 
Example 16
Source File: MyMenuBar.java    From JByteMod-Beta with GNU General Public License v2.0 4 votes vote down vote up
protected void replaceLDC() {
	final JPanel panel = new JPanel(new BorderLayout(5, 5));
	final JPanel input = new JPanel(new GridLayout(0, 1));
	final JPanel labels = new JPanel(new GridLayout(0, 1));
	panel.add(labels, "West");
	panel.add(input, "Center");
	panel.add(new JLabel(JByteMod.res.getResource("big_string_warn")), "South");
	labels.add(new JLabel("Find: "));
	JTextField find = new JTextField();
	input.add(find);
	labels.add(new JLabel("Replace with: "));
	JTextField with = new JTextField();
	input.add(with);
	JComboBox<String> ldctype = new JComboBox<String>(new String[] { "String", "float", "double", "int", "long" });
	ldctype.setSelectedIndex(0);
	labels.add(new JLabel("Ldc Type: "));
	input.add(ldctype);
	JCheckBox exact = new JCheckBox(JByteMod.res.getResource("exact"));
	JCheckBox cases = new JCheckBox(JByteMod.res.getResource("case_sens"));
	labels.add(exact);
	input.add(cases);
	if (JOptionPane.showConfirmDialog(this.jbm, panel, "Replace LDC", JOptionPane.OK_CANCEL_OPTION,
			JOptionPane.PLAIN_MESSAGE, searchIcon) == JOptionPane.OK_OPTION && !find.getText().isEmpty()) {
		int expectedType = ldctype.getSelectedIndex();
		boolean equal = exact.isSelected();
		boolean ignoreCase = !cases.isSelected();
		String findCst = find.getText();
		if (ignoreCase) {
			findCst = findCst.toLowerCase();
		}
		String replaceWith = with.getText();
		int i = 0;
		for (ClassNode cn : jbm.getFile().getClasses().values()) {
			for (MethodNode mn : cn.methods) {
				for (AbstractInsnNode ain : mn.instructions) {
					if (ain.getType() == AbstractInsnNode.LDC_INSN) {
						LdcInsnNode lin = (LdcInsnNode) ain;
						Object cst = lin.cst;
						int type;
						if (cst instanceof String) {
							type = 0;
						} else if (cst instanceof Float) {
							type = 1;
						} else if (cst instanceof Double) {
							type = 2;
						} else if (cst instanceof Long) {
							type = 3;
						} else if (cst instanceof Integer) {
							type = 4;
						} else {
							type = -1;
						}
						String cstStr = cst.toString();
						if (ignoreCase) {
							cstStr = cstStr.toLowerCase();
						}
						if (type == expectedType) {
							if (equal ? cstStr.equals(findCst) : cstStr.contains(findCst)) {
								switch (type) {
								case 0:
									lin.cst = replaceWith;
									break;
								case 1:
									lin.cst = Float.parseFloat(replaceWith);
									break;
								case 2:
									lin.cst = Double.parseDouble(replaceWith);
									break;
								case 3:
									lin.cst = Long.parseLong(replaceWith);
									break;
								case 4:
									lin.cst = Integer.parseInt(replaceWith);
									break;
								}
								i++;
							}
						}
					}
				}
			}
		}
		JByteMod.LOGGER.log(i + " ldc's replaced");
	}
}
 
Example 17
Source File: DevicePanel.java    From FoxTelem with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
protected void saveParam(JComboBox box, String key) {
	int g = box.getSelectedIndex();
	Log.println("SAVED " + key + ": " + g);
	Config.saveGraphIntParam("SDR", 0, 0, device.name, key, g);		
}
 
Example 18
Source File: EmbeddedFrameGrabTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test fails if it throws any exception.
 *
 * @throws Exception
 */
private void init() throws Exception {

    if (!System.getProperty("os.name").startsWith("Windows")) {
        System.out.println("This is Windows only test.");
        return;
    }

    final Frame frame = new Frame("AWT Frame");
    frame.pack();
    frame.setSize(200, 200);
    FramePeer frame_peer = AWTAccessor.getComponentAccessor()
                                .getPeer(frame);
    Class comp_peer_class
            = Class.forName("sun.awt.windows.WComponentPeer");
    Field hwnd_field = comp_peer_class.getDeclaredField("hwnd");
    hwnd_field.setAccessible(true);
    long hwnd = hwnd_field.getLong(frame_peer);

    Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame");
    Constructor constructor
            = clazz.getConstructor(new Class[]{long.class});
    final Frame embedded_frame
            = (Frame) constructor.newInstance(new Object[]{
                new Long(hwnd)});;
    final JComboBox<String> combo = new JComboBox<>(new String[]{
        "Item 1", "Item 2"
    });
    combo.setSelectedIndex(1);
    final Panel p = new Panel();
    p.setLayout(new BorderLayout());
    embedded_frame.add(p, BorderLayout.CENTER);
    embedded_frame.validate();
    p.add(combo);
    p.validate();
    frame.setVisible(true);
    Robot robot = new Robot();
    robot.delay(2000);
    Rectangle clos = new Rectangle(
            combo.getLocationOnScreen(), combo.getSize());
    robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.delay(1000);
    if (!combo.isPopupVisible()) {
        throw new RuntimeException("Combobox popup is not visible!");
    }
    robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height + 3);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.delay(1000);
    if (combo.getSelectedIndex() != 0) {
        throw new RuntimeException("Combobox selection has not changed!");
    }
    embedded_frame.remove(p);
    embedded_frame.dispose();
    frame.dispose();

}
 
Example 19
Source File: LayoutEditor.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
private void defineSwap(com.codename1.ui.layouts.BorderLayout b, String originalPos, JComboBox c) {
    if(c.getSelectedIndex() <= 0) {
        return;
    }
    b.defineLandscapeSwap(originalPos, (String)c.getSelectedItem());
}
 
Example 20
Source File: MainWindow.java    From xdm with GNU General Public License v2.0 4 votes vote down vote up
private void optimizeRWin() {
	JComboBox<String> cmbLang = new JComboBox<>(
			new String[] { StringResource.get("LBL_NET_OPT_DEF"), StringResource.get("LBL_NET_OPT_64"),
					StringResource.get("LBL_NET_OPT_128"), StringResource.get("LBL_NET_OPT_256") });
	cmbLang.setSelectedIndex(0);

	String prompt = StringResource.get("LBL_NET_OPT_MSG");

	Object[] obj = new Object[2];
	obj[0] = prompt;
	obj[1] = cmbLang;

	switch (Config.getInstance().getTcpWindowSize()) {
	case 64:
		cmbLang.setSelectedIndex(1);
		break;
	case 128:
		cmbLang.setSelectedIndex(2);
		break;
	case 256:
		cmbLang.setSelectedIndex(3);
		break;
	default:
		cmbLang.setSelectedIndex(0);
	}

	if (JOptionPane.showOptionDialog(null, obj, StringResource.get("LBL_OPTIMIZE_NETWORK"),
			JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null) == JOptionPane.OK_OPTION) {
		int index = cmbLang.getSelectedIndex();
		if (index != -1) {
			switch (index) {
			case 1:
				Config.getInstance().setTcpWindowSize(64);
				break;
			case 2:
				Config.getInstance().setTcpWindowSize(128);
				break;
			case 3:
				Config.getInstance().setTcpWindowSize(256);
				break;
			default:
				Config.getInstance().setTcpWindowSize(0);
			}
		}
	}

}