All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.intellij.cvsSupport2.ui.ChangeKeywordSubstitutionPanel Maven / Gradle / Ivy

Go to download

A packaging of the IntelliJ Community Edition cvs-plugin library. This is release number 1 of trunk branch 142.

The newest version!
/*
 * Copyright 2000-2011 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.cvsSupport2.ui;

import com.intellij.CvsBundle;
import com.intellij.cvsSupport2.keywordSubstitution.KeywordSubstitutionWrapper;
import org.netbeans.lib.cvsclient.command.KeywordSubstitution;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * author: lesya
 */
public class ChangeKeywordSubstitutionPanel {

  private final JComboBox myKeywordSubstitutionComboBox;
  private final JCheckBox myChangeCheckbox;
  private final JPanel myPanel;

  public ChangeKeywordSubstitutionPanel(KeywordSubstitution defaultSubstitution) {
    myPanel = new JPanel(new GridBagLayout());
    myChangeCheckbox = new JCheckBox(CvsBundle.message("checkbox.change.keyword.substitution.to"));
    myKeywordSubstitutionComboBox = new JComboBox();
    KeywordSubstitutionWrapper.fillComboBox(myKeywordSubstitutionComboBox, defaultSubstitution);

    myChangeCheckbox.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        setEnabling();
      }
    });

    final GridBagConstraints constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.BASELINE_LEADING;
    myPanel.add(myChangeCheckbox, constraints);
    constraints.gridx = 1;
    constraints.weightx = 1.0;
    myPanel.add(myKeywordSubstitutionComboBox, constraints);
    setEnabling();
  }

  private void setEnabling() {
    myKeywordSubstitutionComboBox.setEnabled(myChangeCheckbox.isSelected());
    if (myKeywordSubstitutionComboBox.getSelectedIndex() == -1){
      myKeywordSubstitutionComboBox.setSelectedIndex(0);
    }
  }

  public JComponent getComponent() {
    return myPanel;
  }

  public KeywordSubstitution getKeywordSubstitution() {
    if (!myChangeCheckbox.isSelected()) {
      return null;
    }
    return ((KeywordSubstitutionWrapper)myKeywordSubstitutionComboBox.getSelectedItem()).getSubstitution();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy