private void resetFromFile(@NotNull VirtualFile file, @NotNull Project project) { final Module moduleForFile = ModuleUtilCore.findModuleForFile(file, project); if (moduleForFile == null) { return; } final VirtualFile parent = file.getParent(); if (parent == null) { return; } if (myModule == null) { final Object prev = myModuleCombo.getSelectedItem(); myModuleCombo.setSelectedItem(moduleForFile); if (!moduleForFile.equals(myModuleCombo.getSelectedItem())) { myModuleCombo.setSelectedItem(prev); return; } } else if (!myModule.equals(moduleForFile)) { return; } final JCheckBox checkBox = myCheckBoxes.get(parent.getName()); if (checkBox == null) { return; } for (JCheckBox checkBox1 : myCheckBoxes.values()) { checkBox1.setSelected(false); } checkBox.setSelected(true); myFileNameCombo.getEditor().setItem(file.getName()); }
private void prepareTextComboBox(final Object propertyValue) { // _textComboBox wird in der letzten Zeile editierbar gemacht, und es wird // der übergebene Wert in diese Zeile eingetragen und selektiert, wenn er nicht // einem der anderen Einträge entspricht. if (propertyValue != null) { String propertyValueAsString = (String) propertyValue; final int size = _textComboBox.getModel().getSize(); boolean propertyValueFound = false; for (int i = 0; i < size - 1; i++) { if (propertyValueAsString.equals((String) _textComboBox.getItemAt(i))) { propertyValueFound = true; _textComboBox.setSelectedIndex(i); break; } } if (!propertyValueFound) { _textComboBox.removeItemAt(size - 1); _textComboBox.addItem(propertyValueAsString); _textComboBox.setSelectedIndex(size - 1); } } ItemListener textComboBoxItemListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { if (_textComboBox.getSelectedIndex() == DOTPointPainter.DYNAMIC_TEXT_ITEMS.length - 1) { _textComboBox.setEditable(true); } else { _textComboBox.setEditable(false); } } } }; _textComboBox.addItemListener(textComboBoxItemListener); ActionListener editorActionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { final int length = DOTPointPainter.DYNAMIC_TEXT_ITEMS.length; final int index = length - 1; final ComboBoxEditor editor = _textComboBox.getEditor(); String editedItem = (String) editor.getItem(); _textComboBox.insertItemAt(editedItem, index); final DefaultComboBoxModel model = (DefaultComboBoxModel) _textComboBox.getModel(); if (model.getSize() > length) { // Sieht komisch aus, aber der direkte Weg ging nicht. model.removeElementAt(length); } } }; _textComboBox.getEditor().addActionListener(editorActionListener); }
protected void setPref() { Color color = DisplayOptions.getColor("PlainText"); Font font = DisplayOptions.getFont("PlainText"); m_lblUsername.setForeground(color); m_lblUsername.setFont(font); m_lblPassword.setForeground(color); m_lblPassword.setFont(font); m_cmbUser.getEditor().getEditorComponent().setForeground(color); m_cmbUser.getEditor().getEditorComponent().setFont(font); m_passwordField.setForeground(color); m_passwordField.setFont(font); color = DisplayOptions.getColor("Heading3"); font = DisplayOptions.getFont("Heading3"); m_lblSampleName.setForeground(color); m_pnlTrays.setBorder( BorderDeli.createBorder("Empty", "Sample Trays", "Bottom", "Center", color, font)); VBox.setforeground(color); VBox.setfont(font); }
private StaticPanel createStaticTextPanel(PrimitiveForm primitiveForm, DOTProperty property) { StaticPanel theTextPanel = createStaticComboBoxPanel( primitiveForm, property, "Text: ", DOTPointPainter.STATIC_TEXT_ITEMS); final JComboBox theComboBox = theTextPanel.getComboBox(); if (theComboBox == null) { return theTextPanel; } ItemListener comboBoxItemListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { if (theComboBox.getSelectedIndex() == DOTPointPainter.STATIC_TEXT_ITEMS.length - 1) { theComboBox.setEditable(true); } else { theComboBox.setEditable(false); } } } }; theComboBox.addItemListener(comboBoxItemListener); ActionListener editorActionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { final int length = DOTPointPainter.STATIC_TEXT_ITEMS.length; final int index = length - 1; final ComboBoxEditor editor = theComboBox.getEditor(); String editedItem = (String) editor.getItem(); theComboBox.insertItemAt(editedItem, index); final DefaultComboBoxModel model = (DefaultComboBoxModel) theComboBox.getModel(); if (model.getSize() > length) { // Sieht komisch aus, aber der direkte Weg ging nicht. model.removeElementAt(length); } } }; theComboBox.getEditor().addActionListener(editorActionListener); return theTextPanel; }
public CreateXmlResourceDialog( @NotNull Module module, @NotNull ResourceType resourceType, @Nullable String predefinedName, @Nullable String predefinedValue, boolean chooseName, @Nullable VirtualFile defaultFile) { super(module.getProject()); myResourceType = resourceType; if (predefinedName != null && predefinedName.length() > 0) { if (!chooseName) { myNameLabel.setVisible(false); myNameField.setVisible(false); } myNameField.setText(predefinedName); } if (predefinedValue != null && predefinedValue.length() > 0) { myValueLabel.setVisible(false); myValueField.setVisible(false); myValueField.setText(predefinedValue); } final Set<Module> modulesSet = new HashSet<Module>(); modulesSet.add(module); for (AndroidFacet depFacet : AndroidUtils.getAllAndroidDependencies(module, true)) { modulesSet.add(depFacet.getModule()); } assert modulesSet.size() > 0; if (modulesSet.size() == 1) { myModule = module; myModuleLabel.setVisible(false); myModuleCombo.setVisible(false); } else { myModule = null; final Module[] modules = modulesSet.toArray(new Module[modulesSet.size()]); Arrays.sort( modules, new Comparator<Module>() { @Override public int compare(Module m1, Module m2) { return m1.getName().compareTo(m2.getName()); } }); myModuleCombo.setModel(new DefaultComboBoxModel(modules)); myModuleCombo.setSelectedItem(module); myModuleCombo.setRenderer(new ModuleListCellRendererWrapper(myModuleCombo.getRenderer())); } if (defaultFile == null) { final String defaultFileName = AndroidResourceUtil.getDefaultResourceFileName(resourceType); if (defaultFileName != null) { myFileNameCombo.getEditor().setItem(defaultFileName); } } myDirectoriesList = new CheckBoxList(); myDirectoriesLabel.setLabelFor(myDirectoriesList); final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myDirectoriesList); decorator.setEditAction(null); decorator.disableUpDownActions(); decorator.setAddAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { doAddNewDirectory(); } }); decorator.setRemoveAction( new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { doDeleteDirectory(); } }); final AnActionButton selectAll = new AnActionButton("Select All", null, PlatformIcons.SELECT_ALL_ICON) { @Override public void actionPerformed(AnActionEvent e) { doSelectAllDirs(); } }; decorator.addExtraAction(selectAll); final AnActionButton unselectAll = new AnActionButton("Unselect All", null, PlatformIcons.UNSELECT_ALL_ICON) { @Override public void actionPerformed(AnActionEvent e) { doUnselectAllDirs(); } }; decorator.addExtraAction(unselectAll); myDirectoriesPanel.add(decorator.createPanel()); updateDirectories(true); myModuleCombo.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateDirectories(true); } }); final JCheckBox valuesCheckBox = myCheckBoxes.get(SdkConstants.FD_RES_VALUES); if (valuesCheckBox != null) { valuesCheckBox.setSelected(true); } if (defaultFile != null) { resetFromFile(defaultFile, module.getProject()); } init(); }
@NotNull public String getFileName() { return ((String) myFileNameCombo.getEditor().getItem()).trim(); }
private void updateDirectories(boolean updateFileCombo) { final Module module = getModule(); List<VirtualFile> valuesDirs = Collections.emptyList(); if (module != null) { final AndroidFacet facet = AndroidFacet.getInstance(module); if (facet != null) { myResourceDir = AndroidRootUtil.getResourceDir(facet); if (myResourceDir != null) { valuesDirs = AndroidResourceUtil.getResourceSubdirs( ResourceFolderType.VALUES.getName(), new VirtualFile[] {myResourceDir}); } } } Collections.sort( valuesDirs, new Comparator<VirtualFile>() { @Override public int compare(VirtualFile f1, VirtualFile f2) { return f1.getName().compareTo(f2.getName()); } }); final Map<String, JCheckBox> oldCheckBoxes = myCheckBoxes; final int selectedIndex = myDirectoriesList.getSelectedIndex(); final String selectedDirName = selectedIndex >= 0 ? myDirNames[selectedIndex] : null; final List<JCheckBox> checkBoxList = new ArrayList<JCheckBox>(); myCheckBoxes = new HashMap<String, JCheckBox>(); myDirNames = new String[valuesDirs.size()]; int newSelectedIndex = -1; int i = 0; for (VirtualFile dir : valuesDirs) { final String dirName = dir.getName(); final JCheckBox oldCheckBox = oldCheckBoxes.get(dirName); final boolean selected = oldCheckBox != null && oldCheckBox.isSelected(); final JCheckBox checkBox = new JCheckBox(dirName, selected); checkBoxList.add(checkBox); myCheckBoxes.put(dirName, checkBox); myDirNames[i] = dirName; if (dirName.equals(selectedDirName)) { newSelectedIndex = i; } i++; } myDirectoriesList.setModel(new CollectionListModel<JCheckBox>(checkBoxList)); if (newSelectedIndex >= 0) { myDirectoriesList.setSelectedIndex(newSelectedIndex); } if (checkBoxList.size() == 1) { checkBoxList.get(0).setSelected(true); } if (updateFileCombo) { final Object oldItem = myFileNameCombo.getEditor().getItem(); final Set<String> fileNameSet = new HashSet<String>(); for (VirtualFile valuesDir : valuesDirs) { for (VirtualFile file : valuesDir.getChildren()) { fileNameSet.add(file.getName()); } } final List<String> fileNames = new ArrayList<String>(fileNameSet); Collections.sort(fileNames); myFileNameCombo.setModel(new DefaultComboBoxModel(fileNames.toArray())); myFileNameCombo.getEditor().setItem(oldItem); } }
private JTextField getTextField() { return (JTextField) m_comboBox.getEditor().getEditorComponent(); }
protected void dolayout(String strDir, String strFreq, String strTraynum) { // TopBar String strTitle = gettitle(strFreq); Color color = DisplayOptions.getColor("Heading3"); // Center Panel JPanel panelCenter = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints( 0, 0, 1, 1, 0.2, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0); ImageIcon icon = getImageIcon(); // panelCenter.add(new JLabel(icon)); addComp(panelCenter, new JLabel(icon), gbc, 0, 0); strTitle = getSampleName(strDir, strTraynum); m_lblSampleName = new JLabel(strTitle); if (strTitle == null || !strTitle.trim().equals("")) strTitle = "3"; Font font = m_lblSampleName.getFont(); font = DisplayOptions.getFont(font.getName(), Font.BOLD, 300); m_lblSampleName.setFont(font); m_lblSampleName.setForeground(color); // panelCenter.add(m_lblSampleName); m_pnlSampleName = new JPanel(new CardLayout()); m_pnlSampleName.add(m_lblSampleName, OTHER); addComp(panelCenter, m_pnlSampleName, gbc, 1, 0); m_pnlSampleName.setVisible(false); m_pnlTrays = new JPanel(new GridLayout(1, 0)); // Vast panels VBox pnlVast1 = new VBox(m_pnlTrays, "1"); m_pnlTrays.add(pnlVast1); m_pnlVast[0] = pnlVast1; VBox pnlVast2 = new VBox(m_pnlTrays, "2"); m_pnlTrays.add(pnlVast2); m_pnlVast[1] = pnlVast2; VBox pnlVast3 = new VBox(m_pnlTrays, "3"); m_pnlTrays.add(pnlVast3); m_pnlVast[2] = pnlVast3; VBox pnlVast4 = new VBox(m_pnlTrays, "4"); m_pnlTrays.add(pnlVast4); m_pnlVast[3] = pnlVast4; VBox pnlVast5 = new VBox(m_pnlTrays, "5"); m_pnlTrays.add(pnlVast5); m_pnlVast[4] = pnlVast5; m_pnlSampleName.add(m_pnlTrays, VAST); // Login Panel JPanel panelThird = new JPanel(new BorderLayout()); JPanel panelLogin = new JPanel(new GridBagLayout()); gbc = new GridBagConstraints(); panelThird.add(panelLogin); Object[] aStrUser = getOperators(); m_cmbUser = new JComboBox(aStrUser); BasicComboBoxRenderer renderer = new BasicComboBoxRenderer(); m_cmbUser.setRenderer(renderer); m_cmbUser.setEditable(true); m_passwordField = new JPasswordField(); // *Warning, working around a Java problem* // When we went to the T3500 running Redhat 5.3, the JPasswordField // fields sometimes does not allow ANY entry of characters. Setting // the enableInputMethods() to true fixed this problem. There are // comments that indicate that this could cause the typed characters // to be visible. I have not found that to be a problem. // This may not be required in the future, or could cause characters // to become visible in the future if Java changes it's code. // GRS 8/20/09 m_passwordField.enableInputMethods(true); m_lblLogin = new VLoginLabel(null, "Incorrect username/password \n Please try again ", 0, 0); m_lblLogin.setVisible(false); okButton.setActionCommand("enter"); okButton.addActionListener(this); cancelButton.setActionCommand("cancel"); cancelButton.addActionListener(this); helpButton.setActionCommand("help"); helpButton.addActionListener(this); m_passwordField.addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) enterLogin(); } }); // These is some wierd problem such that sometimes, the vnmrj command // area gets the focus and these items in the login box do not get // the focus. Even clicking in these items does not bring focus to // them. Issuing requestFocus() does not bring focus to them. // I can however, determing if either the operator entry box or // the password box has focus and if neither does, I can unshow and // reshow the panel and that fixes the focus. So, I have added this // to the mouseClicked action. If neither has focus, it will // take focus with setVisible false then true. comboTextField = m_cmbUser.getEditor().getEditorComponent(); m_passwordField.addMouseListener(this); comboTextField.addMouseListener(this); m_lblUsername = new JLabel(Util.getLabel("_Operator")); addComp(panelLogin, m_lblUsername, gbc, 0, 0); addComp(panelLogin, m_cmbUser, gbc, 1, 0); m_lblPassword = new JLabel(Util.getLabel("_Password")); addComp(panelLogin, m_lblPassword, gbc, 0, 1); addComp(panelLogin, m_passwordField, gbc, 1, 1); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridheight = GridBagConstraints.REMAINDER; addComp(panelLogin, m_lblLogin, gbc, 2, 0); setPref(); Container container = getContentPane(); JPanel panelLoginBox = new JPanel(new BorderLayout()); panelLoginBox.add(panelCenter, BorderLayout.CENTER); panelLoginBox.add(panelThird, BorderLayout.SOUTH); container.add(panelLoginBox, BorderLayout.CENTER); }
public MemComboAgent(JComboBox comboBox) { m_comboBox = comboBox; m_editor = (JTextField) comboBox.getEditor().getEditorComponent(); m_editor.addKeyListener(this); }