Changeset 1509 for trunk/src/org/expeditee/items/Item.java
- Timestamp:
- 02/05/20 15:20:37 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/Item.java
r1505 r1509 49 49 import org.expeditee.core.bounds.PolygonBounds; 50 50 import org.expeditee.encryption.core.EncryptedImage; 51 import org.expeditee.encryption.io.EncryptedExpWriter; 51 52 import org.expeditee.encryption.items.KeyType; 53 import org.expeditee.encryption.items.UserAppliedEncryptionPermission; 52 54 import org.expeditee.encryption.items.surrogates.EncryptionDetail; 53 55 import org.expeditee.encryption.items.surrogates.EncryptionDetail.Type; … … 4097 4099 } 4098 4100 } 4099 4101 4100 4102 public void setEncryptionLabel(String label) { 4101 this.getSurrogates().clear(); 4102 this._encryptionLabel = label; 4103 4103 if (label == null) { 4104 _encryptionLabel = null; 4105 return; 4106 } 4107 4104 4108 if (this.getParent().getFrameEncryptionLabel() == null) { 4105 4109 MessageBay.displayMessage("Items can only be entrypted if the frame they are on is."); 4106 4110 return; 4107 4111 } 4112 4108 4113 LabelInfo labelResult = Label.getLabel(label); 4109 4114 if (!labelResult.is(LabelResult.SuccessResolveLabelToKey)) { 4110 4115 MessageBay.displayMessage(labelResult.toString()); 4111 this._encryptionLabel = null;4112 4116 return; 4113 4117 } 4114 4118 4119 String errorMessage = "You do not have sufficient permissions to set the encryption label to " + label; 4120 UserAppliedEncryptionPermission p = getParent().getEncryptionPermission().getPermission(getParent().getOwner(), getParent().getGroupMembers()); 4121 String homogeneousEncryptionLabel = getParent().getHomogeneousEncryptionLabel(); 4122 if (homogeneousEncryptionLabel == null) { homogeneousEncryptionLabel = getParent().getFrameEncryptionLabel(); } 4123 if (homogeneousEncryptionLabel == null) { homogeneousEncryptionLabel = EncryptedExpWriter.getLabelNone(); } 4124 List<String> hetrogeneousFrameOwnerLabels = getParent().getHetrogeneousFrameOwnerLabels(); 4125 4126 switch(p) { 4127 case none: 4128 MessageBay.errorMessage(errorMessage); 4129 return; 4130 case homogeneous: 4131 if (!homogeneousEncryptionLabel.equals(label)) { 4132 MessageBay.errorMessage(errorMessage); 4133 return; 4134 } 4135 break; 4136 case hetrogeneous_owner: 4137 if (!homogeneousEncryptionLabel.equals(label) && !hetrogeneousFrameOwnerLabels.contains(label)) { 4138 MessageBay.errorMessage(errorMessage); 4139 return; 4140 } 4141 break; 4142 case hetrogeneous: break; 4143 } 4144 4145 this.getSurrogates().clear(); 4146 this._encryptionLabel = label; 4147 4115 4148 //Setup surrogate items. 4149 generateSurrogate(labelResult); 4150 } 4151 4152 public void setEncryptionLabelOnLoad(String label) { 4153 this._encryptionLabel = label; 4154 } 4155 4156 /** 4157 * Replaces the given dot item with a text item displaying the given character. 4158 * 4159 * @param dot 4160 * The Dot item to replace. 4161 * 4162 * @param ch 4163 * The character to display as the text for the created Text item. 4164 * 4165 * @return 4166 * The created Text item. 4167 */ 4168 public static Text replaceDot(Item dot, char ch) { 4169 // TODO: Should this make sure 'dot' is actually a Dot and not some other item? cts16 4170 Text text = Text.createText(ch); 4171 Item.DuplicateItem(dot, text); 4172 FrameUtils.setLastEdited(text); 4173 4174 // Copy the lines list so it can be modified 4175 List<Line> lines = new LinkedList<Line>(dot.getLines()); 4176 for (Line line : lines) 4177 line.replaceLineEnd(dot, text); 4178 Frame current = dot.getParentOrCurrentFrame(); 4179 current.removeItem(dot); 4180 ItemUtils.EnclosedCheck(current.getSortedItems()); 4181 return text; 4182 // TODO: Should this add the newly-created Text item to the frame? cts16 4183 } 4184 4185 /** 4186 * Replaces the given text item with a dot 4187 */ 4188 public static Item replaceText(Item text) { 4189 Item dot = new Dot(text.getX(), text.getY(), text.getID()); 4190 Item.DuplicateItem(text, dot); 4191 4192 List<Line> lines = new LinkedList<Line>(); 4193 lines.addAll(text.getLines()); 4194 if (lines.size() > 0) 4195 dot.setColor(lines.get(0).getColor()); 4196 for (Line line : lines) { 4197 line.replaceLineEnd(text, dot); 4198 } 4199 text.delete(); 4200 Frame current = text.getParentOrCurrentFrame(); 4201 current.addItem(dot); 4202 DisplayController.setCursor(Item.DEFAULT_CURSOR); 4203 ItemUtils.EnclosedCheck(current.getSortedItems()); 4204 return dot; 4205 } 4206 4207 public Set<Item> getSurrogates() { 4208 return surrogateItems; 4209 } 4210 4211 private void setAsSurrogateFor(Item primary) { 4212 this.surrogateFor = primary; 4213 } 4214 4215 public void addToSurrogates(Item surrogate) { 4216 if (this.getEncryptionLabel() == null) { 4217 MessageBay.displayMessage("Only Items with encryption labels can have surrogates."); 4218 return; 4219 } 4220 4221 this.getParent().removeItem(surrogate); 4222 this.surrogateItems.add(surrogate); 4223 surrogate.setAsSurrogateFor(this); 4224 this.getParent().addItem(surrogate); 4225 4226 EncryptionDetail reencryptOnSave = new EncryptionDetail(EncryptionDetail.Type.ReencryptOnSave); 4227 EncryptionDetail unencryptedOnSave = new EncryptionDetail(EncryptionDetail.Type.UnencryptedOnSave); 4228 4229 for (Character tag: DefaultFrameWriter.getItemCharTags().keySet()) { 4230 if (tag == 'T') { 4231 primaryPropertyEncryption.put(tag + "", reencryptOnSave.clone()); 4232 } else { 4233 primaryPropertyEncryption.put(tag + "", unencryptedOnSave.clone()); 4234 } 4235 4236 if (tag == 'T' || tag == 'S') { 4237 surrogate.surrogatePropertyInheritance.put(tag + "", false); 4238 } else { 4239 surrogate.surrogatePropertyInheritance.put(tag + "", true); 4240 } 4241 } 4242 4243 for (String tag: DefaultFrameWriter.getItemStrTags().keySet()) { 4244 primaryPropertyEncryption.put(tag, unencryptedOnSave.clone()); 4245 surrogate.surrogatePropertyInheritance.put(tag + "", true); 4246 } 4247 } 4248 4249 public boolean isSurrogate() { 4250 return this.surrogateFor != null; 4251 } 4252 4253 public Item getPrimary() { 4254 return this.surrogateFor; 4255 } 4256 4257 public EncryptionDetail getEncryptionDetailForTag(String tag) { 4258 EncryptionDetail encryptionDetail = primaryPropertyEncryption.get(tag); 4259 4260 if (encryptionDetail == null) { 4261 EncryptionDetail unencryptedOnSave = new EncryptionDetail(EncryptionDetail.Type.UnencryptedOnSave); 4262 return unencryptedOnSave; 4263 } else { 4264 return encryptionDetail; 4265 } 4266 } 4267 4268 public void setEncryptionDetailForTag(String tag, EncryptionDetail encryptionDetail) { 4269 primaryPropertyEncryption.put(tag, encryptionDetail); 4270 } 4271 4272 public boolean isTagInherited(String tag) { 4273 return surrogatePropertyInheritance.get(tag); 4274 } 4275 4276 public void setTagNotInherited(String tag) { 4277 surrogatePropertyInheritance.put(tag, false); 4278 } 4279 4280 public boolean hasAccessToItemAsPrimary() { 4281 String label = this.getEncryptionLabel(); 4282 if (this.isSurrogate() || label == null || label.length() == 0) { 4283 return true; 4284 } 4285 4286 return Label.getLabel(label).is(LabelResult.SuccessResolveLabelToKey); 4287 } 4288 4289 4290 /** 4291 * If when setting a property, we find that the primary has a undeciphered value, when we must continue using that undeciphered value 4292 * when eventually saving. 4293 * @return 4294 */ 4295 protected boolean subjectToInheritanceCheckOnSave(String tag) { 4296 if (tag.equals(DefaultFrameWriter.TYPE_AND_ID_STR)) { 4297 return false; 4298 } 4299 Item primary = getPrimary(); 4300 if (primary == null) return false; 4301 EncryptionDetail primaryItemTagEncryptionDetail = primary.primaryPropertyEncryption.get(tag); 4302 Type primaryItemTagEncryptionDetailType = primaryItemTagEncryptionDetail.getEncryptionDetailType(); 4303 return primaryItemTagEncryptionDetailType != EncryptionDetail.Type.UseUndecipheredValueOnSave; 4304 } 4305 4306 public boolean acceptsKeyboardEnter() { 4307 return _acceptsKeyboardEnter; 4308 } 4309 4310 public void setAcceptsEnter(boolean value) { 4311 if (this.getText() != null && this.getText().equals("Beep")) { 4312 System.err.println(); 4313 } 4314 _acceptsKeyboardEnter = value; 4315 } 4316 4317 private void generateSurrogate(LabelInfo labelResult) { 4116 4318 Item copy = this.copy(); 4117 4319 if (copy.isAnnotation()) { … … 4155 4357 this.addToSurrogates(copy); 4156 4358 } 4157 4158 public void setEncryptionLabelOnLoad(String label) {4159 this._encryptionLabel = label;4160 }4161 4162 /**4163 * Replaces the given dot item with a text item displaying the given character.4164 *4165 * @param dot4166 * The Dot item to replace.4167 *4168 * @param ch4169 * The character to display as the text for the created Text item.4170 *4171 * @return4172 * The created Text item.4173 */4174 public static Text replaceDot(Item dot, char ch) {4175 // TODO: Should this make sure 'dot' is actually a Dot and not some other item? cts164176 Text text = Text.createText(ch);4177 Item.DuplicateItem(dot, text);4178 FrameUtils.setLastEdited(text);4179 4180 // Copy the lines list so it can be modified4181 List<Line> lines = new LinkedList<Line>(dot.getLines());4182 for (Line line : lines)4183 line.replaceLineEnd(dot, text);4184 Frame current = dot.getParentOrCurrentFrame();4185 current.removeItem(dot);4186 ItemUtils.EnclosedCheck(current.getSortedItems());4187 return text;4188 // TODO: Should this add the newly-created Text item to the frame? cts164189 }4190 4191 /**4192 * Replaces the given text item with a dot4193 */4194 public static Item replaceText(Item text) {4195 Item dot = new Dot(text.getX(), text.getY(), text.getID());4196 Item.DuplicateItem(text, dot);4197 4198 List<Line> lines = new LinkedList<Line>();4199 lines.addAll(text.getLines());4200 if (lines.size() > 0)4201 dot.setColor(lines.get(0).getColor());4202 for (Line line : lines) {4203 line.replaceLineEnd(text, dot);4204 }4205 text.delete();4206 Frame current = text.getParentOrCurrentFrame();4207 current.addItem(dot);4208 DisplayController.setCursor(Item.DEFAULT_CURSOR);4209 ItemUtils.EnclosedCheck(current.getSortedItems());4210 return dot;4211 }4212 4213 public Set<Item> getSurrogates() {4214 return surrogateItems;4215 }4216 4217 private void setAsSurrogateFor(Item primary) {4218 this.surrogateFor = primary;4219 }4220 4221 public void addToSurrogates(Item surrogate) {4222 if (this.getEncryptionLabel() == null) {4223 MessageBay.displayMessage("Only Items with encryption labels can have surrogates.");4224 return;4225 }4226 4227 this.getParent().removeItem(surrogate);4228 this.surrogateItems.add(surrogate);4229 surrogate.setAsSurrogateFor(this);4230 this.getParent().addItem(surrogate);4231 4232 EncryptionDetail reencryptOnSave = new EncryptionDetail(EncryptionDetail.Type.ReencryptOnSave);4233 EncryptionDetail unencryptedOnSave = new EncryptionDetail(EncryptionDetail.Type.UnencryptedOnSave);4234 4235 for (Character tag: DefaultFrameWriter.getItemCharTags().keySet()) {4236 if (tag == 'T') {4237 primaryPropertyEncryption.put(tag + "", reencryptOnSave.clone());4238 } else {4239 primaryPropertyEncryption.put(tag + "", unencryptedOnSave.clone());4240 }4241 4242 if (tag == 'T' || tag == 'S') {4243 surrogate.surrogatePropertyInheritance.put(tag + "", false);4244 } else {4245 surrogate.surrogatePropertyInheritance.put(tag + "", true);4246 }4247 }4248 4249 for (String tag: DefaultFrameWriter.getItemStrTags().keySet()) {4250 primaryPropertyEncryption.put(tag, unencryptedOnSave.clone());4251 surrogate.surrogatePropertyInheritance.put(tag + "", true);4252 }4253 }4254 4255 public boolean isSurrogate() {4256 return this.surrogateFor != null;4257 }4258 4259 public Item getPrimary() {4260 return this.surrogateFor;4261 }4262 4263 public EncryptionDetail getEncryptionDetailForTag(String tag) {4264 EncryptionDetail encryptionDetail = primaryPropertyEncryption.get(tag);4265 4266 if (encryptionDetail == null) {4267 EncryptionDetail unencryptedOnSave = new EncryptionDetail(EncryptionDetail.Type.UnencryptedOnSave);4268 return unencryptedOnSave;4269 } else {4270 return encryptionDetail;4271 }4272 }4273 4274 public void setEncryptionDetailForTag(String tag, EncryptionDetail encryptionDetail) {4275 primaryPropertyEncryption.put(tag, encryptionDetail);4276 }4277 4278 public boolean isTagInherited(String tag) {4279 return surrogatePropertyInheritance.get(tag);4280 }4281 4282 public void setTagNotInherited(String tag) {4283 surrogatePropertyInheritance.put(tag, false);4284 }4285 4286 public boolean hasAccessToItemAsPrimary() {4287 String label = this.getEncryptionLabel();4288 if (this.isSurrogate() || label == null || label.length() == 0) {4289 return true;4290 }4291 4292 return Label.getLabel(label).is(LabelResult.SuccessResolveLabelToKey);4293 }4294 4295 4296 /**4297 * If when setting a property, we find that the primary has a undeciphered value, when we must continue using that undeciphered value4298 * when eventually saving.4299 * @return4300 */4301 protected boolean subjectToInheritanceCheckOnSave(String tag) {4302 if (tag.equals(DefaultFrameWriter.TYPE_AND_ID_STR)) {4303 return false;4304 }4305 Item primary = getPrimary();4306 if (primary == null) return false;4307 EncryptionDetail primaryItemTagEncryptionDetail = primary.primaryPropertyEncryption.get(tag);4308 Type primaryItemTagEncryptionDetailType = primaryItemTagEncryptionDetail.getEncryptionDetailType();4309 return primaryItemTagEncryptionDetailType != EncryptionDetail.Type.UseUndecipheredValueOnSave;4310 }4311 4312 public boolean acceptsKeyboardEnter() {4313 return _acceptsKeyboardEnter;4314 }4315 4316 public void setAcceptsEnter(boolean value) {4317 if (this.getText() != null && this.getText().equals("Beep")) {4318 System.err.println();4319 }4320 _acceptsKeyboardEnter = value;4321 }4322 4359 }
Note:
See TracChangeset
for help on using the changeset viewer.