source: trunk/src/org/expeditee/settings/identity/secrets/KeyList.java@ 1431

Last change on this file since 1431 was 1431, checked in by bln4, 5 years ago

Recoding of the Labels class to improve surrogate mode functionality. Surrogate mode is now maintained when you navigate from one frame to another, even if that frame has a different set of labels. Completely different sets of labels cause Expeditee to exit surrogate mode with a message to the user.

File size: 2.3 KB
Line 
1package org.expeditee.settings.identity.secrets;
2
3import java.util.Arrays;
4import java.util.List;
5import java.util.function.Predicate;
6import java.util.stream.Collectors;
7import java.util.stream.Stream;
8
9import org.expeditee.gui.Frame;
10import org.expeditee.items.Text;
11import org.expeditee.setting.ArraySetting;
12import org.expeditee.setting.TextSetting;
13
14public class KeyList {
15
16 public static final TextSetting PersonalKey = new TextSetting("The AES key used to secure your profile frame - do not share with anyone!", "PersonalKey") {
17 @Override
18 public Text generateText() {
19 Text t = new Text("PersonalKey");
20 return t;
21 }
22 };
23
24 public static final TextSetting PrivateKey = new TextSetting("The RSA key used to decrypt things encrypted with your RSA public key - do not share with anyone!", "PrivateKey") {
25 @Override
26 public Text generateText() {
27 Text t = new Text("PrivateKey");
28 return t;
29 }
30 };
31
32 public static final ArraySetting<Text> UserLabels = new ArraySetting<Text>("The labels (and their associated keys) that you have either created or recieved.",
33 "UserLabels", new Text[] { }) {
34
35 @Override
36 public boolean setSetting(Text text) {
37 Frame child = text.getChild();
38 if (child == null) {
39 return false;
40 }
41
42 Predicate<Text> hasNoData = t -> {
43 List<String> data = t.getData();
44 return data == null || data.isEmpty();
45 };
46 List<Text> textItems = child.getBodyTextItems(false);
47 textItems.removeIf(hasNoData);
48 _value = textItems.toArray(new Text[] {});
49
50 return true;
51 }
52
53 @Override
54 public Text generateRepresentation(String label, String frameset) {
55 Text t = new Text(label);
56
57 createChildFrame(frameset, t, "My Labels");
58
59 return t;
60 }
61 };
62
63 public static List<String> getLabelsNameOnly() {
64 Text[] allLabels = UserLabels.get();
65 Stream<String> allLabelsNames = Arrays.asList(allLabels).stream().map(label -> label.getText());
66 return allLabelsNames.collect(Collectors.toList());
67 }
68
69 public static Text getByName(String labelName) {
70 Text[] allLabels = UserLabels.get();
71 for (Text label: allLabels) {
72 if (label.getText().equals(labelName)) {
73 return label;
74 }
75 }
76
77 return null;
78 }
79}
Note: See TracBrowser for help on using the repository browser.