Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
ExpandingNode.java
1 
16 package net.squiz.matrix.matrixtree;
17 
18 import net.squiz.matrix.core.*;
19 
20 public class ExpandingNode extends MatrixTreeNode {
21 
22  private int parentTotalAssets,currentAssetsCount,viewedAssetsCount = 0;
23  private int clicks = 0;
24  private int names = 4;
25  private int initStrWidth = 0;
26  private int firstNameLength = 0;
27  private String cueModeName = "";
28 
29  public ExpandingNode() {
30  super(null, "", 1, "", "", "", 0);
31  }
32 
33  public void setParentTotalAssets(int parentTotalAssets) {
34  this.parentTotalAssets = parentTotalAssets;
35  }
36 
37  public void setCurrentAssetsCount(int currentAssetsCount) {
38  this.currentAssetsCount = currentAssetsCount;
39  }
40 
41  public void setViewedAssetsCount(int viewedAssetsCount) {
42  this.viewedAssetsCount = viewedAssetsCount;
43  }
44 
45  public int getParentTotalAssets() {
46  return parentTotalAssets;
47  }
48 
49  public int getCurrentAssetsCount() {
50  return currentAssetsCount;
51  }
52 
53  public int getViewedAssetsCount() {
54  return viewedAssetsCount;
55  }
56 
57 
58  public int getCurrentLoc() {
59  int currentLoc = 0;
60  currentLoc = viewedAssetsCount;
61 
62  return currentLoc;
63  }
64 
65  public int getInitStrWidth() {
66  return initStrWidth;
67  }
68 
69  public void setInitStrWidth(int width) {
70  if (width > initStrWidth) {
71  initStrWidth = width;
72  }
73  }
74 
75  private void setfirstNameLength(int length) {
76  firstNameLength = length;
77  }
78 
79  private int getFirstNameLength() {
80  return firstNameLength;
81  }
82 
83  public void setClicks(int clicks) {
84  this.clicks = clicks;
85  }
86 
87  public int getClicks() {
88  return clicks;
89  }
90 
91  public String getName() {
92  int to = getCurrentLoc()+AssetManager.getLimit();
93  if ((to > getParentTotalAssets()) && getParentTotalAssets() > 0) {
94  to = getParentTotalAssets();
95  }
96  int total = 0;
97  if (getParentTotalAssets() > 0) {
98  total = getParentTotalAssets();
99  }
100 
101  if (getClicks() == 0 || names < getClicks()) {
102  setClicks(1);
103  }
104 
105  String name = "";
106  if (getClicks() == 1) {
107  String totalStr = "N/A";
108  String fromStr = ""+(getCurrentLoc()+1);
109  String toStr = ""+to;
110  if (total > 0) {
111  totalStr = ""+total;
112  }
113 
114  Object[] transArgs = {
115  fromStr,
116  toStr,
117  totalStr
118  };
119 
120  name = Matrix.translate("asset_map_expanding_node_one",transArgs);
121  setfirstNameLength(name.length());
122  } if (getClicks() == 2) {
123  String fromStr = ""+((int)((getCurrentLoc()+1)/AssetManager.getLimit())+1);
124  String toStr = "N/A";
125  if (total > 0) {
126  toStr = ""+((int)(total/AssetManager.getLimit())+1);
127  }
128  Object[] transArgs = {
129  fromStr,
130  toStr,
131  };
132  name = Matrix.translate("asset_map_expanding_node_two",transArgs);
133  } else if (getClicks() == 3) {
134  String totalStr = "N/A";
135  if (total > 0) {
136  totalStr = ""+total;
137  }
138  Object[] transArgs = {
139  totalStr
140  };
141  name = Matrix.translate("asset_map_expanding_node_three",transArgs);
142  } else if (getClicks() == 4) {
143  int remaining = (total-getCurrentLoc()-AssetManager.getLimit());
144  String remainingStr = "0";
145  if (remaining > 0) {
146  remainingStr = ""+remaining;
147  }
148  Object[] transArgs = {
149  remainingStr
150  };
151  name = Matrix.translate("asset_map_expanding_node_four",transArgs);
152  }
153  if (getFirstNameLength() > name.length()) {
154  int diff = getFirstNameLength() - name.length();
155  for (int i=0; i< diff+4;i++) {
156  name += " ";
157  }
158  }
159 
160  return name;
161  }
162 
163 
164  public void setCueModeName(String name) {
165  cueModeName = name;
166  }
167 
168  public String getCueModeName() {
169  return cueModeName;
170  }
171 
172  public String getAssetName() {
173  return ((ExpandingAsset)getUserObject()).getName();
174  }
175 
176  public boolean usingCueModeName() {
177  return getAssetName().equals(getCueModeName());
178  }
179 
180  public void useCueModeName() {
181  setName(getCueModeName());
182  }
183 
184  public void setName(String name) {
185  ((ExpandingAsset)getUserObject()).setName(name);
186  }
187 
188  public void switchName() {
189  setClicks(0);
190  setName(getName());
191  }
192 
193  public void switchName(int evtX, double boundsX) {
194  int res = evtX - (int)boundsX;
195  if (res > 35) {
196  setClicks(getClicks()+1);
197  setName(getName());
198  }
199  }
200 
201  public class ExpandingAsset extends Asset {
202 
203  String name;
204  public ExpandingAsset(String assetName) {
205  super("0");
206  name = assetName;
207  }
208 
209  public String getName() {
210  return name;
211  }
212 
213  public void setName(String name) {
214  this.name = name;
215  }
216  }
217 }