@Override
 protected void doOKAction() {
   apply((SeverityBasedTextAttributes) myOptionsList.getSelectedValue());
   final Collection<SeverityBasedTextAttributes> infoTypes =
       new HashSet<SeverityBasedTextAttributes>(
           SeverityUtil.getRegisteredHighlightingInfoTypes(mySeverityRegistrar));
   final ListModel listModel = myOptionsList.getModel();
   final List<HighlightSeverity> order = new ArrayList<HighlightSeverity>();
   for (int i = listModel.getSize() - 1; i >= 0; i--) {
     final SeverityBasedTextAttributes info =
         (SeverityBasedTextAttributes) listModel.getElementAt(i);
     order.add(info.getSeverity());
     if (!mySeverityRegistrar.isDefaultSeverity(info.getSeverity())) {
       infoTypes.remove(info);
       final Color stripeColor = info.getAttributes().getErrorStripeColor();
       mySeverityRegistrar.registerSeverity(
           info, stripeColor != null ? stripeColor : LightColors.YELLOW);
     }
   }
   for (SeverityBasedTextAttributes info : infoTypes) {
     mySeverityRegistrar.unregisterSeverity(info.getSeverity());
   }
   mySeverityRegistrar.setOrder(order);
   super.doOKAction();
 }
Example #2
0
  /**
   * Returns an array of the values for the selected cells. The returned values are sorted in
   * increasing index order.
   *
   * @return the selected values or an empty list if nothing is selected
   * @see #isSelectedIndex
   * @see #getModel
   * @see #addListSelectionListener
   */
  public Object[] getCheckBoxListSelectedValues() {
    CheckBoxListSelectionModel listSelectionModel = getCheckBoxListSelectionModel();
    ListModel model = getModel();

    int iMin = listSelectionModel.getMinSelectionIndex();
    int iMax = listSelectionModel.getMaxSelectionIndex();

    if ((iMin < 0) || (iMax < 0)) {
      return new Object[0];
    }

    Object[] temp = new Object[1 + (iMax - iMin)];
    int n = 0;
    for (int i = iMin; i <= iMax; i++) {
      if (listSelectionModel.isAllEntryConsidered() && i == listSelectionModel.getAllEntryIndex()) {
        continue;
      }
      if (listSelectionModel.isSelectedIndex(i)) {
        temp[n] = model.getElementAt(i);
        n++;
      }
    }
    Object[] indices = new Object[n];
    System.arraycopy(temp, 0, indices, 0, n);
    return indices;
  }
Example #3
0
 void profileList_mouseClicked(MouseEvent e) {
   JList theList = (JList) e.getSource();
   ListModel aModel = theList.getModel();
   int index = theList.locationToIndex(e.getPoint());
   if (index < 0) return;
   UniProfile aProfile = (UniProfile) aModel.getElementAt(index);
   nameTextField.setText(aProfile.toString());
 }
 public static String print(ListModel model) {
   StringBuilder result = new StringBuilder();
   for (int i = 0; i < model.getSize(); i++) {
     result.append(toString(model.getElementAt(i), null));
     result.append("\n");
   }
   return result.toString();
 }
  private void updateListHeight(ListModel model) {
    myList.setFixedCellHeight(
        myCellRenderer
            .getListCellRendererComponent(myList, model.getElementAt(0), 0, false, false)
            .getPreferredSize()
            .height);

    myList.setVisibleRowCount(
        Math.min(model.getSize(), UISettings.getInstance().MAX_LOOKUP_LIST_HEIGHT));
  }
  public boolean fillInCommonPrefix(boolean explicitlyInvoked) {
    if (explicitlyInvoked) {
      setFocusDegree(FocusDegree.FOCUSED);
    }

    if (explicitlyInvoked && myCalculating) return false;
    if (!explicitlyInvoked && mySelectionTouched) return false;

    ListModel listModel = getListModel();
    if (listModel.getSize() <= 1) return false;

    if (listModel.getSize() == 0) return false;

    final LookupElement firstItem = (LookupElement) listModel.getElementAt(0);
    if (listModel.getSize() == 1 && firstItem instanceof EmptyLookupItem) return false;

    final PrefixMatcher firstItemMatcher = itemMatcher(firstItem);
    final String oldPrefix = firstItemMatcher.getPrefix();
    final String presentPrefix = oldPrefix + getAdditionalPrefix();
    String commonPrefix = getCaseCorrectedLookupString(firstItem);

    for (int i = 1; i < listModel.getSize(); i++) {
      LookupElement item = (LookupElement) listModel.getElementAt(i);
      if (item instanceof EmptyLookupItem) return false;
      if (!oldPrefix.equals(itemMatcher(item).getPrefix())) return false;

      final String lookupString = getCaseCorrectedLookupString(item);
      final int length = Math.min(commonPrefix.length(), lookupString.length());
      if (length < commonPrefix.length()) {
        commonPrefix = commonPrefix.substring(0, length);
      }

      for (int j = 0; j < length; j++) {
        if (commonPrefix.charAt(j) != lookupString.charAt(j)) {
          commonPrefix = lookupString.substring(0, j);
          break;
        }
      }

      if (commonPrefix.length() == 0 || commonPrefix.length() < presentPrefix.length()) {
        return false;
      }
    }

    if (commonPrefix.equals(presentPrefix)) {
      return false;
    }

    for (int i = 0; i < listModel.getSize(); i++) {
      LookupElement item = (LookupElement) listModel.getElementAt(i);
      if (!itemMatcher(item).cloneWithPrefix(commonPrefix).prefixMatches(item)) {
        return false;
      }
    }

    myOffsets.setInitialPrefix(presentPrefix, explicitlyInvoked);

    replacePrefix(presentPrefix, commonPrefix);
    return true;
  }
Example #7
0
 private void showFailureDetail(Test test) {
   if (test != null) {
     ListModel failures = getFailures();
     for (int i = 0; i < failures.getSize(); i++) {
       TestFailure failure = (TestFailure) failures.getElementAt(i);
       if (failure.failedTest() == test) {
         fFailureView.showFailure(failure);
         return;
       }
     }
   }
   fFailureView.clear();
 }
Example #8
0
 /**
  * Deselects the specified object from the list.
  *
  * @param anObject the object to select
  * @param shouldScroll true if the list should scroll to display the selected object, if one
  *     exists; otherwise false
  */
 public void removeCheckBoxListSelectedValue(Object anObject, boolean shouldScroll) {
   if (anObject != null) {
     int i, c;
     ListModel model = getModel();
     for (i = 0, c = model.getSize(); i < c; i++)
       if (anObject.equals(model.getElementAt(i))) {
         removeCheckBoxListSelectedIndex(i);
         if (shouldScroll) ensureIndexIsVisible(i);
         repaint();
         /** FIX-ME setSelectedIndex does not redraw all the time with the basic l&f* */
         return;
       }
   }
 }
Example #9
0
 /** Initialize the CheckBoxList. */
 protected void init() {
   _checkBoxListSelectionModel = createCheckBoxListSelectionModel(getModel());
   setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
   _listCellRenderer = createCellRenderer();
   _handler = createHandler();
   _checkBoxListSelectionModel.addListSelectionListener(_handler);
   JideSwingUtilities.insertMouseListener(this, _handler, 0);
   addKeyListener(_handler);
   addPropertyChangeListener("model", _handler);
   ListModel model = getModel();
   if (model != null) {
     model.addListDataListener(_handler);
   }
 }
Example #10
0
 @TestOnly
 public boolean setSelectedTemplate(String group, String name) {
   ListModel model = myProjectTypeList.getModel();
   for (int i = 0; i < model.getSize(); i++) {
     TemplatesGroup templatesGroup = (TemplatesGroup) model.getElementAt(i);
     if (group.equals(templatesGroup.getName())) {
       myProjectTypeList.setSelectedIndex(i);
       if (name == null) return getSelectedGroup().getName().equals(group);
       Collection<ProjectTemplate> templates = myTemplatesMap.get(templatesGroup);
       setTemplatesList(templatesGroup, templates, false);
       return myTemplatesList.setSelectedTemplate(name);
     }
   }
   return false;
 }
Example #11
0
    private void update() {
      if (filter == null || filter.length() == 0) {
        super.setModel(originalModel);
      }

      DefaultListModel v = new DefaultListModel();
      for (int i = 0; i < originalModel.getSize(); i++) {
        Object o = originalModel.getElementAt(i);
        String s = String.valueOf(o).toLowerCase();
        if (s.contains(filter)) {
          v.addElement(o);
        }
      }
      super.setModel(v);
      if (v.getSize() == 1) {
        setSelectedIndex(0);
      }
      revalidate();
    }
Example #12
0
 /**
  * Deselects the specified objects from the list and keep all previous selections.
  *
  * @param objects the objects to be selected
  */
 public void removeCheckBoxListSelectedValues(Object[] objects) {
   if (objects != null) {
     Map<Object, String> map = new HashMap<Object, String>();
     for (Object o : objects) {
       map.put(o, "");
     }
     int i, c;
     ListModel model = getModel();
     boolean changed = false;
     for (i = 0, c = model.getSize(); i < c; i++)
       if (map.get(model.getElementAt(i)) != null) {
         removeCheckBoxListSelectedIndex(i);
         changed = true;
       }
     if (changed) {
       repaint();
     }
     map.clear();
   }
 }
Example #13
0
 private void fillListModel(SortedListModel1 model, ListModel newValues) {
   int size = newValues.getSize();
   for (int i = 0; i < size; i++) {
     model.add(newValues.getElementAt(i));
   }
 }
Example #14
0
 private void defaultNonOverriddenConfigurations() {
   ListModel model = herolabsCharacterList.getModel();
   for (int i = 0; i < model.getSize(); i++) {
     config.populateCharacterWithDefaults(((Character) model.getElementAt(i)).getName(), false);
   }
 }
  public ToolBarEditDialog(
      Component comp, DefaultComboBoxModel iconListModel, ToolBarOptionPane.Button current) {
    super(
        GUIUtilities.getParentDialog(comp), jEdit.getProperty("options.toolbar.edit.title"), true);

    JPanel content = new JPanel(new BorderLayout());
    content.setBorder(new EmptyBorder(12, 12, 12, 12));
    setContentPane(content);

    ActionHandler actionHandler = new ActionHandler();
    ButtonGroup grp = new ButtonGroup();

    JPanel typePanel = new JPanel(new GridLayout(3, 1, 6, 6));
    typePanel.setBorder(new EmptyBorder(0, 0, 6, 0));
    typePanel.add(new JLabel(jEdit.getProperty("options.toolbar.edit.caption")));

    separator = new JRadioButton(jEdit.getProperty("options.toolbar" + ".edit.separator"));
    separator.addActionListener(actionHandler);
    grp.add(separator);
    typePanel.add(separator);

    action = new JRadioButton(jEdit.getProperty("options.toolbar" + ".edit.action"));
    action.addActionListener(actionHandler);
    grp.add(action);
    typePanel.add(action);

    content.add(BorderLayout.NORTH, typePanel);

    JPanel actionPanel = new JPanel(new BorderLayout(6, 6));

    ActionSet[] actionsList = jEdit.getActionSets();
    Vector vec = new Vector(actionsList.length);
    for (int i = 0; i < actionsList.length; i++) {
      ActionSet actionSet = actionsList[i];
      if (actionSet.getActionCount() != 0) vec.addElement(actionSet);
    }
    combo = new JComboBox(vec);
    combo.addActionListener(actionHandler);
    actionPanel.add(BorderLayout.NORTH, combo);

    list = new JList();
    list.setVisibleRowCount(8);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    actionPanel.add(BorderLayout.CENTER, new JScrollPane(list));

    JPanel iconPanel = new JPanel(new BorderLayout(0, 3));
    JPanel labelPanel = new JPanel(new GridLayout(2, 1));
    labelPanel.setBorder(new EmptyBorder(0, 0, 0, 12));
    JPanel compPanel = new JPanel(new GridLayout(2, 1));
    grp = new ButtonGroup();
    labelPanel.add(builtin = new JRadioButton(jEdit.getProperty("options.toolbar.edit.builtin")));
    builtin.addActionListener(actionHandler);
    grp.add(builtin);
    labelPanel.add(file = new JRadioButton(jEdit.getProperty("options.toolbar.edit.file")));
    grp.add(file);
    file.addActionListener(actionHandler);
    iconPanel.add(BorderLayout.WEST, labelPanel);
    builtinCombo = new JComboBox(iconListModel);
    builtinCombo.setRenderer(new ToolBarOptionPane.IconCellRenderer());
    compPanel.add(builtinCombo);

    fileButton = new JButton(jEdit.getProperty("options.toolbar.edit.no-icon"));
    fileButton.setMargin(new Insets(1, 1, 1, 1));
    fileButton.setIcon(GUIUtilities.loadIcon("Blank24.gif"));
    fileButton.setHorizontalAlignment(SwingConstants.LEFT);
    fileButton.addActionListener(actionHandler);
    compPanel.add(fileButton);
    iconPanel.add(BorderLayout.CENTER, compPanel);
    actionPanel.add(BorderLayout.SOUTH, iconPanel);

    content.add(BorderLayout.CENTER, actionPanel);

    JPanel southPanel = new JPanel();
    southPanel.setLayout(new BoxLayout(southPanel, BoxLayout.X_AXIS));
    southPanel.setBorder(new EmptyBorder(12, 0, 0, 0));
    southPanel.add(Box.createGlue());
    ok = new JButton(jEdit.getProperty("common.ok"));
    ok.addActionListener(actionHandler);
    getRootPane().setDefaultButton(ok);
    southPanel.add(ok);
    southPanel.add(Box.createHorizontalStrut(6));
    cancel = new JButton(jEdit.getProperty("common.cancel"));
    cancel.addActionListener(actionHandler);
    southPanel.add(cancel);
    southPanel.add(Box.createGlue());

    content.add(BorderLayout.SOUTH, southPanel);

    if (current == null) {
      action.setSelected(true);
      builtin.setSelected(true);
      updateList();
    } else {
      if (current.actionName.equals("-")) {
        separator.setSelected(true);
        builtin.setSelected(true);
      } else {
        action.setSelected(true);
        ActionSet set = jEdit.getActionSetForAction(current.actionName);
        combo.setSelectedItem(set);
        updateList();
        list.setSelectedValue(current, true);

        if (MiscUtilities.isURL(current.iconName)) {
          file.setSelected(true);
          fileIcon = current.iconName;
          try {
            fileButton.setIcon(new ImageIcon(new URL(fileIcon)));
          } catch (MalformedURLException mf) {
            Log.log(Log.ERROR, this, mf);
          }
          fileButton.setText(MiscUtilities.getFileName(fileIcon));
        } else {
          String iconName = MiscUtilities.getFileName(current.iconName);
          builtin.setSelected(true);
          ListModel model = builtinCombo.getModel();
          for (int i = 0; i < model.getSize(); i++) {
            ToolBarOptionPane.IconListEntry entry =
                (ToolBarOptionPane.IconListEntry) model.getElementAt(i);
            if (entry.name.equals(iconName)) {
              builtinCombo.setSelectedIndex(i);
              break;
            }
          }
        }
      }
    }

    updateEnabled();

    pack();
    setLocationRelativeTo(GUIUtilities.getParentDialog(comp));
    show();
  }