Exemplo n.º 1
0
  public CustomizerSources(J2SEProjectProperties uiProperties) {
    this.uiProperties = uiProperties;
    initComponents();
    jScrollPane1.getViewport().setBackground(sourceRoots.getBackground());
    jScrollPane2.getViewport().setBackground(testRoots.getBackground());

    sourceRoots.setModel(uiProperties.SOURCE_ROOTS_MODEL);
    testRoots.setModel(uiProperties.TEST_ROOTS_MODEL);
    sourceRoots.getTableHeader().setReorderingAllowed(false);
    testRoots.getTableHeader().setReorderingAllowed(false);

    FileObject projectFolder = uiProperties.getProject().getProjectDirectory();
    File pf = FileUtil.toFile(projectFolder);
    this.projectLocation.setText(pf == null ? "" : pf.getPath()); // NOI18N

    SourceRootsUi.EditMediator emSR =
        SourceRootsUi.registerEditMediator(
            uiProperties.getProject(),
            uiProperties.getProject().getSourceRoots(),
            sourceRoots,
            addSourceRoot,
            removeSourceRoot,
            upSourceRoot,
            downSourceRoot,
            new LabelCellEditor(sourceRoots, testRoots),
            true);

    SourceRootsUi.EditMediator emTSR =
        SourceRootsUi.registerEditMediator(
            uiProperties.getProject(),
            uiProperties.getProject().getTestSourceRoots(),
            testRoots,
            addTestRoot,
            removeTestRoot,
            upTestRoot,
            downTestRoot,
            new LabelCellEditor(sourceRoots, testRoots),
            true);

    emSR.setRelatedEditMediator(emTSR);
    emTSR.setRelatedEditMediator(emSR);
    this.sourceLevel.setEditable(false);
    this.sourceLevel.setModel(uiProperties.JAVAC_SOURCE_MODEL);
    this.sourceLevel.setRenderer(uiProperties.JAVAC_SOURCE_RENDERER);
    uiProperties.JAVAC_SOURCE_MODEL.addListDataListener(
        new ListDataListener() {
          public void intervalAdded(ListDataEvent e) {
            enableSourceLevel();
          }

          public void intervalRemoved(ListDataEvent e) {
            enableSourceLevel();
          }

          public void contentsChanged(ListDataEvent e) {
            enableSourceLevel();
          }
        });
    enableSourceLevel();
    this.originalEncoding =
        this.uiProperties
            .getProject()
            .evaluator()
            .getProperty(J2SEProjectProperties.SOURCE_ENCODING);
    if (this.originalEncoding == null) {
      this.originalEncoding = Charset.defaultCharset().name();
    }

    this.encoding.setModel(ProjectCustomizer.encodingModel(originalEncoding));
    this.encoding.setRenderer(ProjectCustomizer.encodingRenderer());
    final String lafid = UIManager.getLookAndFeel().getID();
    if (!"Aqua".equals(lafid)) { // NOI18N
      this.encoding.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); // NOI18N
      this.encoding.addItemListener(
          new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent e) {
              javax.swing.JComboBox combo = (javax.swing.JComboBox) e.getSource();
              combo.setPopupVisible(false);
            }
          });
    }
    this.encoding.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            handleEncodingChange();
          }
        });
    initTableVisualProperties(sourceRoots);
    initTableVisualProperties(testRoots);
    uiProperties.addOptionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            CellEditor cellEditor = sourceRoots.getCellEditor();
            if (cellEditor != null) {
              cellEditor.stopCellEditing();
            }
            cellEditor = testRoots.getCellEditor();
            if (cellEditor != null) {
              cellEditor.stopCellEditing();
            }
          }
        });
  }
Exemplo n.º 2
0
  public CustomizerRun(J2SEProjectProperties uiProperties) {
    this.uiProperties = uiProperties;
    initComponents();

    this.project = uiProperties.getProject();

    nextExtensionYPos = 0;
    // BEGIN Deprecated
    compProviderDeprecated = Lookup.getDefault().lookup(J2SERunConfigProvider.class);
    initExtPanel(project);
    // END Deprecated

    for (J2SECategoryExtensionProvider compProvider :
        project.getLookup().lookupAll(J2SECategoryExtensionProvider.class)) {
      if (compProvider.getCategory() == J2SECategoryExtensionProvider.ExtensibleCategory.RUN) {
        if (addExtPanel(project, compProvider, nextExtensionYPos)) {
          compProviders.add(compProvider);
          nextExtensionYPos++;
        }
      }
    }
    addPanelFiller(nextExtensionYPos);

    configs = uiProperties.RUN_CONFIGS;

    data =
        new JTextField[] {
          jTextFieldMainClass, jTextFieldArgs, jTextVMOptions, jTextWorkingDirectory,
        };
    dataLabels =
        new JLabel[] {
          jLabelMainClass, jLabelArgs, jLabelVMOptions, jLabelWorkingDirectory,
        };
    keys =
        new String[] {
          ProjectProperties.MAIN_CLASS,
          ProjectProperties.APPLICATION_ARGS,
          ProjectProperties.RUN_JVM_ARGS,
          ProjectProperties.RUN_WORK_DIR,
        };
    assert data.length == keys.length;

    configChanged(uiProperties.activeConfig);

    configCombo.setRenderer(new ConfigListCellRenderer());

    for (int i = 0; i < data.length; i++) {
      final JTextField field = data[i];
      final String prop = keys[i];
      final JLabel label = dataLabels[i];
      field
          .getDocument()
          .addDocumentListener(
              new DocumentListener() {
                Font basefont = label.getFont();
                Font boldfont = basefont.deriveFont(Font.BOLD);

                {
                  updateFont();
                }

                public void insertUpdate(DocumentEvent e) {
                  changed();
                }

                public void removeUpdate(DocumentEvent e) {
                  changed();
                }

                public void changedUpdate(DocumentEvent e) {}

                void changed() {
                  String config = (String) configCombo.getSelectedItem();
                  if (config.length() == 0) {
                    config = null;
                  }
                  String v = field.getText();
                  if (v != null && config != null && v.equals(configs.get(null).get(prop))) {
                    // default value, do not store as such
                    v = null;
                  }
                  configs.get(config).put(prop, v);
                  updateFont();
                }

                void updateFont() {
                  String v = field.getText();
                  String config = (String) configCombo.getSelectedItem();
                  if (config.length() == 0) {
                    config = null;
                  }
                  String def = configs.get(null).get(prop);
                  label.setFont(
                      config != null
                              && !Utilities.compareObjects(
                                  v != null ? v : "", def != null ? def : "")
                          ? boldfont
                          : basefont);
                }
              });
    }

    jButtonMainClass.addActionListener(
        new MainClassListener(project.getSourceRoots(), jTextFieldMainClass));
  }