1 19 20 21 package org.netbeans.core.windows.model; 22 23 24 import java.util.ArrayList ; 25 import org.netbeans.core.windows.Constants; 26 import org.netbeans.core.windows.ModeStructureSnapshot; 27 import org.netbeans.core.windows.SplitConstraint; 28 29 30 37 final class EditorSplitSubModel extends SplitSubModel { 38 39 41 private final EditorNode editorNode; 42 43 44 public EditorSplitSubModel(Model parentModel, SplitSubModel editorArea) { 45 super(parentModel); 46 47 this.editorNode = new EditorNode(editorArea); 48 49 addNodeToTree(editorNode, new SplitConstraint[0]); 51 } 52 53 54 55 protected boolean removeNodeFromTree(Node node) { 56 if(node == editorNode) { 57 return false; 59 } 60 61 return super.removeNodeFromTree(node); 62 } 63 64 public boolean setEditorNodeConstraints(SplitConstraint[] editorNodeConstraints) { 65 super.removeNodeFromTree(editorNode); 66 return addNodeToTree(editorNode, editorNodeConstraints); 67 } 68 69 public SplitConstraint[] getEditorNodeConstraints() { 70 return editorNode.getNodeConstraints(); 71 } 72 73 public SplitSubModel getEditorArea() { 74 return editorNode.getEditorArea(); 75 } 76 77 public boolean setSplitWeights( ModelElement[] snapshots, double[] splitWeights) { 78 if( super.setSplitWeights( snapshots, splitWeights ) ) { 79 return true; 80 } 81 82 return getEditorArea().setSplitWeights( snapshots, splitWeights ); 83 } 84 85 86 87 static class EditorNode extends SplitSubModel.Node { 88 89 private final SplitSubModel editorArea; 90 91 92 public EditorNode(SplitSubModel editorArea) { 93 this.editorArea = editorArea; 94 } 95 96 public boolean isVisibleInSplit() { 97 return true; 98 } 99 100 public SplitSubModel getEditorArea() { 101 return editorArea; 102 } 103 104 public double getResizeWeight() { 105 return 1D; 106 } 107 108 public ModeStructureSnapshot.ElementSnapshot createSnapshot() { 109 return new ModeStructureSnapshot.EditorSnapshot(this, null, 110 editorArea.createSplitSnapshot(), getResizeWeight()); 111 } 112 } 114 115 protected boolean addNodeToTreeAroundEditor(Node addingNode, String side) { 117 Node attachNode = editorNode; 119 if(attachNode == root) { 120 int addingIndex = (side == Constants.TOP || side == Constants.LEFT) ? 0 : -1; 121 int oldIndex = addingIndex == 0 ? -1 : 0; 122 int orientation = (side == Constants.TOP || side == Constants.BOTTOM) ? Constants.VERTICAL : Constants.HORIZONTAL; 124 SplitNode newSplit = new SplitNode(orientation); 125 newSplit.setChildAt(addingIndex, Constants.DROP_TO_SIDE_RATIO, addingNode); 126 newSplit.setChildAt(oldIndex, 1D - Constants.DROP_TO_SIDE_RATIO, attachNode); 127 root = newSplit; 128 } else { 129 SplitNode parent = attachNode.getParent(); 130 if(parent == null) { 131 return false; 132 } 133 134 int attachIndex = parent.getChildIndex(attachNode); 135 double attachWeight = parent.getChildSplitWeight(attachNode); 136 int orientation = (side == Constants.TOP || side == Constants.BOTTOM) ? Constants.VERTICAL : Constants.HORIZONTAL; 138 SplitNode newSplit = new SplitNode(orientation); 139 parent.removeChild(attachNode); 140 int addingIndex = (side == Constants.TOP || side == Constants.LEFT) ? 0 : -1; 141 int oldIndex = addingIndex == 0 ? -1 : 0; 142 newSplit.setChildAt(addingIndex, Constants.DROP_AROUND_RATIO, addingNode); 143 newSplit.setChildAt(oldIndex, 1D - Constants.DROP_AROUND_RATIO, attachNode); 144 parent.setChildAt(attachIndex, attachWeight, newSplit); 145 } 146 147 return true; 148 } 149 150 } 151 152 | Popular Tags |