copyright: update default copyright
[fedora-idea.git] / plugins / copyright / src / com / maddyhome / idea / copyright / ui / CopyrightConfigurable.java
blob337fca6c8b85c256024232b642dc4c5423348eef
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.maddyhome.idea.copyright.ui;
19 import com.intellij.openapi.options.ConfigurationException;
20 import com.intellij.openapi.project.Project;
21 import com.intellij.openapi.ui.Messages;
22 import com.intellij.openapi.ui.NamedConfigurable;
23 import com.intellij.openapi.util.Comparing;
24 import com.maddyhome.idea.copyright.CopyrightManager;
25 import com.maddyhome.idea.copyright.CopyrightProfile;
26 import com.maddyhome.idea.copyright.pattern.EntityUtil;
27 import com.maddyhome.idea.copyright.pattern.VelocityHelper;
28 import org.jetbrains.annotations.Nls;
29 import org.jetbrains.annotations.NonNls;
30 import org.jetbrains.annotations.Nullable;
32 import javax.swing.*;
33 import java.awt.event.ActionEvent;
34 import java.awt.event.ActionListener;
36 public class CopyrightConfigurable extends NamedConfigurable<CopyrightProfile> {
37 private final CopyrightProfile myCopyrightProfile;
38 private JPanel myWholePanel;
40 private final Project myProject;
41 private boolean myModified;
43 private String myDisplayName;
44 private JEditorPane myCopyrightPane;
45 private JButton myValidateButton;
46 private JTextField myKeywordTf;
47 private JTextField myAllowReplaceTextField;
49 public CopyrightConfigurable(Project project, CopyrightProfile copyrightProfile, Runnable updater) {
50 super(true, updater);
51 myProject = project;
52 myCopyrightProfile = copyrightProfile;
53 myDisplayName = myCopyrightProfile.getName();
56 public void setDisplayName(String s) {
57 myCopyrightProfile.setName(s);
60 public CopyrightProfile getEditableObject() {
61 return myCopyrightProfile;
64 public String getBannerSlogan() {
65 return myCopyrightProfile.getName();
68 public JComponent createOptionsPanel() {
69 myValidateButton.addActionListener(new ActionListener() {
70 public void actionPerformed(ActionEvent e) {
71 try {
72 VelocityHelper.verify(myCopyrightPane.getText());
73 Messages.showInfoMessage(myProject, "Velocity template valid.", "Validation");
75 catch (Exception e1) {
76 Messages.showInfoMessage(myProject, "Velocity template error:\n" + e1.getMessage(), "Validation");
79 });
80 return myWholePanel;
83 @Nls
84 public String getDisplayName() {
85 return myCopyrightProfile.getName();
88 @Nullable
89 public Icon getIcon() {
90 return null;
93 @Nullable
94 @NonNls
95 public String getHelpTopic() {
96 return null;
99 public boolean isModified() {
100 return myModified ||
101 !Comparing.strEqual(EntityUtil.encode(myCopyrightPane.getText().trim()), myCopyrightProfile.getNotice()) ||
102 !Comparing.strEqual(myKeywordTf.getText().trim(), myCopyrightProfile.getKeyword()) ||
103 !Comparing.strEqual(myAllowReplaceTextField.getText().trim(), myCopyrightProfile.getAllowReplaceKeyword()) ||
104 !Comparing.strEqual(myDisplayName, myCopyrightProfile.getName());
107 public void apply() throws ConfigurationException {
108 myCopyrightProfile.setNotice(EntityUtil.encode(myCopyrightPane.getText().trim()));
109 myCopyrightProfile.setKeyword(myKeywordTf.getText());
110 myCopyrightProfile.setAllowReplaceKeyword(myAllowReplaceTextField.getText());
111 CopyrightManager.getInstance(myProject).replaceCopyright(myDisplayName, myCopyrightProfile);
112 myDisplayName = myCopyrightProfile.getName();
113 myModified = false;
116 public void reset() {
117 myDisplayName = myCopyrightProfile.getName();
118 myCopyrightPane.setText(EntityUtil.decode(myCopyrightProfile.getNotice()));
119 myKeywordTf.setText(myCopyrightProfile.getKeyword());
120 myAllowReplaceTextField.setText(myCopyrightProfile.getAllowReplaceKeyword());
123 public void disposeUIResources() {
126 public void setModified(boolean modified) {
127 myModified = modified;