Segment.java revision a0bccbddc52575255c5ce19c9d2c96d9639d26ca
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
17package com.android.ide.common.api;
18
19/**
20 * A segment is a straight horizontal or vertical line between two points, typically an
21 * edge of a node but also possibly some internal segment like a baseline or a center
22 * line, and it can be offset by a margin from the node's visible bounds.
23 */
24public class Segment {
25    /** For horizontal lines, the y coordinate; for vertical lines the x */
26    public final int at;
27
28    /** The starting coordinate along the line */
29    public final int from;
30
31    /** The ending coordinate along the line */
32    public final int to;
33
34    /** Whether the edge is a top edge, a baseline edge, a left edge, etc */
35    public final SegmentType edgeType;
36
37    /**
38     * Whether the edge is offset from the node by a margin or not, or whether it has no
39     * margin
40     */
41    public final MarginType marginType;
42
43    /** The node that contains this edge */
44    public final INode node;
45
46    /**
47     * The id of the node. May be null (in which case id should be generated when
48     * move/resize is completed
49     */
50    public final String id;
51
52    public Segment(int at, int from, int to, INode node, String id, SegmentType edgeType,
53            MarginType marginType) {
54        this.at = at;
55        this.from = from;
56        this.to = to;
57        this.node = node;
58        this.id = id;
59        this.edgeType = edgeType;
60        this.marginType = marginType;
61    }
62
63    @Override
64    public String toString() {
65        String nodeStr = node == null ? "null" : node.getFqcn().substring(
66                node.getFqcn().lastIndexOf(('.')) + 1);
67        return "Segment [edgeType=" + edgeType + ", node=" + nodeStr + ", at=" + at + ", id=" + id
68                + ", from=" + from + ", to=" + to + ", marginType=" + marginType + "]";
69    }
70}
71