Line.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Created by Daniel Nadeau
  3. * daniel.nadeau01@gmail.com
  4. * danielnadeau.blogspot.com
  5. *
  6. * Licensed to the Apache Software Foundation (ASF) under one
  7. or more contributor license agreements. See the NOTICE file
  8. distributed with this work for additional information
  9. regarding copyright ownership. The ASF licenses this file
  10. to you under the Apache License, Version 2.0 (the
  11. "License"); you may not use this file except in compliance
  12. with the License. You may obtain a copy of the License at
  13. http://www.apache.org/licenses/LICENSE-2.0
  14. Unless required by applicable law or agreed to in writing,
  15. software distributed under the License is distributed on an
  16. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. KIND, either express or implied. See the License for the
  18. specific language governing permissions and limitations
  19. under the License.
  20. */
  21. package com.echo.holographlibrary;
  22. import java.util.ArrayList;
  23. public class Line {
  24. private ArrayList<LinePoint> points = new ArrayList<LinePoint>();
  25. private int color;
  26. private boolean showPoints = true;
  27. // 6 has been the default prior to the addition of custom stroke widths
  28. private int strokeWidth = 6;
  29. // since this is a new addition, it has to default to false to be backwards compatible
  30. private boolean isUsingDips = false;
  31. public boolean isUsingDips() {
  32. return isUsingDips;
  33. }
  34. public void setUsingDips(boolean treatSizesAsDips) {
  35. this.isUsingDips = treatSizesAsDips;
  36. }
  37. public int getStrokeWidth() {
  38. return strokeWidth;
  39. }
  40. public void setStrokeWidth(int strokeWidth) {
  41. if (strokeWidth < 0) {
  42. throw new IllegalArgumentException("strokeWidth must not be less than zero");
  43. }
  44. this.strokeWidth = strokeWidth;
  45. }
  46. public int getColor() {
  47. return color;
  48. }
  49. public void setColor(int color) {
  50. this.color = color;
  51. }
  52. public ArrayList<LinePoint> getPoints() {
  53. return points;
  54. }
  55. public void setPoints(ArrayList<LinePoint> points) {
  56. this.points = points;
  57. }
  58. public void addPoint(LinePoint point){
  59. LinePoint p;
  60. for(int i = 0; i < points.size(); i++){
  61. p = points.get(i);
  62. if(point.getX() < p.getX()){
  63. points.add(i, point);
  64. return;
  65. }
  66. }
  67. points.add(point);
  68. }
  69. public void removePoint(LinePoint point){
  70. points.remove(point);
  71. }
  72. public LinePoint getPoint(int index){
  73. return points.get(index);
  74. }
  75. public LinePoint getPoint(float x, float y){
  76. LinePoint p;
  77. for(int i = 0; i < points.size(); i++){
  78. p = points.get(i);
  79. if(p.getX() == x && p.getY() == y)
  80. return p;
  81. }
  82. return null;
  83. }
  84. public int getSize(){
  85. return points.size();
  86. }
  87. public boolean isShowingPoints() {
  88. return showPoints;
  89. }
  90. public void setShowingPoints(boolean showPoints) {
  91. this.showPoints = showPoints;
  92. }
  93. }