private void createNewConfiguration() {
   if (!saveSelectedConfiguration()) return;
   myList.setSelectedValue(null, false);
   CvsRootConfiguration newConfig =
       CvsApplicationLevelConfiguration.createNewConfiguration(
           CvsApplicationLevelConfiguration.getInstance());
   myModel.addElement(newConfig);
   myList.setSelectedValue(newConfig, true);
 }
Ejemplo n.º 2
0
 private void fillList(final HighlightSeverity severity) {
   DefaultListModel model = new DefaultListModel();
   model.removeAllElements();
   final List<SeverityBasedTextAttributes> infoTypes =
       new ArrayList<SeverityBasedTextAttributes>();
   infoTypes.addAll(SeverityUtil.getRegisteredHighlightingInfoTypes(mySeverityRegistrar));
   Collections.sort(
       infoTypes,
       new Comparator<SeverityBasedTextAttributes>() {
         @Override
         public int compare(
             SeverityBasedTextAttributes attributes1, SeverityBasedTextAttributes attributes2) {
           return -mySeverityRegistrar.compare(
               attributes1.getSeverity(), attributes2.getSeverity());
         }
       });
   SeverityBasedTextAttributes preselection = null;
   for (SeverityBasedTextAttributes type : infoTypes) {
     model.addElement(type);
     if (type.getSeverity().equals(severity)) {
       preselection = type;
     }
   }
   myOptionsList.setModel(model);
   myOptionsList.setSelectedValue(preselection, true);
 }
  private void addCreatedSdk(@Nullable final Sdk sdk, boolean newVirtualEnv) {
    if (sdk != null) {
      final PySdkService sdkService = PySdkService.getInstance();
      sdkService.restoreSdk(sdk);

      boolean isVirtualEnv = PythonSdkType.isVirtualEnv(sdk);
      if (isVirtualEnv && !newVirtualEnv) {
        AddVEnvOptionsDialog dialog = new AddVEnvOptionsDialog(myMainPanel);
        dialog.show();
        if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
          return;
        }
        SdkModificator modificator = myModificators.get(sdk);
        setSdkAssociated(modificator, !dialog.makeAvailableToAll());
        myModifiedModificators.add(modificator);
      }
      final Sdk oldSdk = myProjectSdksModel.findSdk(sdk);
      if (oldSdk == null) {
        myProjectSdksModel.addSdk(sdk);
      }
      refreshSdkList();
      mySdkList.setSelectedValue(myProjectSdksModel.findSdk(sdk.getName()), true);
      mySdkListChanged = true;
    }
  }
 /** Update the match list based on the model. */
 private void updateList() {
   @SuppressWarnings("unchecked")
   T[] matchingItems =
       (T[])
           IterUtil.toArray(_pim.getMatchingItems(), Comparable.class); // T erases to Comparable!
   _matchList.setListData(matchingItems);
   _matchList.setSelectedValue(_pim.getCurrentItem(), true);
   updateExtensionLabel();
   updateInfo();
   if (_force) {
     for (int i = 0; i < _buttons.length - 1; ++i) {
       _buttons[i].setEnabled(_matchList.getModel().getSize() > 0);
     }
   }
 }
Ejemplo n.º 5
0
    public void updateClientList() {
      Iterator i = clients.iterator();
      DefaultListModel model = new DefaultListModel();

      EditorClient placebo =
          new EditorClient(self, 0, "                                            ", 0, 0, "");
      model.addElement(placebo);

      while (i.hasNext()) {
        EditorClient c = (EditorClient) i.next();
        model.addElement(c);
      }

      lstClients.setModel(model);
      lstClients.setSelectedValue(currClient, true);
    }
Ejemplo n.º 6
0
  @NotNull
  public static <T extends PsiElement> JBPopup getPsiElementPopup(
      @NotNull T[] elements,
      @NotNull final PsiElementListCellRenderer<T> renderer,
      @Nullable final String title,
      @NotNull final PsiElementProcessor<T> processor,
      @Nullable final T selection) {
    final JList list =
        new JBListWithHintProvider(elements) {
          @Nullable
          @Override
          protected PsiElement getPsiElementForHint(Object selectedValue) {
            return (PsiElement) selectedValue;
          }
        };
    list.setCellRenderer(renderer);

    list.setFont(EditorUtil.getEditorFont());

    if (selection != null) {
      list.setSelectedValue(selection, true);
    }

    final Runnable runnable =
        () -> {
          int[] ids = list.getSelectedIndices();
          if (ids == null || ids.length == 0) return;
          for (Object element : list.getSelectedValues()) {
            if (element != null) {
              processor.execute((T) element);
            }
          }
        };

    PopupChooserBuilder builder = new PopupChooserBuilder(list);
    if (title != null) {
      builder.setTitle(title);
    }
    renderer.installSpeedSearch(builder, true);

    JBPopup popup = builder.setItemChoosenCallback(runnable).createPopup();

    builder.getScrollPane().setBorder(null);
    builder.getScrollPane().setViewportBorder(null);

    return popup;
  }
  private void refreshSdkList() {
    final List<Sdk> pythonSdks = myInterpreterList.getAllPythonSdks(myProject);
    Sdk projectSdk = getSdk();
    if (!myShowOtherProjectVirtualenvs) {
      VirtualEnvProjectFilter.removeNotMatching(myProject, pythonSdks);
    }
    //noinspection unchecked
    mySdkList.setModel(new CollectionListModel<Sdk>(pythonSdks));

    mySdkListChanged = false;
    if (projectSdk != null) {
      projectSdk = myProjectSdksModel.findSdk(projectSdk.getName());
      mySdkList.clearSelection();
      mySdkList.setSelectedValue(projectSdk, true);
      mySdkList.updateUI();
    }
  }
  public EtatPanelDist(
      Hashtable uneHashtable, BoiteChangementEtatSommetDist parent, String defaultValue) {
    ardoise = new EtatArdoiseDist(uneHashtable, parent);
    Vector listeItems = new Vector();
    JList liste = new JList();
    JScrollPane listeAvecAscenseur;
    listeItems.addElement("A");
    listeItems.addElement("B");
    listeItems.addElement("C");
    listeItems.addElement("D");
    listeItems.addElement("E");
    listeItems.addElement("F");
    listeItems.addElement("G");
    listeItems.addElement("H");
    listeItems.addElement("I");
    listeItems.addElement("J");
    listeItems.addElement("K");
    listeItems.addElement("L");
    listeItems.addElement("M");
    listeItems.addElement("N");
    listeItems.addElement("O");
    listeItems.addElement("P");
    listeItems.addElement("Q");
    listeItems.addElement("R");
    listeItems.addElement("S");
    listeItems.addElement("T");
    listeItems.addElement("U");
    listeItems.addElement("V");
    listeItems.addElement("W");
    listeItems.addElement("X");
    listeItems.addElement("Y");
    listeItems.addElement("Z");

    liste = new JList(listeItems);
    liste.setSelectedValue(defaultValue, true);
    ardoise.changerEtat((String) liste.getSelectedValue());
    liste.addListSelectionListener(this);
    setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
    add(ardoise);
    listeAvecAscenseur = new JScrollPane(liste);
    listeAvecAscenseur.setPreferredSize(new Dimension(200, 80));
    add(listeAvecAscenseur);
    setVisible(true);
  }
Ejemplo n.º 9
0
  /**
   * Returns the message to display from the JOptionPane the receiver is providing the look and feel
   * for.
   */
  protected Object getMessage() {
    inputComponent = null;
    if (optionPane != null) {
      if (optionPane.getWantsInput()) {
        /* Create a user component to capture the input. If the
        selectionValues are non null the component and there
        are < 20 values it'll be a combobox, if non null and
        >= 20, it'll be a list, otherwise it'll be a textfield. */
        Object message = optionPane.getMessage();
        Object[] sValues = optionPane.getSelectionValues();
        Object inputValue = optionPane.getInitialSelectionValue();
        JComponent toAdd;

        if (sValues != null) {
          if (sValues.length < 20) {
            JComboBox cBox = new JComboBox();

            cBox.setName("OptionPane.comboBox");
            for (int counter = 0, maxCounter = sValues.length; counter < maxCounter; counter++) {
              cBox.addItem(sValues[counter]);
            }
            if (inputValue != null) {
              cBox.setSelectedItem(inputValue);
            }
            inputComponent = cBox;
            toAdd = cBox;

          } else {
            JList list = new JList(sValues);
            JScrollPane sp = new JScrollPane(list);

            sp.setName("OptionPane.scrollPane");
            list.setName("OptionPane.list");
            list.setVisibleRowCount(10);
            list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            if (inputValue != null) list.setSelectedValue(inputValue, true);
            list.addMouseListener(getHandler());
            toAdd = sp;
            inputComponent = list;
          }

        } else {
          MultiplexingTextField tf = new MultiplexingTextField(20);

          tf.setName("OptionPane.textField");
          tf.setKeyStrokes(new KeyStroke[] {KeyStroke.getKeyStroke("ENTER")});
          if (inputValue != null) {
            String inputString = inputValue.toString();
            tf.setText(inputString);
            tf.setSelectionStart(0);
            tf.setSelectionEnd(inputString.length());
          }
          tf.addActionListener(getHandler());
          toAdd = inputComponent = tf;
        }

        Object[] newMessage;

        if (message == null) {
          newMessage = new Object[1];
          newMessage[0] = toAdd;

        } else {
          newMessage = new Object[2];
          newMessage[0] = message;
          newMessage[1] = toAdd;
        }
        return newMessage;
      }
      return optionPane.getMessage();
    }
    return null;
  }
Ejemplo n.º 10
0
  private void init(Font font) {
    JPanel content = new JPanel(new BorderLayout());
    content.setBorder(new EmptyBorder(12, 12, 12, 12));
    setContentPane(content);

    JPanel listPanel = new JPanel(new GridLayout(1, 3, 6, 6));

    String[] fonts;
    try {
      fonts = getFontList();
    } catch (Exception e) {
      Log.log(Log.ERROR, this, "Broken Java implementation!");

      Log.log(Log.ERROR, this, e);

      fonts = new String[] {"Broken Java implementation!"};
    }

    JPanel familyPanel =
        createTextFieldAndListPanel(
            "font-selector.family", familyField = new JTextField(), familyList = new JList(fonts));
    listPanel.add(familyPanel);

    String[] sizes = {"9", "10", "12", "14", "16", "18", "24"};
    JPanel sizePanel =
        createTextFieldAndListPanel(
            "font-selector.size", sizeField = new JTextField(), sizeList = new JList(sizes));
    listPanel.add(sizePanel);

    String[] styles = {
      jEdit.getProperty("font-selector.plain"),
      jEdit.getProperty("font-selector.bold"),
      jEdit.getProperty("font-selector.italic"),
      jEdit.getProperty("font-selector.bolditalic")
    };

    JPanel stylePanel =
        createTextFieldAndListPanel(
            "font-selector.style", styleField = new JTextField(), styleList = new JList(styles));
    styleField.setEditable(false);
    listPanel.add(stylePanel);

    familyList.setSelectedValue(font.getFamily(), true);
    familyField.setText(font.getFamily());
    sizeList.setSelectedValue(String.valueOf(font.getSize()), true);
    sizeField.setText(String.valueOf(font.getSize()));
    styleList.setSelectedIndex(font.getStyle());
    styleField.setText((String) styleList.getSelectedValue());

    ListHandler listHandler = new ListHandler();
    familyList.addListSelectionListener(listHandler);
    sizeList.addListSelectionListener(listHandler);
    styleList.addListSelectionListener(listHandler);

    content.add(BorderLayout.NORTH, listPanel);

    preview =
        new JLabel(jEdit.getProperty("font-selector.long-text")) {
          public void paintComponent(Graphics g) {
            if (fontSelector != null) fontSelector.setAntiAliasEnabled(g);
            super.paintComponent(g);
          }
        };
    preview.setBorder(new TitledBorder(jEdit.getProperty("font-selector.preview")));

    updatePreview();

    Dimension prefSize = preview.getPreferredSize();
    prefSize.height = 50;
    preview.setPreferredSize(prefSize);

    content.add(BorderLayout.CENTER, preview);

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
    buttons.setBorder(new EmptyBorder(12, 0, 0, 0));
    buttons.add(Box.createGlue());

    ok = new JButton(jEdit.getProperty("common.ok"));
    ok.addActionListener(new ActionHandler());
    getRootPane().setDefaultButton(ok);
    buttons.add(ok);

    buttons.add(Box.createHorizontalStrut(6));

    cancel = new JButton(jEdit.getProperty("common.cancel"));
    cancel.addActionListener(new ActionHandler());
    buttons.add(cancel);

    buttons.add(Box.createGlue());

    content.add(BorderLayout.SOUTH, buttons);

    pack();
    setLocationRelativeTo(getParent());
    setVisible(true);
  }
Ejemplo n.º 11
0
 /**
  * Selects the given <tt>ConfigurationForm</tt>.
  *
  * @param configForm the <tt>ConfigurationForm</tt> to select
  */
 public void setSelected(ConfigurationForm configForm) {
   configList.setSelectedValue(configForm, true);
 }
 public void selectConfiguration(CvsRootConfiguration selectedConfiguration) {
   myList.setSelectedValue(selectedConfiguration, true);
 }
 private void copySelectedConfiguration() {
   if (!saveSelectedConfiguration()) return;
   CvsRootConfiguration newConfig = mySelection.getMyCopy();
   myModel.addElement(newConfig);
   myList.setSelectedValue(newConfig, true);
 }
  private void showCompletionPopup(
      final CompletionResult result, int position, boolean isExplicit) {
    if (myList == null) {
      myList = new JBList();
      myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

      myList.setCellRenderer(
          new GroupedItemsListRenderer(
              new ListItemDescriptor() {
                public String getTextFor(final Object value) {
                  final LookupFile file = (LookupFile) value;

                  if (file.getMacro() != null) {
                    return file.getMacro();
                  } else {
                    return (myCurrentCompletion != null
                                && myCurrentCompletion.myKidsAfterSeparator.contains(file)
                            ? myFinder.getSeparator()
                            : "")
                        + file.getName();
                  }
                }

                public String getTooltipFor(final Object value) {
                  return null;
                }

                public Icon getIconFor(final Object value) {
                  final LookupFile file = (LookupFile) value;
                  return file.getIcon();
                }

                @Nullable
                private Separator getSeparatorAboveOf(Object value) {
                  if (myCurrentCompletion == null) return null;
                  final LookupFile file = (LookupFile) value;

                  final int fileIndex = myCurrentCompletion.myToComplete.indexOf(file);
                  if (fileIndex > 0 && !myCurrentCompletion.myMacros.contains(file)) {
                    final LookupFile prev = myCurrentCompletion.myToComplete.get(fileIndex - 1);
                    if (myCurrentCompletion.myMacros.contains(prev)) {
                      return new Separator("");
                    }
                  }

                  if (myCurrentCompletion.myKidsAfterSeparator.indexOf(file) == 0
                      && myCurrentCompletion.mySiblings.size() > 0) {
                    final LookupFile parent = file.getParent();
                    return parent == null ? new Separator("") : new Separator(parent.getName());
                  }

                  if (myCurrentCompletion.myMacros.size() > 0 && fileIndex == 0) {
                    return new Separator(
                        IdeBundle.message("file.chooser.completion.path.variables.text"));
                  }

                  return null;
                }

                public boolean hasSeparatorAboveOf(final Object value) {
                  return getSeparatorAboveOf(value) != null;
                }

                public String getCaptionAboveOf(final Object value) {
                  final FileTextFieldImpl.Separator separator = getSeparatorAboveOf(value);
                  return separator != null ? separator.getText() : null;
                }
              }));
    }

    if (myCurrentPopup != null) {
      closePopup();
    }

    myCurrentCompletion = result;
    myCurrentCompletionsPos = position;

    if (myCurrentCompletion.myToComplete.size() == 0) {
      showNoSuggestions(isExplicit);
      return;
    }

    myList.setModel(
        new AbstractListModel() {
          public int getSize() {
            return myCurrentCompletion.myToComplete.size();
          }

          public Object getElementAt(final int index) {
            return myCurrentCompletion.myToComplete.get(index);
          }
        });
    myList.getSelectionModel().clearSelection();
    final PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(myList);
    builder.addListener(
        new JBPopupListener() {
          public void beforeShown(LightweightWindowEvent event) {
            myPathTextField.registerKeyboardAction(
                myCancelAction,
                KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
                JComponent.WHEN_IN_FOCUSED_WINDOW);
            for (Action each : myDisabledTextActions) {
              each.setEnabled(false);
            }
          }

          public void onClosed(LightweightWindowEvent event) {
            myPathTextField.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));
            for (Action each : myDisabledTextActions) {
              each.setEnabled(true);
            }
          }
        });

    myCurrentPopup =
        builder
            .setRequestFocus(false)
            .setAdText(getAdText(myCurrentCompletion))
            .setAutoSelectIfEmpty(false)
            .setResizable(false)
            .setCancelCallback(
                new Computable<Boolean>() {
                  public Boolean compute() {
                    final int caret = myPathTextField.getCaretPosition();
                    myPathTextField.setSelectionStart(caret);
                    myPathTextField.setSelectionEnd(caret);
                    myPathTextField.setFocusTraversalKeysEnabled(true);
                    SwingUtilities.invokeLater(
                        new Runnable() {
                          public void run() {
                            getField().requestFocus();
                          }
                        });
                    return Boolean.TRUE;
                  }
                })
            .setItemChoosenCallback(
                new Runnable() {
                  public void run() {
                    processChosenFromCompletion(false);
                  }
                })
            .setCancelKeyEnabled(false)
            .setAlpha(0.1f)
            .setFocusOwners(new Component[] {myPathTextField})
            .createPopup();

    if (result.myPreselected != null) {
      myList.setSelectedValue(result.myPreselected, false);
    }

    myPathTextField.setFocusTraversalKeysEnabled(false);

    myCurrentPopup.showInScreenCoordinates(getField(), getLocationForCaret(myPathTextField));
  }
Ejemplo n.º 15
0
  private void process() {
    int width = Integer.parseInt(xres.getText());
    int height = Integer.parseInt(yres.getText());
    boolean preserveAspect = aspect.isSelected();
    Color bg = new Color(red.getValue(), green.getValue(), blue.getValue());

    String outDir = output.getText();
    String suffix = ((String) format.getSelectedItem()).toLowerCase();
    String preText = prepend.getText();
    String appText = append.getText();

    int scaleType = -1;
    String alg = (String) algorithm.getSelectedItem();
    if (alg.equals("Smooth")) scaleType = Image.SCALE_SMOOTH;
    else if (alg.equals("Standard")) scaleType = Image.SCALE_DEFAULT;
    else if (alg.equals("Fast")) scaleType = Image.SCALE_FAST;
    else if (alg.equals("Replicate")) scaleType = Image.SCALE_REPLICATE;
    else if (alg.equals("Area averaging")) {
      scaleType = Image.SCALE_AREA_AVERAGING;
    }

    DefaultListModel model = (DefaultListModel) list.getModel();
    int size = model.size();
    progress.setValue(0);
    progress.setMaximum(4 * size);

    for (int i = 0; i < size; i++) {
      ThumbFile tf = (ThumbFile) model.elementAt(i);
      list.setSelectedValue(tf, true);
      String tail = " (" + (i + 1) + " of " + size + ")";

      progress.setValue(4 * i);
      progress.setString("Reading" + tail);

      // construct input and output filenames
      String inFile = tf.getPath();
      String outFile = outDir + SLASH + tf.getName();
      int ndx = outFile.lastIndexOf(SLASH);
      String s1 = outFile.substring(0, ndx + SLASH.length());
      String s2 = outFile.substring(ndx + SLASH.length());
      int dot_ndx = s2.lastIndexOf(".");
      if (dot_ndx >= 0) s2 = s2.substring(0, dot_ndx);

      // make the thumbnail file name
      outFile = s1 + preText + s2 + appText + "." + suffix;

      // read in the file to an image
      BufferedImage image = null;
      try {
        image = ImageIO.read(new File(inFile));
      } catch (IOException exc) {
        exc.printStackTrace();
      }

      progress.setValue(4 * i + 1);
      progress.setString("Resizing" + tail);

      // resize image
      int w, h;
      if (preserveAspect) {
        int ow = image.getWidth();
        int oh = image.getHeight();
        double oasp = (double) ow / oh;
        double tasp = (double) width / height;
        if (oasp > tasp) {
          w = width;
          h = (int) (w / oasp);
        } else {
          h = height;
          w = (int) (oasp * h);
        }
      } else {
        w = width;
        h = height;
      }
      Image resized = image.getScaledInstance(w, h, scaleType);

      progress.setValue(4 * i + 2);
      progress.setString("Painting" + tail);

      // create thumbnail
      BufferedImage thumb = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
      Graphics2D g2d = thumb.createGraphics();
      g2d.setColor(bg);
      g2d.fillRect(0, 0, width, height);
      g2d.drawImage(resized, (width - w) / 2, (height - h) / 2, this);
      g2d.dispose();

      progress.setValue(4 * i + 3);
      progress.setString("Writing" + tail);

      // save thumbnail to disk
      File out = new File(outFile);
      File parent = out.getParentFile();
      if (parent != null && !parent.exists()) parent.mkdirs();
      try {
        ImageIO.write(thumb, suffix, out);
      } catch (IOException exc) {
        exc.printStackTrace();
      }
    }

    list.setSelectedIndices(new int[0]);
    progress.setValue(4 * size);
    progress.setString("Complete");
  }