IDEA-51739
[fedora-idea.git] / platform / platform-impl / src / com / intellij / openapi / editor / impl / FoldRegionImpl.java
blob3162ec67a730fb061ba729e452f2cbac8d03c5e0
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.
18 * Created by IntelliJ IDEA.
19 * User: max
20 * Date: Apr 22, 2002
21 * Time: 5:51:22 PM
22 * To change template for new class use
23 * Code Style | Class Templates options (Tools | IDE Options).
25 package com.intellij.openapi.editor.impl;
27 import com.intellij.openapi.editor.Editor;
28 import com.intellij.openapi.editor.FoldRegion;
29 import com.intellij.openapi.editor.FoldingGroup;
30 import com.intellij.openapi.editor.ex.DocumentEx;
31 import org.jetbrains.annotations.NotNull;
32 import org.jetbrains.annotations.Nullable;
34 public class FoldRegionImpl extends RangeMarkerImpl implements FoldRegion {
35 private boolean myIsExpanded;
36 private final Editor myEditor;
37 private final String myPlaceholderText;
38 private final FoldingGroup myGroup;
40 public FoldRegionImpl(Editor editor, int startOffset, int endOffset, String placeholder, FoldingGroup group) {
41 super((DocumentEx)editor.getDocument(), startOffset, endOffset);
42 myGroup = group;
43 myIsExpanded = true;
44 myEditor = editor;
45 myPlaceholderText = placeholder;
48 public boolean isExpanded() {
49 return myIsExpanded;
52 public void setExpanded(boolean expanded) {
53 FoldingModelImpl foldingModel = (FoldingModelImpl)myEditor.getFoldingModel();
54 if (myGroup == null) {
55 doSetExpanded(expanded, foldingModel, this);
56 } else {
57 for (final FoldRegion region : foldingModel.getGroupedRegions(myGroup)) {
58 doSetExpanded(expanded, foldingModel, region);
63 private static void doSetExpanded(boolean expanded, FoldingModelImpl foldingModel, FoldRegion region) {
64 if (expanded) {
65 foldingModel.expandFoldRegion(region);
67 else{
68 foldingModel.collapseFoldRegion(region);
72 public boolean isValid() {
73 return super.isValid() && getStartOffset() + 1 < getEndOffset();
76 public void setExpandedInternal(boolean toExpand) {
77 myIsExpanded = toExpand;
80 @NotNull
81 public String getPlaceholderText() {
82 return myPlaceholderText;
85 public Editor getEditor() {
86 return myEditor;
89 @Nullable
90 public FoldingGroup getGroup() {
91 return myGroup;
94 @SuppressWarnings({"HardCodedStringLiteral"})
95 public String toString() {
96 return "FoldRegion (" + getStartOffset() + ":" + getEndOffset() + ")";