2 * Copyright 2000-2012 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.
16 package com.intellij.application.options.codeStyle.arrangement.match;
18 import com.intellij.application.options.codeStyle.arrangement.ArrangementConstants;
19 import com.intellij.application.options.codeStyle.arrangement.ArrangementNodeDisplayManager;
20 import com.intellij.application.options.codeStyle.arrangement.color.ArrangementColorsProvider;
21 import com.intellij.application.options.codeStyle.arrangement.util.TitleWithToolbar;
22 import com.intellij.ide.ui.customization.CustomizationUtil;
23 import com.intellij.openapi.actionSystem.DataProvider;
24 import com.intellij.openapi.application.ApplicationBundle;
25 import com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule;
26 import com.intellij.psi.codeStyle.arrangement.settings.ArrangementStandardSettingsAware;
27 import com.intellij.ui.components.JBScrollPane;
28 import com.intellij.util.ui.GridBag;
29 import org.jetbrains.annotations.NonNls;
30 import org.jetbrains.annotations.NotNull;
31 import org.jetbrains.annotations.Nullable;
35 import java.util.List;
38 * @author Denis Zhdanov
39 * @since 10/30/12 5:28 PM
41 public class ArrangementMatchingRulesPanel extends JPanel implements DataProvider {
43 @NotNull private final ArrangementMatchingRulesControl myControl;
45 public ArrangementMatchingRulesPanel(@NotNull ArrangementNodeDisplayManager displayManager,
46 @NotNull ArrangementColorsProvider colorsProvider,
47 @NotNull ArrangementStandardSettingsAware settingsFilter)
49 super(new GridBagLayout());
51 JBScrollPane scrollPane = new JBScrollPane();
52 final JViewport viewport = scrollPane.getViewport();
53 ArrangementMatchingRulesControl.RepresentationCallback callback = new ArrangementMatchingRulesControl.RepresentationCallback() {
55 public void ensureVisible(@NotNull Rectangle r) {
56 Rectangle visibleRect = viewport.getViewRect();
57 if (r.y <= visibleRect.y) {
61 int excessiveHeight = r.y + r.height - (visibleRect.y + visibleRect.height);
62 if (excessiveHeight <= 0) {
66 int verticalShift = Math.min(r.y - visibleRect.y, excessiveHeight);
67 if (verticalShift > 0) {
68 viewport.setViewPosition(new Point(visibleRect.x, visibleRect.y + verticalShift));
72 myControl = new ArrangementMatchingRulesControl(displayManager, colorsProvider, settingsFilter, callback);
73 scrollPane.setViewportView(myControl);
74 CustomizationUtil.installPopupHandler(
75 myControl, ArrangementConstants.ACTION_GROUP_MATCHING_RULES_CONTEXT_MENU, ArrangementConstants.RULE_EDITOR_PLACE
78 TitleWithToolbar top = new TitleWithToolbar(
79 ApplicationBundle.message("arrangement.settings.section.match"),
80 ArrangementConstants.ACTION_GROUP_MATCHING_RULES_CONTROL_TOOLBAR,
81 ArrangementConstants.MATCHING_RULES_CONTROL_TOOLBAR_PLACE,
84 add(top, new GridBag().coverLine().fillCellHorizontally().weightx(1));
85 add(scrollPane, new GridBag().fillCell().weightx(1).weighty(1));
89 public List<StdArrangementMatchRule> getRules() {
90 return myControl.getRules();
93 public void setRules(@Nullable List<StdArrangementMatchRule> rules) {
94 myControl.setRules(rules);
99 public Object getData(@NonNls String dataId) {
100 if (ArrangementConstants.MATCHING_RULES_CONTROL_KEY.is(dataId)) {