• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.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
7  *
8  *      http://www.eclipse.org/org/documents/epl-v10.php
9  *
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.
15  */
16 
17 package com.android.ide.common.api;
18 
19 import com.android.annotations.NonNull;
20 import com.android.annotations.Nullable;
21 import com.google.common.annotations.Beta;
22 
23 /**
24  * A segment is a straight horizontal or vertical line between two points, typically an
25  * edge of a node but also possibly some internal segment like a baseline or a center
26  * line, and it can be offset by a margin from the node's visible bounds.
27  * <p>
28  * <b>NOTE: This is not a public or final API; if you rely on this be prepared
29  * to adjust your code for the next tools release.</b>
30  */
31 @Beta
32 public class Segment {
33     /** For horizontal lines, the y coordinate; for vertical lines the x */
34     public final int at;
35 
36     /** The starting coordinate along the line */
37     public final int from;
38 
39     /** The ending coordinate along the line */
40     public final int to;
41 
42     /** Whether the edge is a top edge, a baseline edge, a left edge, etc */
43     @NonNull
44     public final SegmentType edgeType;
45 
46     /**
47      * Whether the edge is offset from the node by a margin or not, or whether it has no
48      * margin
49      */
50     @NonNull
51     public final MarginType marginType;
52 
53     /** The node that contains this edge */
54     @NonNull
55     public final INode node;
56 
57     /**
58      * The id of the node. May be null (in which case id should be generated when
59      * move/resize is completed
60      */
61     @Nullable
62     public final String id;
63 
Segment(int at, int from, int to, @NonNull INode node, @Nullable String id, @NonNull SegmentType edgeType, @NonNull MarginType marginType)64     public Segment(int at, int from, int to, @NonNull INode node, @Nullable String id,
65             @NonNull SegmentType edgeType, @NonNull MarginType marginType) {
66         this.at = at;
67         this.from = from;
68         this.to = to;
69         this.node = node;
70         this.id = id;
71         this.edgeType = edgeType;
72         this.marginType = marginType;
73     }
74 
75     @NonNull
76     @Override
toString()77     public String toString() {
78         String nodeStr = node == null ? "null" : node.getFqcn().substring(
79                 node.getFqcn().lastIndexOf(('.')) + 1);
80         return "Segment [edgeType=" + edgeType + ", node=" + nodeStr + ", at=" + at + ", id=" + id
81                 + ", from=" + from + ", to=" + to + ", marginType=" + marginType + "]";
82     }
83 }
84