source: trunk/src/org/expeditee/agents/ComputeTree.java@ 1415

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

Renamed Frame.getItems() to Frame.getSortedItems() to better represent its functionality.

-> org.apollo.ApolloGestureActions
-> org.apollo.ApolloSystem
-> org.expeditee.actions.Actions
-> org.expeditee.actions.Debug
-> org.expeditee.actions.ExploratorySearchActions
-> org.expeditee.actions.JfxBrowserActions
-> org.expeditee.actions.Misc
-> org.expeditee.actions.Navigation
-> org.expeditee.actions.ScriptBase
-> org.expeditee.actions.Simple
-> org.expeditee.agents.ComputeTree
-> org.expeditee.agents.CopyTree
-> org.expeditee.agents.DisplayComet
-> org.expeditee.agents.DisplayTree
-> org.expeditee.agents.DisplayTreeLeaves
-> org.expeditee.agents.GraphFramesetLinks
-> org.expeditee.agents.TreeProcessor
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gui.DisplayController
-> org.expeditee.gui.FrameCreator
-> org.expeditee.gui.FrameIO
-> org.expeditee.io.DefaultTreeWriter
-> org.expeditee.io.JavaWriter
-> org.expeditee.io.PDF2Writer
-> org.expeditee.io.TXTWriter
-> org.expeditee.io.WebParser
-> org.expeditee.io.flowlayout.XGroupItem
-> org.expeditee.items.Dot
-> org.expeditee.items.Item
-> org.expeditee.items.ItemUtils
-> org.expeditee.network.FrameShare
-> org.expeditee.stats.TreeStats


Created ItemsList class to wrap ArrayList<Item>. Frames now use this new class to store its body list (used for display) as well as its primaryBody and surrogateBody.

-> org.expeditee.agents.Format
-> org.expeditee.agents.HFormat
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gui.Frame
-> org.expeditee.gui.FrameUtils


Refactorted Frame.setResort(bool) to Frame.invalidateSorted() to better function how it is intended to with a more accurate name.

-> org.expeditee.agents.Sort


When writing out .exp files and getting attributes to respond to LEFT + RIGHT click, boolean items are by default true. This has always been the case. An ammendment to this is that defaults can now be established.
Also added 'EnterClick' functionality. If cursored over a item with this property and you press enter, it acts as if you have clicked on it instead.

-> org.expeditee.assets.resources-public.framesets.authentication.1.exp to 6.exp
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gio.input.KBMInputEvent
-> org.expeditee.gio.javafx.JavaFXConversions
-> org.expeditee.gio.swing.SwingConversions
-> org.expeditee.gui.AttributeUtils
-> org.expeditee.io.Conversion
-> org.expeditee.io.DefaultFrameWriter
-> org.expeditee.items.Item


Fixed a bug caused by calling Math.abs on Integer.MIN_VALUE returning unexpected result. Due to zero being a thing, you cannot represent Math.abs(Integer.MIN_VALUE) in a Integer object. The solution is to use Integer.MIN_VALUE + 1 instead of Integer.MIN_VALUE.

-> org.expeditee.core.bounds.CombinationBounds
-> org.expeditee.io.flowlayout.DimensionExtent


Recoded the contains function in EllipticalBounds so that intersection tests containing circles work correctly.

-> org.expeditee.core.bounds.EllipticalBounds


Added toString() to PolygonBounds to allow for useful printing during debugging.

-> org.expeditee.core.bounds.PolygonBounds

Implemented Surrogate Mode!

-> org.expeditee.encryption.io.EncryptedExpReader
-> org.expeditee.encryption.io.EncryptedExpWriter
-> org.expeditee.encryption.items.surrogates.EncryptionDetail
-> org.expeditee.encryption.items.surrogates.Label
-> org.expeditee.gui.FrameUtils
-> org.expeditee.gui.ItemsList
-> org.expeditee.items.Item
-> org.expeditee.items.Text


???? Use Integer.MAX_VALUE cast to a float instead of Float.MAX_VALUE. This fixed some bug which I cannot remember.

-> org.expeditee.gio.TextLayoutManager
-> org.expeditee.gio.swing.SwingTextLayoutManager


Improved solution for dealing with the F10 key taking focus away from Expeditee due to it being a assessibility key.

-> org.expeditee.gio.swing.SwingInputManager


Renamed variable visibleItems in FrameGraphics.paintFrame to itemsToPaintCanditates to better represent functional intent.

-> org.expeditee.gui.FrameGraphics


Improved checking for if personal resources exist before recreating them

-> org.expeditee.gui.FrameIO


Repeated messages to message bay now have a visual feedback instead of just a beep. This visual feedback is in the form of a count of the amount of times it has repeated.

-> org.expeditee.gui.MessageBay


Updated comment on the Vector class to explain what vectors are.

-> org.expeditee.gui.Vector


Added constants to represent all of the property keys in DefaultFrameReader and DefaultFrameWriter.

-> org.expeditee.io.DefaultFrameReader
-> org.expeditee.io.DefaultFrameWriter


Updated the KeyList setting to be more heirarcial with how users will store their Secrets.

-> org.expeditee.settings.identity.secrets.KeyList

File size: 4.5 KB
Line 
1/**
2 * ComputeTree.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.agents;
20
21import java.text.NumberFormat;
22
23import org.expeditee.gui.AttributeUtils;
24import org.expeditee.gui.AttributeValuePair;
25import org.expeditee.gui.Frame;
26import org.expeditee.gui.FrameIO;
27import org.expeditee.items.Item;
28import org.expeditee.items.Text;
29
30public class ComputeTree extends DefaultAgent {
31
32 private static final String COMPUTE_TAG = "@compute:";
33
34 private static final NumberFormat _format = NumberFormat.getInstance();
35
36 private static final String DECIMAL_PLACES_TAG = "@dp:";
37
38 @Override
39 protected Frame process(Frame frame) {
40 _format.setMinimumFractionDigits(0);
41 if (computeFrame(frame) == null && !_stop) {
42 message("Nothing to compute!");
43 }
44
45 return null;
46 }
47
48 /**
49 * Computes the value of a frame.
50 *
51 * @param frame
52 * @return the value of the frame or null if the frame does not have the
53 * compute tag or any values to compute;
54 */
55 private Double computeFrame(Frame frame) {
56 // Search for @Compute frame tag
57 String computeTag = null;
58
59 //TODO can speed this up by using frame.hasAnnotations
60 for (Item i : frame.getSortedItems()) {
61 if (_stop)
62 return null;
63 if (i.isAnnotation()) {
64 String s = ((Text) i).getFirstLine().toLowerCase().trim();
65 if (s.startsWith(COMPUTE_TAG)) {
66 computeTag = s.substring(COMPUTE_TAG.length()).trim();
67 // break;
68 } else if (s.startsWith(DECIMAL_PLACES_TAG)) {
69 try {
70 String[] values = s.substring(
71 DECIMAL_PLACES_TAG.length()).trim().split(
72 "\\s+");
73 int min = 0;
74 int max = 0;
75 if (values.length == 1) {
76 min = Integer.parseInt(values[0]);
77 max = min;
78 } else if (values.length == 2) {
79 min = Integer.parseInt(values[0]);
80 max = Integer.parseInt(values[1]);
81 }
82 _format.setMinimumFractionDigits(min);
83 _format.setMaximumFractionDigits(max);
84 } catch (Exception e) {
85 }
86 }
87 }
88 }
89
90 // Check that the compute tag exists
91 if (computeTag == null)
92 computeTag = "+";
93
94 // check for text versions of the operators
95 if (computeTag.length() > 1) {
96 if (computeTag.equalsIgnoreCase("add"))
97 computeTag = "+";
98 else if (computeTag.equalsIgnoreCase("subtract"))
99 computeTag = "-";
100 else if (computeTag.equalsIgnoreCase("multiply"))
101 computeTag = "*";
102 else if (computeTag.equalsIgnoreCase("divide"))
103 computeTag = "/";
104 }
105 char operator = computeTag.charAt(computeTag.length() - 1);
106 // double defaultValue = (operator == '*' ? 1.0 : 0.0);
107 Double result = null;
108 // Iterate through all valid items on the frame performing the correct
109 // operation
110 for (Item i : frame.getBodyTextItems(false)) {
111 if (_stop)
112 return null;
113 Double value = null;
114 // Process the frame that each item is linked to
115 if (i.getLink() != null) {
116 value = computeFrame(FrameIO.LoadFrame(i.getAbsoluteLink()));
117 // Set the items text
118 if (value != null)
119 AttributeUtils
120 .replaceValue((Text) i, _format.format(value));
121 }
122
123 if (value == null) {
124 try {
125 value = new AttributeValuePair(i.getText())
126 .getDoubleValue();
127 } catch (NumberFormatException e) {
128 continue;
129 }
130 }
131
132 if(value.equals(Double.NaN))
133 continue;
134
135 if (value != null) {
136 _itemCount++;
137
138 // the first time we find an item init result
139 if (result == null) {
140 result = value;
141 } else {
142 switch (operator) {
143 case '*':
144 result *= value;
145 break;
146 case '+':
147 result += value;
148 break;
149 case '-':
150 result -= value;
151 break;
152 case '/':
153 result /= value;
154 break;
155 }
156 }
157 }
158 }
159
160 if (result != null) {
161 AttributeUtils.replaceValue(frame.getTitleItem(), _format
162 .format(result));
163 }
164 _frameCount++;
165 FrameIO.ForceSaveFrame(frame);
166
167 return result;
168 }
169}
Note: See TracBrowser for help on using the repository browser.